00001
00012
00013
00014
00015 #include "circle.h"
00016
00018
00019
00020 #define BACKLIGHT_DIVIDER 500
00022
00023 divider_t HandlerDivider = 0;
00024 static coord_t CharFilter_XMin = 0;
00025 static coord_t CharFilter_XMax = APP_SCREEN_WIDTH;
00026 static coord_t CharFilter_YMin = 0;
00027 static coord_t CharFilter_YMax = APP_SCREEN_HEIGHT;
00028
00029
00030
00031
00032
00033 coord_t Screen_Width;
00034 coord_t Screen_Height;
00035 ENUM_Offset LCD_Offset;
00036 u8 Char_Width = 7;
00037 u8 Char_Height = 14;
00038 u8 Menu_Font = 0;
00039 u8 DeltaY;
00040 u8 Transparency;
00041
00042 const u8* CurrentFont;
00043 tFontDef* CurrentFontDef = ( tFontDef* )& Font_Table.fonts[0];
00044 color_t bmpTmp[LCD_DMA_SIZE];
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00064
00065 void LCD_DrawCharSetFilter( coord_t xmin, coord_t xmax, coord_t ymin, coord_t ymax )
00066 {
00067 CharFilter_XMin = xmin;
00068 CharFilter_XMax = xmax;
00069 CharFilter_YMin = ymin;
00070 CharFilter_YMax = ymax;
00071 }
00072
00073
00074
00075
00076
00077
00078
00093
00094 void LCD_DrawChar( coord_t x, coord_t y, coord_t width, const u8* bmp, color_t textColor, color_t bGndColor, mag_t charMagniCoeff )
00095 {
00096 coord_t i;
00097 coord_t i0 = 0;
00098 coord_t i1 = Char_Width;
00099 counter_t j;
00100 mag_t k1;
00101 mag_t k2;
00102 coord_t lin0;
00103 coord_t lin1;
00104 coord_t x0 = MAX( x, CharFilter_XMin );
00105 coord_t y0 = MAX( y, CharFilter_YMin );
00106 static coord_t width0;
00107 static coord_t height0;
00108 u8 j2;
00109
00110 UNREFERENCED_PARAMETER( width );
00111
00112 width0 = MIN( Char_Width * charMagniCoeff, CharFilter_XMax - x0 );
00113 height0 = MIN( Char_Height * charMagniCoeff, CharFilter_YMax - y0 );
00114
00115 if ( y0 > y )
00116 height0 -= ( y0 - y );
00117
00118 if ( x0 > x )
00119 width0 -= ( x0 - x );
00120
00121 if ( ( width0 <= 0 ) || ( height0 <= 0 ) )
00122 return;
00123
00124 i0 = ( x0 - x ) / charMagniCoeff;
00125 i1 = width0 / charMagniCoeff;
00126 lin0 = ( y0 - y ) ;
00127 lin1 = height0 + lin0;
00128
00129 for ( i = i0; i < i1; i++ )
00130 {
00131
00132 if ( Transparency && ( charMagniCoeff < 4 ) )
00133 LCD_RectRead( x0 + ( charMagniCoeff * i ), y0, charMagniCoeff, height0, ( u8* ) &bmpTmp );
00134
00135
00136 LCD_SetRect_For_Cmd( x0 + ( charMagniCoeff * i ), y0, charMagniCoeff, height0 );
00137
00138
00139 LCD_SendLCDCmd_RAM_Access();
00140
00141
00142 for ( k1 = 0; k1 < charMagniCoeff; k1++ )
00143 {
00144 coord_t n = 0;
00145 j2 = 0;
00146 for ( j = 0x80; j; j >>= 1 , j2++ )
00147 {
00148
00149 for ( k2 = 0; k2 < charMagniCoeff; k2++ , n++ )
00150 {
00151 if ( ( n < lin0 ) || ( n >= lin1 ) )
00152 continue;
00153
00154 if ( ( Transparency == 0 ) || ( charMagniCoeff > 3 ) )
00155 {
00156 LCD_SendPixelData( ( bmp[2 * i] & j ) ? ( textColor ) : ( bGndColor ) );
00157 }
00158 else
00159 {
00160 if ( ( bmp[2 * i] & j ) )
00161 {
00162 LCD_SendPixelData( textColor );
00163 }
00164 else
00165 {
00166 LCD_SendPixelData( bmpTmp[height0 * k1 + n] );
00167 }
00168 }
00169 }
00170 }
00171
00172 for ( j = 0x80; j > ( 16 - Char_Height ); j >>= 1 , j2++ )
00173 {
00174
00175 for ( k2 = 0; k2 < charMagniCoeff; k2++ , n++ )
00176 {
00177 if ( ( n < lin0 ) || ( n >= lin1 ) )
00178 continue;
00179
00180 if ( ( Transparency == 0 ) || ( charMagniCoeff > 3 ) )
00181 {
00182 LCD_SendPixelData( ( bmp[2 * i + 1] & j ) ? ( textColor ) : ( bGndColor ) );
00183 }
00184 else
00185 {
00186 if ( ( bmp[2 * i + 1] & j ) )
00187 {
00188 LCD_SendPixelData( textColor );
00189 }
00190 else
00191 {
00192 LCD_SendPixelData( bmpTmp[height0 * k1 + n] );
00193 }
00194 }
00195 }
00196 }
00197 }
00198
00199 LCD_SendLCDCmd_RAM_Access_End();
00200 }
00201
00202 }
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00220
00221 void LCD_Handler( void )
00222 {
00223 #if BACKLIGHT_INTERFACE
00224 if ( ++HandlerDivider % BACKLIGHT_DIVIDER )
00225 {
00226 return;
00227 }
00228
00229 LCD_BackLightChange();
00230 #endif // BACKLIGHT_INTERFACE
00231 }
00232
00233
00234
00235
00236
00237
00238
00254
00255 void LCD_FillRect_Circle( coord_t x, coord_t y, coord_t width, coord_t height, color_t color )
00256 {
00257 coord_t Line;
00258 coord_t Column;
00259
00260
00261 LCD_SetRect_For_Cmd( x, y, width, height );
00262
00263
00264 LCD_SendLCDCmd_RAM_Access();
00265
00266
00267 for ( Line = width; Line > 0; --Line )
00268 {
00269 for ( Column = height; Column > 0; Column-- )
00270 {
00271 LCD_SendPixelData( color);
00272 }
00273 }
00274
00275
00276 LCD_SendLCDCmd_RAM_Access_End();
00277 }
00278
00279
00280
00281
00282
00283
00293
00294 NODEBUG2 void LCD_ClearAllScreen( color_t color )
00295 {
00296
00297 Rotate_H12_V_Match_TypeDef backupOrientation = LCD_GetScreenOrientation();
00298
00299
00300 LCD_SetScreenOrientation( V12 );
00301 LCD_FillRect_Circle( 0, 0, PHYS_SCREEN_WIDTH, PHYS_SCREEN_HEIGHT, color );
00302
00303
00304 LCD_SetScreenOrientation( backupOrientation );
00305 }
00306
00308
00309
00310
00311
00312
00313
00314
00315
00316
00330
00331 void LCD_FillRect( coord_t x, coord_t y, coord_t width, coord_t height, color_t color )
00332 {
00333
00334
00335
00336 if ( ( LCD_GetScreenOrientation() % 2 ) == 1 )
00337 {
00338 if ( x > Screen_Height )
00339 x = Screen_Height;
00340 if ( ( x + width ) > Screen_Height )
00341 width = Screen_Height - x;
00342
00343
00344 if ( y > Screen_Width )
00345 y = Screen_Width;
00346 if ( ( y + height ) > Screen_Width )
00347 height = Screen_Width - y;
00348 }
00349 else
00350 {
00351
00352 if ( x > Screen_Width )
00353 x = Screen_Width;
00354 if ( ( x + width ) > Screen_Width )
00355 width = Screen_Width - x;
00356
00357
00358 if ( y > Screen_Height )
00359 y = Screen_Height;
00360 if ( ( y + height ) > Screen_Height )
00361 height = Screen_Height - y;
00362 }
00363
00364
00365
00366 LCD_FillRect_Circle( x, y, width, height, color );
00367 }
00368
00369
00370
00371
00372
00373
00387
00388 void LCD_DrawRect( coord_t x, coord_t y, coord_t width, coord_t height, color_t color )
00389 {
00390
00391 LCD_FillRect( x, y, width, 1, color );
00392 LCD_FillRect( x, y + height - 1, width, 1, color );
00393
00394
00395 LCD_FillRect( x, y, 1, height, color );
00396 LCD_FillRect( x + width - 1, y, 1, height, color );
00397 }
00398
00399
00400
00401
00402
00403
00404
00421
00422 void LCD_DisplayChar( coord_t x, coord_t y, u8 ascii, color_t textColor, color_t bGndColor, mag_t charMagCoeff )
00423 {
00424
00425 if ( ( ascii >= CurrentFontDef->ASCII_start ) && ( ascii <= CurrentFontDef->ASCII_end ) )
00426 LCD_DrawChar( x, y, Char_Width, ( u8* )&CurrentFont[( ascii - CurrentFontDef->ASCII_start ) * ( 2 * Char_Width )], textColor, bGndColor, charMagCoeff );
00427 }
00428
00429 #if BACKLIGHT_INTERFACE
00430
00431
00432
00433
00434
00443
00444 void LCD_SetBackLight( backlight_t newBacklightStart )
00445 {
00446 if ( newBacklightStart >= BACKLIGHTMIN )
00447 {
00448 Current_CCR_BackLightStart = newBacklightStart;
00449 }
00450 else
00451 {
00452 Current_CCR_BackLightStart = DEFAULT_CCR_BACKLIGHTSTART;
00453 }
00454 }
00455
00456
00457
00458
00459
00460
00466
00467 void LCD_SetBackLightOff( void )
00468 {
00469 Current_CCR_BackLightStart = 0;
00470 }
00471
00472
00473
00474
00475
00476
00482
00483 void LCD_SetBackLightOn( void )
00484 {
00485 Current_CCR_BackLightStart = DEFAULT_CCR_BACKLIGHTSTART;
00486 }
00487
00488
00489
00490
00491
00492
00500
00501 backlight_t LCD_GetBackLight( void )
00502 {
00503 return Current_CCR_BackLightStart;
00504 }
00505
00506 #endif // BACKLIGHT_INTERFACE
00507
00508
00509
00510
00511
00512
00521
00522 void LCD_SetRotateScreen( bool RotateScreen )
00523 {
00524 CurrentRotateScreen = RotateScreen;
00525 }
00526
00527
00528
00529
00530
00531
00540
00541 bool LCD_GetRotateScreen( void )
00542 {
00543 return CurrentRotateScreen;
00544 }
00545
00546
00547
00548
00549
00550
00558
00559 void LCD_SetScreenOrientation( Rotate_H12_V_Match_TypeDef ScreenOrientation )
00560 {
00561 CurrentScreenOrientation = ScreenOrientation;
00562
00563 LCD_DisplayRotate( CurrentScreenOrientation );
00564 }
00565
00566
00567
00568
00569
00570
00578
00579 Rotate_H12_V_Match_TypeDef LCD_GetScreenOrientation( void )
00580 {
00581 return CurrentScreenOrientation;
00582 }
00583
00584
00585
00586
00587
00588
00595
00596 void LCD_SetFont( const u8* NewFont )
00597 {
00598 CurrentFont = NewFont;
00599 }
00600
00601
00602
00603
00604
00605
00612
00613 void LCD_SetFontDef( tFontDef* FontDef )
00614 {
00615 if ( FontDef )
00616 {
00617 CurrentFontDef = FontDef;
00618 Char_Width = CurrentFontDef->width;
00619 Char_Height = CurrentFontDef->height;
00620 DRAW_SetCharMagniCoeff( CurrentFontDef->FontCoeff );
00621
00622 DeltaY = ( ( ( Char_Height % 2 == 0 ) || ( DRAW_GetCharMagniCoeff() == 2 ) ) ? 2 : 1 );
00623
00624 }
00625 }
00626
00627
00628
00629
00630
00631
00638
00639 tFontDef* LCD_GetFontDef( void )
00640 {
00641 return CurrentFontDef;
00642 }
00643
00644
00645
00646
00647
00648
00654
00655 void LCD_SetDefaultFont( void )
00656 {
00657 LCD_ChangeFont( 0 );
00658 }
00659
00660
00661
00662
00663
00664
00671
00672 void LCD_ChangeFont( enum ENUM_FontID ID )
00673 {
00674 if ( ID < Font_Table.nb )
00675 {
00676 CurrentFontDef = ( tFontDef* ) &Font_Table.fonts[ID];
00677 Char_Width = CurrentFontDef->width;
00678 Char_Height = CurrentFontDef->height;
00679 CurrentFont = CurrentFontDef->font;
00680 DRAW_SetCharMagniCoeff( CurrentFontDef->FontCoeff );
00681
00682 DeltaY = ( ( ( Char_Height % 2 == 0 ) || ( DRAW_GetCharMagniCoeff() == 2 ) ) ? 2 : 1 );
00683 }
00684 }
00685
00686
00687
00688
00689
00690
00700
00701 void LCD_SetOffset( ENUM_Offset Offset )
00702 {
00703
00704 if ( Offset == OFFSET_ON )
00705 {
00706 LCD_FillRect( 0, 0, Offset, APP_SCREEN_HEIGHT, RGB_WHITE );
00707 LCD_FillRect( 0, 0, APP_SCREEN_WIDTH, Offset, RGB_WHITE );
00708 LCD_FillRect( 0, APP_SCREEN_HEIGHT - Offset, APP_SCREEN_WIDTH, Offset, RGB_WHITE );
00709 LCD_FillRect( APP_SCREEN_WIDTH - Offset, 0, Offset, APP_SCREEN_HEIGHT, RGB_WHITE );
00710 }
00711
00712 LCD_Offset = Offset;
00713
00714 Screen_Width = APP_SCREEN_WIDTH - ( 2 * LCD_Offset );
00715 Screen_Height = APP_SCREEN_HEIGHT - ( 2 * LCD_Offset );
00716
00717 POINTER_Info.xPos = ( Screen_Width / 2 ) - ( POINTER_WIDTH / 2 ) - 1;
00718 POINTER_Info.yPos = ( Screen_Width / 2 ) - ( POINTER_WIDTH / 2 ) - 1;
00719 POINTER_Info.shift_PosX = 0;
00720 POINTER_Info.shift_PosY = 0;
00721
00722 PosCurY = Screen_Height - Char_Height;
00723 RightMarginX = Screen_Width;
00724 HighMarginY = Screen_Height;
00725
00726 LCD_DrawCharSetFilter( 0, Screen_Width, 0, Screen_Height );
00727
00728 }
00729
00730
00731
00732
00733
00734
00742
00743 coord_t LCD_GetScreenWidth( void )
00744 {
00745 return Screen_Width;
00746 }
00747
00748
00749
00750
00751
00752
00760
00761 coord_t LCD_GetScreenHeight( void )
00762 {
00763 return Screen_Height;
00764 }
00765
00766
00767
00768
00769
00770
00778
00779 void LCD_SetTransparency( u8 NewTransparency )
00780 {
00781 Transparency = NewTransparency;
00782 }
00783
00784
00785
00786
00787
00788
00796
00797 u8 LCD_GetTransparency( void )
00798 {
00799 return Transparency;
00800 }