• Main Page
  • Related Pages
  • Data Structures
  • Files
  • File List
  • Globals

lcd_spe.c

Go to the documentation of this file.
00001 /****************** COPYRIGHT (C) 2007-2010 RAISONANCE S.A.S. *****************/
00010 /******************************************************************************/
00011 
00012 /* Includes ------------------------------------------------------------------*/
00013 #include "circle.h"
00014 
00015 
00017 
00018 /* Private define ------------------------------------------------------------*/
00019 
00020 /* Private variables ---------------------------------------------------------*/
00021 const u16 primerUpic[] =
00022 {
00023 #include "bmp\Open4_EvoPrimer_screen_180x174_RLE256.h"
00024 };
00025 
00026 /* Vars for timer dedicated for lcd backlight */
00027 static TIM_TimeBaseInitTypeDef      TIM_TimeBaseStructure;
00028 static TIM_OCInitTypeDef            TIM_OCInitStructure;
00029 
00030 /* Public variables ---------------------------------------------------------*/
00031 uint_t Current_CCR_BackLightStart = DEFAULT_CCR_BACKLIGHTSTART;
00032 const unsigned freqTIM2[ 6 ] = { 136, 136, 182, 273, 364,  546 } ;
00033 
00034 /* External variable ---------------------------------------------------------*/
00035 
00036 /* Private function prototypes -----------------------------------------------*/
00037 
00038 /* Private functions ---------------------------------------------------------*/
00039 
00040 
00041 /*******************************************************************************
00042 *
00043 *                                LCD_Interface_Init
00044 *
00045 *******************************************************************************/
00051 /******************************************************************************/
00052 void LCD_Interface_Init( void )
00053 {
00054     // YRT111004 : volatile declaration because in some case the compiler does not
00055     // configure the timing structure
00056     volatile FSMC_NORSRAMInitTypeDef  FSMC_NORSRAMInitStructure;    
00057     volatile FSMC_NORSRAMTimingInitTypeDef  p;
00058     GPIO_InitTypeDef GPIO_InitStructure;
00059 
00060     /*-- GPIO Configuration ------------------------------------------------------*/
00061 
00062     /* SRAM Data lines configuration */
00063     RCC_APB2PeriphClockCmd( GPIO_LCD_D1_PERIPH, ENABLE );
00064     RCC_APB2PeriphClockCmd( GPIO_LCD_D2_PERIPH, ENABLE );
00065 
00066     GPIO_InitStructure.GPIO_Pin =  LCD_D0 | LCD_D1 | LCD_D2 | LCD_D3 ;
00067     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
00068     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
00069     GPIO_Init( GPIOx_D1_LCD, &GPIO_InitStructure );
00070 
00071     GPIO_InitStructure.GPIO_Pin =  LCD_D4 | LCD_D5 | LCD_D6 | LCD_D7 ;
00072     GPIO_Init( GPIOx_D2_LCD, &GPIO_InitStructure );
00073 
00074     /* NOE, NWE and NE1 configuration */
00075     RCC_APB2PeriphClockCmd( GPIO_LCD_CTRL_PERIPH, ENABLE );
00076     GPIO_InitStructure.GPIO_Pin = CtrlPin_RD | CtrlPin_WR | CtrlPin_RS;
00077     GPIO_Init( GPIOx_CTRL_LCD, &GPIO_InitStructure );
00078 
00079     /* Reset : configured as regular GPIO, is not FSMC-controlled */
00080     RCC_APB2PeriphClockCmd( GPIO_LCD_RST_PERIPH, ENABLE );
00081     GPIO_InitStructure.GPIO_Pin = CtrlPin_RST;
00082     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
00083     GPIO_Init( GPIOx_RST_LCD, &GPIO_InitStructure );
00084 
00085     /* CS : configured as regular GPIO, is not FSMC-controlled */
00086     RCC_APB2PeriphClockCmd( GPIO_LCD_CS_PERIPH, ENABLE );
00087     GPIO_InitStructure.GPIO_Pin = CtrlPin_CS;
00088     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
00089     GPIO_Init( GPIOx_CS_LCD, &GPIO_InitStructure );
00090 
00091     GPIO_WriteBit( GPIOx_RST_LCD, CtrlPin_RST, Bit_SET );   /* Reset active at LOW */
00092     GPIO_WriteBit( GPIOx_CS_LCD, CtrlPin_CS, Bit_RESET );   /* CS active at LOW */
00093 
00094 
00095     /*-- FSMC Configuration ------------------------------------------------------*/
00096 
00097     /* Enable the FSMC Clock */
00098     RCC_AHBPeriphClockCmd( RCC_AHBPeriph_FSMC, ENABLE );
00099 
00100     p.FSMC_AddressSetupTime = 1;
00101     p.FSMC_AddressHoldTime = 0;
00102     p.FSMC_DataSetupTime = 2;
00103     p.FSMC_BusTurnAroundDuration = 0;
00104     p.FSMC_CLKDivision = 0;
00105     p.FSMC_DataLatency = 0;
00106     p.FSMC_AccessMode = FSMC_AccessMode_A;
00107 
00108     FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM3;
00109     FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;
00110     FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM;
00111     FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_8b;
00112     FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
00113     FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable;
00114     FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
00115     FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;
00116     FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
00117     FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;
00118     FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
00119     FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
00120     FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
00121     FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = (FSMC_NORSRAMTimingInitTypeDef*) &p;
00122     FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = (FSMC_NORSRAMTimingInitTypeDef*) &p;
00123     FSMC_NORSRAMInit( (FSMC_NORSRAMInitTypeDef*) &FSMC_NORSRAMInitStructure );    
00124 
00125     /* Enable FSMC Bank1_SRAM Bank */
00126     FSMC_NORSRAMCmd( FSMC_Bank1_NORSRAM3, ENABLE );
00127 }
00128 
00129 
00130 /*******************************************************************************
00131 *
00132 *                                LCD_BackLightConfig
00133 *
00134 *******************************************************************************/
00139 /******************************************************************************/
00140 void LCD_BackLightConfig( void )
00141 {
00142     GPIO_InitTypeDef GPIO_InitStructure;
00143 
00144     /* Enable GPIO clock  */
00145     RCC_APB2PeriphClockCmd( GPIO_LCD_BL_PERIPH, ENABLE );
00146 
00147     /* GPIO Configuration : TIM in Output */
00148     GPIO_InitStructure.GPIO_Pin   = GPIO_BACKLIGHT_PIN;
00149     GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF_PP;
00150     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
00151     GPIO_Init( GPIOx_BL_LCD, &GPIO_InitStructure );
00152 
00153     // Remaping TIM4 CH2 on PD13
00154     RCC_APB2PeriphClockCmd( RCC_APB2Periph_AFIO, ENABLE );
00155     GPIO_PinRemapConfig( AFIO_MAPR_TIM4_REMAP, ENABLE );
00156 
00157     /* TIM Configuration -----------------------------------------------------*/
00158     /* TIMCLK = 12 MHz, Prescaler = 0x0 */
00159 
00160     /* Enable TIM clock */
00161     RCC_APB1PeriphClockCmd( TIM_LCD_BL_PERIPH, ENABLE );
00162 
00163     TIM_DeInit( TIM_LCD_BL );
00164     TIM_TimeBaseStructInit( &TIM_TimeBaseStructure );
00165     TIM_OCStructInit( &TIM_OCInitStructure );
00166 
00167     /* Time base configuration */
00168     TIM_TimeBaseStructure.TIM_Period          = 0xFFFF;
00169     TIM_TimeBaseStructure.TIM_Prescaler       = 0x00;
00170     TIM_TimeBaseStructure.TIM_ClockDivision   = 0x0;
00171     TIM_TimeBaseStructure.TIM_CounterMode     = TIM_CounterMode_Up;
00172     TIM_TimeBaseInit( TIM_LCD_BL, &TIM_TimeBaseStructure );
00173 
00174     /* Output Compare Toggle Mode configuration */
00175     TIM_OCInitStructure.TIM_OCMode      = TIM_OCMode_PWM1;
00176     TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;   /* FWLib v2.0*/
00177     TIM_OCInitStructure.TIM_Pulse       = Current_CCR_BackLightStart;
00178     TIM_OCInitStructure.TIM_OCPolarity  = TIM_OCPolarity_High;
00179     TIM_OCxInit( TIM_LCD_BL, &TIM_OCInitStructure );
00180 
00181     TIM_OCxPreloadConfig( TIM_LCD_BL, TIM_OCPreload_Disable );
00182 
00183     TIM_ARRPreloadConfig( TIM_LCD_BL, ENABLE );
00184 
00185     /* Go !!!*/
00186     TIM_Cmd( TIM_LCD_BL, ENABLE );
00187 
00188 }
00189 
00190 
00191 /*******************************************************************************
00192 *
00193 *                                LCD_Write_Reg
00194 *
00195 *******************************************************************************/
00200 /******************************************************************************/
00201 inline void LCD_Write_Reg( u8 regadd, u16 value )
00202 {
00203     // Set index of the register
00204     *( u8 volatile* )( LCD_CMD_MODE_ADDR ) = 0;
00205     *( u8 volatile* )( LCD_CMD_MODE_ADDR ) = regadd;
00206 
00207     // Write into the register (2 x 8 bits transfers, MSB first)
00208     *( u8 volatile* )( LCD_DATA_MODE_ADDR ) = value >> 8;
00209     *( u8 volatile* )( LCD_DATA_MODE_ADDR ) = value & 0xFF;
00210 }
00211 
00212 /*******************************************************************************
00213 *
00214 *                                LCD_Read_Reg
00215 *
00216 *******************************************************************************/
00221 /******************************************************************************/
00222 u16 LCD_Read_Reg( u8 regadd )
00223 {
00224     u16 temp1, temp2;
00225 
00226     // Set index of the register
00227     *( u8 volatile* )( LCD_CMD_MODE_ADDR ) = 0;
00228     *( u8 volatile* )( LCD_CMD_MODE_ADDR ) = regadd;
00229 
00230     // Read the value of the register
00231     temp1 = ( *( u8 volatile* )( LCD_DATA_MODE_ADDR ) ) << 8;
00232     temp2 = ( *( u8 volatile* )( LCD_DATA_MODE_ADDR ) );
00233 
00234     return ( temp1 | temp2 );
00235 }
00236 
00237 /*******************************************************************************
00238 *
00239 *                                LCD_Reset
00240 *
00241 *******************************************************************************/
00246 /******************************************************************************/
00247 void LCD_Reset( void )
00248 {
00249     GPIO_WriteBit( GPIOx_RST_LCD, CtrlPin_RST, Bit_RESET );     /* Reset active at LOW */
00250     Delayms( 300 );
00251     GPIO_WriteBit( GPIOx_RST_LCD, CtrlPin_RST, Bit_SET );       /* Reset active at LOW */
00252     Delayms( 100 );
00253 
00254     return;
00255 }
00256 
00257 
00258 /*******************************************************************************
00259 *
00260 *                                LCD_BackLightChange
00261 *
00262 *******************************************************************************/
00267 /******************************************************************************/
00268 void LCD_BackLightChange( void )
00269 {
00270     /* Output Compare Toggle Mode configuration */
00271     TIM_OCInitStructure.TIM_Pulse = Current_CCR_BackLightStart;
00272 
00273     TIM_OCxInit( TIM_LCD_BL, &TIM_OCInitStructure );
00274 }
00275 
00276 
00277 /*******************************************************************************
00278 *
00279 *                                LCD_SetLogoBW
00280 *
00281 *******************************************************************************/
00287 /******************************************************************************/
00288 void LCD_SetLogoBW( void )
00289 {
00290     DRAW_SetImage( primerUpic, ( Screen_Width - 180 ) / 2, ( Screen_Height - 174) / 2, 180, 174 ) ; /* 180x174 Image Size*/
00291 }
00292 
00293 
00294 /*******************************************************************************
00295 *
00296 *                                LCD_Scroll
00297 *
00298 *******************************************************************************/
00304 /******************************************************************************/
00305 void LCD_Scroll( u8 Ascii, coord_t CurX, coord_t* CurY, coord_t RightMargX, coord_t LeftMargX, coord_t HighMargY, coord_t LowMargY, color_t bGndColor, color_t textColor, mag_t CharMagniCoeff )
00306 {
00307     s16 Nblines, width, i, y;
00308     extern u16 bmpTmp [LCD_DMA_SIZE];
00309 
00310     InitListDMA();
00311     Nblines = ( LowMargY - *CurY ) / DeltaY;
00312     width = RightMargX - LeftMargX;
00313     for ( i = 0; i < Nblines ; i++ )
00314     {
00315         for ( y = HighMargY - DeltaY; y >= LowMargY; y -= DeltaY )
00316         {
00317             if ( width < PHYS_SCREEN_WIDTH )
00318                 {
00319                 LCD_RectRead( LeftMargX, y - DeltaY, width, DeltaY, ( u8* ) &bmpTmp );
00320                 DRAW_SetImage( bmpTmp, LeftMargX, y, width, DeltaY );
00321                 }
00322             else
00323                 {
00324                 LCD_RectRead( LeftMargX, y - DeltaY, PHYS_SCREEN_WIDTH, DeltaY, ( u8* ) &bmpTmp );
00325                 DRAW_SetImage( bmpTmp, LeftMargX, y, PHYS_SCREEN_WIDTH, DeltaY );
00326                 LCD_RectRead( LeftMargX + PHYS_SCREEN_WIDTH, y - DeltaY, width - PHYS_SCREEN_WIDTH, DeltaY, ( u8* ) &bmpTmp );
00327                 DRAW_SetImage( bmpTmp, LeftMargX + PHYS_SCREEN_WIDTH, y, width - PHYS_SCREEN_WIDTH, DeltaY );
00328                 }
00329 //            LIST_LCD_RectRead( LeftMargX, y - DeltaY, width, DeltaY ); // No multiread data with this controller
00330 //            LIST_DRAW_SetImage( LeftMargX, y, width, DeltaY );
00331         }
00332         LCD_FillRect( LeftMargX, LowMargY, width, DeltaY, bGndColor );
00333     }
00334     *CurY = LowMargY;
00335 
00336     // Display the selected bitmap according to the provided ASCII character.
00337     LCD_DisplayChar( CurX, *CurY, Ascii, textColor, bGndColor, CharMagniCoeff );
00338 
00339 }
00340 
00341 
00342 /*******************************************************************************
00343 *
00344 *                                LCD_SendLCDCmd_RAM_Access
00345 *
00346 *******************************************************************************/
00352 /******************************************************************************/
00353 void LCD_SendLCDCmd_RAM_Access( void )
00354 {
00355     LCD_SendLCDCmd( ILI9325_GRAM_DATA );
00356 }
00357 
00358 /*******************************************************************************
00359 *
00360 *                                LCD_SendLCDCmd_RAM_Access_End
00361 *
00362 *******************************************************************************/
00368 /******************************************************************************/
00369 void LCD_SendLCDCmd_RAM_Access_End( void )
00370 {
00371 }
00372 
00373 
00374 /*******************************************************************************
00375 *
00376 *                                LCD_PixelRead
00377 *
00378 *******************************************************************************/
00389 /******************************************************************************/
00390 inline void LCD_PixelRead( u8** ptbmp )
00391 {
00392     static u8 temp1, temp2, blue, red;
00393 
00394     // Send LCD RAM read command
00395     LCD_SendLCDCmd( ILI9325_GRAM_DATA );
00396 
00397     // Two first read bytes are dummy !
00398     LCD_ReadLCDData();
00399     LCD_ReadLCDData();
00400 
00401     // Read the two bytes of the pixel
00402     temp1 = ( u8 ) LCD_ReadLCDData();
00403     blue = ( temp1 & 0xF8 ) >> 3;
00404     temp2 = ( u8 ) LCD_ReadLCDData();
00405     red = ( temp2 & 0x1F ) << 3;
00406 
00407     *( *ptbmp ) = ( temp1 & 0x07 ) | red;
00408     *( *ptbmp + 1 ) = ( temp2 & 0xE0 ) | blue;
00409     *ptbmp += 2;
00410 
00411 }
00412 
00413 /*******************************************************************************
00414 *
00415 *                                LCD_SendLCDCmd_Rotation_Access
00416 *
00417 *******************************************************************************/
00423 /******************************************************************************/
00424 void LCD_SendLCDCmd_Rotation_Access( void )
00425 {
00426     LCD_SendLCDCmd( ILI9325_ENTRY_MOD );
00427 }
00428 
00429 
00430 /*******************************************************************************
00431 *
00432 *                                LCD_SendLCDData16
00433 *
00434 *******************************************************************************/
00444 /******************************************************************************/
00445 void LCD_SendLCDData16( u8 Data_h, u8 Data_l )
00446 {
00447     // Write into the current register
00448     *( u8 volatile* )( LCD_DATA_MODE_ADDR ) = Data_h;
00449     *( u8 volatile* )( LCD_DATA_MODE_ADDR ) = Data_l;
00450 
00451 }
00452 
00454 
00455 /* Public functions ----------------------------------------------------------*/
00456 
00457 /*******************************************************************************
00458 *
00459 *                                LCD_SendLCDCmd
00460 *
00461 *******************************************************************************/
00469 /******************************************************************************/
00470 void LCD_SendLCDCmd( u8 Cmd )
00471 {
00472     // Set index of the register
00473     *( u8 volatile* )( LCD_CMD_MODE_ADDR ) = 0;
00474     *( u8 volatile* )( LCD_CMD_MODE_ADDR ) = Cmd;
00475 }
00476 
00477 /*******************************************************************************
00478 *
00479 *                                LCD_SendLCDData
00480 *
00481 *******************************************************************************/
00491 /******************************************************************************/
00492 void LCD_SendLCDData( u8 Data )
00493 {
00494     // Write into the current register
00495     *( u8 volatile* )( LCD_DATA_MODE_ADDR ) = Data;
00496 }
00497 
00498 
00499 /***********************************************************************************
00500 *
00501 *                                LCD_ReadLCDData
00502 *
00503 ************************************************************************************/
00512 /********************************************************************************/
00513 u32 LCD_ReadLCDData( void )
00514 {
00515     /* Transfer data from the memory */
00516     return (( *( u32 volatile* )( LCD_DATA_MODE_ADDR ) ) );
00517 }
00518 
00519 /*******************************************************************************
00520 *
00521 *                                LCD_DrawPixel
00522 *
00523 *******************************************************************************/
00535 /******************************************************************************/
00536 void LCD_DrawPixel( coord_t XPos, coord_t YPos, color_t Color )
00537 {
00538     /* Select LCD screen area. */
00539     LCD_SetRect_For_Cmd( XPos, YPos, 1, 1 );
00540 
00541     /* Send LCD RAM write command. */
00542     LCD_SendLCDCmd( ILI9325_GRAM_DATA );
00543 
00544     /* Draw pixel.*/
00545     LCD_SendPixelData(Color );
00546 
00547 }
00548 
00549