CircleOS  1
lcd.c
Go to the documentation of this file.
1 /****************** COPYRIGHT (C) 2007-2013 KEOLABS S.A.S. ********************/
12 /******************************************************************************/
13 
14 /* Includes ------------------------------------------------------------------*/
15 #include "circle.h"
16 #if DMA2D_AVAIL
17 #include "DMA2D_Graphic.h"
18 #endif
19 
21 
22 /* Private define ------------------------------------------------------------*/
23 //~ #define BACKLIGHT_DIVIDER 500 /*!< LCD handler step. */
24 
25 /* Private variables ---------------------------------------------------------*/
26 //~ divider_t HandlerDivider = 0;
27 static coord_t CharFilter_XMin = 0; /* Restricted area when painting characters */
28 static coord_t CharFilter_XMax = APP_SCREEN_WIDTH; /* Restricted area when painting characters */
29 static coord_t CharFilter_YMin = 0; /* Restricted area when painting characters */
30 static coord_t CharFilter_YMax = APP_SCREEN_HEIGHT; /* Restricted area when painting characters */
31 
32 
33 /* External variable ---------------------------------------------------------*/
34 
35 /* Public variables ---------------------------------------------------------*/
36 coord_t Screen_Width;
37 coord_t Screen_Height;
38 ENUM_Offset LCD_Offset;
39 u8 Char_Width = 7;
40 u8 Char_Height = 14;
41 u8 Menu_Font = 0;
42 u8 DeltaY;
43 u8 Transparency;
44 
45 const u8* CurrentFont;
46 tFontDef* CurrentFontDef = ( tFontDef* )& Font_Table.fonts[0];
47 color_t bmpTmp[LCD_DMA_SIZE]; /* 16 bits words : buffer to scroll display */
48 
49 /* Private function prototypes -----------------------------------------------*/
50 
51 /* Private functions ---------------------------------------------------------*/
52 
53 /*******************************************************************************
54 *
55 * LCD_DrawCharSetFilter
56 *
57 *******************************************************************************/
67 /******************************************************************************/
68 void LCD_DrawCharSetFilter( coord_t xmin, coord_t xmax, coord_t ymin, coord_t ymax )
69 {
70  CharFilter_XMin = xmin;
71  CharFilter_XMax = xmax;
72  CharFilter_YMin = ymin;
73  CharFilter_YMax = ymax;
74 }
75 
76 
77 /*******************************************************************************
78 *
79 * LCD_DrawChar
80 *
81 *******************************************************************************/
96 /******************************************************************************/
97 void LCD_DrawChar( coord_t x, coord_t y, coord_t width, const u8* bmp, color_t textColor, color_t bGndColor, mag_t charMagniCoeff )
98 {
99  coord_t i;
100  coord_t i0 = 0;
101  coord_t i1 = Char_Width;
102  counter_t j;
103  mag_t k1;
104  mag_t k2;
105  coord_t lin0;
106  coord_t lin1;
107  coord_t x0 = MAX( x, CharFilter_XMin );
108  coord_t y0 = MAX( y, CharFilter_YMin );
109  static coord_t width0;
110  static coord_t height0;
111  u8 j2;
112 
113  UNREFERENCED_PARAMETER( width );
114 
115  width0 = MIN( Char_Width * charMagniCoeff, CharFilter_XMax - x0 );
116  height0 = MIN( Char_Height * charMagniCoeff, CharFilter_YMax - y0 );
117 
118  if ( y0 > y )
119  height0 -= ( y0 - y );
120 
121  if ( x0 > x )
122  width0 -= ( x0 - x );
123 
124  if ( ( width0 <= 0 ) || ( height0 <= 0 ) )
125  return;
126 
127  i0 = ( x0 - x ) / charMagniCoeff;
128  i1 = width0 / charMagniCoeff;
129  lin0 = ( y0 - y ) ;
130  lin1 = height0 + lin0;
131 
132  for ( i = i0; i < i1; i++ )
133  {
134  // Save the column pixels if transparency is on
135  if ( Transparency && ( charMagniCoeff < 4 ) )
136  LCD_RectRead( x0 + ( charMagniCoeff * i ), y0, charMagniCoeff, height0, ( u8* ) &bmpTmp );
137 
138  /* Select the area for LCD output.*/
139 #if DMA2D_AVAIL //Fill Vertically first
140  if ( DMALCD_ModeLCDAccess == LCD_Only )
141 #endif
142  LCD_SetRect_For_Cmd( x0 + ( charMagniCoeff * i ), y0, charMagniCoeff, height0 );
143 
144 
145  /* Select LCD output mode.*/
146  LCD_SendLCDCmd_RAM_Access();
147 
148  // Duplicate the column, horizontally
149  for ( k1 = 0; k1 < charMagniCoeff; k1++ )
150  {
151 
152 #if DMA2D_AVAIL //Fill horizontally first
153  if ( DMALCD_ModeLCDAccess != LCD_Only )
154  LCD_SetRect_For_Cmd( x0 + ( charMagniCoeff * i ) + k1, y0, 1, height0 );
155 #endif
156 
157  coord_t n = 0;
158  j2 = 0;
159  for ( j = 0x80; j; j >>= 1 , j2++ ) // For all 8 bits
160  {
161  // Duplicate the pixel vertically
162  for ( k2 = 0; k2 < charMagniCoeff; k2++ , n++ )
163  {
164  if ( ( n < lin0 ) || ( n >= lin1 ) )
165  continue;
166 
167  if ( ( Transparency == 0 ) || ( charMagniCoeff > 3 ) )
168  {
169  LCD_SendPixelData( ( bmp[2 * i] & j ) ? ( textColor ) : ( bGndColor ) );
170  }
171  else
172  {
173  if ( ( bmp[2 * i] & j ) )
174  {
175  LCD_SendPixelData( textColor );
176  }
177  else
178  {
179  LCD_SendPixelData( bmpTmp[height0 * k1 + n] );
180  }
181  }
182  }
183  }
184 
185  for ( j = 0x80; j > ( 16 - Char_Height ); j >>= 1 , j2++ ) // 8
186  {
187  // Duplicate the pixel vertically
188  for ( k2 = 0; k2 < charMagniCoeff; k2++ , n++ )
189  {
190  if ( ( n < lin0 ) || ( n >= lin1 ) )
191  continue;
192 
193  if ( ( Transparency == 0 ) || ( charMagniCoeff > 3 ) )
194  {
195  LCD_SendPixelData( ( bmp[2 * i + 1] & j ) ? ( textColor ) : ( bGndColor ) );
196  }
197  else
198  {
199  if ( ( bmp[2 * i + 1] & j ) )
200  {
201  LCD_SendPixelData( textColor );
202  }
203  else
204  {
205  LCD_SendPixelData( bmpTmp[height0 * k1 + n] );
206  }
207  }
208  }
209  }
210  }
211  /* End of select screen area to access.*/
212  LCD_SendLCDCmd_RAM_Access_End();
213  }
214 
215 }
216 
217 
218 /* Public functions for CircleOS ---------------------------------------------*/
219 
220 
221 /*******************************************************************************
222 *
223 * LCD_Handler
224 *
225 *******************************************************************************/
233 /******************************************************************************/
234 void LCD_Handler( void )
235 {
236 
237 #if BACKLIGHT_INTERFACE
238  //~ if ( ++HandlerDivider % BACKLIGHT_DIVIDER ) // YRT130718 divider is now managed by scheduler
239  //~ {
240  //~ return;
241  //~ }
242 
243  LCD_BackLightChange();
244 #endif // BACKLIGHT_INTERFACE
245 }
246 
247 
248 /*******************************************************************************
249 *
250 * LCD_FillRect_Circle
251 *
252 *******************************************************************************/
268 /******************************************************************************/
269 void LCD_FillRect_Circle( coord_t x, coord_t y, coord_t width, coord_t height, color_t color )
270 {
271  coord_t Line;
272  coord_t Column;
273 
274  /* Select LCD screen area. */
275  LCD_SetRect_For_Cmd( x, y, width, height );
276 
277  /* Send LCD RAM write command. */
278  LCD_SendLCDCmd_RAM_Access();
279 
280  /* Fill selected LCD screen area with provided color. */
281  for ( Line = width; Line > 0; --Line )
282  {
283  for ( Column = height; Column > 0; Column-- )
284  {
285  LCD_SendPixelData( color );
286  }
287  }
288 
289  /* End of select screen area to access.*/
290  LCD_SendLCDCmd_RAM_Access_End();
291 }
292 
293 /*******************************************************************************
294 *
295 * LCD_ClearAllScreen
296 *
297 *******************************************************************************/
307 /******************************************************************************/
308 NODEBUG2 void LCD_ClearAllScreen( color_t color )
309 {
310  // Backup orientation
312 
313  // Clear the application and toolbar screen
315  LCD_FillRect_Circle( 0, 0, PHYS_SCREEN_WIDTH, PHYS_SCREEN_HEIGHT, color );
316 
317  // Restore orientation
318  LCD_SetScreenOrientation( backupOrientation );
319 }
320 
322 
323 /* Public functions ----------------------------------------------------------*/
324 
325 
326 /*******************************************************************************
327 *
328 * LCD_FillRect
329 *
330 *******************************************************************************/
344 /******************************************************************************/
345 void LCD_FillRect( coord_t x, coord_t y, coord_t width, coord_t height, color_t color )
346 {
347 
348  /* Rq : this fuction is just a wrapper with parameter limit checks*/
349 
350  if ( ( LCD_GetScreenOrientation() % 2 ) == 1 )
351  {
352  if ( x > Screen_Height )
353  x = Screen_Height;
354  if ( ( x + width ) > Screen_Height )
355  width = Screen_Height - x;
356 
357  /* Check the y parameters*/
358  if ( y > Screen_Width )
359  y = Screen_Width;
360  if ( ( y + height ) > Screen_Width )
361  height = Screen_Width - y;
362  }
363  else
364  {
365  /* Check the x parameters*/
366  if ( x > Screen_Width )
367  x = Screen_Width;
368  if ( ( x + width ) > Screen_Width )
369  width = Screen_Width - x;
370 
371  /* Check the y parameters*/
372  if ( y > Screen_Height )
373  y = Screen_Height;
374  if ( ( y + height ) > Screen_Height )
375  height = Screen_Height - y;
376  }
377 
378 
379  /* Call the native function*/
380  LCD_FillRect_Circle( x, y, width, height, color );
381 }
382 
383 /*******************************************************************************
384 *
385 * LCD_DrawRect
386 *
387 *******************************************************************************/
401 /******************************************************************************/
402 void LCD_DrawRect( coord_t x, coord_t y, coord_t width, coord_t height, color_t color )
403 {
404  /* Draw horizontal sides.*/
405  LCD_FillRect( x, y, width, 1, color );
406  LCD_FillRect( x, y + height - 1, width, 1, color );
407 
408  /* Draw vertical sides.*/
409  LCD_FillRect( x, y, 1, height, color );
410  LCD_FillRect( x + width - 1, y, 1, height, color );
411 }
412 
413 
414 /*******************************************************************************
415 *
416 * LCD_DisplayChar
417 *
418 *******************************************************************************/
435 /******************************************************************************/
436 void LCD_DisplayChar( coord_t x, coord_t y, u8 ascii, color_t textColor, color_t bGndColor, mag_t charMagCoeff )
437 {
438  /* Display the selected bitmap according to the provided ASCII character.*/
439  if ( ( ascii >= CurrentFontDef->ASCII_start ) && ( ascii <= CurrentFontDef->ASCII_end ) )
440  LCD_DrawChar( x, y, Char_Width, ( u8* )&CurrentFont[( ascii - CurrentFontDef->ASCII_start ) * ( 2 * Char_Width )], textColor, bGndColor, charMagCoeff );
441 }
442 
443 #if BACKLIGHT_INTERFACE
444 /*******************************************************************************
445 *
446 * LCD_SetBackLight
447 *
448 *******************************************************************************/
457 /******************************************************************************/
458 void LCD_SetBackLight( backlight_t newBacklightStart )
459 {
460  if ( newBacklightStart >= BACKLIGHTMIN )
461  {
462  Current_CCR_BackLightStart = newBacklightStart;
463  }
464  else
465  {
466  Current_CCR_BackLightStart = DEFAULT_CCR_BACKLIGHTSTART;
467  }
468 }
469 
470 /*******************************************************************************
471 *
472 * LCD_SetBackLightOff
473 *
474 *******************************************************************************/
480 /******************************************************************************/
482 {
483  Current_CCR_BackLightStart = 0;
484 }
485 
486 /*******************************************************************************
487 *
488 * LCD_SetBackLightOn
489 *
490 *******************************************************************************/
496 /******************************************************************************/
497 void LCD_SetBackLightOn( void )
498 {
499  Current_CCR_BackLightStart = DEFAULT_CCR_BACKLIGHTSTART;
500 }
501 
502 /*******************************************************************************
503 *
504 * LCD_GetBackLight
505 *
506 *******************************************************************************/
514 /******************************************************************************/
515 backlight_t LCD_GetBackLight( void )
516 {
517  return Current_CCR_BackLightStart;
518 }
519 
520 #endif // BACKLIGHT_INTERFACE
521 
522 /*******************************************************************************
523 *
524 * LCD_SetRotateScreen
525 *
526 *******************************************************************************/
535 /******************************************************************************/
536 void LCD_SetRotateScreen( bool RotateScreen )
537 {
538  CurrentRotateScreen = RotateScreen;
539 }
540 
541 /*******************************************************************************
542 *
543 * LCD_GetRotateScreen
544 *
545 *******************************************************************************/
554 /******************************************************************************/
556 {
557  return CurrentRotateScreen;
558 }
559 
560 /*******************************************************************************
561 *
562 * LCD_SetScreenOrientation
563 *
564 *******************************************************************************/
572 /******************************************************************************/
574 {
575 #if DMA2D_AVAIL
576  DMA2D_ScreenRotate( CurrentScreenOrientation, ScreenOrientation );
577  TOOLBAR_RedrawToolbar( TOOLBAR_REDRAW );
578 #endif
579  CurrentScreenOrientation = ScreenOrientation;
580  LCD_DisplayRotate( CurrentScreenOrientation );
581 #if TOUCHSCREEN_AVAIL
582  TOOLBAR_RedrawToolbar( TOOLBAR_REDRAW );
583 #endif
584 }
585 
586 /*******************************************************************************
587 *
588 * LCD_GetScreenOrientation
589 *
590 *******************************************************************************/
598 /******************************************************************************/
600 {
601  return CurrentScreenOrientation;
602 }
603 
604 /*******************************************************************************
605 *
606 * LCD_SetFont
607 *
608 *******************************************************************************/
615 /******************************************************************************/
616 void LCD_SetFont( const u8* NewFont )
617 {
618  CurrentFont = NewFont;
619 }
620 
621 /*******************************************************************************
622 *
623 * LCD_SetFontDef
624 *
625 *******************************************************************************/
632 /******************************************************************************/
633 void LCD_SetFontDef( tFontDef* FontDef )
634 {
635  if ( FontDef )
636  {
637  CurrentFontDef = FontDef;
638  Char_Width = CurrentFontDef->width;
639  Char_Height = CurrentFontDef->height;
640  DRAW_SetCharMagniCoeff( CurrentFontDef->FontCoeff );
641  //Set DeltaY to prevent scrolling bugs (if odd height or magnification coefficient > 1 )
642  DeltaY = ( ( ( Char_Height % 2 == 0 ) || ( DRAW_GetCharMagniCoeff() == 2 ) ) ? 2 : 1 );
643 
644  }
645 }
646 
647 /*******************************************************************************
648 *
649 * LCD_GetFontDef
650 *
651 *******************************************************************************/
658 /******************************************************************************/
660 {
661  return CurrentFontDef;
662 }
663 
664 /*******************************************************************************
665 *
666 * LCD_SetDefaultFont
667 *
668 *******************************************************************************/
674 /******************************************************************************/
675 void LCD_SetDefaultFont( void )
676 {
677  LCD_ChangeFont( 0 );
678 }
679 
680 /*******************************************************************************
681 *
682 * LCD_ChangeFont
683 *
684 *******************************************************************************/
691 /******************************************************************************/
693 {
694  if ( ID < Font_Table.nb )
695  {
696  CurrentFontDef = ( tFontDef* ) &Font_Table.fonts[ID];
697  Char_Width = CurrentFontDef->width;
698  Char_Height = CurrentFontDef->height;
699  CurrentFont = CurrentFontDef->font;
700  DRAW_SetCharMagniCoeff( CurrentFontDef->FontCoeff );
701  //Set DeltaY to prevent scrolling bugs (if odd height or magnification coefficient > 1 )
702  DeltaY = ( ( ( Char_Height % 2 == 0 ) || ( DRAW_GetCharMagniCoeff() == 2 ) ) ? 2 : 1 );
703  }
704 }
705 
706 /*******************************************************************************
707 *
708 * LCD_SetOffset
709 *
710 *******************************************************************************/
720 /******************************************************************************/
722 {
723 
724  if ( Offset == OFFSET_ON )
725  {
726  LCD_FillRect( 0, 0, Offset, APP_SCREEN_HEIGHT, RGB_WHITE );
727  LCD_FillRect( 0, 0, APP_SCREEN_WIDTH, Offset, RGB_WHITE );
728  LCD_FillRect( 0, APP_SCREEN_HEIGHT - Offset, APP_SCREEN_WIDTH, Offset, RGB_WHITE );
729  LCD_FillRect( APP_SCREEN_WIDTH - Offset, 0, Offset, APP_SCREEN_HEIGHT, RGB_WHITE );
730  }
731 
732  LCD_Offset = Offset;
733 
734  Screen_Width = APP_SCREEN_WIDTH - ( 2 * LCD_Offset );
735  Screen_Height = APP_SCREEN_HEIGHT - ( 2 * LCD_Offset );
736 
737  POINTER_Info.xPos = ( Screen_Width / 2 ) - ( POINTER_WIDTH / 2 ) - 1;
738  POINTER_Info.yPos = ( Screen_Width / 2 ) - ( POINTER_WIDTH / 2 ) - 1;
739  POINTER_Info.shift_PosX = 0;
740  POINTER_Info.shift_PosY = 0;
741 
742  PosCurY = Screen_Height - Char_Height;
743  RightMarginX = Screen_Width;
744  HighMarginY = Screen_Height;
745 
746  LCD_DrawCharSetFilter( 0, Screen_Width, 0, Screen_Height );
747 
748 }
749 
750 /*******************************************************************************
751 *
752 * LCD_GetScreenWidth
753 *
754 *******************************************************************************/
762 /******************************************************************************/
763 coord_t LCD_GetScreenWidth( void )
764 {
765  return Screen_Width;
766 }
767 
768 /*******************************************************************************
769 *
770 * LCD_GetScreenHeight
771 *
772 *******************************************************************************/
780 /******************************************************************************/
781 coord_t LCD_GetScreenHeight( void )
782 {
783  return Screen_Height;
784 }
785 
786 /*******************************************************************************
787 *
788 * LCD_SetTransparency
789 *
790 *******************************************************************************/
798 /******************************************************************************/
799 void LCD_SetTransparency( u8 NewTransparency )
800 {
801  Transparency = NewTransparency;
802 }
803 
804 /*******************************************************************************
805 *
806 * LCD_GetTransparency
807 *
808 *******************************************************************************/
816 /******************************************************************************/
818 {
819  return Transparency;
820 }