OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [CORTEX_STM32L152_IAR/] [system_and_ST_code/] [STM32L152_EVAL/] [stm32l152_eval_lcd.c] - Blame information for rev 582

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.