CircleOS  1
lcd_spe.c
Go to the documentation of this file.
1 /****************** COPYRIGHT (C) 2007-2013 KEOLABS S.A.S. ********************/
10 /******************************************************************************/
11 
12 /* Includes ------------------------------------------------------------------*/
13 #include "circle.h"
14 
15 
17 
18 /* Private define ------------------------------------------------------------*/
19 
20 /* Private variables ---------------------------------------------------------*/
21 const u16 primerUpic[] =
22 {
23 #include "bmp\Open4_EvoPrimer_screen_180x174_RLE256.h"
24 };
25 
26 /* Vars for timer dedicated for lcd backlight */
27 static TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
28 static TIM_OCInitTypeDef TIM_OCInitStructure;
29 
30 /* Public variables ---------------------------------------------------------*/
31 uint_t Current_CCR_BackLightStart = DEFAULT_CCR_BACKLIGHTSTART;
32 const unsigned freqTIM2[ 6 ] = { 136, 136, 182, 273, 364, 546 } ;
33 
34 /* External variable ---------------------------------------------------------*/
35 
36 /* Private function prototypes -----------------------------------------------*/
37 
38 /* Private functions ---------------------------------------------------------*/
39 
40 
41 /*******************************************************************************
42 *
43 * LCD_Interface_Init
44 *
45 *******************************************************************************/
51 /******************************************************************************/
52 void LCD_Interface_Init( void )
53 {
54  // YRT111004 : volatile declaration because in some case the compiler does not
55  // configure the timing structure
56  volatile FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
57  volatile FSMC_NORSRAMTimingInitTypeDef p;
58  GPIO_InitTypeDef GPIO_InitStructure;
59 
60  /*-- GPIO Configuration ------------------------------------------------------*/
61 
62  /* SRAM Data lines configuration */
63  RCC_APB2PeriphClockCmd( GPIO_LCD_D1_PERIPH, ENABLE );
64  RCC_APB2PeriphClockCmd( GPIO_LCD_D2_PERIPH, ENABLE );
65 
66  GPIO_InitStructure.GPIO_Pin = LCD_D0 | LCD_D1 | LCD_D2 | LCD_D3 ;
67  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
68  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
69  GPIO_Init( GPIOx_D1_LCD, &GPIO_InitStructure );
70 
71  GPIO_InitStructure.GPIO_Pin = LCD_D4 | LCD_D5 | LCD_D6 | LCD_D7 ;
72  GPIO_Init( GPIOx_D2_LCD, &GPIO_InitStructure );
73 
74  /* NOE, NWE and NE1 configuration */
75  RCC_APB2PeriphClockCmd( GPIO_LCD_CTRL_PERIPH, ENABLE );
76  GPIO_InitStructure.GPIO_Pin = CtrlPin_RD | CtrlPin_WR | CtrlPin_RS;
77  GPIO_Init( GPIOx_CTRL_LCD, &GPIO_InitStructure );
78 
79  /* Reset : configured as regular GPIO, is not FSMC-controlled */
80  RCC_APB2PeriphClockCmd( GPIO_LCD_RST_PERIPH, ENABLE );
81  GPIO_InitStructure.GPIO_Pin = CtrlPin_RST;
82  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
83  GPIO_Init( GPIOx_RST_LCD, &GPIO_InitStructure );
84 
85  /* CS : configured as regular GPIO, is not FSMC-controlled */
86  RCC_APB2PeriphClockCmd( GPIO_LCD_CS_PERIPH, ENABLE );
87  GPIO_InitStructure.GPIO_Pin = CtrlPin_CS;
88  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
89  GPIO_Init( GPIOx_CS_LCD, &GPIO_InitStructure );
90 
91  GPIO_WriteBit( GPIOx_RST_LCD, CtrlPin_RST, Bit_SET ); /* Reset active at LOW */
92  GPIO_WriteBit( GPIOx_CS_LCD, CtrlPin_CS, Bit_RESET ); /* CS active at LOW */
93 
94 
95  /*-- FSMC Configuration ------------------------------------------------------*/
96 
97  /* Enable the FSMC Clock */
98  RCC_AHBPeriphClockCmd( RCC_AHBPeriph_FSMC, ENABLE );
99 
100  p.FSMC_AddressSetupTime = 1;
101  p.FSMC_AddressHoldTime = 0;
102  p.FSMC_DataSetupTime = 2;
103  p.FSMC_BusTurnAroundDuration = 0;
104  p.FSMC_CLKDivision = 0;
105  p.FSMC_DataLatency = 0;
106  p.FSMC_AccessMode = FSMC_AccessMode_A;
107 
108  FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM3;
109  FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;
110  FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM;
111  FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_8b;
112  FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
113  FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable;
114  FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
115  FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;
116  FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
117  FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;
118  FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
119  FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
120  FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
121  FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = (FSMC_NORSRAMTimingInitTypeDef*) &p;
122  FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = (FSMC_NORSRAMTimingInitTypeDef*) &p;
123  FSMC_NORSRAMInit( (FSMC_NORSRAMInitTypeDef*) &FSMC_NORSRAMInitStructure );
124 
125  /* Enable FSMC Bank1_SRAM Bank */
126  FSMC_NORSRAMCmd( FSMC_Bank1_NORSRAM3, ENABLE );
127 }
128 
129 
130 /*******************************************************************************
131 *
132 * LCD_BackLightConfig
133 *
134 *******************************************************************************/
139 /******************************************************************************/
140 void LCD_BackLightConfig( void )
141 {
142  GPIO_InitTypeDef GPIO_InitStructure;
143 
144  /* Enable GPIO clock */
145  RCC_APB2PeriphClockCmd( GPIO_LCD_BL_PERIPH, ENABLE );
146 
147  /* GPIO Configuration : TIM in Output */
148  GPIO_InitStructure.GPIO_Pin = GPIO_BACKLIGHT_PIN;
149  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
150  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
151  GPIO_Init( GPIOx_BL_LCD, &GPIO_InitStructure );
152 
153  // Remaping TIM4 CH2 on PD13
154  RCC_APB2PeriphClockCmd( RCC_APB2Periph_AFIO, ENABLE );
155  GPIO_PinRemapConfig( AFIO_MAPR_TIM4_REMAP, ENABLE );
156 
157  /* TIM Configuration -----------------------------------------------------*/
158  /* TIMCLK = 12 MHz, Prescaler = 0x0 */
159 
160  /* Enable TIM clock */
161  RCC_APB1PeriphClockCmd( TIM_LCD_BL_PERIPH, ENABLE );
162 
163  TIM_DeInit( TIM_LCD_BL );
164  TIM_TimeBaseStructInit( &TIM_TimeBaseStructure );
165  TIM_OCStructInit( &TIM_OCInitStructure );
166 
167  /* Time base configuration */
168  TIM_TimeBaseStructure.TIM_Period = 0xFFFF;
169  TIM_TimeBaseStructure.TIM_Prescaler = 0x00;
170  TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
171  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
172  TIM_TimeBaseInit( TIM_LCD_BL, &TIM_TimeBaseStructure );
173 
174  /* Output Compare Toggle Mode configuration */
175  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
176  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; /* FWLib v2.0*/
177  TIM_OCInitStructure.TIM_Pulse = Current_CCR_BackLightStart;
178  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
179  TIM_OCxInit( TIM_LCD_BL, &TIM_OCInitStructure );
180 
181  TIM_OCxPreloadConfig( TIM_LCD_BL, TIM_OCPreload_Disable );
182 
183  TIM_ARRPreloadConfig( TIM_LCD_BL, ENABLE );
184 
185  /* Go !!!*/
186  TIM_Cmd( TIM_LCD_BL, ENABLE );
187 
188 }
189 
190 
191 /*******************************************************************************
192 *
193 * LCD_Write_Reg
194 *
195 *******************************************************************************/
200 /******************************************************************************/
201 inline void LCD_Write_Reg( u8 regadd, u16 value )
202 {
203  // Set index of the register
204  *( u8 volatile* )( LCD_CMD_MODE_ADDR ) = 0;
205  *( u8 volatile* )( LCD_CMD_MODE_ADDR ) = regadd;
206 
207  // Write into the register (2 x 8 bits transfers, MSB first)
208  *( u8 volatile* )( LCD_DATA_MODE_ADDR ) = value >> 8;
209  *( u8 volatile* )( LCD_DATA_MODE_ADDR ) = value & 0xFF;
210 }
211 
212 /*******************************************************************************
213 *
214 * LCD_Read_Reg
215 *
216 *******************************************************************************/
221 /******************************************************************************/
222 u16 LCD_Read_Reg( u8 regadd )
223 {
224  u16 temp1, temp2;
225 
226  // Set index of the register
227  *( u8 volatile* )( LCD_CMD_MODE_ADDR ) = 0;
228  *( u8 volatile* )( LCD_CMD_MODE_ADDR ) = regadd;
229 
230  // Read the value of the register
231  temp1 = ( *( u8 volatile* )( LCD_DATA_MODE_ADDR ) ) << 8;
232  temp2 = ( *( u8 volatile* )( LCD_DATA_MODE_ADDR ) );
233 
234  return ( temp1 | temp2 );
235 }
236 
237 /*******************************************************************************
238 *
239 * LCD_Reset
240 *
241 *******************************************************************************/
246 /******************************************************************************/
247 void LCD_Reset( void )
248 {
249  GPIO_WriteBit( GPIOx_RST_LCD, CtrlPin_RST, Bit_RESET ); /* Reset active at LOW */
250  Delayms( 300 );
251  GPIO_WriteBit( GPIOx_RST_LCD, CtrlPin_RST, Bit_SET ); /* Reset active at LOW */
252  Delayms( 100 );
253 
254  return;
255 }
256 
257 
258 /*******************************************************************************
259 *
260 * LCD_BackLightChange
261 *
262 *******************************************************************************/
267 /******************************************************************************/
268 void LCD_BackLightChange( void )
269 {
270  /* Output Compare Toggle Mode configuration */
271  TIM_OCInitStructure.TIM_Pulse = Current_CCR_BackLightStart;
272 
273  TIM_OCxInit( TIM_LCD_BL, &TIM_OCInitStructure );
274 }
275 
276 
277 /*******************************************************************************
278 *
279 * LCD_SetLogoBW
280 *
281 *******************************************************************************/
287 /******************************************************************************/
288 void LCD_SetLogoBW( void )
289 {
290  DRAW_SetImage( primerUpic, ( Screen_Width - 180 ) / 2, ( Screen_Height - 174) / 2, 180, 174 ) ; /* 180x174 Image Size*/
291 }
292 
293 
294 /*******************************************************************************
295 *
296 * LCD_Scroll
297 *
298 *******************************************************************************/
304 /******************************************************************************/
305 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 )
306 {
307  s16 Nblines, width, i, y;
308  extern u16 bmpTmp [LCD_DMA_SIZE];
309 
310  InitListDMA();
311  Nblines = ( LowMargY - *CurY ) / DeltaY;
312  width = RightMargX - LeftMargX;
313  for ( i = 0; i < Nblines ; i++ )
314  {
315  for ( y = HighMargY - DeltaY; y >= LowMargY; y -= DeltaY )
316  {
317  if ( width < PHYS_SCREEN_WIDTH )
318  {
319  LCD_RectRead( LeftMargX, y - DeltaY, width, DeltaY, ( u8* ) &bmpTmp );
320  DRAW_SetImage( bmpTmp, LeftMargX, y, width, DeltaY );
321  }
322  else
323  {
324  LCD_RectRead( LeftMargX, y - DeltaY, PHYS_SCREEN_WIDTH, DeltaY, ( u8* ) &bmpTmp );
325  DRAW_SetImage( bmpTmp, LeftMargX, y, PHYS_SCREEN_WIDTH, DeltaY );
326  LCD_RectRead( LeftMargX + PHYS_SCREEN_WIDTH, y - DeltaY, width - PHYS_SCREEN_WIDTH, DeltaY, ( u8* ) &bmpTmp );
327  DRAW_SetImage( bmpTmp, LeftMargX + PHYS_SCREEN_WIDTH, y, width - PHYS_SCREEN_WIDTH, DeltaY );
328  }
329 // LIST_LCD_RectRead( LeftMargX, y - DeltaY, width, DeltaY ); // No multiread data with this controller
330 // LIST_DRAW_SetImage( LeftMargX, y, width, DeltaY );
331  }
332  LCD_FillRect( LeftMargX, LowMargY, width, DeltaY, bGndColor );
333  }
334  *CurY = LowMargY;
335 
336  // Display the selected bitmap according to the provided ASCII character.
337  LCD_DisplayChar( CurX, *CurY, Ascii, textColor, bGndColor, charMagniCoeff );
338 
339 }
340 
341 
342 /*******************************************************************************
343 *
344 * LCD_SendLCDCmd_RAM_Access
345 *
346 *******************************************************************************/
352 /******************************************************************************/
353 void LCD_SendLCDCmd_RAM_Access( void )
354 {
355  LCD_SendLCDCmd( ILI9325_GRAM_DATA );
356 }
357 
358 /*******************************************************************************
359 *
360 * LCD_SendLCDCmd_RAM_Access_End
361 *
362 *******************************************************************************/
368 /******************************************************************************/
369 void LCD_SendLCDCmd_RAM_Access_End( void )
370 {
371 }
372 
373 
374 /*******************************************************************************
375 *
376 * LCD_PixelRead
377 *
378 *******************************************************************************/
394 /******************************************************************************/
395 inline void LCD_PixelRead( u8** ptbmp )
396 {
397  u8 temp1, temp2, blue, red;
398 
399  // Send LCD RAM read command
400  LCD_SendLCDCmd( ILI9325_GRAM_DATA );
401 
402  // Two first read bytes are dummy !
403  LCD_ReadLCDData();
404  LCD_ReadLCDData();
405 
406  // Read the two bytes of the pixel
407  temp1 = ( u8 ) LCD_ReadLCDData();
408  blue = ( temp1 & 0xF8 ) >> 3;
409  temp2 = ( u8 ) LCD_ReadLCDData();
410  red = ( temp2 & 0x1F ) << 3;
411 
412  *( *ptbmp ) = ( temp1 & 0x07 ) | red;
413  *( *ptbmp + 1 ) = ( temp2 & 0xE0 ) | blue;
414  *ptbmp += 2;
415 }
416 
417 /*******************************************************************************
418 *
419 * LCD_SendLCDCmd_Rotation_Access
420 *
421 *******************************************************************************/
427 /******************************************************************************/
428 void LCD_SendLCDCmd_Rotation_Access( void )
429 {
430  LCD_SendLCDCmd( ILI9325_ENTRY_MOD );
431 }
432 
433 
434 /*******************************************************************************
435 *
436 * LCD_SendLCDData16
437 *
438 *******************************************************************************/
448 /******************************************************************************/
449 void LCD_SendLCDData16( u8 Data_h, u8 Data_l )
450 {
451  // Write into the current register
452  *( u8 volatile* )( LCD_DATA_MODE_ADDR ) = Data_h;
453  *( u8 volatile* )( LCD_DATA_MODE_ADDR ) = Data_l;
454 
455 }
456 
458 
459 /* Public functions ----------------------------------------------------------*/
460 
461 /*******************************************************************************
462 *
463 * LCD_SendLCDCmd
464 *
465 *******************************************************************************/
473 /******************************************************************************/
474 void LCD_SendLCDCmd( u8 Cmd )
475 {
476  // Set index of the register
477  *( u8 volatile* )( LCD_CMD_MODE_ADDR ) = 0;
478  *( u8 volatile* )( LCD_CMD_MODE_ADDR ) = Cmd;
479 }
480 
481 /*******************************************************************************
482 *
483 * LCD_SendLCDData
484 *
485 *******************************************************************************/
495 /******************************************************************************/
496 void LCD_SendLCDData( u8 Data )
497 {
498  // Write into the current register
499  *( u8 volatile* )( LCD_DATA_MODE_ADDR ) = Data;
500 }
501 
502 
503 /***********************************************************************************
504 *
505 * LCD_ReadLCDData
506 *
507 ************************************************************************************/
516 /********************************************************************************/
517 u32 LCD_ReadLCDData( void )
518 {
519  u32 tmp;
520 
521  /* Transfer data from the memory */
522  tmp = ( ( *( u8 volatile* )( LCD_DATA_MODE_ADDR ) ) );
523 
524  return tmp;
525 }
526 
527 /*******************************************************************************
528 *
529 * LCD_DrawPixel
530 *
531 *******************************************************************************/
543 /******************************************************************************/
544 void LCD_DrawPixel( coord_t XPos, coord_t YPos, color_t Color )
545 {
546  /* Select LCD screen area. */
547  LCD_SetRect_For_Cmd( XPos, YPos, 1, 1 );
548 
549  /* Send LCD RAM write command. */
550  LCD_SendLCDCmd( ILI9325_GRAM_DATA );
551 
552  /* Draw pixel.*/
553  LCD_SendPixelData(Color );
554 
555 }
556 
557