comparison libs/STM32F10x_StdPeriph_Lib_V3.5.0/Utilities/STM32_EVAL/STM3210E_EVAL/stm3210e_eval_lcd.c @ 0:c59513fd84fb

Initial commit of STM32 test code.
author Daniel O'Connor <darius@dons.net.au>
date Mon, 03 Oct 2011 21:19:15 +1030
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:c59513fd84fb
1 /**
2 ******************************************************************************
3 * @file stm3210e_eval_lcd.c
4 * @author MCD Application Team
5 * @version V4.5.0
6 * @date 07-March-2011
7 * @brief This file includes the LCD driver for AM-240320L8TNQW00H
8 * (LCD_ILI9320) and AM-240320LDTNQW00H (LCD_SPFD5408B) Liquid Crystal
9 * Display Module of STM3210E-EVAL board.
10 ******************************************************************************
11 * @attention
12 *
13 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
14 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
15 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
16 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
17 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
18 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
19 *
20 * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>
21 ******************************************************************************
22 */
23
24 /* Includes ------------------------------------------------------------------*/
25 #include "stm3210e_eval_lcd.h"
26 #include "../Common/fonts.c"
27
28 /** @addtogroup Utilities
29 * @{
30 */
31
32 /** @addtogroup STM32_EVAL
33 * @{
34 */
35
36 /** @addtogroup STM3210E_EVAL
37 * @{
38 */
39
40 /** @defgroup STM3210E_EVAL_LCD
41 * @brief This file includes the LCD driver for AM-240320L8TNQW00H
42 * (LCD_ILI9320) and AM-240320LDTNQW00H (LCD_SPFD5408B) Liquid Crystal
43 * Display Module of STM3210E-EVAL board.
44 * @{
45 */
46
47 /** @defgroup STM3210E_EVAL_LCD_Private_TypesDefinitions
48 * @{
49 */
50 typedef struct
51 {
52 __IO uint16_t LCD_REG;
53 __IO uint16_t LCD_RAM;
54 } LCD_TypeDef;
55 /**
56 * @}
57 */
58
59
60 /** @defgroup STM3210E_EVAL_LCD_Private_Defines
61 * @{
62 */
63 /* Note: LCD /CS is CE4 - Bank 4 of NOR/SRAM Bank 1~4 */
64 #define LCD_BASE ((uint32_t)(0x60000000 | 0x0C000000))
65 #define LCD ((LCD_TypeDef *) LCD_BASE)
66 #define MAX_POLY_CORNERS 200
67 #define POLY_Y(Z) ((int32_t)((Points + Z)->X))
68 #define POLY_X(Z) ((int32_t)((Points + Z)->Y))
69 /**
70 * @}
71 */
72
73 /** @defgroup STM3210E_EVAL_LCD_Private_Macros
74 * @{
75 */
76 #define ABS(X) ((X) > 0 ? (X) : -(X))
77 /**
78 * @}
79 */
80
81 /** @defgroup STM3210E_EVAL_LCD_Private_Variables
82 * @{
83 */
84 static sFONT *LCD_Currentfonts;
85 /* Global variables to set the written text color */
86 static __IO uint16_t TextColor = 0x0000, BackColor = 0xFFFF;
87
88 /**
89 * @}
90 */
91
92
93 /** @defgroup STM3210E_EVAL_LCD_Private_FunctionPrototypes
94 * @{
95 */
96 #ifndef USE_Delay
97 static void delay(vu32 nCount);
98 #endif /* USE_Delay*/
99 static void PutPixel(int16_t x, int16_t y);
100 static void LCD_PolyLineRelativeClosed(pPoint Points, uint16_t PointCount, uint16_t Closed);
101 /**
102 * @}
103 */
104
105
106 /** @defgroup STM3210E_EVAL_LCD_Private_Functions
107 * @{
108 */
109
110 /**
111 * @brief DeInitializes the LCD.
112 * @param None
113 * @retval None
114 */
115 void LCD_DeInit(void)
116 {
117 GPIO_InitTypeDef GPIO_InitStructure;
118
119 /*!< LCD Display Off */
120 LCD_DisplayOff();
121
122 /* BANK 4 (of NOR/SRAM Bank 1~4) is disabled */
123 FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM4, ENABLE);
124
125 /*!< LCD_SPI DeInit */
126 FSMC_NORSRAMDeInit(FSMC_Bank1_NORSRAM4);
127
128 /* Set PD.00(D2), PD.01(D3), PD.04(NOE), PD.05(NWE), PD.08(D13), PD.09(D14),
129 PD.10(D15), PD.14(D0), PD.15(D1) as input floating */
130 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5 |
131 GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_14 |
132 GPIO_Pin_15;
133 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
134 GPIO_Init(GPIOD, &GPIO_InitStructure);
135 /* Set PE.07(D4), PE.08(D5), PE.09(D6), PE.10(D7), PE.11(D8), PE.12(D9), PE.13(D10),
136 PE.14(D11), PE.15(D12) as alternate function push pull */
137 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 |
138 GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 |
139 GPIO_Pin_15;
140 GPIO_Init(GPIOE, &GPIO_InitStructure);
141 /* Set PF.00(A0 (RS)) as alternate function push pull */
142 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
143 GPIO_Init(GPIOF, &GPIO_InitStructure);
144 /* Set PG.12(NE4 (LCD/CS)) as alternate function push pull - CE3(LCD /CS) */
145 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
146 GPIO_Init(GPIOG, &GPIO_InitStructure);
147 }
148
149 /**
150 * @brief Initializes the LCD.
151 * @param None
152 * @retval None
153 */
154 void STM3210E_LCD_Init(void)
155 {
156 /* Configure the LCD Control pins --------------------------------------------*/
157 LCD_CtrlLinesConfig();
158 /* Configure the FSMC Parallel interface -------------------------------------*/
159 LCD_FSMCConfig();
160
161 _delay_(5); /* delay 50 ms */
162 /* Check if the LCD is SPFD5408B Controller */
163 if(LCD_ReadReg(0x00) == 0x5408)
164 {
165 /* Start Initial Sequence ------------------------------------------------*/
166 LCD_WriteReg(LCD_REG_1, 0x0100); /* Set SS bit */
167 LCD_WriteReg(LCD_REG_2, 0x0700); /* Set 1 line inversion */
168 LCD_WriteReg(LCD_REG_3, 0x1030); /* Set GRAM write direction and BGR=1. */
169 LCD_WriteReg(LCD_REG_4, 0x0000); /* Resize register */
170 LCD_WriteReg(LCD_REG_8, 0x0202); /* Set the back porch and front porch */
171 LCD_WriteReg(LCD_REG_9, 0x0000); /* Set non-display area refresh cycle ISC[3:0] */
172 LCD_WriteReg(LCD_REG_10, 0x0000); /* FMARK function */
173 LCD_WriteReg(LCD_REG_12, 0x0000); /* RGB 18-bit System interface setting */
174 LCD_WriteReg(LCD_REG_13, 0x0000); /* Frame marker Position */
175 LCD_WriteReg(LCD_REG_15, 0x0000); /* RGB interface polarity, no impact */
176 /* Power On sequence -----------------------------------------------------*/
177 LCD_WriteReg(LCD_REG_16, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
178 LCD_WriteReg(LCD_REG_17, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
179 LCD_WriteReg(LCD_REG_18, 0x0000); /* VREG1OUT voltage */
180 LCD_WriteReg(LCD_REG_19, 0x0000); /* VDV[4:0] for VCOM amplitude */
181 _delay_(20); /* Dis-charge capacitor power voltage (200ms) */
182 LCD_WriteReg(LCD_REG_17, 0x0007); /* DC1[2:0], DC0[2:0], VC[2:0] */
183 _delay_(5); /* Delay 50 ms */
184 LCD_WriteReg(LCD_REG_16, 0x12B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
185 _delay_(5); /* Delay 50 ms */
186 LCD_WriteReg(LCD_REG_18, 0x01BD); /* External reference voltage= Vci */
187 _delay_(5);
188 LCD_WriteReg(LCD_REG_19, 0x1400); /* VDV[4:0] for VCOM amplitude */
189 LCD_WriteReg(LCD_REG_41, 0x000E); /* VCM[4:0] for VCOMH */
190 _delay_(5); /* Delay 50 ms */
191 LCD_WriteReg(LCD_REG_32, 0x0000); /* GRAM horizontal Address */
192 LCD_WriteReg(LCD_REG_33, 0x013F); /* GRAM Vertical Address */
193 /* Adjust the Gamma Curve (SPFD5408B)-------------------------------------*/
194 LCD_WriteReg(LCD_REG_48, 0x0b0d);
195 LCD_WriteReg(LCD_REG_49, 0x1923);
196 LCD_WriteReg(LCD_REG_50, 0x1c26);
197 LCD_WriteReg(LCD_REG_51, 0x261c);
198 LCD_WriteReg(LCD_REG_52, 0x2419);
199 LCD_WriteReg(LCD_REG_53, 0x0d0b);
200 LCD_WriteReg(LCD_REG_54, 0x1006);
201 LCD_WriteReg(LCD_REG_55, 0x0610);
202 LCD_WriteReg(LCD_REG_56, 0x0706);
203 LCD_WriteReg(LCD_REG_57, 0x0304);
204 LCD_WriteReg(LCD_REG_58, 0x0e05);
205 LCD_WriteReg(LCD_REG_59, 0x0e01);
206 LCD_WriteReg(LCD_REG_60, 0x010e);
207 LCD_WriteReg(LCD_REG_61, 0x050e);
208 LCD_WriteReg(LCD_REG_62, 0x0403);
209 LCD_WriteReg(LCD_REG_63, 0x0607);
210 /* Set GRAM area ---------------------------------------------------------*/
211 LCD_WriteReg(LCD_REG_80, 0x0000); /* Horizontal GRAM Start Address */
212 LCD_WriteReg(LCD_REG_81, 0x00EF); /* Horizontal GRAM End Address */
213 LCD_WriteReg(LCD_REG_82, 0x0000); /* Vertical GRAM Start Address */
214 LCD_WriteReg(LCD_REG_83, 0x013F); /* Vertical GRAM End Address */
215 LCD_WriteReg(LCD_REG_96, 0xA700); /* Gate Scan Line */
216 LCD_WriteReg(LCD_REG_97, 0x0001); /* NDL, VLE, REV */
217 LCD_WriteReg(LCD_REG_106, 0x0000); /* set scrolling line */
218 /* Partial Display Control -----------------------------------------------*/
219 LCD_WriteReg(LCD_REG_128, 0x0000);
220 LCD_WriteReg(LCD_REG_129, 0x0000);
221 LCD_WriteReg(LCD_REG_130, 0x0000);
222 LCD_WriteReg(LCD_REG_131, 0x0000);
223 LCD_WriteReg(LCD_REG_132, 0x0000);
224 LCD_WriteReg(LCD_REG_133, 0x0000);
225 /* Panel Control ---------------------------------------------------------*/
226 LCD_WriteReg(LCD_REG_144, 0x0010);
227 LCD_WriteReg(LCD_REG_146, 0x0000);
228 LCD_WriteReg(LCD_REG_147, 0x0003);
229 LCD_WriteReg(LCD_REG_149, 0x0110);
230 LCD_WriteReg(LCD_REG_151, 0x0000);
231 LCD_WriteReg(LCD_REG_152, 0x0000);
232 /* Set GRAM write direction and BGR=1
233 I/D=01 (Horizontal : increment, Vertical : decrement)
234 AM=1 (address is updated in vertical writing direction) */
235 LCD_WriteReg(LCD_REG_3, 0x1018);
236 LCD_WriteReg(LCD_REG_7, 0x0112); /* 262K color and display ON */
237 LCD_SetFont(&LCD_DEFAULT_FONT);
238 return;
239 }
240 /* Start Initial Sequence ----------------------------------------------------*/
241 LCD_WriteReg(LCD_REG_229,0x8000); /* Set the internal vcore voltage */
242 LCD_WriteReg(LCD_REG_0, 0x0001); /* Start internal OSC. */
243 LCD_WriteReg(LCD_REG_1, 0x0100); /* set SS and SM bit */
244 LCD_WriteReg(LCD_REG_2, 0x0700); /* set 1 line inversion */
245 LCD_WriteReg(LCD_REG_3, 0x1030); /* set GRAM write direction and BGR=1. */
246 LCD_WriteReg(LCD_REG_4, 0x0000); /* Resize register */
247 LCD_WriteReg(LCD_REG_8, 0x0202); /* set the back porch and front porch */
248 LCD_WriteReg(LCD_REG_9, 0x0000); /* set non-display area refresh cycle ISC[3:0] */
249 LCD_WriteReg(LCD_REG_10, 0x0000); /* FMARK function */
250 LCD_WriteReg(LCD_REG_12, 0x0000); /* RGB interface setting */
251 LCD_WriteReg(LCD_REG_13, 0x0000); /* Frame marker Position */
252 LCD_WriteReg(LCD_REG_15, 0x0000); /* RGB interface polarity */
253 /* Power On sequence ---------------------------------------------------------*/
254 LCD_WriteReg(LCD_REG_16, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
255 LCD_WriteReg(LCD_REG_17, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
256 LCD_WriteReg(LCD_REG_18, 0x0000); /* VREG1OUT voltage */
257 LCD_WriteReg(LCD_REG_19, 0x0000); /* VDV[4:0] for VCOM amplitude */
258 _delay_(20); /* Dis-charge capacitor power voltage (200ms) */
259 LCD_WriteReg(LCD_REG_16, 0x17B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
260 LCD_WriteReg(LCD_REG_17, 0x0137); /* DC1[2:0], DC0[2:0], VC[2:0] */
261 _delay_(5); /* Delay 50 ms */
262 LCD_WriteReg(LCD_REG_18, 0x0139); /* VREG1OUT voltage */
263 _delay_(5); /* Delay 50 ms */
264 LCD_WriteReg(LCD_REG_19, 0x1d00); /* VDV[4:0] for VCOM amplitude */
265 LCD_WriteReg(LCD_REG_41, 0x0013); /* VCM[4:0] for VCOMH */
266 _delay_(5); /* Delay 50 ms */
267 LCD_WriteReg(LCD_REG_32, 0x0000); /* GRAM horizontal Address */
268 LCD_WriteReg(LCD_REG_33, 0x0000); /* GRAM Vertical Address */
269 /* Adjust the Gamma Curve ----------------------------------------------------*/
270 LCD_WriteReg(LCD_REG_48, 0x0006);
271 LCD_WriteReg(LCD_REG_49, 0x0101);
272 LCD_WriteReg(LCD_REG_50, 0x0003);
273 LCD_WriteReg(LCD_REG_53, 0x0106);
274 LCD_WriteReg(LCD_REG_54, 0x0b02);
275 LCD_WriteReg(LCD_REG_55, 0x0302);
276 LCD_WriteReg(LCD_REG_56, 0x0707);
277 LCD_WriteReg(LCD_REG_57, 0x0007);
278 LCD_WriteReg(LCD_REG_60, 0x0600);
279 LCD_WriteReg(LCD_REG_61, 0x020b);
280
281 /* Set GRAM area -------------------------------------------------------------*/
282 LCD_WriteReg(LCD_REG_80, 0x0000); /* Horizontal GRAM Start Address */
283 LCD_WriteReg(LCD_REG_81, 0x00EF); /* Horizontal GRAM End Address */
284 LCD_WriteReg(LCD_REG_82, 0x0000); /* Vertical GRAM Start Address */
285 LCD_WriteReg(LCD_REG_83, 0x013F); /* Vertical GRAM End Address */
286 LCD_WriteReg(LCD_REG_96, 0x2700); /* Gate Scan Line */
287 LCD_WriteReg(LCD_REG_97, 0x0001); /* NDL,VLE, REV */
288 LCD_WriteReg(LCD_REG_106, 0x0000); /* set scrolling line */
289 /* Partial Display Control ---------------------------------------------------*/
290 LCD_WriteReg(LCD_REG_128, 0x0000);
291 LCD_WriteReg(LCD_REG_129, 0x0000);
292 LCD_WriteReg(LCD_REG_130, 0x0000);
293 LCD_WriteReg(LCD_REG_131, 0x0000);
294 LCD_WriteReg(LCD_REG_132, 0x0000);
295 LCD_WriteReg(LCD_REG_133, 0x0000);
296 /* Panel Control -------------------------------------------------------------*/
297 LCD_WriteReg(LCD_REG_144, 0x0010);
298 LCD_WriteReg(LCD_REG_146, 0x0000);
299 LCD_WriteReg(LCD_REG_147, 0x0003);
300 LCD_WriteReg(LCD_REG_149, 0x0110);
301 LCD_WriteReg(LCD_REG_151, 0x0000);
302 LCD_WriteReg(LCD_REG_152, 0x0000);
303 /* Set GRAM write direction and BGR = 1 */
304 /* I/D=01 (Horizontal : increment, Vertical : decrement) */
305 /* AM=1 (address is updated in vertical writing direction) */
306 LCD_WriteReg(LCD_REG_3, 0x1018);
307 LCD_WriteReg(LCD_REG_7, 0x0173); /* 262K color and display ON */
308 LCD_SetFont(&LCD_DEFAULT_FONT);
309 }
310
311 /**
312 * @brief Sets the LCD Text and Background colors.
313 * @param _TextColor: specifies the Text Color.
314 * @param _BackColor: specifies the Background Color.
315 * @retval None
316 */
317 void LCD_SetColors(__IO uint16_t _TextColor, __IO uint16_t _BackColor)
318 {
319 TextColor = _TextColor;
320 BackColor = _BackColor;
321 }
322
323 /**
324 * @brief Gets the LCD Text and Background colors.
325 * @param _TextColor: pointer to the variable that will contain the Text
326 Color.
327 * @param _BackColor: pointer to the variable that will contain the Background
328 Color.
329 * @retval None
330 */
331 void LCD_GetColors(__IO uint16_t *_TextColor, __IO uint16_t *_BackColor)
332 {
333 *_TextColor = TextColor; *_BackColor = BackColor;
334 }
335
336 /**
337 * @brief Sets the Text color.
338 * @param Color: specifies the Text color code RGB(5-6-5).
339 * @retval None
340 */
341 void LCD_SetTextColor(__IO uint16_t Color)
342 {
343 TextColor = Color;
344 }
345
346
347 /**
348 * @brief Sets the Background color.
349 * @param Color: specifies the Background color code RGB(5-6-5).
350 * @retval None
351 */
352 void LCD_SetBackColor(__IO uint16_t Color)
353 {
354 BackColor = Color;
355 }
356
357 /**
358 * @brief Sets the Text Font.
359 * @param fonts: specifies the font to be used.
360 * @retval None
361 */
362 void LCD_SetFont(sFONT *fonts)
363 {
364 LCD_Currentfonts = fonts;
365 }
366
367 /**
368 * @brief Gets the Text Font.
369 * @param None.
370 * @retval the used font.
371 */
372 sFONT *LCD_GetFont(void)
373 {
374 return LCD_Currentfonts;
375 }
376
377 /**
378 * @brief Clears the selected line.
379 * @param Line: the Line to be cleared.
380 * This parameter can be one of the following values:
381 * @arg Linex: where x can be 0..n
382 * @retval None
383 */
384 void LCD_ClearLine(uint8_t Line)
385 {
386 uint16_t refcolumn = LCD_PIXEL_WIDTH - 1;
387 /* Send the string character by character on lCD */
388 while (((refcolumn + 1)&0xFFFF) >= LCD_Currentfonts->Width)
389 {
390 /* Display one character on LCD */
391 LCD_DisplayChar(Line, refcolumn, ' ');
392 /* Decrement the column position by 16 */
393 refcolumn -= LCD_Currentfonts->Width;
394 }
395 }
396
397
398 /**
399 * @brief Clears the hole LCD.
400 * @param Color: the color of the background.
401 * @retval None
402 */
403 void LCD_Clear(uint16_t Color)
404 {
405 uint32_t index = 0;
406
407 LCD_SetCursor(0x00, 0x013F);
408 LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
409 for(index = 0; index < 76800; index++)
410 {
411 LCD->LCD_RAM = Color;
412 }
413 }
414
415
416 /**
417 * @brief Sets the cursor position.
418 * @param Xpos: specifies the X position.
419 * @param Ypos: specifies the Y position.
420 * @retval None
421 */
422 void LCD_SetCursor(uint8_t Xpos, uint16_t Ypos)
423 {
424 LCD_WriteReg(LCD_REG_32, Xpos);
425 LCD_WriteReg(LCD_REG_33, Ypos);
426 }
427
428
429 /**
430 * @brief Draws a character on LCD.
431 * @param Xpos: the Line where to display the character shape.
432 * @param Ypos: start column address.
433 * @param c: pointer to the character data.
434 * @retval None
435 */
436 void LCD_DrawChar(uint8_t Xpos, uint16_t Ypos, const uint16_t *c)
437 {
438 uint32_t index = 0, i = 0;
439 uint8_t Xaddress = 0;
440
441 Xaddress = Xpos;
442
443 LCD_SetCursor(Xaddress, Ypos);
444
445 for(index = 0; index < LCD_Currentfonts->Height; index++)
446 {
447 LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
448 for(i = 0; i < LCD_Currentfonts->Width; i++)
449 {
450 if((((c[index] & ((0x80 << ((LCD_Currentfonts->Width / 12 ) * 8 ) ) >> i)) == 0x00) &&(LCD_Currentfonts->Width <= 12))||
451 (((c[index] & (0x1 << i)) == 0x00)&&(LCD_Currentfonts->Width > 12 )))
452
453 {
454 LCD_WriteRAM(BackColor);
455 }
456 else
457 {
458 LCD_WriteRAM(TextColor);
459 }
460 }
461 Xaddress++;
462 LCD_SetCursor(Xaddress, Ypos);
463 }
464 }
465
466
467 /**
468 * @brief Displays one character (16dots width, 24dots height).
469 * @param Line: the Line where to display the character shape .
470 * This parameter can be one of the following values:
471 * @arg Linex: where x can be 0..9
472 * @param Column: start column address.
473 * @param Ascii: character ascii code, must be between 0x20 and 0x7E.
474 * @retval None
475 */
476 void LCD_DisplayChar(uint8_t Line, uint16_t Column, uint8_t Ascii)
477 {
478 Ascii -= 32;
479 LCD_DrawChar(Line, Column, &LCD_Currentfonts->table[Ascii * LCD_Currentfonts->Height]);
480 }
481
482
483 /**
484 * @brief Displays a maximum of 20 char on the LCD.
485 * @param Line: the Line where to display the character shape .
486 * This parameter can be one of the following values:
487 * @arg Linex: where x can be 0..9
488 * @param *ptr: pointer to string to display on LCD.
489 * @retval None
490 */
491 void LCD_DisplayStringLine(uint8_t Line, uint8_t *ptr)
492 {
493 uint16_t refcolumn = LCD_PIXEL_WIDTH - 1;
494
495 /* Send the string character by character on lCD */
496 while ((*ptr != 0) & (((refcolumn + 1) & 0xFFFF) >= LCD_Currentfonts->Width))
497 {
498 /* Display one character on LCD */
499 LCD_DisplayChar(Line, refcolumn, *ptr);
500 /* Decrement the column position by 16 */
501 refcolumn -= LCD_Currentfonts->Width;
502 /* Point on the next character */
503 ptr++;
504 }
505 }
506
507
508 /**
509 * @brief Sets a display window
510 * @param Xpos: specifies the X buttom left position.
511 * @param Ypos: specifies the Y buttom left position.
512 * @param Height: display window height.
513 * @param Width: display window width.
514 * @retval None
515 */
516 void LCD_SetDisplayWindow(uint8_t Xpos, uint16_t Ypos, uint8_t Height, uint16_t Width)
517 {
518 /* Horizontal GRAM Start Address */
519 if(Xpos >= Height)
520 {
521 LCD_WriteReg(LCD_REG_80, (Xpos - Height + 1));
522 }
523 else
524 {
525 LCD_WriteReg(LCD_REG_80, 0);
526 }
527 /* Horizontal GRAM End Address */
528 LCD_WriteReg(LCD_REG_81, Xpos);
529 /* Vertical GRAM Start Address */
530 if(Ypos >= Width)
531 {
532 LCD_WriteReg(LCD_REG_82, (Ypos - Width + 1));
533 }
534 else
535 {
536 LCD_WriteReg(LCD_REG_82, 0);
537 }
538 /* Vertical GRAM End Address */
539 LCD_WriteReg(LCD_REG_83, Ypos);
540 LCD_SetCursor(Xpos, Ypos);
541 }
542
543
544 /**
545 * @brief Disables LCD Window mode.
546 * @param None
547 * @retval None
548 */
549 void LCD_WindowModeDisable(void)
550 {
551 LCD_SetDisplayWindow(239, 0x13F, 240, 320);
552 LCD_WriteReg(LCD_REG_3, 0x1018);
553 }
554
555
556 /**
557 * @brief Displays a line.
558 * @param Xpos: specifies the X position.
559 * @param Ypos: specifies the Y position.
560 * @param Length: line length.
561 * @param Direction: line direction.
562 * This parameter can be one of the following values: Vertical or Horizontal.
563 * @retval None
564 */
565 void LCD_DrawLine(uint8_t Xpos, uint16_t Ypos, uint16_t Length, uint8_t Direction)
566 {
567 uint32_t i = 0;
568
569 LCD_SetCursor(Xpos, Ypos);
570 if(Direction == LCD_DIR_HORIZONTAL)
571 {
572 LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
573 for(i = 0; i < Length; i++)
574 {
575 LCD_WriteRAM(TextColor);
576 }
577 }
578 else
579 {
580 for(i = 0; i < Length; i++)
581 {
582 LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
583 LCD_WriteRAM(TextColor);
584 Xpos++;
585 LCD_SetCursor(Xpos, Ypos);
586 }
587 }
588 }
589
590
591 /**
592 * @brief Displays a rectangle.
593 * @param Xpos: specifies the X position.
594 * @param Ypos: specifies the Y position.
595 * @param Height: display rectangle height.
596 * @param Width: display rectangle width.
597 * @retval None
598 */
599 void LCD_DrawRect(uint8_t Xpos, uint16_t Ypos, uint8_t Height, uint16_t Width)
600 {
601 LCD_DrawLine(Xpos, Ypos, Width, LCD_DIR_HORIZONTAL);
602 LCD_DrawLine((Xpos + Height), Ypos, Width, LCD_DIR_HORIZONTAL);
603
604 LCD_DrawLine(Xpos, Ypos, Height, LCD_DIR_VERTICAL);
605 LCD_DrawLine(Xpos, (Ypos - Width + 1), Height, LCD_DIR_VERTICAL);
606 }
607
608
609 /**
610 * @brief Displays a circle.
611 * @param Xpos: specifies the X position.
612 * @param Ypos: specifies the Y position.
613 * @param Radius
614 * @retval None
615 */
616 void LCD_DrawCircle(uint8_t Xpos, uint16_t Ypos, uint16_t Radius)
617 {
618 int32_t D;/* Decision Variable */
619 uint32_t CurX;/* Current X Value */
620 uint32_t CurY;/* Current Y Value */
621
622 D = 3 - (Radius << 1);
623 CurX = 0;
624 CurY = Radius;
625
626 while (CurX <= CurY)
627 {
628 LCD_SetCursor(Xpos + CurX, Ypos + CurY);
629 LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
630 LCD_WriteRAM(TextColor);
631 LCD_SetCursor(Xpos + CurX, Ypos - CurY);
632 LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
633 LCD_WriteRAM(TextColor);
634 LCD_SetCursor(Xpos - CurX, Ypos + CurY);
635 LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
636 LCD_WriteRAM(TextColor);
637 LCD_SetCursor(Xpos - CurX, Ypos - CurY);
638 LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
639 LCD_WriteRAM(TextColor);
640 LCD_SetCursor(Xpos + CurY, Ypos + CurX);
641 LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
642 LCD_WriteRAM(TextColor);
643 LCD_SetCursor(Xpos + CurY, Ypos - CurX);
644 LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
645 LCD_WriteRAM(TextColor);
646 LCD_SetCursor(Xpos - CurY, Ypos + CurX);
647 LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
648 LCD_WriteRAM(TextColor);
649 LCD_SetCursor(Xpos - CurY, Ypos - CurX);
650 LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
651 LCD_WriteRAM(TextColor);
652 if (D < 0)
653 {
654 D += (CurX << 2) + 6;
655 }
656 else
657 {
658 D += ((CurX - CurY) << 2) + 10;
659 CurY--;
660 }
661 CurX++;
662 }
663 }
664
665
666 /**
667 * @brief Displays a monocolor picture.
668 * @param Pict: pointer to the picture array.
669 * @retval None
670 */
671 void LCD_DrawMonoPict(const uint32_t *Pict)
672 {
673 uint32_t index = 0, i = 0;
674 LCD_SetCursor(0, (LCD_PIXEL_WIDTH - 1));
675 LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
676 for(index = 0; index < 2400; index++)
677 {
678 for(i = 0; i < 32; i++)
679 {
680 if((Pict[index] & (1 << i)) == 0x00)
681 {
682 LCD_WriteRAM(BackColor);
683 }
684 else
685 {
686 LCD_WriteRAM(TextColor);
687 }
688 }
689 }
690 }
691
692
693 /**
694 * @brief Displays a bitmap picture loaded in the internal Flash.
695 * @param BmpAddress: Bmp picture address in the internal Flash.
696 * @retval None
697 */
698 void LCD_WriteBMP(uint32_t BmpAddress)
699 {
700 uint32_t index = 0, size = 0;
701 /* Read bitmap size */
702 size = *(__IO uint16_t *) (BmpAddress + 2);
703 size |= (*(__IO uint16_t *) (BmpAddress + 4)) << 16;
704 /* Get bitmap data address offset */
705 index = *(__IO uint16_t *) (BmpAddress + 10);
706 index |= (*(__IO uint16_t *) (BmpAddress + 12)) << 16;
707 size = (size - index)/2;
708 BmpAddress += index;
709 /* Set GRAM write direction and BGR = 1 */
710 /* I/D=00 (Horizontal : decrement, Vertical : decrement) */
711 /* AM=1 (address is updated in vertical writing direction) */
712 LCD_WriteReg(LCD_REG_3, 0x1008);
713
714 LCD_WriteRAM_Prepare();
715
716 for(index = 0; index < size; index++)
717 {
718 LCD_WriteRAM(*(__IO uint16_t *)BmpAddress);
719 BmpAddress += 2;
720 }
721
722 /* Set GRAM write direction and BGR = 1 */
723 /* I/D = 01 (Horizontal : increment, Vertical : decrement) */
724 /* AM = 1 (address is updated in vertical writing direction) */
725 LCD_WriteReg(LCD_REG_3, 0x1018);
726 }
727
728 /**
729 * @brief Displays a full rectangle.
730 * @param Xpos: specifies the X position.
731 * @param Ypos: specifies the Y position.
732 * @param Height: rectangle height.
733 * @param Width: rectangle width.
734 * @retval None
735 */
736 void LCD_DrawFullRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
737 {
738 LCD_SetTextColor(TextColor);
739
740 LCD_DrawLine(Xpos, Ypos, Width, LCD_DIR_HORIZONTAL);
741 LCD_DrawLine((Xpos + Height), Ypos, Width, LCD_DIR_HORIZONTAL);
742
743 LCD_DrawLine(Xpos, Ypos, Height, LCD_DIR_VERTICAL);
744 LCD_DrawLine(Xpos, (Ypos - Width + 1), Height, LCD_DIR_VERTICAL);
745
746 Width -= 2;
747 Height--;
748 Ypos--;
749
750 LCD_SetTextColor(BackColor);
751
752 while(Height--)
753 {
754 LCD_DrawLine(++Xpos, Ypos, Width, LCD_DIR_HORIZONTAL);
755 }
756
757 LCD_SetTextColor(TextColor);
758 }
759
760 /**
761 * @brief Displays a full circle.
762 * @param Xpos: specifies the X position.
763 * @param Ypos: specifies the Y position.
764 * @param Radius
765 * @retval None
766 */
767 void LCD_DrawFullCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius)
768 {
769 int32_t D; /* Decision Variable */
770 uint32_t CurX;/* Current X Value */
771 uint32_t CurY;/* Current Y Value */
772
773 D = 3 - (Radius << 1);
774
775 CurX = 0;
776 CurY = Radius;
777
778 LCD_SetTextColor(BackColor);
779
780 while (CurX <= CurY)
781 {
782 if(CurY > 0)
783 {
784 LCD_DrawLine(Xpos - CurX, Ypos + CurY, 2*CurY, LCD_DIR_HORIZONTAL);
785 LCD_DrawLine(Xpos + CurX, Ypos + CurY, 2*CurY, LCD_DIR_HORIZONTAL);
786 }
787
788 if(CurX > 0)
789 {
790 LCD_DrawLine(Xpos - CurY, Ypos + CurX, 2*CurX, LCD_DIR_HORIZONTAL);
791 LCD_DrawLine(Xpos + CurY, Ypos + CurX, 2*CurX, LCD_DIR_HORIZONTAL);
792 }
793 if (D < 0)
794 {
795 D += (CurX << 2) + 6;
796 }
797 else
798 {
799 D += ((CurX - CurY) << 2) + 10;
800 CurY--;
801 }
802 CurX++;
803 }
804
805 LCD_SetTextColor(TextColor);
806 LCD_DrawCircle(Xpos, Ypos, Radius);
807 }
808
809 /**
810 * @brief Displays an uni line (between two points).
811 * @param x1: specifies the point 1 x position.
812 * @param y1: specifies the point 1 y position.
813 * @param x2: specifies the point 2 x position.
814 * @param y2: specifies the point 2 y position.
815 * @retval None
816 */
817 void LCD_DrawUniLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
818 {
819 int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0,
820 yinc1 = 0, yinc2 = 0, den = 0, num = 0, numadd = 0, numpixels = 0,
821 curpixel = 0;
822
823 deltax = ABS(x2 - x1); /* The difference between the x's */
824 deltay = ABS(y2 - y1); /* The difference between the y's */
825 x = x1; /* Start x off at the first pixel */
826 y = y1; /* Start y off at the first pixel */
827
828 if (x2 >= x1) /* The x-values are increasing */
829 {
830 xinc1 = 1;
831 xinc2 = 1;
832 }
833 else /* The x-values are decreasing */
834 {
835 xinc1 = -1;
836 xinc2 = -1;
837 }
838
839 if (y2 >= y1) /* The y-values are increasing */
840 {
841 yinc1 = 1;
842 yinc2 = 1;
843 }
844 else /* The y-values are decreasing */
845 {
846 yinc1 = -1;
847 yinc2 = -1;
848 }
849
850 if (deltax >= deltay) /* There is at least one x-value for every y-value */
851 {
852 xinc1 = 0; /* Don't change the x when numerator >= denominator */
853 yinc2 = 0; /* Don't change the y for every iteration */
854 den = deltax;
855 num = deltax / 2;
856 numadd = deltay;
857 numpixels = deltax; /* There are more x-values than y-values */
858 }
859 else /* There is at least one y-value for every x-value */
860 {
861 xinc2 = 0; /* Don't change the x for every iteration */
862 yinc1 = 0; /* Don't change the y when numerator >= denominator */
863 den = deltay;
864 num = deltay / 2;
865 numadd = deltax;
866 numpixels = deltay; /* There are more y-values than x-values */
867 }
868
869 for (curpixel = 0; curpixel <= numpixels; curpixel++)
870 {
871 PutPixel(x, y); /* Draw the current pixel */
872 num += numadd; /* Increase the numerator by the top of the fraction */
873 if (num >= den) /* Check if numerator >= denominator */
874 {
875 num -= den; /* Calculate the new numerator value */
876 x += xinc1; /* Change the x as appropriate */
877 y += yinc1; /* Change the y as appropriate */
878 }
879 x += xinc2; /* Change the x as appropriate */
880 y += yinc2; /* Change the y as appropriate */
881 }
882 }
883
884 /**
885 * @brief Displays an polyline (between many points).
886 * @param Points: pointer to the points array.
887 * @param PointCount: Number of points.
888 * @retval None
889 */
890 void LCD_PolyLine(pPoint Points, uint16_t PointCount)
891 {
892 int16_t X = 0, Y = 0;
893
894 if(PointCount < 2)
895 {
896 return;
897 }
898
899 while(--PointCount)
900 {
901 X = Points->X;
902 Y = Points->Y;
903 Points++;
904 LCD_DrawUniLine(X, Y, Points->X, Points->Y);
905 }
906 }
907
908 /**
909 * @brief Displays an relative polyline (between many points).
910 * @param Points: pointer to the points array.
911 * @param PointCount: Number of points.
912 * @param Closed: specifies if the draw is closed or not.
913 * 1: closed, 0 : not closed.
914 * @retval None
915 */
916 static void LCD_PolyLineRelativeClosed(pPoint Points, uint16_t PointCount, uint16_t Closed)
917 {
918 int16_t X = 0, Y = 0;
919 pPoint First = Points;
920
921 if(PointCount < 2)
922 {
923 return;
924 }
925 X = Points->X;
926 Y = Points->Y;
927 while(--PointCount)
928 {
929 Points++;
930 LCD_DrawUniLine(X, Y, X + Points->X, Y + Points->Y);
931 X = X + Points->X;
932 Y = Y + Points->Y;
933 }
934 if(Closed)
935 {
936 LCD_DrawUniLine(First->X, First->Y, X, Y);
937 }
938 }
939
940 /**
941 * @brief Displays a closed polyline (between many points).
942 * @param Points: pointer to the points array.
943 * @param PointCount: Number of points.
944 * @retval None
945 */
946 void LCD_ClosedPolyLine(pPoint Points, uint16_t PointCount)
947 {
948 LCD_PolyLine(Points, PointCount);
949 LCD_DrawUniLine(Points->X, Points->Y, (Points+PointCount-1)->X, (Points+PointCount-1)->Y);
950 }
951
952 /**
953 * @brief Displays a relative polyline (between many points).
954 * @param Points: pointer to the points array.
955 * @param PointCount: Number of points.
956 * @retval None
957 */
958 void LCD_PolyLineRelative(pPoint Points, uint16_t PointCount)
959 {
960 LCD_PolyLineRelativeClosed(Points, PointCount, 0);
961 }
962
963 /**
964 * @brief Displays a closed relative polyline (between many points).
965 * @param Points: pointer to the points array.
966 * @param PointCount: Number of points.
967 * @retval None
968 */
969 void LCD_ClosedPolyLineRelative(pPoint Points, uint16_t PointCount)
970 {
971 LCD_PolyLineRelativeClosed(Points, PointCount, 1);
972 }
973
974
975 /**
976 * @brief Displays a full polyline (between many points).
977 * @param Points: pointer to the points array.
978 * @param PointCount: Number of points.
979 * @retval None
980 */
981 void LCD_FillPolyLine(pPoint Points, uint16_t PointCount)
982 {
983 /* public-domain code by Darel Rex Finley, 2007 */
984 uint16_t nodes = 0, nodeX[MAX_POLY_CORNERS], pixelX = 0, pixelY = 0, i = 0,
985 j = 0, swap = 0;
986 uint16_t IMAGE_LEFT = 0, IMAGE_RIGHT = 0, IMAGE_TOP = 0, IMAGE_BOTTOM = 0;
987
988 IMAGE_LEFT = IMAGE_RIGHT = Points->X;
989 IMAGE_TOP= IMAGE_BOTTOM = Points->Y;
990
991 for(i = 1; i < PointCount; i++)
992 {
993 pixelX = POLY_X(i);
994 if(pixelX < IMAGE_LEFT)
995 {
996 IMAGE_LEFT = pixelX;
997 }
998 if(pixelX > IMAGE_RIGHT)
999 {
1000 IMAGE_RIGHT = pixelX;
1001 }
1002
1003 pixelY = POLY_Y(i);
1004 if(pixelY < IMAGE_TOP)
1005 {
1006 IMAGE_TOP = pixelY;
1007 }
1008 if(pixelY > IMAGE_BOTTOM)
1009 {
1010 IMAGE_BOTTOM = pixelY;
1011 }
1012 }
1013
1014 LCD_SetTextColor(BackColor);
1015
1016 /* Loop through the rows of the image. */
1017 for (pixelY = IMAGE_TOP; pixelY < IMAGE_BOTTOM; pixelY++)
1018 {
1019 /* Build a list of nodes. */
1020 nodes = 0; j = PointCount-1;
1021
1022 for (i = 0; i < PointCount; i++)
1023 {
1024 if (POLY_Y(i)<(double) pixelY && POLY_Y(j)>=(double) pixelY || POLY_Y(j)<(double) pixelY && POLY_Y(i)>=(double) pixelY)
1025 {
1026 nodeX[nodes++]=(int) (POLY_X(i)+((pixelY-POLY_Y(i))*(POLY_X(j)-POLY_X(i)))/(POLY_Y(j)-POLY_Y(i)));
1027 }
1028 j = i;
1029 }
1030
1031 /* Sort the nodes, via a simple "Bubble" sort. */
1032 i = 0;
1033 while (i < nodes-1)
1034 {
1035 if (nodeX[i]>nodeX[i+1])
1036 {
1037 swap = nodeX[i];
1038 nodeX[i] = nodeX[i+1];
1039 nodeX[i+1] = swap;
1040 if(i)
1041 {
1042 i--;
1043 }
1044 }
1045 else
1046 {
1047 i++;
1048 }
1049 }
1050
1051 /* Fill the pixels between node pairs. */
1052 for (i = 0; i < nodes; i+=2)
1053 {
1054 if(nodeX[i] >= IMAGE_RIGHT)
1055 {
1056 break;
1057 }
1058 if(nodeX[i+1] > IMAGE_LEFT)
1059 {
1060 if (nodeX[i] < IMAGE_LEFT)
1061 {
1062 nodeX[i]=IMAGE_LEFT;
1063 }
1064 if(nodeX[i+1] > IMAGE_RIGHT)
1065 {
1066 nodeX[i+1] = IMAGE_RIGHT;
1067 }
1068 LCD_SetTextColor(BackColor);
1069 LCD_DrawLine(pixelY, nodeX[i+1], nodeX[i+1] - nodeX[i], LCD_DIR_HORIZONTAL);
1070 LCD_SetTextColor(TextColor);
1071 PutPixel(pixelY, nodeX[i+1]);
1072 PutPixel(pixelY, nodeX[i]);
1073 /* for (j=nodeX[i]; j<nodeX[i+1]; j++) PutPixel(j,pixelY); */
1074 }
1075 }
1076 }
1077
1078 /* draw the edges */
1079 LCD_SetTextColor(TextColor);
1080 }
1081
1082 /**
1083 * @brief Writes to the selected LCD register.
1084 * @param LCD_Reg: address of the selected register.
1085 * @param LCD_RegValue: value to write to the selected register.
1086 * @retval None
1087 */
1088 void LCD_WriteReg(uint8_t LCD_Reg, uint16_t LCD_RegValue)
1089 {
1090 /* Write 16-bit Index, then Write Reg */
1091 LCD->LCD_REG = LCD_Reg;
1092 /* Write 16-bit Reg */
1093 LCD->LCD_RAM = LCD_RegValue;
1094 }
1095
1096
1097 /**
1098 * @brief Reads the selected LCD Register.
1099 * @param LCD_Reg: address of the selected register.
1100 * @retval LCD Register Value.
1101 */
1102 uint16_t LCD_ReadReg(uint8_t LCD_Reg)
1103 {
1104 /* Write 16-bit Index (then Read Reg) */
1105 LCD->LCD_REG = LCD_Reg;
1106 /* Read 16-bit Reg */
1107 return (LCD->LCD_RAM);
1108 }
1109
1110
1111 /**
1112 * @brief Prepare to write to the LCD RAM.
1113 * @param None
1114 * @retval None
1115 */
1116 void LCD_WriteRAM_Prepare(void)
1117 {
1118 LCD->LCD_REG = LCD_REG_34;
1119 }
1120
1121
1122 /**
1123 * @brief Writes to the LCD RAM.
1124 * @param RGB_Code: the pixel color in RGB mode (5-6-5).
1125 * @retval None
1126 */
1127 void LCD_WriteRAM(uint16_t RGB_Code)
1128 {
1129 /* Write 16-bit GRAM Reg */
1130 LCD->LCD_RAM = RGB_Code;
1131 }
1132
1133
1134 /**
1135 * @brief Reads the LCD RAM.
1136 * @param None
1137 * @retval LCD RAM Value.
1138 */
1139 uint16_t LCD_ReadRAM(void)
1140 {
1141 /* Write 16-bit Index (then Read Reg) */
1142 LCD->LCD_REG = LCD_REG_34; /* Select GRAM Reg */
1143 /* Read 16-bit Reg */
1144 return LCD->LCD_RAM;
1145 }
1146
1147
1148 /**
1149 * @brief Power on the LCD.
1150 * @param None
1151 * @retval None
1152 */
1153 void LCD_PowerOn(void)
1154 {
1155 /* Power On sequence ---------------------------------------------------------*/
1156 LCD_WriteReg(LCD_REG_16, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
1157 LCD_WriteReg(LCD_REG_17, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
1158 LCD_WriteReg(LCD_REG_18, 0x0000); /* VREG1OUT voltage */
1159 LCD_WriteReg(LCD_REG_19, 0x0000); /* VDV[4:0] for VCOM amplitude*/
1160 _delay_(20); /* Dis-charge capacitor power voltage (200ms) */
1161 LCD_WriteReg(LCD_REG_16, 0x17B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
1162 LCD_WriteReg(LCD_REG_17, 0x0137); /* DC1[2:0], DC0[2:0], VC[2:0] */
1163 _delay_(5); /* Delay 50 ms */
1164 LCD_WriteReg(LCD_REG_18, 0x0139); /* VREG1OUT voltage */
1165 _delay_(5); /* Delay 50 ms */
1166 LCD_WriteReg(LCD_REG_19, 0x1d00); /* VDV[4:0] for VCOM amplitude */
1167 LCD_WriteReg(LCD_REG_41, 0x0013); /* VCM[4:0] for VCOMH */
1168 _delay_(5); /* Delay 50 ms */
1169 LCD_WriteReg(LCD_REG_7, 0x0173); /* 262K color and display ON */
1170 }
1171
1172
1173 /**
1174 * @brief Enables the Display.
1175 * @param None
1176 * @retval None
1177 */
1178 void LCD_DisplayOn(void)
1179 {
1180 /* Display On */
1181 LCD_WriteReg(LCD_REG_7, 0x0173); /* 262K color and display ON */
1182 }
1183
1184
1185 /**
1186 * @brief Disables the Display.
1187 * @param None
1188 * @retval None
1189 */
1190 void LCD_DisplayOff(void)
1191 {
1192 /* Display Off */
1193 LCD_WriteReg(LCD_REG_7, 0x0);
1194 }
1195
1196
1197 /**
1198 * @brief Configures LCD Control lines (FSMC Pins) in alternate function mode.
1199 * @param None
1200 * @retval None
1201 */
1202 void LCD_CtrlLinesConfig(void)
1203 {
1204 GPIO_InitTypeDef GPIO_InitStructure;
1205 /* Enable FSMC, GPIOD, GPIOE, GPIOF, GPIOG and AFIO clocks */
1206 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
1207 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE |
1208 RCC_APB2Periph_GPIOF | RCC_APB2Periph_GPIOG |
1209 RCC_APB2Periph_AFIO, ENABLE);
1210 /* Set PD.00(D2), PD.01(D3), PD.04(NOE), PD.05(NWE), PD.08(D13), PD.09(D14),
1211 PD.10(D15), PD.14(D0), PD.15(D1) as alternate function push pull */
1212 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5 |
1213 GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_14 |
1214 GPIO_Pin_15;
1215 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
1216 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
1217 GPIO_Init(GPIOD, &GPIO_InitStructure);
1218 /* Set PE.07(D4), PE.08(D5), PE.09(D6), PE.10(D7), PE.11(D8), PE.12(D9), PE.13(D10),
1219 PE.14(D11), PE.15(D12) as alternate function push pull */
1220 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 |
1221 GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 |
1222 GPIO_Pin_15;
1223 GPIO_Init(GPIOE, &GPIO_InitStructure);
1224 /* Set PF.00(A0 (RS)) as alternate function push pull */
1225 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
1226 GPIO_Init(GPIOF, &GPIO_InitStructure);
1227 /* Set PG.12(NE4 (LCD/CS)) as alternate function push pull - CE3(LCD /CS) */
1228 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
1229 GPIO_Init(GPIOG, &GPIO_InitStructure);
1230 }
1231
1232
1233 /**
1234 * @brief Configures the Parallel interface (FSMC) for LCD(Parallel mode)
1235 * @param None
1236 * @retval None
1237 */
1238 void LCD_FSMCConfig(void)
1239 {
1240 FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
1241 FSMC_NORSRAMTimingInitTypeDef p;
1242 /*-- FSMC Configuration ------------------------------------------------------*/
1243 /*----------------------- SRAM Bank 4 ----------------------------------------*/
1244 /* FSMC_Bank1_NORSRAM4 configuration */
1245 p.FSMC_AddressSetupTime = 1;
1246 p.FSMC_AddressHoldTime = 0;
1247 p.FSMC_DataSetupTime = 2;
1248 p.FSMC_BusTurnAroundDuration = 0;
1249 p.FSMC_CLKDivision = 0;
1250 p.FSMC_DataLatency = 0;
1251 p.FSMC_AccessMode = FSMC_AccessMode_A;
1252 /* Color LCD configuration ------------------------------------
1253 LCD configured as follow:
1254 - Data/Address MUX = Disable
1255 - Memory Type = SRAM
1256 - Data Width = 16bit
1257 - Write Operation = Enable
1258 - Extended Mode = Enable
1259 - Asynchronous Wait = Disable */
1260 FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM4;
1261 FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;
1262 FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM;
1263 FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b;
1264 FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
1265 FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable;
1266 FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
1267 FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;
1268 FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
1269 FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;
1270 FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
1271 FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
1272 FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
1273 FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;
1274 FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;
1275 FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
1276 /* BANK 4 (of NOR/SRAM Bank 1~4) is enabled */
1277 FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM4, ENABLE);
1278 }
1279
1280 /**
1281 * @brief Displays a pixel.
1282 * @param x: pixel x.
1283 * @param y: pixel y.
1284 * @retval None
1285 */
1286 static void PutPixel(int16_t x, int16_t y)
1287 {
1288 if(x < 0 || x > 239 || y < 0 || y > 319)
1289 {
1290 return;
1291 }
1292 LCD_DrawLine(x, y, 1, LCD_DIR_HORIZONTAL);
1293 }
1294
1295 #ifndef USE_Delay
1296 /**
1297 * @brief Inserts a delay time.
1298 * @param nCount: specifies the delay time length.
1299 * @retval None
1300 */
1301 static void delay(vu32 nCount)
1302 {
1303 vu32 index = 0;
1304 for(index = (100000 * nCount); index != 0; index--)
1305 {
1306 }
1307 }
1308 #endif /* USE_Delay*/
1309 /**
1310 * @}
1311 */
1312
1313 /**
1314 * @}
1315 */
1316
1317 /**
1318 * @}
1319 */
1320
1321 /**
1322 * @}
1323 */
1324
1325 /**
1326 * @}
1327 */
1328
1329 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/