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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [CORTEX_STM32F107_GCC_Rowley/] [LCD/] [lcd.c] - Blame information for rev 582

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 582 jeremybenn
/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
2
* File Name          : lcd.c
3
* Author             : MCD Application Team
4
* Version            : VX.Y.Z
5
* Date               : mm/dd/yyyy
6
* Description        : This file includes the LCD driver for AM-240320L8TNQW00H
7
*                      (LCD_ILI9320) Liquid Crystal Display Module of STM3210D-EVAL
8
*                      board.
9
********************************************************************************
10
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
11
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
12
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
13
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
14
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
15
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
16
*******************************************************************************/
17
 
18
/* Includes ------------------------------------------------------------------*/
19
#include "FreeRTOS.h"
20
#include "task.h"
21
 
22
#include    <stdio.h>
23
#include    <string.h>
24
#include    <ctype.h>
25
#include    <stdlib.h>
26
#include    <stdarg.h>
27
 
28
#include    <stm32f10x_conf.h>
29
#include    <stm32f10x_lib.h>
30
 
31
#include    "STM3210D_lcd.h"
32
#include        "fonts.h"
33
 
34
extern void timerDly(unsigned int);
35
 
36
/* Private typedef -----------------------------------------------------------*/
37
/* Private define ------------------------------------------------------------*/
38
#define START_BYTE      0x70
39
#define SET_INDEX       0x00
40
#define READ_STATUS     0x01
41
#define LCD_WRITE_REG   0x02
42
#define LCD_READ_REG    0x03
43
 
44
/* Private macro -------------------------------------------------------------*/
45
/* Private variables ---------------------------------------------------------*/
46
  /* Global variables to set the written text color */
47
static  vu16 TextColor = 0x0000, BackColor = 0xFFFF;
48
 
49
/* Private function prototypes -----------------------------------------------*/
50
/* Private functions ---------------------------------------------------------*/
51
 
52
#define timerDly( x )   vTaskDelay( ( x * 10 ) / portTICK_RATE_MS );
53
#define vBlockToWait( x )
54
 
