00001
00010
00011
00012
00013 #include "circle.h"
00014
00015
00017
00018
00019
00020
00021 u16 LCDStatus = 0;
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00043
00044 void LCD_Init( void )
00045 {
00046 Screen_Width = APP_SCREEN_WIDTH;
00047 Screen_Height = APP_SCREEN_HEIGHT;
00048
00049
00050
00051 Delayms( 10 );
00052
00053
00054 LCD_Interface_Init();
00055
00056 LCD_Reset();
00057
00058 LCD_Controller_init();
00059
00060 LCD_SetOffset( OFFSET_OFF );
00061 LCD_SetDefaultFont();
00062 LCD_SetTransparency( 0 );
00063
00064 LCD_ClearAllScreen( RGB_WHITE );
00065
00066
00067 #if BACKLIGHT_INTERFACE
00068 LCD_SetBackLight( UTIL_ReadBackupRegister( BKP_BKLIGHT ) );
00069 #endif
00070 LCD_BackLightConfig();
00071
00072 LCDStatus = LCD_CheckLCDStatus();
00073 }
00074
00075
00076
00077
00078
00079
00084
00085 void LCD_Controller_init( void )
00086 {
00087
00088 LCD_Write_Reg( ILI9325_TIMING_CTRL_1, 0x3008 );
00089 LCD_Write_Reg( ILI9325_TIMING_CTRL_2, 0x0012 );
00090 LCD_Write_Reg( ILI9325_TIMING_CTRL_3, 0x1231 );
00091
00092 LCD_Write_Reg( ILI9325_START_OSC, 0x0001 );
00093 Delayms( 50 );
00094
00095 LCD_Write_Reg( ILI9325_DRV_OUTPUT_CTRL_1, 0x0100 );
00096 LCD_Write_Reg( ILI9325_LCD_DRV_CTRL, 0x0700 );
00097
00098 LCD_Write_Reg( ILI9325_ENTRY_MOD, V12_MADCTRVAL );
00099
00100
00101 LCD_Write_Reg( ILI9325_RESIZE_CTRL, 0x0000 );
00102 LCD_Write_Reg( ILI9325_DIS_CTRL_2, 0x0202 );
00103 LCD_Write_Reg( ILI9325_DIS_CTRL_3, 0x0000 );
00104 LCD_Write_Reg( ILI9325_DIS_CTRL_4, 0x0000 );
00105 LCD_Write_Reg( ILI9325_RGB_CTRL_1, 0x0000 );
00106
00107 LCD_Write_Reg( ILI9325_FRAME_MARKER_POS, 0x0000 );
00108 LCD_Write_Reg( ILI9325_RGB_CTRL_2, 0x0000 );
00109
00110
00111 LCD_Power_ON();
00112
00113
00114 LCD_Gamma_Adjust();
00115
00116
00117 LCD_Write_Reg( ILI9325_HOR_ADDR_START, 0x0000 );
00118 LCD_Write_Reg( ILI9325_HOR_ADDR_END, 0x00EF );
00119 LCD_Write_Reg( ILI9325_VET_ADDR_START, 0x0000 );
00120 LCD_Write_Reg( ILI9325_VET_ADDR_END, 0x013F );
00121
00122 LCD_Write_Reg( ILI9325_DRV_OUTPUT_CTRL_2, 0xA700 );
00123
00124 LCD_Write_Reg( ILI9325_BASE_IMG_CTRL, 0x0001 );
00125 LCD_Write_Reg( ILI9325_VSCROLL_CTRL, 0x0000 );
00126
00127
00128 LCD_Write_Reg( ILI9325_PAR_IMG1_POS, 0 );
00129 LCD_Write_Reg( ILI9325_PAR_IMG1_START, 0 );
00130 LCD_Write_Reg( ILI9325_PAR_IMG1_END, 0 );
00131 LCD_Write_Reg( ILI9325_PAR_IMG2_POS, 0 );
00132 LCD_Write_Reg( ILI9325_PAR_IMG2_START, 0 );
00133 LCD_Write_Reg( ILI9325_PAR_IMG2_END, 0 );
00134
00135
00136 LCD_Write_Reg( ILI9325_PAN_CTRL_1, 0x0010 );
00137 LCD_Write_Reg( ILI9325_PAN_CTRL_2, 0x0000 );
00138 LCD_Write_Reg( ILI9325_PAN_CTRL_3, 0x0003 );
00139 LCD_Write_Reg( ILI9325_PAN_CTRL_4, 0x0110 );
00140 LCD_Write_Reg( ILI9325_PAN_CTRL_5, 0x0000 );
00141 LCD_Write_Reg( ILI9325_PAN_CTRL_6, 0x0000 );
00142
00143
00144 LCD_Write_Reg( ILI9325_DIS_CTRL_1, 0x0133 );
00145
00146 LCD_Write_Reg( 0xE4, 0x1430 );
00147
00148
00149 LCD_Write_Reg( ILI9325_GRAM_HADDR, 0x0000 );
00150 LCD_Write_Reg( ILI9325_GRAM_VADDR, 0x0000 );
00151
00152
00153 }
00154
00155
00156
00157
00158
00159
00164
00165 void LCD_Power_ON( void )
00166 {
00167
00168 LCD_Write_Reg( ILI9325_POW_CTRL_1, 0x0000 );
00169 LCD_Write_Reg( ILI9325_POW_CTRL_2, 0x0007 );
00170 LCD_Write_Reg( ILI9325_POW_CTRL_3, 0x0000 );
00171 LCD_Write_Reg( ILI9325_POW_CTRL_4, 0x0000 );
00172 Delayms( 200 );
00173
00174 LCD_Write_Reg( ILI9325_POW_CTRL_1, 0x1690 );
00175
00176 LCD_Write_Reg( ILI9325_POW_CTRL_2, 0x0221 );
00177 Delayms( 50 );
00178
00179 LCD_Write_Reg( ILI9325_POW_CTRL_3, 0x0018 );
00180 Delayms( 50 );
00181
00182 LCD_Write_Reg( ILI9325_POW_CTRL_4, 0x1800 );
00183 LCD_Write_Reg( ILI9325_POW_CTRL_7, 0x002A );
00184 LCD_Write_Reg( ILI9325_FRM_RATE_COLOR, 0x000B );
00185 Delayms( 50 );
00186
00187 return;
00188 }
00189
00190
00191
00192
00193
00194
00199
00200 void LCD_Gamma_Adjust( void )
00201 {
00202 LCD_Write_Reg( ILI9325_GAMMA_CTRL_1, 0x0004 );
00203 LCD_Write_Reg( ILI9325_GAMMA_CTRL_2, 0x0007 );
00204 LCD_Write_Reg( ILI9325_GAMMA_CTRL_3, 0x0006 );
00205 LCD_Write_Reg( ILI9325_GAMMA_CTRL_4, 0x0206 );
00206 LCD_Write_Reg( ILI9325_GAMMA_CTRL_5, 0x0408 );
00207 LCD_Write_Reg( ILI9325_GAMMA_CTRL_6, 0x0507 );
00208 LCD_Write_Reg( ILI9325_GAMMA_CTRL_7, 0x0200 );
00209 LCD_Write_Reg( ILI9325_GAMMA_CTRL_8, 0x0707 );
00210 LCD_Write_Reg( ILI9325_GAMMA_CTRL_9, 0x0504 );
00211 LCD_Write_Reg( ILI9325_GAMMA_CTRL_10, 0x0F02 );
00212 return;
00213 }
00214
00215
00216
00217
00218
00219
00220
00225
00226 u16 LCD_CheckLCDStatus( void )
00227 {
00228
00229 u16 IDcode = LCD_Read_Reg( ILI9325_DRV_CODE );
00230 return IDcode;
00231 }
00232
00233
00234
00235
00236
00237
00238
00243
00244 void LCD_Batt( coord_t xBat, coord_t yBat, bool fDisplayTime, u16 BatState,
00245 u16* OldBatState, divider_t _div, coord_t* widthBat, coord_t* heightBat )
00246 {
00247 color_t bat_color;
00248 static counter_t last_time = 0;
00249 counter_t new_time = RTC_GetCounter();
00250 u8 fill;
00251 bool fBlink;
00252
00253 UNREFERENCED_PARAMETER( BatState );
00254 UNREFERENCED_PARAMETER( OldBatState );
00255 UNREFERENCED_PARAMETER( _div );
00256
00257 if ( ( fDisplayTime == 1 ) && ( last_time != new_time ) )
00258 {
00259 last_time = new_time;
00260 switch ( PWR_CurrentState )
00261 {
00262 case PWR_STATE_UNDEF:
00263 return;
00264
00265 case PWR_STATE_NOBAT:
00266 bat_color = RGB_PINK;
00267 fill = 100;
00268 fBlink = TRUE;
00269 break;
00270
00271 case PWR_STATE_CHARGING:
00272 bat_color = RGB_BLUE;
00273 fill = 50;
00274 fBlink = TRUE;
00275 break;
00276
00277 case PWR_STATE_FULL:
00278 bat_color = RGB_GREEN;
00279 fill = 100;
00280 fBlink = FALSE;
00281 break;
00282
00283 case PWR_STATE_NORMAL:
00284 bat_color = RGB_BLACK;
00285 fBlink = FALSE;
00286 fill = PWR_BatteryLevel;
00287 break;
00288
00289 case PWR_STATE_LOW:
00290 bat_color = RGB_YELLOW;
00291 fBlink = TRUE;
00292 fill = PWR_BatteryLevel;
00293 break;
00294
00295 case PWR_STATE_EMPTY:
00296 bat_color = RGB_RED;
00297 fill = 100;
00298 fBlink = TRUE;
00299 break;
00300 }
00301
00302 *widthBat = ( 20 * fill ) / 100;
00303
00304 if ( *widthBat > 20 )
00305 {
00306 *widthBat = 20;
00307 }
00308
00309 if ( fBlink && ( new_time & 1 ) )
00310 {
00311 LCD_FillRect_Circle( ( xBat + 22 ) - *widthBat , yBat + 2 , *widthBat , *heightBat , ( PWR_CurrentState == PWR_STATE_LOW ) ? bat_color : RGB_WHITE );
00312 LCD_FillRect_Circle( xBat + 2 , yBat + 2 , 20 - *widthBat , *heightBat , ( PWR_CurrentState == PWR_STATE_LOW ) ? bat_color : RGB_WHITE );
00313 }
00314 else
00315 {
00316 LCD_FillRect_Circle( ( xBat + 22 ) - *widthBat , yBat + 2 , *widthBat , *heightBat , ( PWR_CurrentState == PWR_STATE_LOW ) ? RGB_WHITE : bat_color );
00317 LCD_FillRect_Circle( xBat + 2 , yBat + 2 , 20 - *widthBat , *heightBat , ( PWR_CurrentState == PWR_STATE_LOW ) ? RGB_RED : RGB_WHITE );
00318 }
00319 }
00320 }
00321
00322
00323
00324
00325
00326
00331
00332 void LCD_Clear( u16 xBat, u16 yBat )
00333 {
00334 UNREFERENCED_PARAMETER( xBat );
00335 UNREFERENCED_PARAMETER( yBat );
00336
00337 #if TOUCHSCREEN_AVAIL
00338 if ( TOUCHSCR_GetMode() != TS_CALIBRATION )
00339 {
00340 TOUCHSCR_SetMode( TS_DRAWING );
00341 }
00342 #endif
00343
00344 DRAW_Batt();
00345
00346 #if TOUCHSCREEN_AVAIL
00347 TOOLBAR_SetDefaultToolbar();
00348 #endif
00349 }
00350
00351
00352
00353
00354
00355
00362
00363 void LCD_DisplayRotate( Rotate_H12_V_Match_TypeDef H12 )
00364 {
00365
00366
00367 LCD_SendLCDCmd_Rotation_Access();
00368
00369
00370 switch ( H12 )
00371 {
00372 case V3 :
00373 LCD_SendLCDData16( V3_MADCTRVAL >> 8, V3_MADCTRVAL & 0xFF );
00374
00375 break;
00376
00377 case V6 :
00378 LCD_SendLCDData16( V6_MADCTRVAL >> 8, V6_MADCTRVAL & 0xFF );
00379
00380 break;
00381
00382 case V9 :
00383 LCD_SendLCDData16( V9_MADCTRVAL >> 8, V9_MADCTRVAL & 0xFF );
00384
00385 break;
00386
00387 case V12 :
00388 default :
00389 LCD_SendLCDData16( V12_MADCTRVAL >> 8, V12_MADCTRVAL & 0xFF );
00390 break;
00391
00392 case V12BMP :
00393 LCD_SendLCDData16( V12BMP_MADCTRVAL >> 8, V12BMP_MADCTRVAL & 0xFF );
00394
00395 break;
00396
00397 case V3BMP :
00398 LCD_SendLCDData16( V3BMP_MADCTRVAL >> 8, V3BMP_MADCTRVAL & 0xFF );
00399
00400 break;
00401
00402 case V6BMP :
00403 LCD_SendLCDData16( V6BMP_MADCTRVAL >> 8, V6BMP_MADCTRVAL & 0xFF );
00404
00405 break;
00406
00407 case V9BMP :
00408 LCD_SendLCDData16( V9BMP_MADCTRVAL >> 8, V9BMP_MADCTRVAL & 0xFF );
00409 break;
00410 }
00411 }
00412
00414
00415
00416
00417
00418
00419
00420
00421
00436
00437 void LCD_RectRead( coord_t x, coord_t y, coord_t width, coord_t height, u8* bmp )
00438 {
00439 u32 line, col;
00440 u16 col0, line0;
00441
00442
00443 switch ( CurrentScreenOrientation )
00444 {
00445 case V12:
00446
00447 col0 = Screen_Width - x - 1 + LCD_Offset;
00448 line0 = y + LCD_Offset;
00449 for ( col = 0; col < width; col++ )
00450 {
00451
00452 LCD_Write_Reg( ILI9325_GRAM_HADDR, col0 - col );
00453
00454 for ( line = 0; line < height; line++ )
00455 {
00456
00457 LCD_Write_Reg( ILI9325_GRAM_VADDR, line0 + line );
00458
00459
00460 LCD_PixelRead( &bmp );
00461 }
00462 }
00463 break;
00464
00465 case V3:
00466
00467 col0 = y + LCD_Offset;
00468 line0 = x + LCD_Offset;
00469 for ( line = 0; line < width; line++ )
00470 {
00471
00472 LCD_Write_Reg( ILI9325_GRAM_VADDR, line0 + line );
00473
00474 for ( col = 0; col < height; col++ )
00475 {
00476
00477 LCD_Write_Reg( ILI9325_GRAM_HADDR, col0 + col );
00478
00479
00480 LCD_PixelRead( &bmp );
00481 }
00482 }
00483 break;
00484
00485 case V6:
00486
00487 col0 = x + LCD_Offset;
00488 line0 = Screen_Height - y - 1 + LCD_Offset;
00489 for ( col = 0; col < width; col++ )
00490 {
00491
00492 LCD_Write_Reg( ILI9325_GRAM_HADDR, col0 + col );
00493
00494 for ( line = 0; line < height; line++ )
00495 {
00496
00497 LCD_Write_Reg( ILI9325_GRAM_VADDR, line0 - line );
00498
00499
00500 LCD_PixelRead( &bmp );
00501 }
00502 }
00503 break;
00504
00505 case V9:
00506
00507 col0 = Screen_Width - y - 1 + LCD_Offset;
00508 line0 = Screen_Height - x - 1 + LCD_Offset;
00509 for ( line = 0; line < width; line++ )
00510 {
00511
00512 LCD_Write_Reg( ILI9325_GRAM_VADDR, line0 - line );
00513
00514 for ( col = 0; col < height; col++ )
00515 {
00516
00517 LCD_Write_Reg( ILI9325_GRAM_HADDR, col0 - col );
00518
00519
00520 LCD_PixelRead( &bmp );
00521 }
00522 }
00523 break;
00524
00525 }
00526 }
00527
00528
00529
00530
00531
00532
00545
00546 u16 LCD_GetPixel( coord_t x, coord_t y )
00547 {
00548 u16 val;
00549 u8 pixel[2];
00550
00551 LCD_RectRead( x, y, 1, 1, &pixel[0] );
00552 val = ( pixel[1] << 8 ) | pixel[0];
00553 return val;
00554 }
00555
00556
00557
00558
00559
00560
00573
00574 void LCD_SetRect_For_Cmd( coord_t x, coord_t y, coord_t width, coord_t height )
00575 {
00576
00577
00578 switch ( CurrentScreenOrientation % 4 )
00579 {
00580 case V12:
00581
00582 LCD_Write_Reg( ILI9325_HOR_ADDR_START, Screen_Width - x - width + LCD_Offset );
00583
00584
00585 LCD_Write_Reg( ILI9325_HOR_ADDR_END, Screen_Width - x - 1 + LCD_Offset );
00586
00587
00588 LCD_Write_Reg( ILI9325_VET_ADDR_START, y + LCD_Offset ) ;
00589
00590
00591 LCD_Write_Reg( ILI9325_VET_ADDR_END, y + height - 1 + LCD_Offset );
00592
00593
00594 LCD_Write_Reg( ILI9325_GRAM_HADDR, Screen_Width - x - 1 + LCD_Offset );
00595
00596
00597 LCD_Write_Reg( ILI9325_GRAM_VADDR, y + LCD_Offset );
00598 break;
00599
00600 case V3:
00601
00602 LCD_Write_Reg( ILI9325_HOR_ADDR_START, y + LCD_Offset );
00603
00604
00605 LCD_Write_Reg( ILI9325_HOR_ADDR_END, y + height - 1 + LCD_Offset );
00606
00607
00608 LCD_Write_Reg( ILI9325_VET_ADDR_START, x + LCD_Offset ) ;
00609
00610
00611 LCD_Write_Reg( ILI9325_VET_ADDR_END, x + width - 1 + LCD_Offset );
00612
00613
00614 LCD_Write_Reg( ILI9325_GRAM_HADDR, y + LCD_Offset );
00615
00616
00617 LCD_Write_Reg( ILI9325_GRAM_VADDR, x + LCD_Offset );
00618 break;
00619
00620 case V6:
00621
00622 LCD_Write_Reg( ILI9325_HOR_ADDR_START, x + LCD_Offset );
00623
00624
00625 LCD_Write_Reg( ILI9325_HOR_ADDR_END, x + width - 1 + LCD_Offset );
00626
00627
00628 LCD_Write_Reg( ILI9325_VET_ADDR_START, Screen_Height - y - height + LCD_Offset ) ;
00629
00630
00631 LCD_Write_Reg( ILI9325_VET_ADDR_END, Screen_Height - y - 1 + LCD_Offset );
00632
00633
00634 LCD_Write_Reg( ILI9325_GRAM_HADDR, x + LCD_Offset );
00635
00636
00637 LCD_Write_Reg( ILI9325_GRAM_VADDR, Screen_Height - y - 1 + LCD_Offset );
00638 break;
00639
00640 case V9:
00641
00642 LCD_Write_Reg( ILI9325_HOR_ADDR_START, Screen_Width - y - height + LCD_Offset );
00643
00644
00645 LCD_Write_Reg( ILI9325_HOR_ADDR_END, Screen_Width - y - 1 + LCD_Offset );
00646
00647
00648 LCD_Write_Reg( ILI9325_VET_ADDR_START, Screen_Height - x - width + LCD_Offset ) ;
00649
00650
00651 LCD_Write_Reg( ILI9325_VET_ADDR_END, Screen_Height - x - 1 + LCD_Offset );
00652
00653
00654 LCD_Write_Reg( ILI9325_GRAM_HADDR, Screen_Width - y - 1 + LCD_Offset );
00655
00656
00657 LCD_Write_Reg( ILI9325_GRAM_VADDR, Screen_Height - x - 1 + LCD_Offset );
00658 break;
00659 }
00660 }
00661
00662
00663
00664
00665
00666
00678
00679 void LCD_FullScreen( bool FullScreenONOFF )
00680 {
00681
00682 if ( FullScreenONOFF != 0 )
00683 {
00684
00685 #if TOUCHSCREEN_AVAIL
00686 UTIL_SetSchHandler( TOOLBAR_SCHHDL_ID, 0 );
00687 #endif
00688
00689
00690 LCD_SetRotateScreen( 0 );
00691 LCD_SetOffset( OFFSET_OFF );
00692 Screen_Width = PHYS_SCREEN_WIDTH;
00693 Screen_Height = PHYS_SCREEN_HEIGHT;
00694
00695
00696 if ( ( LCD_GetScreenOrientation() % 2 ) == 1 )
00697 {
00698 PosCurY = PHYS_SCREEN_WIDTH - Char_Height;
00699 RightMarginX = PHYS_SCREEN_HEIGHT;
00700 HighMarginY = PHYS_SCREEN_WIDTH;
00701 LCD_DrawCharSetFilter( 0, PHYS_SCREEN_HEIGHT, 0, PHYS_SCREEN_WIDTH );
00702 POINTER_SetRect( 0, 0, PHYS_SCREEN_HEIGHT - CurrentPointerWidth, PHYS_SCREEN_WIDTH - CurrentPointerHeight );
00703 }
00704 else
00705 {
00706 PosCurY = PHYS_SCREEN_HEIGHT - Char_Height;
00707 RightMarginX = PHYS_SCREEN_WIDTH;
00708 HighMarginY = PHYS_SCREEN_HEIGHT;
00709 LCD_DrawCharSetFilter( 0, PHYS_SCREEN_WIDTH, 0, PHYS_SCREEN_HEIGHT );
00710 POINTER_SetRect( 0, 0, PHYS_SCREEN_WIDTH - CurrentPointerWidth, PHYS_SCREEN_HEIGHT - CurrentPointerHeight );
00711 }
00712 }
00713 else
00714 {
00715
00716
00717 #if TOUCHSCREEN_AVAIL
00718 UTIL_SetSchHandler( TOOLBAR_SCHHDL_ID, TOOLBAR_Handler );
00719 #endif
00720
00721
00722 LCD_SetRotateScreen( 1 );
00723
00724
00725 LCD_SetOffset( OFFSET_ON );
00726 LCD_DrawCharSetFilter( 0, APP_SCREEN_WIDTH, 0, APP_SCREEN_HEIGHT );
00727 POINTER_SetRectScreen();
00728 }
00729
00730 }
00731
00732
00733
00734
00735
00736
00746
00747 void LCD_SendPixelData( color_t color )
00748 {
00749 LCD_SendLCDData( color & 0xFF );
00750 LCD_SendLCDData( color >> 8 );
00751 }