2 ******************************************************************************
\r
3 * @file stm32l152_eval_lcd.c
\r
4 * @author MCD Application Team
\r
7 * @brief This file includes the LCD driver for AM-240320L8TNQW00H (LCD_ILI9320),
\r
8 * AM-240320LDTNQW00H (LCD_SPFD5408B) Liquid Crystal Display Module
\r
9 * of STM32L152-EVAL board.
\r
10 ******************************************************************************
\r
13 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
\r
14 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
\r
15 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
\r
16 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
\r
17 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
\r
18 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
\r
20 * <h2><center>© COPYRIGHT 2010 STMicroelectronics</center></h2>
\r
23 /* Includes ------------------------------------------------------------------*/
\r
24 #include "stm32l152_eval_lcd.h"
\r
25 #include "../Common/fonts.c"
\r
27 /** @addtogroup Utilities
\r
31 /** @addtogroup STM32_EVAL
\r
35 /** @addtogroup STM32L152_EVAL
\r
39 /** @defgroup STM32L152_EVAL_LCD
\r
40 * @brief This file includes the LCD driver for AM-240320L8TNQW00H (LCD_ILI9320),
\r
41 * AM-240320LDTNQW00H (LCD_SPFD5408B) Liquid Crystal Display Module
\r
42 * of STM32L152-EVAL board.
\r
46 /** @defgroup STM32L152_EVAL_LCD_Private_Types
\r
53 /** @defgroup STM32L152_EVAL_LCD_Private_Defines
\r
56 #define LCD_ILI9320 0x9320
\r
57 #define LCD_SPFD5408 0x5408
\r
58 #define START_BYTE 0x70
\r
59 #define SET_INDEX 0x00
\r
60 #define READ_STATUS 0x01
\r
61 #define LCD_WRITE_REG 0x02
\r
62 #define LCD_READ_REG 0x03
\r
63 #define MAX_POLY_CORNERS 200
\r
64 #define POLY_Y(Z) ((int32_t)((Points + Z)->X))
\r
65 #define POLY_X(Z) ((int32_t)((Points + Z)->Y))
\r
70 /** @defgroup STM32L152_EVAL_LCD_Private_Macros
\r
73 #define ABS(X) ((X) > 0 ? (X) : -(X))
\r
78 /** @defgroup STM32L152_EVAL_LCD_Private_Variables
\r
81 static sFONT *LCD_Currentfonts;
\r
82 /* Global variables to set the written text color */
\r
83 static __IO uint16_t TextColor = 0x0000, BackColor = 0xFFFF;
\r
84 static __IO uint32_t LCDType = LCD_SPFD5408;
\r
89 /** @defgroup STM32L152_EVAL_LCD_Private_Function_Prototypes
\r
93 static void delay(__IO uint32_t nCount);
\r
94 #endif /* USE_Delay*/
\r
96 static void PutPixel(int16_t x, int16_t y);
\r
97 static void LCD_PolyLineRelativeClosed(pPoint Points, uint16_t PointCount, uint16_t Closed);
\r
103 /** @defgroup STM32L152_EVAL_LCD_Private_Functions
\r
108 * @brief DeInitializes the LCD.
\r
112 void STM32L152_LCD_DeInit(void)
\r
114 GPIO_InitTypeDef GPIO_InitStructure;
\r
116 /*!< LCD Display Off */
\r
119 /*!< LCD_SPI disable */
\r
120 SPI_Cmd(LCD_SPI, DISABLE);
\r
122 /*!< LCD_SPI DeInit */
\r
123 SPI_DeInit(LCD_SPI);
\r
125 /*!< Disable SPI clock */
\r
126 RCC_APB1PeriphClockCmd(LCD_SPI_CLK, DISABLE);
\r
128 /* Configure NCS in Output Push-Pull mode */
\r
129 GPIO_InitStructure.GPIO_Pin = LCD_NCS_PIN;
\r
130 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
\r
131 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
\r
132 GPIO_Init(LCD_NCS_GPIO_PORT, &GPIO_InitStructure);
\r
134 /* Configure SPI pins: SCK, MISO and MOSI */
\r
135 GPIO_InitStructure.GPIO_Pin = LCD_SPI_SCK_PIN;
\r
136 GPIO_Init(LCD_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
\r
138 GPIO_InitStructure.GPIO_Pin = LCD_SPI_MISO_PIN;
\r
139 GPIO_Init(LCD_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
\r
141 GPIO_InitStructure.GPIO_Pin = LCD_SPI_MOSI_PIN;
\r
142 GPIO_Init(LCD_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
\r
146 * @brief Setups the LCD.
\r
150 void LCD_Setup(void)
\r
152 /* Configure the LCD Control pins --------------------------------------------*/
\r
153 LCD_CtrlLinesConfig();
\r
155 /* Configure the LCD_SPI interface ----------------------------------------------*/
\r
158 if(LCDType == LCD_SPFD5408)
\r
160 /* Start Initial Sequence --------------------------------------------------*/
\r
161 LCD_WriteReg(LCD_REG_227, 0x3008); /* Set internal timing */
\r
162 LCD_WriteReg(LCD_REG_231, 0x0012); /* Set internal timing */
\r
163 LCD_WriteReg(LCD_REG_239, 0x1231); /* Set internal timing */
\r
164 LCD_WriteReg(LCD_REG_1, 0x0100); /* Set SS and SM bit */
\r
165 LCD_WriteReg(LCD_REG_2, 0x0700); /* Set 1 line inversion */
\r
166 LCD_WriteReg(LCD_REG_3, 0x1030); /* Set GRAM write direction and BGR=1. */
\r
167 LCD_WriteReg(LCD_REG_4, 0x0000); /* Resize register */
\r
168 LCD_WriteReg(LCD_REG_8, 0x0202); /* Set the back porch and front porch */
\r
169 LCD_WriteReg(LCD_REG_9, 0x0000); /* Set non-display area refresh cycle ISC[3:0] */
\r
170 LCD_WriteReg(LCD_REG_10, 0x0000); /* FMARK function */
\r
171 LCD_WriteReg(LCD_REG_12, 0x0000); /* RGB interface setting */
\r
172 LCD_WriteReg(LCD_REG_13, 0x0000); /* Frame marker Position */
\r
173 LCD_WriteReg(LCD_REG_15, 0x0000); /* RGB interface polarity */
\r
174 /* Power On sequence -------------------------------------------------------*/
\r
175 LCD_WriteReg(LCD_REG_16, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
\r
176 LCD_WriteReg(LCD_REG_17, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
\r
177 LCD_WriteReg(LCD_REG_18, 0x0000); /* VREG1OUT voltage */
\r
178 LCD_WriteReg(LCD_REG_19, 0x0000); /* VDV[4:0] for VCOM amplitude */
\r
179 _delay_(20); /* Dis-charge capacitor power voltage (200ms) */
\r
180 LCD_WriteReg(LCD_REG_17, 0x0007); /* DC1[2:0], DC0[2:0], VC[2:0] */
\r
181 _delay_(5); /* Delay 50 ms */
\r
182 LCD_WriteReg(LCD_REG_16, 0x12B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
\r
183 _delay_(5); /* Delay 50 ms */
\r
184 LCD_WriteReg(LCD_REG_18, 0x01BD); /* External reference voltage= Vci */
\r
185 _delay_(5); /* Delay 50 ms */
\r
186 LCD_WriteReg(LCD_REG_19, 0x1400); /* VDV[4:0] for VCOM amplitude */
\r
187 LCD_WriteReg(LCD_REG_41, 0x000E); /* VCM[4:0] for VCOMH */
\r
188 _delay_(5); /* Delay 50 ms */
\r
189 LCD_WriteReg(LCD_REG_32, 0x0000); /* GRAM horizontal Address */
\r
190 LCD_WriteReg(LCD_REG_33, 0x013F); /* GRAM Vertical Address */
\r
191 /* Adjust the Gamma Curve --------------------------------------------------*/
\r
192 LCD_WriteReg(LCD_REG_48, 0x0007);
\r
193 LCD_WriteReg(LCD_REG_49, 0x0302);
\r
194 LCD_WriteReg(LCD_REG_50, 0x0105);
\r
195 LCD_WriteReg(LCD_REG_53, 0x0206);
\r
196 LCD_WriteReg(LCD_REG_54, 0x0808);
\r
197 LCD_WriteReg(LCD_REG_55, 0x0206);
\r
198 LCD_WriteReg(LCD_REG_56, 0x0504);
\r
199 LCD_WriteReg(LCD_REG_57, 0x0007);
\r
200 LCD_WriteReg(LCD_REG_60, 0x0105);
\r
201 LCD_WriteReg(LCD_REG_61, 0x0808);
\r
202 /* Set GRAM area -----------------------------------------------------------*/
\r
203 LCD_WriteReg(LCD_REG_80, 0x0000); /* Horizontal GRAM Start Address */
\r
204 LCD_WriteReg(LCD_REG_81, 0x00EF); /* Horizontal GRAM End Address */
\r
205 LCD_WriteReg(LCD_REG_82, 0x0000); /* Vertical GRAM Start Address */
\r
206 LCD_WriteReg(LCD_REG_83, 0x013F); /* Vertical GRAM End Address */
\r
207 LCD_WriteReg(LCD_REG_96, 0xA700); /* Gate Scan Line */
\r
208 LCD_WriteReg(LCD_REG_97, 0x0001); /* NDL,VLE, REV */
\r
209 LCD_WriteReg(LCD_REG_106, 0x0000); /* Set scrolling line */
\r
210 /* Partial Display Control -------------------------------------------------*/
\r
211 LCD_WriteReg(LCD_REG_128, 0x0000);
\r
212 LCD_WriteReg(LCD_REG_129, 0x0000);
\r
213 LCD_WriteReg(LCD_REG_130, 0x0000);
\r
214 LCD_WriteReg(LCD_REG_131, 0x0000);
\r
215 LCD_WriteReg(LCD_REG_132, 0x0000);
\r
216 LCD_WriteReg(LCD_REG_133, 0x0000);
\r
217 /* Panel Control -----------------------------------------------------------*/
\r
218 LCD_WriteReg(LCD_REG_144, 0x0010);
\r
219 LCD_WriteReg(LCD_REG_146, 0x0000);
\r
220 LCD_WriteReg(LCD_REG_147, 0x0003);
\r
221 LCD_WriteReg(LCD_REG_149, 0x0110);
\r
222 LCD_WriteReg(LCD_REG_151, 0x0000);
\r
223 LCD_WriteReg(LCD_REG_152, 0x0000);
\r
224 /* Set GRAM write direction and BGR = 1
\r
225 I/D=01 (Horizontal : increment, Vertical : decrement)
\r
226 AM=1 (address is updated in vertical writing direction) */
\r
227 LCD_WriteReg(LCD_REG_3, 0x1018);
\r
228 LCD_WriteReg(LCD_REG_7, 0x0112); /* 262K color and display ON */
\r
230 else if(LCDType == LCD_ILI9320)
\r
232 _delay_(5); /* Delay 50 ms */
\r
233 /* Start Initial Sequence ------------------------------------------------*/
\r
234 LCD_WriteReg(LCD_REG_229, 0x8000); /* Set the internal vcore voltage */
\r
235 LCD_WriteReg(LCD_REG_0, 0x0001); /* Start internal OSC. */
\r
236 LCD_WriteReg(LCD_REG_1, 0x0100); /* set SS and SM bit */
\r
237 LCD_WriteReg(LCD_REG_2, 0x0700); /* set 1 line inversion */
\r
238 LCD_WriteReg(LCD_REG_3, 0x1030); /* set GRAM write direction and BGR=1. */
\r
239 LCD_WriteReg(LCD_REG_4, 0x0000); /* Resize register */
\r
240 LCD_WriteReg(LCD_REG_8, 0x0202); /* set the back porch and front porch */
\r
241 LCD_WriteReg(LCD_REG_9, 0x0000); /* set non-display area refresh cycle ISC[3:0] */
\r
242 LCD_WriteReg(LCD_REG_10, 0x0000); /* FMARK function */
\r
243 LCD_WriteReg(LCD_REG_12, 0x0000); /* RGB interface setting */
\r
244 LCD_WriteReg(LCD_REG_13, 0x0000); /* Frame marker Position */
\r
245 LCD_WriteReg(LCD_REG_15, 0x0000); /* RGB interface polarity */
\r
246 /* Power On sequence -----------------------------------------------------*/
\r
247 LCD_WriteReg(LCD_REG_16, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
\r
248 LCD_WriteReg(LCD_REG_17, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
\r
249 LCD_WriteReg(LCD_REG_18, 0x0000); /* VREG1OUT voltage */
\r
250 LCD_WriteReg(LCD_REG_19, 0x0000); /* VDV[4:0] for VCOM amplitude */
\r
251 _delay_(20); /* Dis-charge capacitor power voltage (200ms) */
\r
252 LCD_WriteReg(LCD_REG_16, 0x17B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
\r
253 LCD_WriteReg(LCD_REG_17, 0x0137); /* DC1[2:0], DC0[2:0], VC[2:0] */
\r
254 _delay_(5); /* Delay 50 ms */
\r
255 LCD_WriteReg(LCD_REG_18, 0x0139); /* VREG1OUT voltage */
\r
256 _delay_(5); /* Delay 50 ms */
\r
257 LCD_WriteReg(LCD_REG_19, 0x1d00); /* VDV[4:0] for VCOM amplitude */
\r
258 LCD_WriteReg(LCD_REG_41, 0x0013); /* VCM[4:0] for VCOMH */
\r
259 _delay_(5); /* Delay 50 ms */
\r
260 LCD_WriteReg(LCD_REG_32, 0x0000); /* GRAM horizontal Address */
\r
261 LCD_WriteReg(LCD_REG_33, 0x0000); /* GRAM Vertical Address */
\r
262 /* Adjust the Gamma Curve ------------------------------------------------*/
\r
263 LCD_WriteReg(LCD_REG_48, 0x0006);
\r
264 LCD_WriteReg(LCD_REG_49, 0x0101);
\r
265 LCD_WriteReg(LCD_REG_50, 0x0003);
\r
266 LCD_WriteReg(LCD_REG_53, 0x0106);
\r
267 LCD_WriteReg(LCD_REG_54, 0x0b02);
\r
268 LCD_WriteReg(LCD_REG_55, 0x0302);
\r
269 LCD_WriteReg(LCD_REG_56, 0x0707);
\r
270 LCD_WriteReg(LCD_REG_57, 0x0007);
\r
271 LCD_WriteReg(LCD_REG_60, 0x0600);
\r
272 LCD_WriteReg(LCD_REG_61, 0x020b);
\r
274 /* Set GRAM area ---------------------------------------------------------*/
\r
275 LCD_WriteReg(LCD_REG_80, 0x0000); /* Horizontal GRAM Start Address */
\r
276 LCD_WriteReg(LCD_REG_81, 0x00EF); /* Horizontal GRAM End Address */
\r
277 LCD_WriteReg(LCD_REG_82, 0x0000); /* Vertical GRAM Start Address */
\r
278 LCD_WriteReg(LCD_REG_83, 0x013F); /* Vertical GRAM End Address */
\r
279 LCD_WriteReg(LCD_REG_96, 0x2700); /* Gate Scan Line */
\r
280 LCD_WriteReg(LCD_REG_97, 0x0001); /* NDL,VLE, REV */
\r
281 LCD_WriteReg(LCD_REG_106, 0x0000); /* set scrolling line */
\r
282 /* Partial Display Control -----------------------------------------------*/
\r
283 LCD_WriteReg(LCD_REG_128, 0x0000);
\r
284 LCD_WriteReg(LCD_REG_129, 0x0000);
\r
285 LCD_WriteReg(LCD_REG_130, 0x0000);
\r
286 LCD_WriteReg(LCD_REG_131, 0x0000);
\r
287 LCD_WriteReg(LCD_REG_132, 0x0000);
\r
288 LCD_WriteReg(LCD_REG_133, 0x0000);
\r
289 /* Panel Control ---------------------------------------------------------*/
\r
290 LCD_WriteReg(LCD_REG_144, 0x0010);
\r
291 LCD_WriteReg(LCD_REG_146, 0x0000);
\r
292 LCD_WriteReg(LCD_REG_147, 0x0003);
\r
293 LCD_WriteReg(LCD_REG_149, 0x0110);
\r
294 LCD_WriteReg(LCD_REG_151, 0x0000);
\r
295 LCD_WriteReg(LCD_REG_152, 0x0000);
\r
296 /* Set GRAM write direction and BGR = 1 */
\r
297 /* I/D=01 (Horizontal : increment, Vertical : decrement) */
\r
298 /* AM=1 (address is updated in vertical writing direction) */
\r
299 LCD_WriteReg(LCD_REG_3, 0x1018);
\r
300 LCD_WriteReg(LCD_REG_7, 0x0173); /* 262K color and display ON */
\r
306 * @brief Initializes the LCD.
\r
310 void STM32L152_LCD_Init(void)
\r
312 /* Setups the LCD */
\r
315 /* Try to read new LCD controller ID 0x5408 */
\r
316 if (LCD_ReadReg(LCD_REG_0) == LCD_SPFD5408)
\r
318 LCDType = LCD_SPFD5408;
\r
322 LCDType = LCD_ILI9320;
\r
323 /* Setups the LCD */
\r
327 LCD_SetFont(&LCD_DEFAULT_FONT);
\r
331 * @brief Sets the LCD Text and Background colors.
\r
332 * @param _TextColor: specifies the Text Color.
\r
333 * @param _BackColor: specifies the Background Color.
\r
336 void LCD_SetColors(__IO uint16_t _TextColor, __IO uint16_t _BackColor)
\r
338 TextColor = _TextColor;
\r
339 BackColor = _BackColor;
\r
343 * @brief Gets the LCD Text and Background colors.
\r
344 * @param _TextColor: pointer to the variable that will contain the Text
\r
346 * @param _BackColor: pointer to the variable that will contain the Background
\r
350 void LCD_GetColors(__IO uint16_t *_TextColor, __IO uint16_t *_BackColor)
\r
352 *_TextColor = TextColor; *_BackColor = BackColor;
\r
356 * @brief Sets the Text color.
\r
357 * @param Color: specifies the Text color code RGB(5-6-5).
\r
360 void LCD_SetTextColor(__IO uint16_t Color)
\r
367 * @brief Sets the Background color.
\r
368 * @param Color: specifies the Background color code RGB(5-6-5).
\r
371 void LCD_SetBackColor(__IO uint16_t Color)
\r
377 * @brief Sets the Text Font.
\r
378 * @param fonts: specifies the font to be used.
\r
381 void LCD_SetFont(sFONT *fonts)
\r
383 LCD_Currentfonts = fonts;
\r
387 * @brief Gets the Text Font.
\r
389 * @retval the used font.
\r
391 sFONT *LCD_GetFont(void)
\r
393 return LCD_Currentfonts;
\r
397 * @brief Clears the selected line.
\r
398 * @param Line: the Line to be cleared.
\r
399 * This parameter can be one of the following values:
\r
400 * @arg Linex: where x can be 0..n
\r
403 void LCD_ClearLine(uint8_t Line)
\r
405 uint16_t refcolumn = LCD_PIXEL_WIDTH - 1;
\r
407 /* Send the string character by character on lCD */
\r
408 while (((refcolumn + 1) & 0xFFFF) >= LCD_Currentfonts->Width)
\r
410 /* Display one character on LCD */
\r
411 LCD_DisplayChar(Line, refcolumn, ' ');
\r
412 /* Decrement the column position by 16 */
\r
413 refcolumn -= LCD_Currentfonts->Width;
\r
419 * @brief Clears the hole LCD.
\r
420 * @param Color: the color of the background.
\r
423 void LCD_Clear(uint16_t Color)
\r
425 uint32_t index = 0;
\r
427 LCD_SetCursor(0x00, 0x013F);
\r
429 LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
\r
431 for(index = 0; index < 76800; index++)
\r
433 LCD_WriteRAM(Color);
\r
436 LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
\r
442 * @brief Sets the cursor position.
\r
443 * @param Xpos: specifies the X position.
\r
444 * @param Ypos: specifies the Y position.
\r
447 void LCD_SetCursor(uint8_t Xpos, uint16_t Ypos)
\r
449 LCD_WriteReg(LCD_REG_32, Xpos);
\r
450 LCD_WriteReg(LCD_REG_33, Ypos);
\r
455 * @brief Draws a character on LCD.
\r
456 * @param Xpos: the Line where to display the character shape.
\r
457 * @param Ypos: start column address.
\r
458 * @param c: pointer to the character data.
\r
461 void LCD_DrawChar(uint8_t Xpos, uint16_t Ypos, const uint16_t *c)
\r
463 uint32_t index = 0, i = 0;
\r
464 uint8_t Xaddress = 0;
\r
468 LCD_SetCursor(Xaddress, Ypos);
\r
470 for(index = 0; index < LCD_Currentfonts->Height; index++)
\r
472 LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
\r
474 for(i = 0; i < LCD_Currentfonts->Width; i++)
\r
476 if((((c[index] & ((0x80 << ((LCD_Currentfonts->Width / 12 ) * 8 ) ) >> i)) == 0x00) &&(LCD_Currentfonts->Width <= 12))||
\r
477 (((c[index] & (0x1 << i)) == 0x00)&&(LCD_Currentfonts->Width > 12 )))
\r
480 LCD_WriteRAM(BackColor);
\r
484 LCD_WriteRAM(TextColor);
\r
488 LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
\r
490 LCD_SetCursor(Xaddress, Ypos);
\r
496 * @brief Displays one character (16dots width, 24dots height).
\r
497 * @param Line: the Line where to display the character shape .
\r
498 * This parameter can be one of the following values:
\r
499 * @arg Linex: where x can be 0..9
\r
500 * @param Column: start column address.
\r
501 * @param Ascii: character ascii code, must be between 0x20 and 0x7E.
\r
504 void LCD_DisplayChar(uint8_t Line, uint16_t Column, uint8_t Ascii)
\r
507 LCD_DrawChar(Line, Column, &LCD_Currentfonts->table[Ascii * LCD_Currentfonts->Height]);
\r
512 * @brief Displays a maximum of 20 char on the LCD.
\r
513 * @param Line: the Line where to display the character shape .
\r
514 * This parameter can be one of the following values:
\r
515 * @arg Linex: where x can be 0..9
\r
516 * @param *ptr: pointer to string to display on LCD.
\r
519 void LCD_DisplayStringLine(uint8_t Line, uint8_t *ptr)
\r
521 uint16_t refcolumn = LCD_PIXEL_WIDTH - 1;
\r
523 /* Send the string character by character on lCD */
\r
524 while ((*ptr != 0) & (((refcolumn + 1) & 0xFFFF) >= LCD_Currentfonts->Width))
\r
526 /* Display one character on LCD */
\r
527 LCD_DisplayChar(Line, refcolumn, *ptr);
\r
528 /* Decrement the column position by 16 */
\r
529 refcolumn -= LCD_Currentfonts->Width;
\r
530 /* Point on the next character */
\r
537 * @brief Sets a display window
\r
538 * @param Xpos: specifies the X buttom left position.
\r
539 * @param Ypos: specifies the Y buttom left position.
\r
540 * @param Height: display window height.
\r
541 * @param Width: display window width.
\r
544 void LCD_SetDisplayWindow(uint8_t Xpos, uint16_t Ypos, uint8_t Height, uint16_t Width)
\r
546 /* Horizontal GRAM Start Address */
\r
549 LCD_WriteReg(LCD_REG_80, (Xpos - Height + 1));
\r
553 LCD_WriteReg(LCD_REG_80, 0);
\r
555 /* Horizontal GRAM End Address */
\r
556 LCD_WriteReg(LCD_REG_81, Xpos);
\r
557 /* Vertical GRAM Start Address */
\r
560 LCD_WriteReg(LCD_REG_82, (Ypos - Width + 1));
\r
564 LCD_WriteReg(LCD_REG_82, 0);
\r
566 /* Vertical GRAM End Address */
\r
567 LCD_WriteReg(LCD_REG_83, Ypos);
\r
569 LCD_SetCursor(Xpos, Ypos);
\r
574 * @brief Disables LCD Window mode.
\r
578 void LCD_WindowModeDisable(void)
\r
580 LCD_SetDisplayWindow(239, 0x13F, 240, 320);
\r
581 LCD_WriteReg(LCD_REG_3, 0x1018);
\r
585 * @brief Displays a line.
\r
586 * @param Xpos: specifies the X position.
\r
587 * @param Ypos: specifies the Y position.
\r
588 * @param Length: line length.
\r
589 * @param Direction: line direction.
\r
590 * This parameter can be one of the following values: Vertical or Horizontal.
\r
593 void LCD_DrawLine(uint8_t Xpos, uint16_t Ypos, uint16_t Length, uint8_t Direction)
\r
597 LCD_SetCursor(Xpos, Ypos);
\r
599 if(Direction == LCD_DIR_HORIZONTAL)
\r
601 LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
\r
603 for(i = 0; i < Length; i++)
\r
605 LCD_WriteRAM(TextColor);
\r
607 LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
\r
611 for(i = 0; i < Length; i++)
\r
613 LCD_WriteRAMWord(TextColor);
\r
615 LCD_SetCursor(Xpos, Ypos);
\r
622 * @brief Displays a rectangle.
\r
623 * @param Xpos: specifies the X position.
\r
624 * @param Ypos: specifies the Y position.
\r
625 * @param Height: display rectangle height.
\r
626 * @param Width: display rectangle width.
\r
629 void LCD_DrawRect(uint8_t Xpos, uint16_t Ypos, uint8_t Height, uint16_t Width)
\r
631 LCD_DrawLine(Xpos, Ypos, Width, LCD_DIR_HORIZONTAL);
\r
632 LCD_DrawLine((Xpos + Height), Ypos, Width, LCD_DIR_HORIZONTAL);
\r
634 LCD_DrawLine(Xpos, Ypos, Height, LCD_DIR_VERTICAL);
\r
635 LCD_DrawLine(Xpos, (Ypos - Width + 1), Height, LCD_DIR_VERTICAL);
\r
640 * @brief Displays a circle.
\r
641 * @param Xpos: specifies the X position.
\r
642 * @param Ypos: specifies the Y position.
\r
646 void LCD_DrawCircle(uint8_t Xpos, uint16_t Ypos, uint16_t Radius)
\r
648 int32_t D;/* Decision Variable */
\r
649 uint32_t CurX;/* Current X Value */
\r
650 uint32_t CurY;/* Current Y Value */
\r
652 D = 3 - (Radius << 1);
\r
656 while (CurX <= CurY)
\r
658 LCD_SetCursor(Xpos + CurX, Ypos + CurY);
\r
659 LCD_WriteRAMWord(TextColor);
\r
660 LCD_SetCursor(Xpos + CurX, Ypos - CurY);
\r
661 LCD_WriteRAMWord(TextColor);
\r
663 LCD_SetCursor(Xpos - CurX, Ypos + CurY);
\r
664 LCD_WriteRAMWord(TextColor);
\r
666 LCD_SetCursor(Xpos - CurX, Ypos - CurY);
\r
667 LCD_WriteRAMWord(TextColor);
\r
669 LCD_SetCursor(Xpos + CurY, Ypos + CurX);
\r
670 LCD_WriteRAMWord(TextColor);
\r
672 LCD_SetCursor(Xpos + CurY, Ypos - CurX);
\r
673 LCD_WriteRAMWord(TextColor);
\r
675 LCD_SetCursor(Xpos - CurY, Ypos + CurX);
\r
676 LCD_WriteRAMWord(TextColor);
\r
678 LCD_SetCursor(Xpos - CurY, Ypos - CurX);
\r
679 LCD_WriteRAMWord(TextColor);
\r
683 D += (CurX << 2) + 6;
\r
687 D += ((CurX - CurY) << 2) + 10;
\r
696 * @brief Displays a monocolor picture.
\r
697 * @param Pict: pointer to the picture array.
\r
700 void LCD_DrawMonoPict(const uint32_t *Pict)
\r
702 uint32_t index = 0, i = 0;
\r
703 LCD_SetCursor(0, (LCD_PIXEL_WIDTH - 1));
\r
705 LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
\r
707 for(index = 0; index < 2400; index++)
\r
709 for(i = 0; i < 32; i++)
\r
711 if((Pict[index] & (1 << i)) == 0x00)
\r
713 LCD_WriteRAM(BackColor);
\r
717 LCD_WriteRAM(TextColor);
\r
722 LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
\r
725 #ifdef USE_LCD_DrawBMP
\r
727 * @brief Displays a bitmap picture loaded in the SPI Flash.
\r
728 * @param BmpAddress: Bmp picture address in the SPI Flash.
\r
731 void LCD_DrawBMP(uint32_t BmpAddress)
\r
733 uint32_t i = 0, size = 0;
\r
734 /* Read bitmap size */
\r
735 SPI_FLASH_BufferRead((uint8_t*)&size, BmpAddress + 2, 4);
\r
736 /* get bitmap data address offset */
\r
737 SPI_FLASH_BufferRead((uint8_t*)&i, BmpAddress + 10, 4);
\r
739 size = (size - i)/2;
\r
740 SPI_FLASH_StartReadSequence(BmpAddress + i);
\r
742 SPI_Cmd(SPI1, DISABLE);
\r
743 /* SPI in 16-bit mode */
\r
744 SPI_DataSizeConfig(SPI1, SPI_DataSize_16b);
\r
746 SPI_Cmd(SPI1, ENABLE);
\r
748 if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
\r
750 /* Set GRAM write direction and BGR = 1 */
\r
751 /* I/D=00 (Horizontal : decrement, Vertical : decrement) */
\r
752 /* AM=1 (address is updated in vertical writing direction) */
\r
753 LCD_WriteReg(LCD_REG_3, 0x1008);
\r
754 LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
\r
757 /* Read bitmap data from SPI Flash and send them to LCD */
\r
758 for(i = 0; i < size; i++)
\r
760 LCD_WriteRAM(__REV16(SPI_FLASH_SendHalfWord(0xA5A5)));
\r
762 if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
\r
764 LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
\r
767 /* Deselect the FLASH: Chip Select high */
\r
768 SPI_FLASH_CS_HIGH();
\r
770 SPI_Cmd(SPI1, DISABLE);
\r
771 /* SPI in 8-bit mode */
\r
772 SPI_DataSizeConfig(SPI1, SPI_DataSize_8b);
\r
774 SPI_Cmd(SPI1, ENABLE);
\r
776 if((LCDType == LCD_ILI9320) || (LCDType == LCD_SPFD5408))
\r
778 /* Set GRAM write direction and BGR = 1 */
\r
779 /* I/D = 01 (Horizontal : increment, Vertical : decrement) */
\r
780 /* AM = 1 (address is updated in vertical writing direction) */
\r
781 LCD_WriteReg(LCD_REG_3, 0x1018);
\r
784 #endif /* USE_LCD_DrawBMP */
\r
787 * @brief Displays a full rectangle.
\r
788 * @param Xpos: specifies the X position.
\r
789 * @param Ypos: specifies the Y position.
\r
790 * @param Height: rectangle height.
\r
791 * @param Width: rectangle width.
\r
794 void LCD_DrawFullRect(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height)
\r
796 LCD_SetTextColor(TextColor);
\r
798 LCD_DrawLine(Xpos, Ypos, Width, LCD_DIR_HORIZONTAL);
\r
799 LCD_DrawLine((Xpos + Height), Ypos, Width, LCD_DIR_HORIZONTAL);
\r
801 LCD_DrawLine(Xpos, Ypos, Height, LCD_DIR_VERTICAL);
\r
802 LCD_DrawLine(Xpos, (Ypos - Width + 1), Height, LCD_DIR_VERTICAL);
\r
808 LCD_SetTextColor(BackColor);
\r
812 LCD_DrawLine(++Xpos, Ypos, Width, LCD_DIR_HORIZONTAL);
\r
815 LCD_SetTextColor(TextColor);
\r
819 * @brief Displays a full circle.
\r
820 * @param Xpos: specifies the X position.
\r
821 * @param Ypos: specifies the Y position.
\r
825 void LCD_DrawFullCircle(uint16_t Xpos, uint16_t Ypos, uint16_t Radius)
\r
827 int32_t D; /* Decision Variable */
\r
828 uint32_t CurX;/* Current X Value */
\r
829 uint32_t CurY;/* Current Y Value */
\r
831 D = 3 - (Radius << 1);
\r
836 LCD_SetTextColor(BackColor);
\r
838 while (CurX <= CurY)
\r
842 LCD_DrawLine(Xpos - CurX, Ypos + CurY, 2*CurY, LCD_DIR_HORIZONTAL);
\r
843 LCD_DrawLine(Xpos + CurX, Ypos + CurY, 2*CurY, LCD_DIR_HORIZONTAL);
\r
848 LCD_DrawLine(Xpos - CurY, Ypos + CurX, 2*CurX, LCD_DIR_HORIZONTAL);
\r
849 LCD_DrawLine(Xpos + CurY, Ypos + CurX, 2*CurX, LCD_DIR_HORIZONTAL);
\r
853 D += (CurX << 2) + 6;
\r
857 D += ((CurX - CurY) << 2) + 10;
\r
863 LCD_SetTextColor(TextColor);
\r
864 LCD_DrawCircle(Xpos, Ypos, Radius);
\r
868 * @brief Displays an uni line (between two points).
\r
869 * @param x1: specifies the point 1 x position.
\r
870 * @param y1: specifies the point 1 y position.
\r
871 * @param x2: specifies the point 2 x position.
\r
872 * @param y2: specifies the point 2 y position.
\r
875 void LCD_DrawUniLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
\r
877 int16_t deltax = 0, deltay = 0, x = 0, y = 0, xinc1 = 0, xinc2 = 0,
\r
878 yinc1 = 0, yinc2 = 0, den = 0, num = 0, numadd = 0, numpixels = 0,
\r
881 deltax = ABS(x2 - x1); /* The difference between the x's */
\r
882 deltay = ABS(y2 - y1); /* The difference between the y's */
\r
883 x = x1; /* Start x off at the first pixel */
\r
884 y = y1; /* Start y off at the first pixel */
\r
886 if (x2 >= x1) /* The x-values are increasing */
\r
891 else /* The x-values are decreasing */
\r
897 if (y2 >= y1) /* The y-values are increasing */
\r
902 else /* The y-values are decreasing */
\r
908 if (deltax >= deltay) /* There is at least one x-value for every y-value */
\r
910 xinc1 = 0; /* Don't change the x when numerator >= denominator */
\r
911 yinc2 = 0; /* Don't change the y for every iteration */
\r
915 numpixels = deltax; /* There are more x-values than y-values */
\r
917 else /* There is at least one y-value for every x-value */
\r
919 xinc2 = 0; /* Don't change the x for every iteration */
\r
920 yinc1 = 0; /* Don't change the y when numerator >= denominator */
\r
924 numpixels = deltay; /* There are more y-values than x-values */
\r
927 for (curpixel = 0; curpixel <= numpixels; curpixel++)
\r
929 PutPixel(x, y); /* Draw the current pixel */
\r
930 num += numadd; /* Increase the numerator by the top of the fraction */
\r
931 if (num >= den) /* Check if numerator >= denominator */
\r
933 num -= den; /* Calculate the new numerator value */
\r
934 x += xinc1; /* Change the x as appropriate */
\r
935 y += yinc1; /* Change the y as appropriate */
\r
937 x += xinc2; /* Change the x as appropriate */
\r
938 y += yinc2; /* Change the y as appropriate */
\r
943 * @brief Displays an polyline (between many points).
\r
944 * @param Points: pointer to the points array.
\r
945 * @param PointCount: Number of points.
\r
948 void LCD_PolyLine(pPoint Points, uint16_t PointCount)
\r
950 int16_t X = 0, Y = 0;
\r
957 while(--PointCount)
\r
962 LCD_DrawUniLine(X, Y, Points->X, Points->Y);
\r
967 * @brief Displays an relative polyline (between many points).
\r
968 * @param Points: pointer to the points array.
\r
969 * @param PointCount: Number of points.
\r
970 * @param Closed: specifies if the draw is closed or not.
\r
971 * 1: closed, 0 : not closed.
\r
974 static void LCD_PolyLineRelativeClosed(pPoint Points, uint16_t PointCount, uint16_t Closed)
\r
976 int16_t X = 0, Y = 0;
\r
977 pPoint First = Points;
\r
985 while(--PointCount)
\r
988 LCD_DrawUniLine(X, Y, X + Points->X, Y + Points->Y);
\r
994 LCD_DrawUniLine(First->X, First->Y, X, Y);
\r
999 * @brief Displays a closed polyline (between many points).
\r
1000 * @param Points: pointer to the points array.
\r
1001 * @param PointCount: Number of points.
\r
1004 void LCD_ClosedPolyLine(pPoint Points, uint16_t PointCount)
\r
1006 LCD_PolyLine(Points, PointCount);
\r
1007 LCD_DrawUniLine(Points->X, Points->Y, (Points+PointCount-1)->X, (Points+PointCount-1)->Y);
\r
1011 * @brief Displays a relative polyline (between many points).
\r
1012 * @param Points: pointer to the points array.
\r
1013 * @param PointCount: Number of points.
\r
1016 void LCD_PolyLineRelative(pPoint Points, uint16_t PointCount)
\r
1018 LCD_PolyLineRelativeClosed(Points, PointCount, 0);
\r
1022 * @brief Displays a closed relative polyline (between many points).
\r
1023 * @param Points: pointer to the points array.
\r
1024 * @param PointCount: Number of points.
\r
1027 void LCD_ClosedPolyLineRelative(pPoint Points, uint16_t PointCount)
\r
1029 LCD_PolyLineRelativeClosed(Points, PointCount, 1);
\r
1034 * @brief Displays a full polyline (between many points).
\r
1035 * @param Points: pointer to the points array.
\r
1036 * @param PointCount: Number of points.
\r
1039 void LCD_FillPolyLine(pPoint Points, uint16_t PointCount)
\r
1041 /* public-domain code by Darel Rex Finley, 2007 */
\r
1042 uint16_t nodes = 0, nodeX[MAX_POLY_CORNERS], pixelX = 0, pixelY = 0, i = 0,
\r
1044 uint16_t IMAGE_LEFT = 0, IMAGE_RIGHT = 0, IMAGE_TOP = 0, IMAGE_BOTTOM = 0;
\r
1046 IMAGE_LEFT = IMAGE_RIGHT = Points->X;
\r
1047 IMAGE_TOP= IMAGE_BOTTOM = Points->Y;
\r
1049 for(i = 1; i < PointCount; i++)
\r
1051 pixelX = POLY_X(i);
\r
1052 if(pixelX < IMAGE_LEFT)
\r
1054 IMAGE_LEFT = pixelX;
\r
1056 if(pixelX > IMAGE_RIGHT)
\r
1058 IMAGE_RIGHT = pixelX;
\r
1061 pixelY = POLY_Y(i);
\r
1062 if(pixelY < IMAGE_TOP)
\r
1064 IMAGE_TOP = pixelY;
\r
1066 if(pixelY > IMAGE_BOTTOM)
\r
1068 IMAGE_BOTTOM = pixelY;
\r
1072 LCD_SetTextColor(BackColor);
\r
1074 /* Loop through the rows of the image. */
\r
1075 for (pixelY = IMAGE_TOP; pixelY < IMAGE_BOTTOM; pixelY++)
\r
1077 /* Build a list of nodes. */
\r
1078 nodes = 0; j = PointCount-1;
\r
1080 for (i = 0; i < PointCount; i++)
\r
1082 if (POLY_Y(i)<(double) pixelY && POLY_Y(j)>=(double) pixelY || POLY_Y(j)<(double) pixelY && POLY_Y(i)>=(double) pixelY)
\r
1084 nodeX[nodes++]=(int) (POLY_X(i)+((pixelY-POLY_Y(i))*(POLY_X(j)-POLY_X(i)))/(POLY_Y(j)-POLY_Y(i)));
\r
1089 /* Sort the nodes, via a simple
\93Bubble
\94 sort. */
\r
1091 while (i < nodes-1)
\r
1093 if (nodeX[i]>nodeX[i+1])
\r
1096 nodeX[i] = nodeX[i+1];
\r
1097 nodeX[i+1] = swap;
\r
1109 /* Fill the pixels between node pairs. */
\r
1110 for (i = 0; i < nodes; i+=2)
\r
1112 if(nodeX[i] >= IMAGE_RIGHT)
\r
1116 if(nodeX[i+1] > IMAGE_LEFT)
\r
1118 if (nodeX[i] < IMAGE_LEFT)
\r
1120 nodeX[i]=IMAGE_LEFT;
\r
1122 if(nodeX[i+1] > IMAGE_RIGHT)
\r
1124 nodeX[i+1] = IMAGE_RIGHT;
\r
1126 LCD_SetTextColor(BackColor);
\r
1127 LCD_DrawLine(pixelY, nodeX[i+1], nodeX[i+1] - nodeX[i], LCD_DIR_HORIZONTAL);
\r
1128 LCD_SetTextColor(TextColor);
\r
1129 PutPixel(pixelY, nodeX[i+1]);
\r
1130 PutPixel(pixelY, nodeX[i]);
\r
1131 /* for (j=nodeX[i]; j<nodeX[i+1]; j++) PutPixel(j,pixelY); */
\r
1136 /* draw the edges */
\r
1137 LCD_SetTextColor(TextColor);
\r
1141 * @brief Reset LCD control line(/CS) and Send Start-Byte
\r
1142 * @param Start_Byte: the Start-Byte to be sent
\r
1145 void LCD_nCS_StartByte(uint8_t Start_Byte)
\r
1147 LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_RESET);
\r
1149 SPI_SendData(LCD_SPI, Start_Byte);
\r
1151 while(SPI_GetFlagStatus(LCD_SPI, SPI_FLAG_BSY) != RESET)
\r
1158 * @brief Writes index to select the LCD register.
\r
1159 * @param LCD_Reg: address of the selected register.
\r
1162 void LCD_WriteRegIndex(uint8_t LCD_Reg)
\r
1164 /* Reset LCD control line(/CS) and Send Start-Byte */
\r
1165 LCD_nCS_StartByte(START_BYTE | SET_INDEX);
\r
1167 /* Write 16-bit Reg Index (High Byte is 0) */
\r
1168 SPI_SendData(LCD_SPI, 0x00);
\r
1170 while(SPI_GetFlagStatus(LCD_SPI, SPI_FLAG_BSY) != RESET)
\r
1174 SPI_SendData(LCD_SPI, LCD_Reg);
\r
1176 while(SPI_GetFlagStatus(LCD_SPI, SPI_FLAG_BSY) != RESET)
\r
1180 LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
\r
1185 * @brief Writes to the selected LCD ILI9320 register.
\r
1186 * @param LCD_Reg: address of the selected register.
\r
1187 * @param LCD_RegValue: value to write to the selected register.
\r
1190 void LCD_WriteReg(uint8_t LCD_Reg, uint16_t LCD_RegValue)
\r
1192 /* Write 16-bit Index (then Write Reg) */
\r
1193 LCD_WriteRegIndex(LCD_Reg);
\r
1195 /* Write 16-bit Reg */
\r
1196 /* Reset LCD control line(/CS) and Send Start-Byte */
\r
1197 LCD_nCS_StartByte(START_BYTE | LCD_WRITE_REG);
\r
1199 SPI_SendData(LCD_SPI, LCD_RegValue >> 8);
\r
1201 while(SPI_GetFlagStatus(LCD_SPI, SPI_FLAG_BSY) != RESET)
\r
1205 SPI_SendData(LCD_SPI, (LCD_RegValue & 0xFF));
\r
1207 while(SPI_GetFlagStatus(LCD_SPI, SPI_FLAG_BSY) != RESET)
\r
1211 LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
\r
1216 * @brief Reads the selected LCD Register.
\r
1217 * @param LCD_Reg: address of the selected register.
\r
1218 * @retval LCD Register Value.
\r
1220 uint16_t LCD_ReadReg(uint8_t LCD_Reg)
\r
1225 /* LCD_SPI prescaler: 4 */
\r
1226 LCD_SPI->CR1 &= 0xFFC7;
\r
1227 LCD_SPI->CR1 |= 0x0008;
\r
1228 /* Write 16-bit Index (then Read Reg) */
\r
1229 LCD_WriteRegIndex(LCD_Reg);
\r
1230 /* Read 16-bit Reg */
\r
1231 /* Reset LCD control line(/CS) and Send Start-Byte */
\r
1232 LCD_nCS_StartByte(START_BYTE | LCD_READ_REG);
\r
1234 for(i = 0; i < 5; i++)
\r
1236 SPI_SendData(LCD_SPI, 0xFF);
\r
1237 while(SPI_GetFlagStatus(LCD_SPI, SPI_FLAG_BSY) != RESET)
\r
1240 /* One byte of invalid dummy data read after the start byte */
\r
1241 while(SPI_GetFlagStatus(LCD_SPI, SPI_FLAG_RXNE) == RESET)
\r
1244 SPI_ReceiveData(LCD_SPI);
\r
1247 SPI_SendData(LCD_SPI, 0xFF);
\r
1249 /* Read upper byte */
\r
1250 while(SPI_GetFlagStatus(LCD_SPI, SPI_FLAG_BSY) != RESET)
\r
1254 /* Read lower byte */
\r
1255 while(SPI_GetFlagStatus(LCD_SPI, SPI_FLAG_RXNE) == RESET)
\r
1258 tmp = SPI_ReceiveData(LCD_SPI);
\r
1261 SPI_SendData(LCD_SPI, 0xFF);
\r
1262 while(SPI_GetFlagStatus(LCD_SPI, SPI_FLAG_BSY) != RESET)
\r
1266 /* Read lower byte */
\r
1267 while(SPI_GetFlagStatus(LCD_SPI, SPI_FLAG_RXNE) == RESET)
\r
1271 tmp = ((tmp & 0xFF) << 8) | SPI_ReceiveData(LCD_SPI);
\r
1272 LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
\r
1274 /* LCD_SPI prescaler: 2 */
\r
1275 LCD_SPI->CR1 &= 0xFFC7;
\r
1282 * @brief Prepare to write to the LCD RAM.
\r
1286 void LCD_WriteRAM_Prepare(void)
\r
1288 LCD_WriteRegIndex(LCD_REG_34); /* Select GRAM Reg */
\r
1290 /* Reset LCD control line(/CS) and Send Start-Byte */
\r
1291 LCD_nCS_StartByte(START_BYTE | LCD_WRITE_REG);
\r
1296 * @brief Writes 1 word to the LCD RAM.
\r
1297 * @param RGB_Code: the pixel color in RGB mode (5-6-5).
\r
1300 void LCD_WriteRAMWord(uint16_t RGB_Code)
\r
1302 LCD_WriteRAM_Prepare();
\r
1304 LCD_WriteRAM(RGB_Code);
\r
1306 LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
\r
1310 * @brief Writes to the LCD RAM.
\r
1311 * @param RGB_Code: the pixel color in RGB mode (5-6-5).
\r
1314 void LCD_WriteRAM(uint16_t RGB_Code)
\r
1316 SPI_SendData(LCD_SPI, RGB_Code >> 8);
\r
1317 while(SPI_GetFlagStatus(LCD_SPI, SPI_FLAG_BSY) != RESET)
\r
1320 SPI_SendData(LCD_SPI, RGB_Code & 0xFF);
\r
1321 while(SPI_GetFlagStatus(LCD_SPI, SPI_FLAG_BSY) != RESET)
\r
1328 * @brief Power on the LCD.
\r
1332 void LCD_PowerOn(void)
\r
1334 /* Power On sequence ---------------------------------------------------------*/
\r
1335 LCD_WriteReg(LCD_REG_16, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
\r
1336 LCD_WriteReg(LCD_REG_17, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
\r
1337 LCD_WriteReg(LCD_REG_18, 0x0000); /* VREG1OUT voltage */
\r
1338 LCD_WriteReg(LCD_REG_19, 0x0000); /* VDV[4:0] for VCOM amplitude */
\r
1339 _delay_(20); /* Dis-charge capacitor power voltage (200ms) */
\r
1340 LCD_WriteReg(LCD_REG_16, 0x17B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
\r
1341 LCD_WriteReg(LCD_REG_17, 0x0137); /* DC1[2:0], DC0[2:0], VC[2:0] */
\r
1342 _delay_(5); /* Delay 50 ms */
\r
1343 LCD_WriteReg(LCD_REG_18, 0x0139); /* VREG1OUT voltage */
\r
1344 _delay_(5); /* delay 50 ms */
\r
1345 LCD_WriteReg(LCD_REG_19, 0x1d00); /* VDV[4:0] for VCOM amplitude */
\r
1346 LCD_WriteReg(LCD_REG_41, 0x0013); /* VCM[4:0] for VCOMH */
\r
1347 _delay_(5); /* delay 50 ms */
\r
1348 LCD_WriteReg(LCD_REG_7, 0x0173); /* 262K color and display ON */
\r
1353 * @brief Enables the Display.
\r
1357 void LCD_DisplayOn(void)
\r
1360 LCD_WriteReg(LCD_REG_7, 0x0173); /* 262K color and display ON */
\r
1365 * @brief Disables the Display.
\r
1369 void LCD_DisplayOff(void)
\r
1372 LCD_WriteReg(LCD_REG_7, 0x0);
\r
1377 * @brief Configures LCD control lines in Output Push-Pull mode.
\r
1381 void LCD_CtrlLinesConfig(void)
\r
1383 GPIO_InitTypeDef GPIO_InitStructure;
\r
1385 RCC_AHBPeriphClockCmd(LCD_NCS_GPIO_CLK, ENABLE);
\r
1387 /* Configure NCS (PF.02) in Output Push-Pull mode */
\r
1388 GPIO_InitStructure.GPIO_Pin = LCD_NCS_PIN;
\r
1389 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
\r
1390 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
\r
1391 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
\r
1392 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
\r
1393 GPIO_Init(LCD_NCS_GPIO_PORT, &GPIO_InitStructure);
\r
1395 LCD_CtrlLinesWrite(LCD_NCS_GPIO_PORT, LCD_NCS_PIN, Bit_SET);
\r
1400 * @brief Sets or reset LCD control lines.
\r
1401 * @param GPIOx: where x can be B or D to select the GPIO peripheral.
\r
1402 * @param CtrlPins: the Control line.
\r
1403 * This parameter can be:
\r
1404 * @arg LCD_NCS_PIN: Chip Select pin
\r
1405 * @arg LCD_NWR_PIN: Read/Write Selection pin
\r
1406 * @arg LCD_RS_PIN: Register/RAM Selection pin
\r
1407 * @param BitVal: specifies the value to be written to the selected bit.
\r
1408 * This parameter can be:
\r
1409 * @arg Bit_RESET: to clear the port pin
\r
1410 * @arg Bit_SET: to set the port pin
\r
1413 void LCD_CtrlLinesWrite(GPIO_TypeDef* GPIOx, uint16_t CtrlPins, BitAction BitVal)
\r
1415 /* Set or Reset the control line */
\r
1416 GPIO_WriteBit(GPIOx, CtrlPins, BitVal);
\r
1421 * @brief Configures the LCD_SPI interface.
\r
1425 void LCD_SPIConfig(void)
\r
1427 SPI_InitTypeDef SPI_InitStructure;
\r
1428 GPIO_InitTypeDef GPIO_InitStructure;
\r
1430 /* Enable LCD_SPI_SCK_GPIO_CLK, LCD_SPI_MISO_GPIO_CLK and LCD_SPI_MOSI_GPIO_CLK clock */
\r
1431 RCC_AHBPeriphClockCmd(LCD_SPI_SCK_GPIO_CLK | LCD_SPI_MISO_GPIO_CLK | LCD_SPI_MOSI_GPIO_CLK, ENABLE);
\r
1433 /* Enable LCD_SPI and SYSCFG clock */
\r
1434 RCC_APB2PeriphClockCmd(LCD_SPI_CLK | RCC_APB2Periph_SYSCFG, ENABLE);
\r
1436 /* Configure LCD_SPI SCK pin */
\r
1437 GPIO_InitStructure.GPIO_Pin = LCD_SPI_SCK_PIN;
\r
1438 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
\r
1439 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
\r
1440 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
\r
1441 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
\r
1442 GPIO_Init(LCD_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
\r
1444 /* Configure LCD_SPI MISO pin */
\r
1445 GPIO_InitStructure.GPIO_Pin = LCD_SPI_MISO_PIN;
\r
1446 GPIO_Init(LCD_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
\r
1448 /* Configure LCD_SPI MOSI pin */
\r
1449 GPIO_InitStructure.GPIO_Pin = LCD_SPI_MOSI_PIN;
\r
1450 GPIO_Init(LCD_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
\r
1452 /* Connect PE.13 to SPI SCK */
\r
1453 GPIO_PinAFConfig(LCD_SPI_SCK_GPIO_PORT, LCD_SPI_SCK_SOURCE, LCD_SPI_SCK_AF);
\r
1455 /* Connect PE.14 to SPI MISO */
\r
1456 GPIO_PinAFConfig(LCD_SPI_MISO_GPIO_PORT, LCD_SPI_MISO_SOURCE, LCD_SPI_MISO_AF);
\r
1458 /* Connect PE.15 to SPI MOSI */
\r
1459 GPIO_PinAFConfig(LCD_SPI_MOSI_GPIO_PORT, LCD_SPI_MOSI_SOURCE, LCD_SPI_MOSI_AF);
\r
1461 SPI_DeInit(LCD_SPI);
\r
1464 SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
\r
1465 SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
\r
1466 SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
\r
1467 SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
\r
1468 SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
\r
1469 SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
\r
1470 SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
\r
1471 SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
\r
1472 SPI_InitStructure.SPI_CRCPolynomial = 7;
\r
1473 SPI_Init(LCD_SPI, &SPI_InitStructure);
\r
1476 SPI_Cmd(LCD_SPI, ENABLE);
\r
1480 * @brief Displays a pixel.
\r
1481 * @param x: pixel x.
\r
1482 * @param y: pixel y.
\r
1485 static void PutPixel(int16_t x, int16_t y)
\r
1487 if(x < 0 || x > 239 || y < 0 || y > 319)
\r
1491 LCD_DrawLine(x, y, 1, LCD_DIR_HORIZONTAL);
\r
1496 * @brief Inserts a delay time.
\r
1497 * @param nCount: specifies the delay time length.
\r
1500 static void delay(__IO uint32_t nCount)
\r
1502 __IO uint32_t index = 0;
\r
1503 for(index = (34000 * nCount); index != 0; index--)
\r
1507 #endif /* USE_Delay*/
\r
1528 /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
\r