55
/*******************************************************************************
56
* Function Name  : LCD_Setup
57
* Description    : Setups the LCD.
58
* Input          : None
59
* Output         : None
60
* Return         : None
61
*******************************************************************************/
62
void LCD_Setup(void)
63
{
64
/* Configure the LCD Control pins --------------------------------------------*/
65
  LCD_CtrlLinesConfig();
66
 
67
/* Configure the SPI3 interface ----------------------------------------------*/
68
  LCD_SPIConfig();
69
 
70
  timerDly(5); /* Delay 50 ms */
71
  /* Start Initial Sequence ------------------------------------------------*/
72
  LCD_WriteReg(R229, 0x8000); /* Set the internal vcore voltage */
73
  LCD_WriteReg(R0,  0x0001); /* Start internal OSC. */
74
  LCD_WriteReg(R1,  0x0100); /* set SS and SM bit */
75
  LCD_WriteReg(R2,  0x0700); /* set 1 line inversion */
76
  LCD_WriteReg(R3,  0x1030); /* set GRAM write direction and BGR=1. */
77
  LCD_WriteReg(R4,  0x0000); /* Resize register */
78
  LCD_WriteReg(R8,  0x0202); /* set the back porch and front porch */
79
  LCD_WriteReg(R9,  0x0000); /* set non-display area refresh cycle ISC[3:0] */
80
  LCD_WriteReg(R10, 0x0000); /* FMARK function */
81
  LCD_WriteReg(R12, 0x0000); /* RGB interface setting */
82
  LCD_WriteReg(R13, 0x0000); /* Frame marker Position */
83
  LCD_WriteReg(R15, 0x0000); /* RGB interface polarity */
84
 
85
  /* Power On sequence -----------------------------------------------------*/
86
  LCD_WriteReg(R16, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
87
  LCD_WriteReg(R17, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
88
  LCD_WriteReg(R18, 0x0000); /* VREG1OUT voltage */
89
  LCD_WriteReg(R19, 0x0000); /* VDV[4:0] for VCOM amplitude */
90
  timerDly(20);                 /* Dis-charge capacitor power voltage (200ms) */
91
  LCD_WriteReg(R16, 0x17B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
92
  LCD_WriteReg(R17, 0x0137); /* DC1[2:0], DC0[2:0], VC[2:0] */
93
  timerDly(5);                  /* Delay 50 ms */
94
  LCD_WriteReg(R18, 0x0139); /* VREG1OUT voltage */
95
  timerDly(5);                  /* Delay 50 ms */
96
  LCD_WriteReg(R19, 0x1d00); /* VDV[4:0] for VCOM amplitude */
97
  LCD_WriteReg(R41, 0x0013); /* VCM[4:0] for VCOMH */
98
  timerDly(5);                  /* Delay 50 ms */
99
  LCD_WriteReg(R32, 0x0000); /* GRAM horizontal Address */
100
  LCD_WriteReg(R33, 0x0000); /* GRAM Vertical Address */
101
 
102
  /* Adjust the Gamma Curve ------------------------------------------------*/
103
  LCD_WriteReg(R48, 0x0006);
104
  LCD_WriteReg(R49, 0x0101);
105
  LCD_WriteReg(R50, 0x0003);
106
  LCD_WriteReg(R53, 0x0106);
107
  LCD_WriteReg(R54, 0x0b02);
108
  LCD_WriteReg(R55, 0x0302);
109
  LCD_WriteReg(R56, 0x0707);
110
  LCD_WriteReg(R57, 0x0007);
111
  LCD_WriteReg(R60, 0x0600);
112
  LCD_WriteReg(R61, 0x020b);
113
 
114
  /* Set GRAM area ---------------------------------------------------------*/
115
  LCD_WriteReg(R80, 0x0000); /* Horizontal GRAM Start Address */
116
  LCD_WriteReg(R81, 0x00EF); /* Horizontal GRAM End Address */
117
  LCD_WriteReg(R82, 0x0000); /* Vertical GRAM Start Address */
118
  LCD_WriteReg(R83, 0x013F); /* Vertical GRAM End Address */
119
 
120
  LCD_WriteReg(R96,  0x2700); /* Gate Scan Line */
121
  LCD_WriteReg(R97,  0x0001); /* NDL,VLE, REV */
122
  LCD_WriteReg(R106, 0x0000); /* set scrolling line */
123
 
124
  /* Partial Display Control -----------------------------------------------*/
125
  LCD_WriteReg(R128, 0x0000);
126
  LCD_WriteReg(R129, 0x0000);
127
  LCD_WriteReg(R130, 0x0000);
128
  LCD_WriteReg(R131, 0x0000);
129
  LCD_WriteReg(R132, 0x0000);
130
  LCD_WriteReg(R133, 0x0000);
131
 
132
  /* Panel Control ---------------------------------------------------------*/
133
  LCD_WriteReg(R144, 0x0010);
134
  LCD_WriteReg(R146, 0x0000);
135
  LCD_WriteReg(R147, 0x0003);
136
  LCD_WriteReg(R149, 0x0110);
137
  LCD_WriteReg(R151, 0x0000);
138
  LCD_WriteReg(R152, 0x0000);
139
 
140
  /* Set GRAM write direction and BGR = 1 */
141
  /* I/D=01 (Horizontal : increment, Vertical : decrement) */
142
  /* AM=1 (address is updated in vertical writing direction) */
143
  LCD_WriteReg(R3, 0x1018);
144
 
145
  LCD_WriteReg(R7, 0x0173); /* 262K color and display ON */
146
}
147
 
148
/*******************************************************************************
149
* Function Name  : STM3210D_LCD_Init
150
* Description    : Initializes the LCD.
151
* Input          : None
152
* Output         : None
153
* Return         : None
154
*******************************************************************************/
155
void STM3210D_LCD_Init(void)
156
{
157
  /* Setups the LCD */
158
  LCD_Setup();
159
}
160
 
161
/*******************************************************************************
162
* Function Name  : LCD_SetTextColor
163
* Description    : Sets the Text color.
164
* Input          : - Color: specifies the Text color code RGB(5-6-5).
165
* Output         : - TextColor: Text color global variable used by LCD_DrawChar
166
*                  and LCD_DrawPicture functions.
167
* Return         : None
168
*******************************************************************************/
169
void LCD_SetTextColor(vu16 Color)
170
{
171
  TextColor = Color;
172
}
173
 
174
/*******************************************************************************
175
* Function Name  : LCD_SetBackColor
176
* Description    : Sets the Background color.
177
* Input          : - Color: specifies the Background color code RGB(5-6-5).
178
* Output         : - BackColor: Background color global variable used by
179
*                  LCD_DrawChar and LCD_DrawPicture functions.
180
* Return         : None
181
*******************************************************************************/
182
void LCD_SetBackColor(vu16 Color)
183
{
184
  BackColor = Color;
185
}
186
 
187
/*******************************************************************************
188
* Function Name  : LCD_ClearLine
189
* Description    : Clears the selected line.
190
* Input          : - Line: the Line to be cleared.
191
*                    This parameter can be one of the following values:
192
*                       - Linex: where x can be 0..9
193
* Output         : None
194
* Return         : None
195
*******************************************************************************/
196
void LCD_ClearLine(u8 Line)
197
{
198
  LCD_DisplayStringLine(Line, ( unsigned char * ) "                    ");
199
}
200
 
201
/*******************************************************************************
202
* Function Name  : LCD_Clear
203
* Description    : Clears the hole LCD.
204
* Input          : Color: the color of the background.
205
* Output         : None
206
* Return         : None
207
*******************************************************************************/
208
void LCD_Clear(u16 Color)
209
{
210
  vu32 index = 0;
211
 
212
  LCD_SetCursor(0x00, 0x013F);
213
 
214
  LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
215
 
216
  for(index = 0; index < 76800; index++)
217
  {
218
    LCD_WriteRAM(Color);
219
  }
220
 
221
  LCD_CtrlLinesWrite(GPIOB, CtrlPin_NCS, Bit_SET);
222
 
223
}
224
 
225
/*******************************************************************************
226
* Function Name  : LCD_SetCursor
227
* Description    : Sets the cursor position.
228
* Input          : - Xpos: specifies the X position.
229
*                  - Ypos: specifies the Y position.
230
* Output         : None
231
* Return         : None
232
*******************************************************************************/
233
void LCD_SetCursor(u8 Xpos, u16 Ypos)
234
{
235
 LCD_WriteReg(R32, Xpos);
236
 LCD_WriteReg(R33, Ypos);
237
}
238
 
239
/*******************************************************************************
240
* Function Name  : LCD_DrawChar
241
* Description    : Draws a character on LCD.
242
* Input          : - Xpos: the Line where to display the character shape.
243
*                    This parameter can be one of the following values:
244
*                       - Linex: where x can be 0..9
245
*                  - Ypos: start column address.
246
*                  - c: pointer to the character data.
247
* Output         : None
248
* Return         : None
249
*******************************************************************************/
250
void LCD_DrawChar(u8 Xpos, u16 Ypos, uc16 *c)
251
{
252
  vu32 index = 0, i = 0;
253
  vu8 Xaddress = 0;
254
 
255
  Xaddress = Xpos;
256
 
257
  LCD_SetCursor(Xaddress, Ypos);
258
 
259
  for(index = 0; index < 24; index++)
260
  {
261
    LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
262
 
263
    for(i = 0; i < 16; i++)
264
    {
265
      if((c[index] & (1 << i)) == 0x00)
266
      {
267
        LCD_WriteRAM(BackColor);
268
      }
269
      else
270
      {
271
        LCD_WriteRAM(TextColor);
272
      }
273
    }
274
    LCD_CtrlLinesWrite(GPIOB, CtrlPin_NCS, Bit_SET);
275
    Xaddress++;
276
    LCD_SetCursor(Xaddress, Ypos);
277
  }
278
}
279
 
280
/*******************************************************************************
281
* Function Name  : LCD_DisplayChar
282
* Description    : Displays one character (16dots width, 24dots height).
283
* Input          : - Line: the Line where to display the character shape .
284
*                    This parameter can be one of the following values:
285
*                       - Linex: where x can be 0..9
286
*                  - Column: start column address.
287
*                  - Ascii: character ascii code, must be between 0x20 and 0x7E.
288
* Output         : None
289
* Return         : None
290
*******************************************************************************/
291
void LCD_DisplayChar(u8 Line, u16 Column, u8 Ascii)
292
{
293
  Ascii -= 32;
294
  LCD_DrawChar(Line, Column, &ASCII_Table[Ascii * 24]);
295
}
296
 
297
/*******************************************************************************
298
* Function Name  : LCD_DisplayStringLine
299
* Description    : Displays a maximum of 20 char on the LCD.
300
* Input          : - Line: the Line where to display the character shape .
301
*                    This parameter can be one of the following values:
302
*                       - Linex: where x can be 0..9
303
*                  - *ptr: pointer to string to display on LCD.
304
* Output         : None
305
* Return         : None
306
*******************************************************************************/
307
void LCD_DisplayStringLine(u8 Line, u8 *ptr)
308
{
309
  vu32 i = 0;
310
  vu16 refcolumn = 319;
311
 
312
  /* Send the string character by character on lCD */
313
  while ((*ptr != 0) & (i < 20))
314
  {
315
    /* Display one character on LCD */
316
    LCD_DisplayChar(Line, refcolumn, *ptr);
317
    /* Decrement the column position by 16 */
318
    refcolumn -= 16;
319
    /* Point on the next character */
320
    ptr++;
321
    /* Increment the character counter */
322
    i++;
323
  }
324
}
325
 
326
/*******************************************************************************
327
* Function Name  : LCD_SetDisplayWindow
328
* Description    : Sets a display window
329
* Input          : - Xpos: specifies the X buttom left position.
330
*                  - Ypos: specifies the Y buttom left position.
331
*                  - Height: display window height.
332
*                  - Width: display window width.
333
* Output         : None
334
* Return         : None
335
*******************************************************************************/
336
void LCD_SetDisplayWindow(u8 Xpos, u16 Ypos, u8 Height, u16 Width)
337
{
338
  /* Horizontal GRAM Start Address */
339
  if(Xpos >= Height)
340
  {
341
    LCD_WriteReg(R80, (Xpos - Height + 1));
342
  }
343
  else
344
  {
345
    LCD_WriteReg(R80, 0);
346
  }
347
  /* Horizontal GRAM End Address */
348
  LCD_WriteReg(R81, Xpos);
349
  /* Vertical GRAM Start Address */
350
  if(Ypos >= Width)
351
  {
352
    LCD_WriteReg(R82, (Ypos - Width + 1));
353
  }
354
  else
355
  {
356
    LCD_WriteReg(R82, 0);
357
  }
358
  /* Vertical GRAM End Address */
359
  LCD_WriteReg(R83, Ypos);
360
  LCD_SetCursor(Xpos, Ypos);
361
}
362
 
363
/*******************************************************************************
364
* Function Name  : LCD_WindowModeDisable
365
* Description    : Disables LCD Window mode.
366
* Input          : None
367
* Output         : None
368
* Return         : None
369
*******************************************************************************/
370
void LCD_WindowModeDisable(void)
371
{
372
  LCD_SetDisplayWindow(239, 0x13F, 240, 320);
373
  LCD_WriteReg(R3, 0x1018);
374
}
375
/*******************************************************************************
376
* Function Name  : LCD_DrawLine
377
* Description    : Displays a line.
378
* Input          : - Xpos: specifies the X position.
379
*                  - Ypos: specifies the Y position.
380
*                  - Length: line length.
381
*                  - Direction: line direction.
382
*                    This parameter can be one of the following values: Vertical
383
*                    or Horizontal.
384
* Output         : None
385
* Return         : None
386
*******************************************************************************/
387
void LCD_DrawLine(u8 Xpos, u16 Ypos, u16 Length, u8 Direction)
388
{
389
  u32 i = 0;
390
 
391
  LCD_SetCursor(Xpos, Ypos);
392
 
393
  if(Direction == Horizontal)
394
  {
395
    LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
396
 
397
    for(i = 0; i < Length; i++)
398
    {
399
      LCD_WriteRAM(TextColor);
400
    }
401
    LCD_CtrlLinesWrite(GPIOB, CtrlPin_NCS, Bit_SET);
402
  }
403
  else
404
  {
405
    for(i = 0; i < Length; i++)
406
    {
407
      LCD_WriteRAMWord(TextColor);
408
      Xpos++;
409
      LCD_SetCursor(Xpos, Ypos);
410
    }
411
  }
412
}
413
 
414
/*******************************************************************************
415
* Function Name  : LCD_DrawRect
416
* Description    : Displays a rectangle.
417
* Input          : - Xpos: specifies the X position.
418
*                  - Ypos: specifies the Y position.
419
*                  - Height: display rectangle height.
420
*                  - Width: display rectangle width.
421
* Output         : None
422
* Return         : None
423
*******************************************************************************/
424
void LCD_DrawRect(u8 Xpos, u16 Ypos, u8 Height, u16 Width)
425
{
426
  LCD_DrawLine(Xpos, Ypos, Width, Horizontal);
427
  LCD_DrawLine((Xpos + Height), Ypos, Width, Horizontal);
428
 
429
  LCD_DrawLine(Xpos, Ypos, Height, Vertical);
430
  LCD_DrawLine(Xpos, (Ypos - Width + 1), Height, Vertical);
431
}
432
 
433
/*******************************************************************************
434
* Function Name  : LCD_DrawCircle
435
* Description    : Displays a circle.
436
* Input          : - Xpos: specifies the X position.
437
*                  - Ypos: specifies the Y position.
438
*                  - Height: display rectangle height.
439
*                  - Width: display rectangle width.
440
* Output         : None
441
* Return         : None
442
*******************************************************************************/
443
void LCD_DrawCircle(u8 Xpos, u16 Ypos, u16 Radius)
444
{
445
  s32  D;/* Decision Variable */
446
  u32  CurX;/* Current X Value */
447
  u32  CurY;/* Current Y Value */
448
 
449
  D = 3 - (Radius << 1);
450
  CurX = 0;
451
  CurY = Radius;
452
 
453
  while (CurX <= CurY)
454
  {
455
    LCD_SetCursor(Xpos + CurX, Ypos + CurY);
456
    LCD_WriteRAMWord(TextColor);
457
 
458
    LCD_SetCursor(Xpos + CurX, Ypos - CurY);
459
    LCD_WriteRAMWord(TextColor);
460
 
461
    LCD_SetCursor(Xpos - CurX, Ypos + CurY);
462
    LCD_WriteRAMWord(TextColor);
463
 
464
    LCD_SetCursor(Xpos - CurX, Ypos - CurY);
465
    LCD_WriteRAMWord(TextColor);
466
 
467
    LCD_SetCursor(Xpos + CurY, Ypos + CurX);
468
    LCD_WriteRAMWord(TextColor);
469
 
470
    LCD_SetCursor(Xpos + CurY, Ypos - CurX);
471
    LCD_WriteRAMWord(TextColor);
472
 
473
    LCD_SetCursor(Xpos - CurY, Ypos + CurX);
474
    LCD_WriteRAMWord(TextColor);
475
 
476
    LCD_SetCursor(Xpos - CurY, Ypos - CurX);
477
    LCD_WriteRAMWord(TextColor);
478
 
479
    if (D < 0)
480
    {
481
      D += (CurX << 2) + 6;
482
    }
483
    else
484
    {
485
      D += ((CurX - CurY) << 2) + 10;
486
      CurY--;
487
    }
488
    CurX++;
489
  }
490
}
491
 
492
/*******************************************************************************
493
* Function Name  : LCD_DrawMonoPict
494
* Description    : Displays a monocolor picture.
495
* Input          : - Pict: pointer to the picture array.
496
* Output         : None
497
* Return         : None
498
*******************************************************************************/
499
void LCD_DrawMonoPict(uc32 *Pict)
500
{
501
  u32 index = 0, i = 0;
502
 
503
  LCD_SetCursor(0, 319);
504
  LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
505
 
506
  for(index = 0; index < 2400; index++)
507
  {
508
    for(i = 0; i < 32; i++)
509
    {
510
      if((Pict[index] & (1 << i)) == 0x00)
511
      {
512
        LCD_WriteRAM(BackColor);
513
      }
514
      else
515
      {
516
        LCD_WriteRAM(TextColor);
517
      }
518
    }
519
  }
520
  LCD_CtrlLinesWrite(GPIOB, CtrlPin_NCS, Bit_SET);
521
 
522
}
523
 
524
///*******************************************************************************
525
//* Function Name  : LCD_DrawBMP
526
//* Description    : Displays a bitmap picture loaded in the SPI Flash.
527
//* Input          : - BmpAddress: Bmp picture address in the SPI Flash.
528
//* Output         : None
529
//* Return         : None
530
//*******************************************************************************/
531
//void LCD_DrawBMP(u32 BmpAddress)
532
//{
533
//  u32 i = 0, size = 0;
534
//
535
//  /* Read bitmap size */
536
//  SPI_FLASH_BufferRead((u8*)&size, BmpAddress + 2, 4);
537
//
538
//  /* get bitmap data address offset */
539
//  SPI_FLASH_BufferRead((u8*)&i, BmpAddress + 10, 4);
540
//
541
//  size = (size - i)/2;
542
//
543
//  SPI_FLASH_StartReadSequence(BmpAddress + i);
544
//
545
//  /* Disable SPI1  */
546
//  SPI_Cmd(SPI1, DISABLE);
547
//  /* SPI in 16-bit mode */
548
//  SPI_DataSizeConfig(SPI1, SPI_DataSize_16b);
549
//
550
//  /* Enable SPI1  */
551
//  SPI_Cmd(SPI1, ENABLE);
552
//
553
//  /* Set GRAM write direction and BGR = 1 */
554
//  /* I/D=00 (Horizontal : decrement, Vertical : decrement) */
555
//  /* AM=1 (address is updated in vertical writing direction) */
556
//  LCD_WriteReg(R3, 0x1008);
557
//
558
//  LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
559
//
560
//  /* Read bitmap data from SPI Flash and send them to LCD */
561
//  for(i = 0; i < size; i++)
562
//  {
563
//    LCD_WriteRAM(__REV_HalfWord(SPI_FLASH_SendHalfWord(0xA5A5)));
564
//  }
565
//
566
//  LCD_CtrlLinesWrite(GPIOB, CtrlPin_NCS, Bit_SET);
567
//
568
//  /* Deselect the FLASH: Chip Select high */
569
//  SPI_FLASH_CS_HIGH();
570
//
571
//  /* Disable SPI1  */
572
//  SPI_Cmd(SPI1, DISABLE);
573
//  /* SPI in 8-bit mode */
574
//  SPI_DataSizeConfig(SPI1, SPI_DataSize_8b);
575
//
576
//  /* Enable SPI1  */
577
//  SPI_Cmd(SPI1, ENABLE);
578
//
579
//  /* Set GRAM write direction and BGR = 1 */
580
//  /* I/D = 01 (Horizontal : increment, Vertical : decrement) */
581
//  /* AM = 1 (address is updated in vertical writing direction) */
582
//  LCD_WriteReg(R3, 0x1018);
583
//}
584
 
585
/*******************************************************************************
586
* Function Name  : LCD_DrawBMP
587
* Description    : Displays a bitmap picture loaded in the SPI Flash.
588
* Input          : - BmpAddress: Bmp picture address in the SPI Flash.
589
* Output         : None
590
* Return         : None
591
*******************************************************************************/
592
void LCD_DrawBMP(uc16 *BmpAddress)
593
{
594
  u32 i = 0, size = 0;
595
 
596
  /* Read bitmap size */
597
  size = BmpAddress[1] | (BmpAddress[2] << 16);
598
 
599
  /* get bitmap data address offset */
600
  i = BmpAddress[5] | (BmpAddress[6] << 16);
601
 
602
  size = (size - i)/2;
603
 
604
  BmpAddress += i/2;
605
  /* Set GRAM write direction and BGR = 1 */
606
  /* I/D=00 (Horizontal : decrement, Vertical : decrement) */
607
  /* AM=1 (address is updated in vertical writing direction) */
608
  LCD_WriteReg(R3, 0x1008);
609
 
610
  LCD_WriteRAM_Prepare(); /* Prepare to write GRAM */
611
 
612
  /* Read bitmap data from SPI Flash and send them to LCD */
613
  for(i = 0; i < size; i++)
614
  {
615
    LCD_WriteRAM(BmpAddress[i]);
616
  }
617
 
618
  LCD_CtrlLinesWrite(GPIOB, CtrlPin_NCS, Bit_SET);
619
 
620
  /* Set GRAM write direction and BGR = 1 */
621
  /* I/D = 01 (Horizontal : increment, Vertical : decrement) */
622
  /* AM = 1 (address is updated in vertical writing direction) */
623
  LCD_WriteReg(R3, 0x1018);
624
}
625
 
626
/*******************************************************************************
627
* Function Name  : LCD_nCS_StartByte
628
* Description    : Reset LCD control line(/CS) and Send Start-Byte
629
* Input          : - Start_Byte: the Start-Byte to be sent
630
* Output         : None
631
* Return         : None
632
*******************************************************************************/
633
void LCD_nCS_StartByte(u8 Start_Byte)
634
{
635
  LCD_CtrlLinesWrite(GPIOB, CtrlPin_NCS, Bit_RESET);
636
 
637
  SPI_I2S_SendData(SPI3, Start_Byte);
638
  while(SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_BSY) != RESET)
639
  {
640
        vBlockToWait( 1 );
641
  }
642
}
643
 
644
/*******************************************************************************
645
* Function Name  : LCD_WriteRegIndex
646
* Description    : Writes index to select the LCD register.
647
* Input          : - LCD_Reg: address of the selected register.
648
* Output         : None
649
* Return         : None
650
*******************************************************************************/
651
void LCD_WriteRegIndex(u8 LCD_Reg)
652
{
653
  /* Reset LCD control line(/CS) and Send Start-Byte */
654
  LCD_nCS_StartByte(START_BYTE | SET_INDEX);
655
 
656
  /* Write 16-bit Reg Index (High Byte is 0) */
657
  SPI_I2S_SendData(SPI3, 0x00);
658
  while(SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_BSY) != RESET)
659
  {
660
        vBlockToWait( 1 );
661
  }
662
  SPI_I2S_SendData(SPI3, LCD_Reg);
663
  while(SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_BSY) != RESET)
664
  {
665
        vBlockToWait( 1 );
666
  }
667
 
668
  LCD_CtrlLinesWrite(GPIOB, CtrlPin_NCS, Bit_SET);
669
}
670
 
671
/*******************************************************************************
672
* Function Name  : LCD_ReadReg
673
* Description    : Reads the selected LCD Register.
674
* Input          : None
675
* Output         : None
676
* Return         : LCD Register Value.
677
*******************************************************************************/
678
u16 LCD_ReadReg(u8 LCD_Reg)
679
{
680
  vu16 tmp = 0;
681
  vu8 i = 0;
682
 
683
  /* SPI3 prescaler: 4 */
684
  SPI3->CR1 &= 0xFFC7;
685
  SPI3->CR1 |= 0x0008;
686
 
687
  /* Write 16-bit Index (then Read Reg) */
688
  LCD_WriteRegIndex(LCD_Reg);
689
 
690
  /* Read 16-bit Reg */
691
  /* Reset LCD control line(/CS) and Send Start-Byte */
692
  LCD_nCS_StartByte(START_BYTE | LCD_READ_REG);
693
 
694
  for(i = 0; i < 5; i++)
695
  {
696
    SPI_I2S_SendData(SPI3, 0xFF);
697
 
698
    while(SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_BSY) != RESET)
699
    {
700
                vBlockToWait( 1 );
701
    }
702
    /* One byte of invalid dummy data read after the start byte */
703
    while(SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_RXNE) == RESET)
704
    {
705
                vBlockToWait( 1 );
706
    }
707
    SPI_I2S_ReceiveData(SPI3);
708
  }
709
 
710
  SPI_I2S_SendData(SPI3, 0xFF);
711
  /* Read upper byte */
712
  while(SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_BSY) != RESET)
713
  {
714
        vBlockToWait( 1 );
715
  }
716
  /* Read lower byte */
717
  while(SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_RXNE) == RESET)
718
  {
719
        vBlockToWait( 1 );
720
  }
721
  tmp = SPI_I2S_ReceiveData(SPI3);
722
 
723
 
724
  SPI_I2S_SendData(SPI3, 0xFF);
725
  while(SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_BSY) != RESET)
726
  {
727
        vBlockToWait( 1 );
728
  }
729
  /* Read lower byte */
730
  while(SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_RXNE) == RESET)
731
  {
732
        vBlockToWait( 1 );
733
  }
734
  tmp = ((tmp & 0xFF) << 8) | SPI_I2S_ReceiveData(SPI3);
735
 
736
  LCD_CtrlLinesWrite(GPIOB, CtrlPin_NCS, Bit_SET);
737
 
738
  /* SPI3 prescaler: 2 */
739
  SPI3->CR1 &= 0xFFC7;
740
 
741
  return tmp;
742
}
743
 
744
/*******************************************************************************
745
* Function Name  : LCD_WriteRAM_Prepare
746
* Description    : Prepare to write to the LCD RAM.
747
* Input          : None
748
* Output         : None
749
* Return         : None
750
*******************************************************************************/
751
void LCD_WriteRAM_Prepare(void)
752
{
753
  LCD_WriteRegIndex(R34); /* Select GRAM Reg */
754
 
755
  /* Reset LCD control line(/CS) and Send Start-Byte */
756
  LCD_nCS_StartByte(START_BYTE | LCD_WRITE_REG);
757
}
758
 
759
/*******************************************************************************
760
* Function Name  : LCD_WriteRAMWord
761
* Description    : Writes 1 word to the LCD RAM.
762
* Input          : - RGB_Code: the pixel color in RGB mode (5-6-5).
763
* Output         : None
764
* Return         : None
765
*******************************************************************************/
766
void LCD_WriteRAMWord(u16 RGB_Code)
767
{
768
  LCD_WriteRAM_Prepare();
769
 
770
  LCD_WriteRAM(RGB_Code);
771
 
772
  LCD_CtrlLinesWrite(GPIOB, CtrlPin_NCS, Bit_SET);
773
}
774
 
775
/*******************************************************************************
776
* Function Name  : LCD_WriteReg
777
* Description    : Writes to the selected LCD register.
778
* Input          : - LCD_Reg: address of the selected register.
779
*                  - LCD_RegValue: value to write to the selected register.
780
* Output         : None
781
* Return         : None
782
*******************************************************************************/
783
void LCD_WriteReg(u8 LCD_Reg, u16 LCD_RegValue)
784
{
785
  /* Write 16-bit Index (then Write Reg) */
786
  LCD_WriteRegIndex(LCD_Reg);
787
 
788
  /* Write 16-bit Reg */
789
  /* Reset LCD control line(/CS) and Send Start-Byte */
790
  LCD_nCS_StartByte(START_BYTE | LCD_WRITE_REG);
791
 
792
  SPI_I2S_SendData(SPI3, LCD_RegValue>>8);
793
  while(SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_BSY) != RESET)
794
  {
795
        vBlockToWait( 1 );
796
  }
797
  SPI_I2S_SendData(SPI3, (LCD_RegValue & 0xFF));
798
  while(SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_BSY) != RESET)
799
  {
800
        vBlockToWait( 1 );
801
  }
802
 
803
  LCD_CtrlLinesWrite(GPIOB, CtrlPin_NCS, Bit_SET);
804
}
805
 
806
 
807
/*******************************************************************************
808
* Function Name  : LCD_WriteRAM
809
* Description    : Writes to the LCD RAM.
810
* Input          : - RGB_Code: the pixel color in RGB mode (5-6-5).
811
* Output         : None
812
* Return         : None
813
*******************************************************************************/
814
void LCD_WriteRAM(u16 RGB_Code)
815
{
816
  SPI_I2S_SendData(SPI3, RGB_Code >> 8);
817
  while(SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_BSY) != RESET)
818
  {
819
        vBlockToWait( 1 );
820
  }
821
  SPI_I2S_SendData(SPI3, RGB_Code & 0xFF);
822
 
823
  while(SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_BSY) != RESET)
824
  {
825
        vBlockToWait( 1 );
826
  }
827
}
828
 
829
/*******************************************************************************
830
* Function Name  : LCD_PowerOn
831
* Description    : Power on the LCD.
832
* Input          : None
833
* Output         : None
834
* Return         : None
835
*******************************************************************************/
836
void LCD_PowerOn(void)
837
{
838
  /* Power On sequence ---------------------------------------------------------*/
839
  LCD_WriteReg(R16, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
840
  LCD_WriteReg(R17, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */
841
  LCD_WriteReg(R18, 0x0000); /* VREG1OUT voltage */
842
  LCD_WriteReg(R19, 0x0000); /* VDV[4:0] for VCOM amplitude */
843
  timerDly(20);                 /* Dis-charge capacitor power voltage (200ms) */
844
  LCD_WriteReg(R16, 0x17B0); /* SAP, BT[3:0], AP, DSTB, SLP, STB */
845
  LCD_WriteReg(R17, 0x0137); /* DC1[2:0], DC0[2:0], VC[2:0] */
846
  timerDly(5);                  /* delay 50 ms */
847
  LCD_WriteReg(R18, 0x0139); /* VREG1OUT voltage */
848
  timerDly(5);                  /* delay 50 ms */
849
  LCD_WriteReg(R19, 0x1d00); /* VDV[4:0] for VCOM amplitude */
850
  LCD_WriteReg(R41, 0x0013); /* VCM[4:0] for VCOMH */
851
  timerDly(5);                  /* delay 50 ms */
852
  LCD_WriteReg(R7, 0x0173);  /* 262K color and display ON */
853
}
854
 
855
/*******************************************************************************
856
* Function Name  : LCD_DisplayOn
857
* Description    : Enables the Display.
858
* Input          : None
859
* Output         : None
860
* Return         : None
861
*******************************************************************************/
862
void LCD_DisplayOn(void)
863
{
864
  /* Display On */
865
  LCD_WriteReg(R7, 0x0173); /* 262K color and display ON */
866
 
867
}
868
 
869
/*******************************************************************************
870
* Function Name  : LCD_DisplayOff
871
* Description    : Disables the Display.
872
* Input          : None
873
* Output         : None
874
* Return         : None
875
*******************************************************************************/
876
void LCD_DisplayOff(void)
877
{
878
  /* Display Off */
879
  LCD_WriteReg(R7, 0x0);
880
}
881
 
882
/*******************************************************************************
883
* Function Name  : LCD_CtrlLinesConfig
884
* Description    : Configures LCD control lines in Output Push-Pull mode.
885
* Input          : None
886
* Output         : None
887
* Return         : None
888
*******************************************************************************/
889
void LCD_CtrlLinesConfig(void)
890
{
891
  GPIO_InitTypeDef GPIO_InitStructure;
892
 
893
  /* Configure NCS (PB.02) in Output Push-Pull mode */
894
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
895
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
896
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
897
  GPIO_Init(GPIOB, &GPIO_InitStructure);
898
 
899
  /* Configure NWR(RNW), RS (PD.15, PD.07) in Output Push-Pull mode */
900
//  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_15;
901
//  GPIO_Init(GPIOD, &GPIO_InitStructure);
902
 
903
//  LCD_CtrlLinesWrite(GPIOD, CtrlPin_NWR, Bit_SET);
904
//  LCD_CtrlLinesWrite(GPIOD, CtrlPin_RS, Bit_SET);
905
}
906
 
907
/*******************************************************************************
908
* Function Name  : LCD_CtrlLinesWrite
909
* Description    : Sets or reset LCD control lines.
910
* Input          : - GPIOx: where x can be B or D to select the GPIO peripheral.
911
*                  - CtrlPins: the Control line. This parameter can be:
912
*                       - CtrlPin_NCS: Chip Select pin (PB.02)
913
*                       - CtrlPin_NWR: Read/Write Selection pin (PD.15)
914
*                       - CtrlPin_RS: Register/RAM Selection pin (PD.07)
915
*                  - BitVal: specifies the value to be written to the selected bit.
916
*                    This parameter can be:
917
*                       - Bit_RESET: to clear the port pin
918
*                       - Bit_SET: to set the port pin
919
* Output         : None
920
* Return         : None
921
*******************************************************************************/
922
void LCD_CtrlLinesWrite(GPIO_TypeDef* GPIOx, u16 CtrlPins, BitAction BitVal)
923
{
924
  /* Set or Reset the control line */
925
  GPIO_WriteBit(GPIOx, CtrlPins, BitVal);
926
}
927
 
928
/*******************************************************************************
929
* Function Name  : LCD_SPIConfig
930
* Description    : Configures the SPI3 interface.
931
* Input          : None
932
* Output         : None
933
* Return         : None
934
*******************************************************************************/
935
void LCD_SPIConfig(void)
936
{
937
  SPI_InitTypeDef    SPI_InitStructure;
938
  GPIO_InitTypeDef   GPIO_InitStructure;
939
 
940
  /* Enable GPIOC clock */
941
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO, ENABLE);
942
 
943
  //GPIO_PinRemapConfig(GPIO_Remap_SPI3, ENABLE);
944
  AFIO->MAPR |= GPIO_Remap_SPI3;
945
 
946
  /* Enable SPI3 clock  */
947
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI3, ENABLE);
948
 
949
  /* Configure SPI3 pins: SCK, MISO and MOSI */
950
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12;
951
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
952
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
953
  GPIO_Init(GPIOC, &GPIO_InitStructure);
954
 
955
  SPI_I2S_DeInit(SPI3);
956
 
957
  /* SPI3 Config */
958
  SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
959
  SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
960
  SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
961
  SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
962
  SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
963
  SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
964
  SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;
965
  SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
966
  SPI_Init(SPI3, &SPI_InitStructure);
967
 
968
  /* SPI3 enable */
969
  SPI_Cmd(SPI3, ENABLE);
970
}
971
 
972
/******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/

powered by: WebSVN 2.1.0

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