Mercurial > ~darius > hgwebdir.cgi > stm32temp
comparison libs/STM32F10x_StdPeriph_Lib_V3.5.0/Utilities/STM32_EVAL/STM32L152_EVAL/stm32l152_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 stm32l152_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 (LCD_ILI9320), | |
8 * AM-240320LDTNQW00H (LCD_SPFD5408B) Liquid Crystal Display Module | |
9 * of STM32L152-EVAL board RevB. | |
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>© COPYRIGHT 2011 STMicroelectronics</center></h2> | |
21 ****************************************************************************** | |
22 */ | |
23 | |
24 /* Includes ------------------------------------------------------------------*/ | |
25 #include "stm32l152_eval_lcd.h" | |
26 #include "../Common/fonts.c" | |
27 | |
28 /** @addtogroup Utilities | |
29 * @{ | |
30 */ | |
31 | |
32 /** @addtogroup STM32_EVAL | |
33 * @{ | |
34 */ | |
35 | |
36 /** @addtogroup STM32L152_EVAL | |
37 * @{ | |
38 */ | |
39 | |
40 /** @defgroup STM32L152_EVAL_LCD | |
41 * @brief This file includes the LCD driver for AM-240320L8TNQW00H (LCD_ILI9320), | |
42 * AM-240320LDTNQW00H (LCD_SPFD5408B) Liquid Crystal Display Module | |
43 * of STM32L152-EVAL board. | |
44 * @{ | |
45 */ | |
46 | |
47 /** @defgroup STM32L152_EVAL_LCD_Private_Types | |
48 * @{ | |
49 */ | |
50 /** | |
51 * @} | |
52 */ | |
53 | |
54 /** @defgroup STM32L152_EVAL_LCD_Private_Defines | |
55 * @{ | |
56 */ | |
57 #define LCD_ILI9320 0x9320 | |
58 #define LCD_SPFD5408 0x5408 | |
59 #define START_BYTE 0x70 | |
60 #define SET_INDEX 0x00 | |
61 #define READ_STATUS 0x01 | |
62 #define LCD_WRITE_REG 0x02 | |
63 #define LCD_READ_REG 0x03 | |
64 #define MAX_POLY_CORNERS 200 | |
65 #define POLY_Y(Z) ((int32_t)((Points + Z)->X)) | |
66 #define POLY_X(Z) ((int32_t)((Points + Z)->Y)) | |
67 /** | |
68 * @} | |
69 */ | |
70 | |
71 /** @defgroup STM32L152_EVAL_LCD_Private_Macros | |
72 * @{ | |
73 */ | |
74 #define ABS(X) ((X) > 0 ? (X) : -(X)) | |
75 /** | |
76 * @} | |
77 */ | |
78 | |
79 /** @defgroup STM32L152_EVAL_LCD_Private_Variables | |
80 * @{ | |
81 */ | |
82 static sFONT *LCD_Currentfonts; | |
83 /* Global variables to set the written text color */ | |
84 static __IO uint16_t TextColor = 0x0000, BackColor = 0xFFFF; | |
85 static __IO uint32_t LCDType = LCD_SPFD5408; | |
86 /** | |
87 * @} | |
88 */ | |
89 | |
90 /** @defgroup STM32L152_EVAL_LCD_Private_Function_Prototypes | |
91 * @{ | |
92 */ | |
93 #ifndef USE_Delay | |
94 static void delay(__IO uint32_t nCount); | |
95 #endif /* USE_Delay*/ | |
96 | |
97 static void PutPixel(int16_t x, int16_t y); | |
98 static void LCD_PolyLineRelativeClosed(pPoint Points, uint16_t PointCount, uint16_t Closed); | |
99 | |
100 /** | |
101 * @} | |
102 */ | |
103 | |
104 /** @defgroup STM32L152_EVAL_LCD_Private_Functions | |
105 * @{ | |
106 */ | |
107 | |
108 /** | |
109 * @brief DeInitializes the LCD. | |
110 * @param None | |
111 * @retval None | |
112 */ | |
113 void STM32L152_LCD_DeInit(void) | |
114 { | |
115 GPIO_InitTypeDef GPIO_InitStructure; | |
116 | |
117 /*!< LCD Display Off */ | |
118 LCD_DisplayOff(); | |
119 | |
120 /*!< LCD_SPI disable */ | |
121 SPI_Cmd(LCD_SPI, DISABLE); | |
122 | |
123 /*!< LCD_SPI DeInit */ | |
124 SPI_DeInit(LCD_SPI); | |
125 | |
126 /*!< Disable SPI clock */ | |
127 RCC_APB1PeriphClockCmd(LCD_SPI_CLK, DISABLE); | |
128 | |
129 /* Configure NCS in Output Push-Pull mode */ | |
130 GPIO_InitStructure.GPIO_Pin = LCD_NCS_PIN; | |
131 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; | |
132 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; | |
133 GPIO_Init(LCD_NCS_GPIO_PORT, &GPIO_InitStructure); | |
134 | |
135 /* Configure SPI pins: SCK, MISO and MOSI */ | |
136 GPIO_InitStructure.GPIO_Pin = LCD_SPI_SCK_PIN; | |
137 GPIO_Init(LCD_SPI_SCK_GPIO_PORT, &GPIO_InitStructure); | |
138 | |
139 GPIO_InitStructure.GPIO_Pin = LCD_SPI_MISO_PIN; | |
140 GPIO_Init(LCD_SPI_MISO_GPIO_PORT, &GPIO_InitStructure); | |
141 | |
142 GPIO_InitStructure.GPIO_Pin = LCD_SPI_MOSI_PIN; | |
143 GPIO_Init(LCD_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure); | |
144 } | |
145 | |
146 /** | |
147 * @brief Setups the LCD. | |
148 * @param None | |
149 * @retval None | |
150 */ | |
151 void LCD_Setup(void) | |
152 { | |
153 /* Configure the LCD Control pins --------------------------------------------*/ | |
154 LCD_CtrlLinesConfig(); | |
155 | |
156 /* Configure the LCD_SPI interface ----------------------------------------------*/ | |
157 LCD_SPIConfig(); | |
158 | |
159 if(LCDType == LCD_SPFD5408) | |
160 { | |
161 /* Start Initial Sequence --------------------------------------------------*/ | |
162 LCD_WriteReg(LCD_REG_227, 0x3008); /* Set internal timing */ | |
163 LCD_WriteReg(LCD_REG_231, 0x0012); /* Set internal timing */ | |
164 LCD_WriteReg(LCD_REG_239, 0x1231); /* Set internal timing */ | |
165 LCD_WriteReg(LCD_REG_1, 0x0100); /* Set SS and SM bit */ | |
166 LCD_WriteReg(LCD_REG_2, 0x0700); /* Set 1 line inversion */ | |
167 LCD_WriteReg(LCD_REG_3, 0x1030); /* Set GRAM write direction and BGR=1. */ | |
168 LCD_WriteReg(LCD_REG_4, 0x0000); /* Resize register */ | |
169 LCD_WriteReg(LCD_REG_8, 0x0202); /* Set the back porch and front porch */ | |
170 LCD_WriteReg(LCD_REG_9, 0x0000); /* Set non-display area refresh cycle ISC[3:0] */ | |
171 LCD_WriteReg(LCD_REG_10, 0x0000); /* FMARK function */ | |
172 LCD_WriteReg(LCD_REG_12, 0x0000); /* RGB interface setting */ | |
173 LCD_WriteReg(LCD_REG_13, 0x0000); /* Frame marker Position */ | |
174 LCD_WriteReg(LCD_REG_15, 0x0000); /* RGB interface polarity */ | |
175 /* Power On sequence -------------------------------------------------------*/ | |
176 LCD_WriteReg(LCD_REG_16, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */ | |
177 LCD_WriteReg(LCD_REG_17, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */ | |
178 LCD_WriteReg(LCD_REG_18, 0x0000); /* VREG1OUT voltage */ | |
179 LCD_WriteReg(LCD_REG_19, 0x0000); /* VDV[4:0] for VCOM amplitude */ | |
180 _delay_(20); /* Dis-charge capacitor power voltage (200ms) */ | |
181 LCD_WriteReg(LCD_REG_17, 0x0007); /* DC1[2:0], DC0[2:0], VC[2:0] */ | |
182 _delay_(5); /* Delay 50 ms */ | |
183 LCD_WriteReg(LCD_REG_16, 0x12B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */ | |
184 _delay_(5); /* Delay 50 ms */ | |
185 LCD_WriteReg(LCD_REG_18, 0x01BD); /* External reference voltage= Vci */ | |
186 _delay_(5); /* Delay 50 ms */ | |
187 LCD_WriteReg(LCD_REG_19, 0x1400); /* VDV[4:0] for VCOM amplitude */ | |
188 LCD_WriteReg(LCD_REG_41, 0x000E); /* VCM[4:0] for VCOMH */ | |
189 _delay_(5); /* Delay 50 ms */ | |
190 LCD_WriteReg(LCD_REG_32, 0x0000); /* GRAM horizontal Address */ | |
191 LCD_WriteReg(LCD_REG_33, 0x013F); /* GRAM Vertical Address */ | |
192 /* Adjust the Gamma Curve --------------------------------------------------*/ | |
193 LCD_WriteReg(LCD_REG_48, 0x0007); | |
194 LCD_WriteReg(LCD_REG_49, 0x0302); | |
195 LCD_WriteReg(LCD_REG_50, 0x0105); | |
196 LCD_WriteReg(LCD_REG_53, 0x0206); | |
197 LCD_WriteReg(LCD_REG_54, 0x0808); | |
198 LCD_WriteReg(LCD_REG_55, 0x0206); | |
199 LCD_WriteReg(LCD_REG_56, 0x0504); | |
200 LCD_WriteReg(LCD_REG_57, 0x0007); | |
201 LCD_WriteReg(LCD_REG_60, 0x0105); | |
202 LCD_WriteReg(LCD_REG_61, 0x0808); | |
203 /* Set GRAM area -----------------------------------------------------------*/ | |
204 LCD_WriteReg(LCD_REG_80, 0x0000); /* Horizontal GRAM Start Address */ | |
205 LCD_WriteReg(LCD_REG_81, 0x00EF); /* Horizontal GRAM End Address */ | |
206 LCD_WriteReg(LCD_REG_82, 0x0000); /* Vertical GRAM Start Address */ | |
207 LCD_WriteReg(LCD_REG_83, 0x013F); /* Vertical GRAM End Address */ | |
208 LCD_WriteReg(LCD_REG_96, 0xA700); /* Gate Scan Line */ | |
209 LCD_WriteReg(LCD_REG_97, 0x0001); /* NDL,VLE, REV */ | |
210 LCD_WriteReg(LCD_REG_106, 0x0000); /* Set scrolling line */ | |
211 /* Partial Display Control -------------------------------------------------*/ | |
212 LCD_WriteReg(LCD_REG_128, 0x0000); | |
213 LCD_WriteReg(LCD_REG_129, 0x0000); | |
214 LCD_WriteReg(LCD_REG_130, 0x0000); | |
215 LCD_WriteReg(LCD_REG_131, 0x0000); | |
216 LCD_WriteReg(LCD_REG_132, 0x0000); | |
217 LCD_WriteReg(LCD_REG_133, 0x0000); | |
218 /* Panel Control -----------------------------------------------------------*/ | |
219 LCD_WriteReg(LCD_REG_144, 0x0010); | |
220 LCD_WriteReg(LCD_REG_146, 0x0000); | |
221 LCD_WriteReg(LCD_REG_147, 0x0003); | |
222 LCD_WriteReg(LCD_REG_149, 0x0110); | |
223 LCD_WriteReg(LCD_REG_151, 0x0000); | |
224 LCD_WriteReg(LCD_REG_152, 0x0000); | |
225 /* Set GRAM write direction and BGR = 1 | |
226 I/D=01 (Horizontal : increment, Vertical : decrement) | |
227 AM=1 (address is updated in vertical writing direction) */ | |
228 LCD_WriteReg(LCD_REG_3, 0x1018); | |
229 LCD_WriteReg(LCD_REG_7, 0x0112); /* 262K color and display ON */ | |
230 } | |
231 else if(LCDType == LCD_ILI9320) | |
232 { | |
233 _delay_(5); /* Delay 50 ms */ | |
234 /* Start Initial Sequence ------------------------------------------------*/ | |
235 LCD_WriteReg(LCD_REG_229, 0x8000); /* Set the internal vcore voltage */ | |
236 LCD_WriteReg(LCD_REG_0, 0x0001); /* Start internal OSC. */ | |
237 LCD_WriteReg(LCD_REG_1, 0x0100); /* set SS and SM bit */ | |
238 LCD_WriteReg(LCD_REG_2, 0x0700); /* set 1 line inversion */ | |
239 LCD_WriteReg(LCD_REG_3, 0x1030); /* set GRAM write direction and BGR=1. */ | |
240 LCD_WriteReg(LCD_REG_4, 0x0000); /* Resize register */ | |
241 LCD_WriteReg(LCD_REG_8, 0x0202); /* set the back porch and front porch */ | |
242 LCD_WriteReg(LCD_REG_9, 0x0000); /* set non-display area refresh cycle ISC[3:0] */ | |
243 LCD_WriteReg(LCD_REG_10, 0x0000); /* FMARK function */ | |
244 LCD_WriteReg(LCD_REG_12, 0x0000); /* RGB interface setting */ | |
245 LCD_WriteReg(LCD_REG_13, 0x0000); /* Frame marker Position */ | |
246 LCD_WriteReg(LCD_REG_15, 0x0000); /* RGB interface polarity */ | |
247 /* Power On sequence -----------------------------------------------------*/ | |
248 LCD_WriteReg(LCD_REG_16, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */ | |
249 LCD_WriteReg(LCD_REG_17, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */ | |
250 LCD_WriteReg(LCD_REG_18, 0x0000); /* VREG1OUT voltage */ | |
251 LCD_WriteReg(LCD_REG_19, 0x0000); /* VDV[4:0] for VCOM amplitude */ | |
252 _delay_(20); /* Dis-charge capacitor power voltage (200ms) */ | |
253 LCD_WriteReg(LCD_REG_16, 0x17B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */ | |
254 LCD_WriteReg(LCD_REG_17, 0x0137); /* DC1[2:0], DC0[2:0], VC[2:0] */ | |
255 _delay_(5); /* Delay 50 ms */ | |
256 LCD_WriteReg(LCD_REG_18, 0x0139); /* VREG1OUT voltage */ | |
257 _delay_(5); /* Delay 50 ms */ | |
258 LCD_WriteReg(LCD_REG_19, 0x1d00); /* VDV[4:0] for VCOM amplitude */ | |
259 LCD_WriteReg(LCD_REG_41, 0x0013); /* VCM[4:0] for VCOMH */ | |
260 _delay_(5); /* Delay 50 ms */ | |
261 LCD_WriteReg(LCD_REG_32, 0x0000); /* GRAM horizontal Address */ | |
262 LCD_WriteReg(LCD_REG_33, 0x0000); /* GRAM Vertical Address */ | |
263 /* Adjust the Gamma Curve ------------------------------------------------*/ | |
264 LCD_WriteReg(LCD_REG_48, 0x0006); | |
265 LCD_WriteReg(LCD_REG_49, 0x0101); | |
266 LCD_WriteReg(LCD_REG_50, 0x0003); | |
267 LCD_WriteReg(LCD_REG_53, 0x0106); | |
268 LCD_WriteReg(LCD_REG_54, 0x0b02); | |
269 LCD_WriteReg(LCD_REG_55, 0x0302); | |
270 LCD_WriteReg(LCD_REG_56, 0x0707); | |
271 LCD_WriteReg(LCD_REG_57, 0x0007); | |
272 LCD_WriteReg(LCD_REG_60, 0x0600); | |
273 LCD_WriteReg(LCD_REG_61, 0x020b); | |
274 | |
275 /* Set GRAM area ---------------------------------------------------------*/ | |
276 LCD_WriteReg(LCD_REG_80, 0x0000); /* Horizontal GRAM Start Address */ | |
277 LCD_WriteReg(LCD_REG_81, 0x00EF); /* Horizontal GRAM End Address */ | |
278 LCD_WriteReg(LCD_REG_82, 0x0000); /* Vertical GRAM Start Address */ | |
279 LCD_WriteReg(LCD_REG_83, 0x013F); /* Vertical GRAM End Address */ | |
280 LCD_WriteReg(LCD_REG_96, 0x2700); /* Gate Scan Line */ | |
281 LCD_WriteReg(LCD_REG_97, 0x0001); /* NDL,VLE, REV */ | |
282 LCD_WriteReg(LCD_REG_106, 0x0000); /* set scrolling line */ | |
283 /* Partial Display Control -----------------------------------------------*/ | |
284 LCD_WriteReg(LCD_REG_128, 0x0000); | |
285 LCD_WriteReg(LCD_REG_129, 0x0000); | |
286 LCD_WriteReg(LCD_REG_130, 0x0000); | |
287 LCD_WriteReg(LCD_REG_131, 0x0000); | |
288 LCD_WriteReg(LCD_REG_132, 0x0000); | |
289 LCD_WriteReg(LCD_REG_133, 0x0000); | |
290 /* Panel Control ---------------------------------------------------------*/ | |
291 LCD_WriteReg(LCD_REG_144, 0x0010); | |
292 LCD_WriteReg(LCD_REG_146, 0x0000); | |
293 LCD_WriteReg(LCD_REG_147, 0x0003); | |
294 LCD_WriteReg(LCD_REG_149, 0x0110); | |
295 LCD_WriteReg(LCD_REG_151, 0x0000); | |
296 LCD_WriteReg(LCD_REG_152, 0x0000); | |
297 /* Set GRAM write direction and BGR = 1 */ | |
298 /* I/D=01 (Horizontal : increment, Vertical : decrement) */ | |
299 /* AM=1 (address is updated in vertical writing direction) */ | |
300 LCD_WriteReg(LCD_REG_3, 0x1018); | |
301 LCD_WriteReg(LCD_REG_7, 0x0173); /* 262K color and display ON */ | |
302 } | |
303 } | |
304 | |
305 | |
306 /** | |
307 * @brief Initializes the LCD. | |
308 * @param None | |
309 * @retval None | |
310 */ | |
311 void STM32L152_LCD_Init(void) | |
312 { | |
313 /* Setups the LCD */ | |
314 LCD_Setup(); | |
315 | |
316 /* Try to read new LCD controller ID 0x5408 */ | |
317 if (LCD_ReadReg(LCD_REG_0) == LCD_SPFD5408) | |
318 { | |
319 LCDType = LCD_SPFD5408; | |
320 } | |
321 else | |
322 { | |
323 LCDType = LCD_ILI9320; | |
324 /* Setups the LCD */ | |
325 LCD_Setup(); | |
326 } | |
327 | |
328 LCD_SetFont(&LCD_DEFAULT_FONT); | |
329 } | |
330 | |
331 /** | |
332 * @brief Sets the LCD Text and Background colors. | |
333 * @param _TextColor: specifies the Text Color. | |
334 * @param _BackColor: specifies the Background Color. | |
335 * @retval None | |
336 */ | |
337 void LCD_SetColors(__IO uint16_t _TextColor, __IO uint16_t _BackColor) | |
338 { | |
339 TextColor = _TextColor; | |
340 BackColor = _BackColor; | |
341 } | |
342 | |
343 /** | |
344 * @brief Gets the LCD Text and Background colors. | |
345 * @param _TextColor: pointer to the variable that will contain the Text | |
346 Color. | |
347 * @param _BackColor: pointer to the variable that will contain the Background | |
348 Color. | |
349 * @retval None | |
350 */ | |
351 void LCD_GetColors(__IO uint16_t *_TextColor, __IO uint16_t *_BackColor) | |
352 { | |
353 *_TextColor = TextColor; *_BackColor = BackColor; | |
354 } | |
355 | |
356 /** | |
357 * @brief Sets the Text color. | |
358 * @param Color: specifies the Text color code RGB(5-6-5). | |
359 * @retval None | |
360 */ | |
361 void LCD_SetTextColor(__IO uint16_t Color) | |
362 { | |
363 TextColor = Color; | |
364 } | |
365 | |
366 | |
367 /** | |
368 * @brief Sets the Background color. | |
369 * @param Color: specifies the Background color code RGB(5-6-5). | |
370 * @retval None | |
371 */ | |
372 void LCD_SetBackColor(__IO uint16_t Color) | |
373 { | |
374 BackColor = Color; | |
375 } | |
376 | |
377 /** | |
378 * @brief Sets the Text Font. | |
379 * @param fonts: specifies the font to be used. | |
380 * @retval None | |
381 */ | |
382 void LCD_SetFont(sFONT *fonts) | |
383 { | |
384 LCD_Currentfonts = fonts; | |
385 } | |
386 | |
387 /** | |
388 * @brief Gets the Text Font. | |
389 * @param None. | |
390 * @retval the used font. | |
391 */ | |
392 sFONT *LCD_GetFont(void) | |
393 { | |
394 return LCD_Currentfonts; | |
395 } | |
396 | |
397 /** | |
398 * @brief Clears the selected line. | |
399 * @param Line: the Line to be cleared. | |
400 * This parameter can be one of the following values: | |
401 * @arg Linex: where x can be 0..n | |
402 * @retval None | |
403 */ | |
404 void LCD_ClearLine(uint8_t Line) | |
405 { | |
406 uint16_t refcolumn = LCD_PIXEL_WIDTH - 1; | |
407 | |
408 /* Send the string character by character on lCD */ | |
409 while (((refcolumn + 1) & 0xFFFF) >= LCD_Currentfonts->Width) | |
410 { | |
411 /* Display one character on LCD */ | |
412 LCD_DisplayChar(Line, refcolumn, ' '); | |
413 /* Decrement the column position by 16 */ | |
414 refcolumn -= LCD_Currentfonts->Width; | |
415 } | |
416 } | |
417 | |
418 | |
419 /** | |
420 * @brief Clears the hole LCD. | |
421 * @param Color: the color of the background. | |
422 * @retval None | |
423 */ | |
424 void LCD_Clear(uint16_t Color) | |
425 { | |
426 uint32_t index = 0; | |
427 | |
428 LCD_SetCursor(0x00, 0x013F); | |
429 | |
430 LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */ | |
431 | |
432 for(index = 0; index < 76800; index++) | |
433 { | |
434 LCD_WriteRAM(Color); | |
435 } | |
436 | |
437 LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET); | |
438 | |
439 } | |
440 | |
441 | |
442 /** | |
443 * @brief Sets the cursor position. | |
444 * @param Xpos: specifies the X position. | |
445 * @param Ypos: specifies the Y position. | |
446 * @retval None | |
447 */ | |
448 void LCD_SetCursor(uint8_t Xpos, uint16_t Ypos) | |
449 { | |
450 LCD_WriteReg(LCD_REG_32, Xpos); | |
451 LCD_WriteReg(LCD_REG_33, Ypos); | |
452 } | |
453 | |
454 | |
455 /** | |
456 * @brief Draws a character on LCD. | |
457 * @param Xpos: the Line where to display the character shape. | |
458 * @param Ypos: start column address. | |
459 * @param c: pointer to the character data. | |
460 * @retval None | |
461 */ | |
462 void LCD_DrawChar(uint8_t Xpos, uint16_t Ypos, const uint16_t *c) | |
463 { | |
464 uint32_t index = 0, i = 0; | |
465 uint8_t Xaddress = 0; | |
466 | |
467 Xaddress = Xpos; | |
468 | |
469 LCD_SetCursor(Xaddress, Ypos); | |
470 | |
471 for(index = 0; index < LCD_Currentfonts->Height; index++) | |
472 { | |
473 LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */ | |
474 | |
475 for(i = 0; i < LCD_Currentfonts->Width; i++) | |
476 { | |
477 if((((c[index] & ((0x80 << ((LCD_Currentfonts->Width / 12 ) * 8 ) ) >> i)) == 0x00) &&(LCD_Currentfonts->Width <= 12))|| | |
478 (((c[index] & (0x1 << i)) == 0x00)&&(LCD_Currentfonts->Width > 12 ))) | |
479 | |
480 { | |
481 LCD_WriteRAM(BackColor); | |
482 } | |
483 else | |
484 { | |
485 LCD_WriteRAM(TextColor); | |
486 } | |
487 } | |
488 | |
489 LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET); | |
490 Xaddress++; | |
491 LCD_SetCursor(Xaddress, Ypos); | |
492 } | |
493 } | |
494 | |
495 | |
496 /** | |
497 * @brief Displays one character (16dots width, 24dots height). | |
498 * @param Line: the Line where to display the character shape . | |
499 * This parameter can be one of the following values: | |
500 * @arg Linex: where x can be 0..9 | |
501 * @param Column: start column address. | |
502 * @param Ascii: character ascii code, must be between 0x20 and 0x7E. | |
503 * @retval None | |
504 */ | |
505 void LCD_DisplayChar(uint8_t Line, uint16_t Column, uint8_t Ascii) | |
506 { | |
507 Ascii -= 32; | |
508 LCD_DrawChar(Line, Column, &LCD_Currentfonts->table[Ascii * LCD_Currentfonts->Height]); | |
509 } | |
510 | |
511 | |
512 /** | |
513 * @brief Displays a maximum of 20 char on the LCD. | |
514 * @param Line: the Line where to display the character shape . | |
515 * This parameter can be one of the following values: | |
516 * @arg Linex: where x can be 0..9 | |
517 * @param *ptr: pointer to string to display on LCD. | |
518 * @retval None | |
519 */ | |
520 void LCD_DisplayStringLine(uint8_t Line, uint8_t *ptr) | |
521 { | |
522 uint16_t refcolumn = LCD_PIXEL_WIDTH - 1; | |
523 | |
524 /* Send the string character by character on lCD */ | |
525 while ((*ptr != 0) & (((refcolumn + 1) & 0xFFFF) >= LCD_Currentfonts->Width)) | |
526 { | |
527 /* Display one character on LCD */ | |
528 LCD_DisplayChar(Line, refcolumn, *ptr); | |
529 /* Decrement the column position by 16 */ | |
530 refcolumn -= LCD_Currentfonts->Width; | |
531 /* Point on the next character */ | |
532 ptr++; | |
533 } | |
534 } | |
535 | |
536 | |
537 /** | |
538 * @brief Sets a display window | |
539 * @param Xpos: specifies the X buttom left position. | |
540 * @param Ypos: specifies the Y buttom left position. | |
541 * @param Height: display window height. | |
542 * @param Width: display window width. | |
543 * @retval None | |
544 */ | |
545 void LCD_SetDisplayWindow(uint8_t Xpos, uint16_t Ypos, uint8_t Height, uint16_t Width) | |
546 { | |
547 /* Horizontal GRAM Start Address */ | |
548 if(Xpos >= Height) | |
549 { | |
550 LCD_WriteReg(LCD_REG_80, (Xpos - Height + 1)); | |
551 } | |
552 else | |
553 { | |
554 LCD_WriteReg(LCD_REG_80, 0); | |
555 } | |
556 /* Horizontal GRAM End Address */ | |
557 LCD_WriteReg(LCD_REG_81, Xpos); | |
558 /* Vertical GRAM Start Address */ | |
559 if(Ypos >= Width) | |
560 { | |
561 LCD_WriteReg(LCD_REG_82, (Ypos - Width + 1)); | |
562 } | |
563 else | |
564 { | |
565 LCD_WriteReg(LCD_REG_82, 0); | |
566 } | |
567 /* Vertical GRAM End Address */ | |
568 LCD_WriteReg(LCD_REG_83, Ypos); | |
569 | |
570 LCD_SetCursor(Xpos, Ypos); | |
571 } | |
572 | |
573 | |
574 /** | |
575 * @brief Disables LCD Window mode. | |
576 * @param None | |
577 * @retval None | |
578 */ | |
579 void LCD_WindowModeDisable(void) | |
580 { | |
581 LCD_SetDisplayWindow(239, 0x13F, 240, 320); | |
582 LCD_WriteReg(LCD_REG_3, 0x1018); | |
583 } | |
584 | |
585 /** | |
586 * @brief Displays a line. | |
587 * @param Xpos: specifies the X position. | |
588 * @param Ypos: specifies the Y position. | |
589 * @param Length: line length. | |
590 * @param Direction: line direction. | |
591 * This parameter can be one of the following values: Vertical or Horizontal. | |
592 * @retval None | |
593 */ | |
594 void LCD_DrawLine(uint8_t Xpos, uint16_t Ypos, uint16_t Length, uint8_t Direction) | |
595 { | |
596 uint32_t i = 0; | |
597 | |
598 LCD_SetCursor(Xpos, Ypos); | |
599 | |
600 if(Direction == LCD_DIR_HORIZONTAL) | |
601 { | |
602 LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */ | |
603 | |
604 for(i = 0; i < Length; i++) | |
605 { | |
606 LCD_WriteRAM(TextColor); | |
607 } | |
608 LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET); | |
609 } | |
610 else | |
611 { | |
612 for(i = 0; i < Length; i++) | |
613 { | |
614 LCD_WriteRAMWord(TextColor); | |
615 Xpos++; | |
616 LCD_SetCursor(Xpos, Ypos); | |
617 } | |
618 } | |
619 } | |
620 | |
621 | |
622 /** | |
623 * @brief Displays a rectangle. | |
624 * @param Xpos: specifies the X position. | |
625 * @param Ypos: specifies the Y position. | |
626 * @param Height: display rectangle height. | |
627 * @param Width: display rectangle width. | |
628 * @retval None | |
629 */ | |
630 void LCD_DrawRect(uint8_t Xpos, uint16_t Ypos, uint8_t Height, uint16_t Width) | |
631 { | |
632 LCD_DrawLine(Xpos, Ypos, Width, LCD_DIR_HORIZONTAL); | |
633 LCD_DrawLine((Xpos + Height), Ypos, Width, LCD_DIR_HORIZONTAL); | |
634 | |
635 LCD_DrawLine(Xpos, Ypos, Height, LCD_DIR_VERTICAL); | |
636 LCD_DrawLine(Xpos, (Ypos - Width + 1), Height, LCD_DIR_VERTICAL); | |
637 } | |
638 | |
639 | |
640 /** | |
641 * @brief Displays a circle. | |
642 * @param Xpos: specifies the X position. | |
643 * @param Ypos: specifies the Y position. | |
644 * @param Radius | |
645 * @retval None | |
646 */ | |
647 void LCD_DrawCircle(uint8_t Xpos, uint16_t Ypos, uint16_t Radius) | |
648 { | |
649 int32_t D;/* Decision Variable */ | |
650 uint32_t CurX;/* Current X Value */ | |
651 uint32_t CurY;/* Current Y Value */ | |
652 | |
653 D = 3 - (Radius << 1); | |
654 CurX = 0; | |
655 CurY = Radius; | |
656 | |
657 while (CurX <= CurY) | |
658 { | |
659 LCD_SetCursor(Xpos + CurX, Ypos + CurY); | |
660 LCD_WriteRAMWord(TextColor); | |
661 LCD_SetCursor(Xpos + CurX, Ypos - CurY); | |
662 LCD_WriteRAMWord(TextColor); | |
663 | |
664 LCD_SetCursor(Xpos - CurX, Ypos + CurY); | |
665 LCD_WriteRAMWord(TextColor); | |
666 | |
667 LCD_SetCursor(Xpos - CurX, Ypos - CurY); | |
668 LCD_WriteRAMWord(TextColor); | |
669 | |
670 LCD_SetCursor(Xpos + CurY, Ypos + CurX); | |
671 LCD_WriteRAMWord(TextColor); | |
672 | |
673 LCD_SetCursor(Xpos + CurY, Ypos - CurX); | |
674 LCD_WriteRAMWord(TextColor); | |
675 | |
676 LCD_SetCursor(Xpos - CurY, Ypos + CurX); | |
677 LCD_WriteRAMWord(TextColor); | |
678 | |
679 LCD_SetCursor(Xpos - CurY, Ypos - CurX); | |
680 LCD_WriteRAMWord(TextColor); | |
681 | |
682 if (D < 0) | |
683 { | |
684 D += (CurX << 2) + 6; | |
685 } | |
686 else | |
687 { | |
688 D += ((CurX - CurY) << 2) + 10; | |
689 CurY--; | |
690 } | |
691 CurX++; | |
692 } | |
693 } | |
694 | |
695 | |
696 /** | |
697 * @brief Displays a monocolor picture. | |
698 * @param Pict: pointer to the picture array. | |
699 * @retval None | |
700 */ | |
701 void LCD_DrawMonoPict(const uint32_t *Pict) | |
702 { | |
703 uint32_t index = 0, i = 0; | |
704 LCD_SetCursor(0, (LCD_PIXEL_WIDTH - 1)); | |
705 | |
706 LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */ | |
707 | |
708 for(index = 0; index < 2400; index++) | |
709 { | |
710 for(i = 0; i < 32; i++) | |
711 { | |
712 if((Pict[index] & (1 << i)) == 0x00) | |
713 { | |
714 LCD_WriteRAM(BackColor); | |
715 } | |
716 else | |
717 { | |
718 LCD_WriteRAM(TextColor); | |
719 } | |
720 } | |
721 } | |
722 | |
723 LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET); | |
724 } | |
725 | |
726 #ifdef USE_LCD_DrawBMP | |
727 /** | |
728 * @brief Displays a bitmap picture loaded in the SPI Flash. | |
729 * @param BmpAddress: Bmp picture address in the SPI Flash. | |
730 * @retval None | |
731 */ | |
732 void LCD_DrawBMP(uint32_t BmpAddress) | |
733 { | |
734 uint32_t i = 0, size = 0; | |
735 /* Read bitmap size */ | |
736 sFLASH_ReadBuffer((uint8_t*)&size, BmpAddress + 2, 4); | |
737 /* get bitmap data address offset */ | |
738 sFLASH_ReadBuffer((uint8_t*)&i, BmpAddress + 10, 4); | |
739 | |
740 size = (size - i)/2; | |
741 sFLASH_StartReadSequence(BmpAddress + i); | |
742 /* Disable LCD_SPI */ | |
743 SPI_Cmd(LCD_SPI, DISABLE); | |
744 /* SPI in 16-bit mode */ | |
745 SPI_DataSizeConfig(LCD_SPI, SPI_DataSize_16b); | |
746 /* Enable LCD_SPI */ | |
747 SPI_Cmd(LCD_SPI, ENABLE); | |
748 | |
749 if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408)) | |
750 { | |
751 /* Set GRAM write direction and BGR = 1 */ | |
752 /* I/D=00 (Horizontal : decrement, Vertical : decrement) */ | |
753 /* AM=1 (address is updated in vertical writing direction) */ | |
754 LCD_WriteReg(LCD_REG_3, 0x1008); | |
755 LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */ | |
756 } | |
757 | |
758 /* Read bitmap data from SPI Flash and send them to LCD */ | |
759 for(i = 0; i < size; i++) | |
760 { | |
761 LCD_WriteRAM(__REV16(sFLASH_SendHalfWord(0xA5A5))); | |
762 } | |
763 if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408)) | |
764 { | |
765 LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET); | |
766 } | |
767 | |
768 /* Deselect the FLASH: Chip Select high */ | |
769 sFLASH_CS_HIGH(); | |
770 /* Disable LCD_SPI */ | |
771 SPI_Cmd(LCD_SPI, DISABLE); | |
772 /* SPI in 8-bit mode */ | |
773 SPI_DataSizeConfig(LCD_SPI, SPI_DataSize_8b); | |
774 /* Enable LCD_SPI */ | |
775 SPI_Cmd(LCD_SPI, ENABLE); | |
776 | |
777 if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408)) | |
778 { | |
779 /* Set GRAM write direction and BGR = 1 */ | |
780 /* I/D = 01 (Horizontal : increment, Vertical : decrement) */ | |
781 /* AM = 1 (address is updated in vertical writing direction) */ | |
782 LCD_WriteReg(LCD_REG_3, 0x1018); | |
783 } | |
784 } | |
785 #endif /* USE_LCD_DrawBMP */ | |
786 | |
787 /** | |
788 * @brief Displays a full rectangle. | |
789 * @param Xpos: specifies the X position. | |
790 * @param Ypos: specifies the Y position. | |
791 * @param Height: rectangle height. | |
792 * @param Width: rectangle width. | |
793 * @retval None | |
794 */ | |
795 void LCD_DrawFullRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height) | |
796 { | |
797 LCD_SetTextColor(TextColor); | |
798 | |
799 LCD_DrawLine(Xpos, Ypos, Width, LCD_DIR_HORIZONTAL); | |
800 LCD_DrawLine((Xpos + Height), Ypos, Width, LCD_DIR_HORIZONTAL); | |
801 | |
802 LCD_DrawLine(Xpos, Ypos, Height, LCD_DIR_VERTICAL); | |
803 LCD_DrawLine(Xpos, (Ypos - Width + 1), Height, LCD_DIR_VERTICAL); | |
804 | |
805 Width -= 2; | |
806 Height--; | |
807 Ypos--; | |
808 | |
809 LCD_SetTextColor(BackColor); | |
810 | |
811 while(Height--) | |
812 { | |
813 LCD_DrawLine(++Xpos, Ypos, Width, LCD_DIR_HORIZONTAL); | |
814 } | |
815 | |
816 LCD_SetTextColor(TextColor); | |
817 } | |
818 | |
819 /** | |
820 * @brief Displays a full circle. | |
821 * @param Xpos: specifies the X position. | |
822 * @param Ypos: specifies the Y position. | |
823 * @param Radius | |
824 * @retval None | |
825 */ | |
826 void LCD_DrawFullCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius) | |
827 { | |
828 int32_t D; /* Decision Variable */ | |
829 uint32_t CurX;/* Current X Value */ | |
830 uint32_t CurY;/* Current Y Value */ | |
831 | |
832 D = 3 - (Radius << 1); | |
833 | |
834 CurX = 0; | |
835 CurY = Radius; | |
836 | |
837 LCD_SetTextColor(BackColor); | |
838 | |
839 while (CurX <= CurY) | |
840 { | |
841 if(CurY > 0) | |
842 { | |
843 LCD_DrawLine(Xpos - CurX, Ypos + CurY, 2*CurY, LCD_DIR_HORIZONTAL); | |
844 LCD_DrawLine(Xpos + CurX, Ypos + CurY, 2*CurY, LCD_DIR_HORIZONTAL); | |
845 } | |
846 | |
847 if(CurX > 0) | |
848 { | |
849 LCD_DrawLine(Xpos - CurY, Ypos + CurX, 2*CurX, LCD_DIR_HORIZONTAL); | |
850 LCD_DrawLine(Xpos + CurY, Ypos + CurX, 2*CurX, LCD_DIR_HORIZONTAL); | |
851 } | |
852 if (D < 0) | |
853 { | |
854 D += (CurX << 2) + 6; | |
855 } | |
856 else | |
857 { | |
858 D += ((CurX - CurY) << 2) + 10; | |
859 CurY--; | |
860 } | |
861 CurX++; | |
862 } | |
863 | |
864 LCD_SetTextColor(TextColor); | |
865 LCD_DrawCircle(Xpos, Ypos, Radius); | |
866 } | |
867 | |
868 /** | |
869 * @brief Displays an uni line (between two points). | |
870 * @param x1: specifies the point 1 x position. | |
871 * @param y1: specifies the point 1 y position. | |
872 * @param x2: specifies the point 2 x position. | |
873 * @param y2: specifies the point 2 y position. | |
874 * @retval None | |
875 */ | |
876 void LCD_DrawUniLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2) | |
877 { | |
878 int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0, | |
879 yinc1 = 0, yinc2 = 0, den = 0, num = 0, numadd = 0, numpixels = 0, | |
880 curpixel = 0; | |
881 | |
882 deltax = ABS(x2 - x1); /* The difference between the x's */ | |
883 deltay = ABS(y2 - y1); /* The difference between the y's */ | |
884 x = x1; /* Start x off at the first pixel */ | |
885 y = y1; /* Start y off at the first pixel */ | |
886 | |
887 if (x2 >= x1) /* The x-values are increasing */ | |
888 { | |
889 xinc1 = 1; | |
890 xinc2 = 1; | |
891 } | |
892 else /* The x-values are decreasing */ | |
893 { | |
894 xinc1 = -1; | |
895 xinc2 = -1; | |
896 } | |
897 | |
898 if (y2 >= y1) /* The y-values are increasing */ | |
899 { | |
900 yinc1 = 1; | |
901 yinc2 = 1; | |
902 } | |
903 else /* The y-values are decreasing */ | |
904 { | |
905 yinc1 = -1; | |
906 yinc2 = -1; | |
907 } | |
908 | |
909 if (deltax >= deltay) /* There is at least one x-value for every y-value */ | |
910 { | |
911 xinc1 = 0; /* Don't change the x when numerator >= denominator */ | |
912 yinc2 = 0; /* Don't change the y for every iteration */ | |
913 den = deltax; | |
914 num = deltax / 2; | |
915 numadd = deltay; | |
916 numpixels = deltax; /* There are more x-values than y-values */ | |
917 } | |
918 else /* There is at least one y-value for every x-value */ | |
919 { | |
920 xinc2 = 0; /* Don't change the x for every iteration */ | |
921 yinc1 = 0; /* Don't change the y when numerator >= denominator */ | |
922 den = deltay; | |
923 num = deltay / 2; | |
924 numadd = deltax; | |
925 numpixels = deltay; /* There are more y-values than x-values */ | |
926 } | |
927 | |
928 for (curpixel = 0; curpixel <= numpixels; curpixel++) | |
929 { | |
930 PutPixel(x, y); /* Draw the current pixel */ | |
931 num += numadd; /* Increase the numerator by the top of the fraction */ | |
932 if (num >= den) /* Check if numerator >= denominator */ | |
933 { | |
934 num -= den; /* Calculate the new numerator value */ | |
935 x += xinc1; /* Change the x as appropriate */ | |
936 y += yinc1; /* Change the y as appropriate */ | |
937 } | |
938 x += xinc2; /* Change the x as appropriate */ | |
939 y += yinc2; /* Change the y as appropriate */ | |
940 } | |
941 } | |
942 | |
943 /** | |
944 * @brief Displays an polyline (between many points). | |
945 * @param Points: pointer to the points array. | |
946 * @param PointCount: Number of points. | |
947 * @retval None | |
948 */ | |
949 void LCD_PolyLine(pPoint Points, uint16_t PointCount) | |
950 { | |
951 int16_t X = 0, Y = 0; | |
952 | |
953 if(PointCount < 2) | |
954 { | |
955 return; | |
956 } | |
957 | |
958 while(--PointCount) | |
959 { | |
960 X = Points->X; | |
961 Y = Points->Y; | |
962 Points++; | |
963 LCD_DrawUniLine(X, Y, Points->X, Points->Y); | |
964 } | |
965 } | |
966 | |
967 /** | |
968 * @brief Displays an relative polyline (between many points). | |
969 * @param Points: pointer to the points array. | |
970 * @param PointCount: Number of points. | |
971 * @param Closed: specifies if the draw is closed or not. | |
972 * 1: closed, 0 : not closed. | |
973 * @retval None | |
974 */ | |
975 static void LCD_PolyLineRelativeClosed(pPoint Points, uint16_t PointCount, uint16_t Closed) | |
976 { | |
977 int16_t X = 0, Y = 0; | |
978 pPoint First = Points; | |
979 | |
980 if(PointCount < 2) | |
981 { | |
982 return; | |
983 } | |
984 X = Points->X; | |
985 Y = Points->Y; | |
986 while(--PointCount) | |
987 { | |
988 Points++; | |
989 LCD_DrawUniLine(X, Y, X + Points->X, Y + Points->Y); | |
990 X = X + Points->X; | |
991 Y = Y + Points->Y; | |
992 } | |
993 if(Closed) | |
994 { | |
995 LCD_DrawUniLine(First->X, First->Y, X, Y); | |
996 } | |
997 } | |
998 | |
999 /** | |
1000 * @brief Displays a closed polyline (between many points). | |
1001 * @param Points: pointer to the points array. | |
1002 * @param PointCount: Number of points. | |
1003 * @retval None | |
1004 */ | |
1005 void LCD_ClosedPolyLine(pPoint Points, uint16_t PointCount) | |
1006 { | |
1007 LCD_PolyLine(Points, PointCount); | |
1008 LCD_DrawUniLine(Points->X, Points->Y, (Points+PointCount-1)->X, (Points+PointCount-1)->Y); | |
1009 } | |
1010 | |
1011 /** | |
1012 * @brief Displays a relative polyline (between many points). | |
1013 * @param Points: pointer to the points array. | |
1014 * @param PointCount: Number of points. | |
1015 * @retval None | |
1016 */ | |
1017 void LCD_PolyLineRelative(pPoint Points, uint16_t PointCount) | |
1018 { | |
1019 LCD_PolyLineRelativeClosed(Points, PointCount, 0); | |
1020 } | |
1021 | |
1022 /** | |
1023 * @brief Displays a closed relative polyline (between many points). | |
1024 * @param Points: pointer to the points array. | |
1025 * @param PointCount: Number of points. | |
1026 * @retval None | |
1027 */ | |
1028 void LCD_ClosedPolyLineRelative(pPoint Points, uint16_t PointCount) | |
1029 { | |
1030 LCD_PolyLineRelativeClosed(Points, PointCount, 1); | |
1031 } | |
1032 | |
1033 | |
1034 /** | |
1035 * @brief Displays a full polyline (between many points). | |
1036 * @param Points: pointer to the points array. | |
1037 * @param PointCount: Number of points. | |
1038 * @retval None | |
1039 */ | |
1040 void LCD_FillPolyLine(pPoint Points, uint16_t PointCount) | |
1041 { | |
1042 /* public-domain code by Darel Rex Finley, 2007 */ | |
1043 uint16_t nodes = 0, nodeX[MAX_POLY_CORNERS], pixelX = 0, pixelY = 0, i = 0, | |
1044 j = 0, swap = 0; | |
1045 uint16_t IMAGE_LEFT = 0, IMAGE_RIGHT = 0, IMAGE_TOP = 0, IMAGE_BOTTOM = 0; | |
1046 | |
1047 IMAGE_LEFT = IMAGE_RIGHT = Points->X; | |
1048 IMAGE_TOP= IMAGE_BOTTOM = Points->Y; | |
1049 | |
1050 for(i = 1; i < PointCount; i++) | |
1051 { | |
1052 pixelX = POLY_X(i); | |
1053 if(pixelX < IMAGE_LEFT) | |
1054 { | |
1055 IMAGE_LEFT = pixelX; | |
1056 } | |
1057 if(pixelX > IMAGE_RIGHT) | |
1058 { | |
1059 IMAGE_RIGHT = pixelX; | |
1060 } | |
1061 | |
1062 pixelY = POLY_Y(i); | |
1063 if(pixelY < IMAGE_TOP) | |
1064 { | |
1065 IMAGE_TOP = pixelY; | |
1066 } | |
1067 if(pixelY > IMAGE_BOTTOM) | |
1068 { | |
1069 IMAGE_BOTTOM = pixelY; | |
1070 } | |
1071 } | |
1072 | |
1073 LCD_SetTextColor(BackColor); | |
1074 | |
1075 /* Loop through the rows of the image. */ | |
1076 for (pixelY = IMAGE_TOP; pixelY < IMAGE_BOTTOM; pixelY++) | |
1077 { | |
1078 /* Build a list of nodes. */ | |
1079 nodes = 0; j = PointCount-1; | |
1080 | |
1081 for (i = 0; i < PointCount; i++) | |
1082 { | |
1083 if (POLY_Y(i)<(double) pixelY && POLY_Y(j)>=(double) pixelY || POLY_Y(j)<(double) pixelY && POLY_Y(i)>=(double) pixelY) | |
1084 { | |
1085 nodeX[nodes++]=(int) (POLY_X(i)+((pixelY-POLY_Y(i))*(POLY_X(j)-POLY_X(i)))/(POLY_Y(j)-POLY_Y(i))); | |
1086 } | |
1087 j = i; | |
1088 } | |
1089 | |
1090 /* Sort the nodes, via a simple "Bubble" sort. */ | |
1091 i = 0; | |
1092 while (i < nodes-1) | |
1093 { | |
1094 if (nodeX[i]>nodeX[i+1]) | |
1095 { | |
1096 swap = nodeX[i]; | |
1097 nodeX[i] = nodeX[i+1]; | |
1098 nodeX[i+1] = swap; | |
1099 if(i) | |
1100 { | |
1101 i--; | |
1102 } | |
1103 } | |
1104 else | |
1105 { | |
1106 i++; | |
1107 } | |
1108 } | |
1109 | |
1110 /* Fill the pixels between node pairs. */ | |
1111 for (i = 0; i < nodes; i+=2) | |
1112 { | |
1113 if(nodeX[i] >= IMAGE_RIGHT) | |
1114 { | |
1115 break; | |
1116 } | |
1117 if(nodeX[i+1] > IMAGE_LEFT) | |
1118 { | |
1119 if (nodeX[i] < IMAGE_LEFT) | |
1120 { | |
1121 nodeX[i]=IMAGE_LEFT; | |
1122 } | |
1123 if(nodeX[i+1] > IMAGE_RIGHT) | |
1124 { | |
1125 nodeX[i+1] = IMAGE_RIGHT; | |
1126 } | |
1127 LCD_SetTextColor(BackColor); | |
1128 LCD_DrawLine(pixelY, nodeX[i+1], nodeX[i+1] - nodeX[i], LCD_DIR_HORIZONTAL); | |
1129 LCD_SetTextColor(TextColor); | |
1130 PutPixel(pixelY, nodeX[i+1]); | |
1131 PutPixel(pixelY, nodeX[i]); | |
1132 /* for (j=nodeX[i]; j<nodeX[i+1]; j++) PutPixel(j,pixelY); */ | |
1133 } | |
1134 } | |
1135 } | |
1136 | |
1137 /* draw the edges */ | |
1138 LCD_SetTextColor(TextColor); | |
1139 } | |
1140 | |
1141 /** | |
1142 * @brief Reset LCD control line(/CS) and Send Start-Byte | |
1143 * @param Start_Byte: the Start-Byte to be sent | |
1144 * @retval None | |
1145 */ | |
1146 void LCD_nCS_StartByte(uint8_t Start_Byte) | |
1147 { | |
1148 LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_RESET); | |
1149 | |
1150 SPI_SendData(LCD_SPI, Start_Byte); | |
1151 | |
1152 while(SPI_GetFlagStatus(LCD_SPI, SPI_FLAG_BSY) != RESET) | |
1153 { | |
1154 } | |
1155 } | |
1156 | |
1157 | |
1158 /** | |
1159 * @brief Writes index to select the LCD register. | |
1160 * @param LCD_Reg: address of the selected register. | |
1161 * @retval None | |
1162 */ | |
1163 void LCD_WriteRegIndex(uint8_t LCD_Reg) | |
1164 { | |
1165 /* Reset LCD control line(/CS) and Send Start-Byte */ | |
1166 LCD_nCS_StartByte(START_BYTE | SET_INDEX); | |
1167 | |
1168 /* Write 16-bit Reg Index (High Byte is 0) */ | |
1169 SPI_SendData(LCD_SPI, 0x00); | |
1170 | |
1171 while(SPI_GetFlagStatus(LCD_SPI, SPI_FLAG_BSY) != RESET) | |
1172 { | |
1173 } | |
1174 | |
1175 SPI_SendData(LCD_SPI, LCD_Reg); | |
1176 | |
1177 while(SPI_GetFlagStatus(LCD_SPI, SPI_FLAG_BSY) != RESET) | |
1178 { | |
1179 } | |
1180 | |
1181 LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET); | |
1182 } | |
1183 | |
1184 | |
1185 /** | |
1186 * @brief Writes to the selected LCD ILI9320 register. | |
1187 * @param LCD_Reg: address of the selected register. | |
1188 * @param LCD_RegValue: value to write to the selected register. | |
1189 * @retval None | |
1190 */ | |
1191 void LCD_WriteReg(uint8_t LCD_Reg, uint16_t LCD_RegValue) | |
1192 { | |
1193 /* Write 16-bit Index (then Write Reg) */ | |
1194 LCD_WriteRegIndex(LCD_Reg); | |
1195 | |
1196 /* Write 16-bit Reg */ | |
1197 /* Reset LCD control line(/CS) and Send Start-Byte */ | |
1198 LCD_nCS_StartByte(START_BYTE | LCD_WRITE_REG); | |
1199 | |
1200 SPI_SendData(LCD_SPI, LCD_RegValue >> 8); | |
1201 | |
1202 while(SPI_GetFlagStatus(LCD_SPI, SPI_FLAG_BSY) != RESET) | |
1203 { | |
1204 } | |
1205 | |
1206 SPI_SendData(LCD_SPI, (LCD_RegValue & 0xFF)); | |
1207 | |
1208 while(SPI_GetFlagStatus(LCD_SPI, SPI_FLAG_BSY) != RESET) | |
1209 { | |
1210 } | |
1211 | |
1212 LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET); | |
1213 } | |
1214 | |
1215 | |
1216 /** | |
1217 * @brief Reads the selected LCD Register. | |
1218 * @param LCD_Reg: address of the selected register. | |
1219 * @retval LCD Register Value. | |
1220 */ | |
1221 uint16_t LCD_ReadReg(uint8_t LCD_Reg) | |
1222 { | |
1223 uint16_t tmp = 0; | |
1224 uint8_t i = 0; | |
1225 | |
1226 /* LCD_SPI prescaler: 4 */ | |
1227 LCD_SPI->CR1 &= 0xFFC7; | |
1228 LCD_SPI->CR1 |= 0x0008; | |
1229 /* Write 16-bit Index (then Read Reg) */ | |
1230 LCD_WriteRegIndex(LCD_Reg); | |
1231 /* Read 16-bit Reg */ | |
1232 /* Reset LCD control line(/CS) and Send Start-Byte */ | |
1233 LCD_nCS_StartByte(START_BYTE | LCD_READ_REG); | |
1234 | |
1235 for(i = 0; i < 5; i++) | |
1236 { | |
1237 SPI_SendData(LCD_SPI, 0xFF); | |
1238 while(SPI_GetFlagStatus(LCD_SPI, SPI_FLAG_BSY) != RESET) | |
1239 { | |
1240 } | |
1241 /* One byte of invalid dummy data read after the start byte */ | |
1242 while(SPI_GetFlagStatus(LCD_SPI, SPI_FLAG_RXNE) == RESET) | |
1243 { | |
1244 } | |
1245 SPI_ReceiveData(LCD_SPI); | |
1246 } | |
1247 | |
1248 SPI_SendData(LCD_SPI, 0xFF); | |
1249 | |
1250 /* Read upper byte */ | |
1251 while(SPI_GetFlagStatus(LCD_SPI, SPI_FLAG_BSY) != RESET) | |
1252 { | |
1253 } | |
1254 | |
1255 /* Read lower byte */ | |
1256 while(SPI_GetFlagStatus(LCD_SPI, SPI_FLAG_RXNE) == RESET) | |
1257 { | |
1258 } | |
1259 tmp = SPI_ReceiveData(LCD_SPI); | |
1260 | |
1261 | |
1262 SPI_SendData(LCD_SPI, 0xFF); | |
1263 while(SPI_GetFlagStatus(LCD_SPI, SPI_FLAG_BSY) != RESET) | |
1264 { | |
1265 } | |
1266 | |
1267 /* Read lower byte */ | |
1268 while(SPI_GetFlagStatus(LCD_SPI, SPI_FLAG_RXNE) == RESET) | |
1269 { | |
1270 } | |
1271 | |
1272 tmp = ((tmp & 0xFF) << 8) | SPI_ReceiveData(LCD_SPI); | |
1273 LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET); | |
1274 | |
1275 /* LCD_SPI prescaler: 2 */ | |
1276 LCD_SPI->CR1 &= 0xFFC7; | |
1277 | |
1278 return tmp; | |
1279 } | |
1280 | |
1281 | |
1282 /** | |
1283 * @brief Prepare to write to the LCD RAM. | |
1284 * @param None | |
1285 * @retval None | |
1286 */ | |
1287 void LCD_WriteRAM_Prepare(void) | |
1288 { | |
1289 LCD_WriteRegIndex(LCD_REG_34); /* Select GRAM Reg */ | |
1290 | |
1291 /* Reset LCD control line(/CS) and Send Start-Byte */ | |
1292 LCD_nCS_StartByte(START_BYTE | LCD_WRITE_REG); | |
1293 } | |
1294 | |
1295 | |
1296 /** | |
1297 * @brief Writes 1 word to the LCD RAM. | |
1298 * @param RGB_Code: the pixel color in RGB mode (5-6-5). | |
1299 * @retval None | |
1300 */ | |
1301 void LCD_WriteRAMWord(uint16_t RGB_Code) | |
1302 { | |
1303 LCD_WriteRAM_Prepare(); | |
1304 | |
1305 LCD_WriteRAM(RGB_Code); | |
1306 | |
1307 LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET); | |
1308 } | |
1309 | |
1310 /** | |
1311 * @brief Writes to the LCD RAM. | |
1312 * @param RGB_Code: the pixel color in RGB mode (5-6-5). | |
1313 * @retval None | |
1314 */ | |
1315 void LCD_WriteRAM(uint16_t RGB_Code) | |
1316 { | |
1317 SPI_SendData(LCD_SPI, RGB_Code >> 8); | |
1318 while(SPI_GetFlagStatus(LCD_SPI, SPI_FLAG_BSY) != RESET) | |
1319 { | |
1320 } | |
1321 SPI_SendData(LCD_SPI, RGB_Code & 0xFF); | |
1322 while(SPI_GetFlagStatus(LCD_SPI, SPI_FLAG_BSY) != RESET) | |
1323 { | |
1324 } | |
1325 } | |
1326 | |
1327 | |
1328 /** | |
1329 * @brief Power on the LCD. | |
1330 * @param None | |
1331 * @retval None | |
1332 */ | |
1333 void LCD_PowerOn(void) | |
1334 { | |
1335 /* Power On sequence ---------------------------------------------------------*/ | |
1336 LCD_WriteReg(LCD_REG_16, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */ | |
1337 LCD_WriteReg(LCD_REG_17, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */ | |
1338 LCD_WriteReg(LCD_REG_18, 0x0000); /* VREG1OUT voltage */ | |
1339 LCD_WriteReg(LCD_REG_19, 0x0000); /* VDV[4:0] for VCOM amplitude */ | |
1340 _delay_(20); /* Dis-charge capacitor power voltage (200ms) */ | |
1341 LCD_WriteReg(LCD_REG_16, 0x17B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */ | |
1342 LCD_WriteReg(LCD_REG_17, 0x0137); /* DC1[2:0], DC0[2:0], VC[2:0] */ | |
1343 _delay_(5); /* Delay 50 ms */ | |
1344 LCD_WriteReg(LCD_REG_18, 0x0139); /* VREG1OUT voltage */ | |
1345 _delay_(5); /* delay 50 ms */ | |
1346 LCD_WriteReg(LCD_REG_19, 0x1d00); /* VDV[4:0] for VCOM amplitude */ | |
1347 LCD_WriteReg(LCD_REG_41, 0x0013); /* VCM[4:0] for VCOMH */ | |
1348 _delay_(5); /* delay 50 ms */ | |
1349 LCD_WriteReg(LCD_REG_7, 0x0173); /* 262K color and display ON */ | |
1350 } | |
1351 | |
1352 | |
1353 /** | |
1354 * @brief Enables the Display. | |
1355 * @param None | |
1356 * @retval None | |
1357 */ | |
1358 void LCD_DisplayOn(void) | |
1359 { | |
1360 /* Display On */ | |
1361 LCD_WriteReg(LCD_REG_7, 0x0173); /* 262K color and display ON */ | |
1362 } | |
1363 | |
1364 | |
1365 /** | |
1366 * @brief Disables the Display. | |
1367 * @param None | |
1368 * @retval None | |
1369 */ | |
1370 void LCD_DisplayOff(void) | |
1371 { | |
1372 /* Display Off */ | |
1373 LCD_WriteReg(LCD_REG_7, 0x0); | |
1374 } | |
1375 | |
1376 | |
1377 /** | |
1378 * @brief Configures LCD control lines in Output Push-Pull mode. | |
1379 * @param None | |
1380 * @retval None | |
1381 */ | |
1382 void LCD_CtrlLinesConfig(void) | |
1383 { | |
1384 GPIO_InitTypeDef GPIO_InitStructure; | |
1385 | |
1386 RCC_AHBPeriphClockCmd(LCD_NCS_GPIO_CLK, ENABLE); | |
1387 | |
1388 /* Configure NCS (PF.02) in Output Push-Pull mode */ | |
1389 GPIO_InitStructure.GPIO_Pin = LCD_NCS_PIN; | |
1390 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; | |
1391 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; | |
1392 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; | |
1393 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; | |
1394 GPIO_Init(LCD_NCS_GPIO_PORT, &GPIO_InitStructure); | |
1395 | |
1396 LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET); | |
1397 } | |
1398 | |
1399 | |
1400 /** | |
1401 * @brief Sets or reset LCD control lines. | |
1402 * @param GPIOx: where x can be B or D to select the GPIO peripheral. | |
1403 * @param CtrlPins: the Control line. | |
1404 * This parameter can be: | |
1405 * @arg LCD_NCS_PIN: Chip Select pin | |
1406 * @arg LCD_NWR_PIN: Read/Write Selection pin | |
1407 * @arg LCD_RS_PIN: Register/RAM Selection pin | |
1408 * @param BitVal: specifies the value to be written to the selected bit. | |
1409 * This parameter can be: | |
1410 * @arg Bit_RESET: to clear the port pin | |
1411 * @arg Bit_SET: to set the port pin | |
1412 * @retval None | |
1413 */ | |
1414 void LCD_CtrlLinesWrite(GPIO_TypeDef* GPIOx, uint16_t CtrlPins, BitAction BitVal) | |
1415 { | |
1416 /* Set or Reset the control line */ | |
1417 GPIO_WriteBit(GPIOx, CtrlPins, BitVal); | |
1418 } | |
1419 | |
1420 | |
1421 /** | |
1422 * @brief Configures the LCD_SPI interface. | |
1423 * @param None | |
1424 * @retval None | |
1425 */ | |
1426 void LCD_SPIConfig(void) | |
1427 { | |
1428 SPI_InitTypeDef SPI_InitStructure; | |
1429 GPIO_InitTypeDef GPIO_InitStructure; | |
1430 | |
1431 /* Enable LCD_SPI_SCK_GPIO_CLK, LCD_SPI_MISO_GPIO_CLK and LCD_SPI_MOSI_GPIO_CLK clock */ | |
1432 RCC_AHBPeriphClockCmd(LCD_SPI_SCK_GPIO_CLK | LCD_SPI_MISO_GPIO_CLK | LCD_SPI_MOSI_GPIO_CLK, ENABLE); | |
1433 | |
1434 /* Enable LCD_SPI and SYSCFG clock */ | |
1435 RCC_APB2PeriphClockCmd(LCD_SPI_CLK | RCC_APB2Periph_SYSCFG, ENABLE); | |
1436 | |
1437 /* Configure LCD_SPI SCK pin */ | |
1438 GPIO_InitStructure.GPIO_Pin = LCD_SPI_SCK_PIN; | |
1439 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz; | |
1440 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; | |
1441 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; | |
1442 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; | |
1443 GPIO_Init(LCD_SPI_SCK_GPIO_PORT, &GPIO_InitStructure); | |
1444 | |
1445 /* Configure LCD_SPI MISO pin */ | |
1446 GPIO_InitStructure.GPIO_Pin = LCD_SPI_MISO_PIN; | |
1447 GPIO_Init(LCD_SPI_MISO_GPIO_PORT, &GPIO_InitStructure); | |
1448 | |
1449 /* Configure LCD_SPI MOSI pin */ | |
1450 GPIO_InitStructure.GPIO_Pin = LCD_SPI_MOSI_PIN; | |
1451 GPIO_Init(LCD_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure); | |
1452 | |
1453 /* Connect PE.13 to SPI SCK */ | |
1454 GPIO_PinAFConfig(LCD_SPI_SCK_GPIO_PORT, LCD_SPI_SCK_SOURCE, LCD_SPI_SCK_AF); | |
1455 | |
1456 /* Connect PE.14 to SPI MISO */ | |
1457 GPIO_PinAFConfig(LCD_SPI_MISO_GPIO_PORT, LCD_SPI_MISO_SOURCE, LCD_SPI_MISO_AF); | |
1458 | |
1459 /* Connect PE.15 to SPI MOSI */ | |
1460 GPIO_PinAFConfig(LCD_SPI_MOSI_GPIO_PORT, LCD_SPI_MOSI_SOURCE, LCD_SPI_MOSI_AF); | |
1461 | |
1462 SPI_DeInit(LCD_SPI); | |
1463 | |
1464 /* SPI Config */ | |
1465 SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; | |
1466 SPI_InitStructure.SPI_Mode = SPI_Mode_Master; | |
1467 SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; | |
1468 SPI_InitStructure.SPI_CPOL = SPI_CPOL_High; | |
1469 SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; | |
1470 SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; | |
1471 SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2; | |
1472 SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; | |
1473 SPI_InitStructure.SPI_CRCPolynomial = 7; | |
1474 SPI_Init(LCD_SPI, &SPI_InitStructure); | |
1475 | |
1476 /* SPI enable */ | |
1477 SPI_Cmd(LCD_SPI, ENABLE); | |
1478 } | |
1479 | |
1480 /** | |
1481 * @brief Displays a pixel. | |
1482 * @param x: pixel x. | |
1483 * @param y: pixel y. | |
1484 * @retval None | |
1485 */ | |
1486 static void PutPixel(int16_t x, int16_t y) | |
1487 { | |
1488 if(x < 0 || x > 239 || y < 0 || y > 319) | |
1489 { | |
1490 return; | |
1491 } | |
1492 LCD_DrawLine(x, y, 1, LCD_DIR_HORIZONTAL); | |
1493 } | |
1494 | |
1495 #ifndef USE_Delay | |
1496 /** | |
1497 * @brief Inserts a delay time. | |
1498 * @param nCount: specifies the delay time length. | |
1499 * @retval None | |
1500 */ | |
1501 static void delay(__IO uint32_t nCount) | |
1502 { | |
1503 __IO uint32_t index = 0; | |
1504 for(index = (34000 * nCount); index != 0; index--) | |
1505 { | |
1506 } | |
1507 } | |
1508 #endif /* USE_Delay*/ | |
1509 /** | |
1510 * @} | |
1511 */ | |
1512 | |
1513 /** | |
1514 * @} | |
1515 */ | |
1516 | |
1517 /** | |
1518 * @} | |
1519 */ | |
1520 | |
1521 /** | |
1522 * @} | |
1523 */ | |
1524 | |
1525 /** | |
1526 * @} | |
1527 */ | |
1528 | |
1529 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ |