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

Subversion Repositories openrisc

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 582 jeremybenn
/********************* (C) COPYRIGHT 2007 RAISONANCE S.A.S. *******************/
2
/**
3
*
4
* @file     lcd.c
5
* @brief    The LCD driver for the ST7637.
6
* @author   FL
7
* @date     07/2007
8
*
9
**/
10
/******************************************************************************/
11
 
12
/* Includes ------------------------------------------------------------------*/
13
#include "lcd.h"
14
#include "circle.h"
15
 
16
/// @cond Internal
17
 
18
/* Private define ------------------------------------------------------------*/
19
#define V9_MADCTRVAL                0x90     /*!< Left orientation value.     */
20
#define V12_MADCTRVAL               0x30     /*!< Up orientation value.       */
21
#define V3_MADCTRVAL                0x50     /*!< Right orientation value.    */
22
#define V6_MADCTRVAL                0xF0     /*!< Bottom orientation value.   */
23
#define BACKLIGHT_DIVIDER           500      /*!< LCD handler step.           */
24
 
25
/* Private variables ---------------------------------------------------------*/
26
 
27
// vars for timer dedicated for lcd backlight
28
static TIM_TimeBaseInitTypeDef      TIM_TimeBaseStructure;
29
static TIM_OCInitTypeDef            TIM_OCInitStructure;
30
static int                          HandlerDivider             = 0;
31
 
32
int                                 Current_CCR_BackLightStart = DEFAULT_CCR_BACKLIGHTSTART;
33
 
34
/* External variable ---------------------------------------------------------*/
35
extern GPIO_InitTypeDef             GPIO_InitStructure;
36
extern u16                          CCR_BackLight_Tab[5];
37
extern int                          CurrentRotateScreen;
38
extern Rotate_H12_V_Match_TypeDef   CurrentScreenOrientation;
39
 
40
/*! ASCII Table. Each character is 7 column (7dots large) on two pages (16dots high)
41
    7 column character: Two 8 bit data to display one column*/
42
static const u8 AsciiDotsTable[95 * 14 ] = {
43
  /* ASCII 32  */  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
44
  /* ASCII 33  */  0x00,0x00,0x00,0x00,0x00,0x00,0x13,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,
45
  /* ASCII 34  */  0x00,0x00,0x00,0xe0,0x00,0x20,0x00,0x00,0x00,0xe0,0x00,0x20,0x00,0x00,
46
  /* ASCII 35  */  0x00,0x00,0x35,0x00,0x0f,0x80,0x35,0x60,0x0f,0x80,0x05,0x60,0x00,0x00,
47
  /* ASCII 36  */  0x00,0x00,0x0d,0x80,0x0a,0x40,0x3a,0x60,0x06,0x40,0x00,0x00,0x00,0x00,
48
  /* ASCII 37  */  0x00,0x00,0x02,0x40,0x02,0xa0,0x0a,0x40,0x15,0x00,0x09,0x00,0x00,0x00,
49
  /* ASCII 38  */  0x00,0x00,0x0c,0x00,0x13,0x00,0x14,0x80,0x08,0x80,0x14,0x00,0x00,0x00,
50
  /* ASCII 39  */  0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,
51
  /* ASCII 40  */  0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0x80,0x60,0x60,0x00,0x00,0x00,0x00,
52
  /* ASCII 41  */  0x00,0x00,0x00,0x00,0x60,0x60,0x1f,0x80,0x00,0x00,0x00,0x00,0x00,0x00,
53
  /* ASCII 42  */  0x00,0x00,0x00,0x40,0x03,0x40,0x00,0xe0,0x03,0x40,0x00,0x40,0x00,0x00,
54
  /* ASCII 43  */  0x02,0x00,0x02,0x00,0x02,0x00,0x1f,0xc0,0x02,0x00,0x02,0x00,0x02,0x00,
55
  /* ASCII 44  */  0x00,0x00,0x00,0x00,0x60,0x00,0x38,0x00,0x08,0x00,0x00,0x00,0x00,0x00,
56
  /* ASCII 45  */  0x00,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x00,0x00,
57
  /* ASCII 46  */  0x00,0x00,0x00,0x00,0x18,0x00,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
58
  /* ASCII 47  */  0x00,0x00,0x20,0x00,0x18,0x00,0x06,0x00,0x01,0x80,0x00,0x60,0x00,0x00,
59
  /* ASCII 48  */  0x00,0x00,0x0f,0xc0,0x10,0x20,0x10,0x20,0x10,0x20,0x0f,0xc0,0x00,0x00,
60
  /* ASCII 49  */  0x00,0x00,0x10,0x00,0x10,0x20,0x1f,0xe0,0x10,0x00,0x10,0x00,0x00,0x00,
61
  /* ASCII 50  */  0x00,0x00,0x18,0x40,0x14,0x20,0x12,0x20,0x11,0x20,0x18,0xc0,0x00,0x00,
62
  /* ASCII 51  */  0x00,0x00,0x08,0x40,0x10,0x20,0x11,0x20,0x11,0x20,0x0e,0xc0,0x00,0x00,
63
  /* ASCII 52  */  0x00,0x00,0x06,0x00,0x05,0x00,0x04,0xc0,0x14,0x20,0x1f,0xe0,0x14,0x00,
64
  /* ASCII 53  */  0x00,0x00,0x08,0x00,0x11,0xe0,0x11,0x20,0x11,0x20,0x0e,0x20,0x00,0x00,
65
  /* ASCII 54  */  0x00,0x00,0x0f,0x80,0x11,0x40,0x11,0x20,0x11,0x20,0x0e,0x20,0x00,0x00,
66
  /* ASCII 55  */  0x00,0x00,0x00,0x60,0x00,0x20,0x18,0x20,0x07,0x20,0x00,0xe0,0x00,0x00,
67
  /* ASCII 56  */  0x00,0x00,0x0e,0xc0,0x11,0x20,0x11,0x20,0x11,0x20,0x0e,0xc0,0x00,0x00,
68
  /* ASCII 57  */  0x00,0x00,0x11,0xc0,0x12,0x20,0x12,0x20,0x0a,0x20,0x07,0xc0,0x00,0x00,
69
  /* ASCII 58  */  0x00,0x00,0x00,0x00,0x19,0x80,0x19,0x80,0x00,0x00,0x00,0x00,0x00,0x00,
70
  /* ASCII 59  */  0x00,0x00,0x00,0x00,0x30,0x00,0x19,0x80,0x09,0x80,0x00,0x00,0x00,0x00,
71
  /* ASCII 60  */  0x02,0x00,0x05,0x00,0x05,0x00,0x08,0x80,0x10,0x40,0x10,0x40,0x00,0x00,
72
  /* ASCII 61  */  0x00,0x00,0x05,0x00,0x05,0x00,0x05,0x00,0x05,0x00,0x05,0x00,0x00,0x00,
73
  /* ASCII 62  */  0x10,0x40,0x10,0x40,0x08,0x80,0x05,0x00,0x05,0x00,0x02,0x00,0x00,0x00,
74
  /* ASCII 63  */  0x00,0x00,0x00,0x00,0x10,0x80,0x14,0x40,0x02,0x40,0x01,0x80,0x00,0x00,
75
  /* ASCII 64  */  0x00,0x00,0x1f,0xe0,0x20,0x10,0x23,0x10,0x24,0x90,0x17,0xe0,0x00,0x00,
76
  /* ASCII 65  */  0x10,0x00,0x1c,0x00,0x17,0xa0,0x04,0x60,0x17,0x80,0x1c,0x00,0x10,0x00,
77
  /* ASCII 66  */  0x10,0x20,0x1f,0xe0,0x11,0x20,0x11,0x20,0x11,0x20,0x0e,0xc0,0x00,0x00,
78
  /* ASCII 67  */  0x00,0x00,0x0f,0xc0,0x10,0x20,0x10,0x20,0x10,0x20,0x08,0x60,0x00,0x00,
79
  /* ASCII 68  */  0x10,0x20,0x1f,0xe0,0x10,0x20,0x10,0x20,0x08,0x40,0x07,0x80,0x00,0x00,
80
  /* ASCII 69  */  0x10,0x20,0x1f,0xe0,0x11,0x20,0x13,0xa0,0x10,0x20,0x18,0x60,0x00,0x00,
81
  /* ASCII 70  */  0x00,0x00,0x10,0x20,0x1f,0xe0,0x11,0x20,0x03,0xa0,0x00,0x20,0x00,0x60,
82
  /* ASCII 71  */  0x00,0x00,0x0f,0xc0,0x10,0x20,0x10,0x20,0x12,0x20,0x0e,0x60,0x02,0x00,
83
  /* ASCII 72  */  0x10,0x20,0x1f,0xe0,0x11,0x20,0x01,0x00,0x11,0x20,0x1f,0xe0,0x10,0x20,
84
  /* ASCII 73  */  0x00,0x00,0x10,0x20,0x10,0x20,0x1f,0xe0,0x10,0x20,0x10,0x20,0x00,0x00,
85
  /* ASCII 74  */  0x00,0x00,0x0e,0x00,0x10,0x20,0x10,0x20,0x0f,0xe0,0x00,0x20,0x00,0x00,
86
  /* ASCII 75  */  0x10,0x20,0x1f,0xe0,0x12,0x20,0x03,0x00,0x04,0xa0,0x18,0x60,0x10,0x20,
87
  /* ASCII 76  */  0x00,0x00,0x10,0x20,0x1f,0xe0,0x10,0x20,0x10,0x00,0x1c,0x00,0x00,0x00,
88
  /* ASCII 77  */  0x10,0x20,0x1f,0xe0,0x10,0xe0,0x03,0x00,0x10,0xe0,0x1f,0xe0,0x10,0x20,
89
  /* ASCII 78  */  0x10,0x20,0x1f,0xe0,0x10,0xe0,0x07,0x00,0x18,0x20,0x1f,0xe0,0x00,0x20,
90
  /* ASCII 79  */  0x00,0x00,0x0f,0xc0,0x10,0x20,0x10,0x20,0x10,0x20,0x0f,0xc0,0x00,0x00,
91
  /* ASCII 80  */  0x00,0x00,0x10,0x20,0x1f,0xe0,0x12,0x20,0x02,0x20,0x01,0xc0,0x00,0x00,
92
  /* ASCII 81  */  0x00,0x00,0x0f,0xc0,0x10,0x20,0x30,0x20,0x30,0x20,0x2f,0xc0,0x00,0x00,
93
  /* ASCII 82  */  0x10,0x20,0x1f,0xe0,0x12,0x20,0x02,0x20,0x06,0x20,0x09,0xc0,0x10,0x00,
94
  /* ASCII 83  */  0x00,0x00,0x18,0xc0,0x09,0x20,0x11,0x20,0x11,0x40,0x0e,0x60,0x00,0x00,
95
  /* ASCII 84  */  0x00,0x60,0x00,0x20,0x10,0x20,0x1f,0xe0,0x10,0x20,0x00,0x20,0x00,0x60,
96
  /* ASCII 85  */  0x00,0x20,0x0f,0xe0,0x10,0x20,0x10,0x00,0x10,0x20,0x0f,0xe0,0x00,0x20,
97
  /* ASCII 86  */  0x00,0x20,0x00,0xe0,0x07,0x20,0x18,0x00,0x07,0x20,0x00,0xe0,0x00,0x20,
98
  /* ASCII 87  */  0x00,0x20,0x0f,0xe0,0x10,0x20,0x0f,0x00,0x10,0x20,0x0f,0xe0,0x00,0x20,
99
  /* ASCII 88  */  0x10,0x20,0x18,0x60,0x04,0x80,0x03,0x00,0x04,0x80,0x18,0x60,0x10,0x20,
100
  /* ASCII 89  */  0x00,0x20,0x00,0x60,0x11,0xa0,0x1e,0x00,0x11,0xa0,0x00,0x60,0x00,0x20,
101
  /* ASCII 90  */  0x00,0x00,0x18,0x60,0x14,0x20,0x13,0x20,0x10,0xa0,0x18,0x60,0x00,0x00,
102
  /* ASCII 91  */  0x00,0x00,0x00,0x00,0x7f,0xe0,0x40,0x20,0x40,0x20,0x00,0x00,0x00,0x00,
103
  /* ASCII 92  */  0x00,0x00,0x00,0x20,0x01,0xc0,0x06,0x00,0x38,0x00,0x00,0x00,0x00,0x00,
104
  /* ASCII 93  */  0x00,0x00,0x00,0x00,0x40,0x20,0x40,0x20,0x7f,0xe0,0x00,0x00,0x00,0x00,
105
  /* ASCII 94  */  0x00,0x00,0x01,0x00,0x00,0x80,0x00,0x60,0x00,0x80,0x01,0x00,0x00,0x00,
106
  /* ASCII 95  */  0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,
107
  /* ASCII 96  */  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x40,0x00,0x00,0x00,0x00,
108
  /* ASCII 97  */  0x00,0x00,0x0d,0x00,0x12,0x80,0x12,0x80,0x12,0x80,0x1f,0x00,0x10,0x00,
109
  /* ASCII 98  */  0x10,0x20,0x1f,0xe0,0x11,0x00,0x10,0x80,0x10,0x80,0x0f,0x00,0x00,0x00,
110
  /* ASCII 99  */  0x00,0x00,0x0f,0x00,0x10,0x80,0x10,0x80,0x10,0x80,0x09,0x80,0x00,0x00,
111
  /* ASCII 100 */  0x00,0x00,0x0f,0x00,0x10,0x80,0x10,0x80,0x11,0x20,0x1f,0xe0,0x10,0x00,
112
  /* ASCII 101 */  0x00,0x00,0x0f,0x00,0x12,0x80,0x12,0x80,0x12,0x80,0x13,0x00,0x00,0x00,
113
  /* ASCII 102 */  0x00,0x00,0x10,0x80,0x1f,0xc0,0x10,0xa0,0x10,0xa0,0x10,0xa0,0x00,0x00,
114
  /* ASCII 103 */  0x00,0x00,0x0f,0x00,0x50,0x80,0x50,0x80,0x51,0x00,0x3f,0x80,0x00,0x80,
115
  /* ASCII 104 */  0x10,0x20,0x1f,0xe0,0x11,0x00,0x00,0x80,0x10,0x80,0x1f,0x00,0x10,0x00,
116
  /* ASCII 105 */  0x00,0x00,0x10,0x80,0x10,0x80,0x1f,0xa0,0x10,0x00,0x10,0x00,0x00,0x00,
117
  /* ASCII 106 */  0x00,0x00,0x40,0x80,0x40,0x80,0x40,0xa0,0x3f,0x80,0x00,0x00,0x00,0x00,
118
  /* ASCII 107 */  0x10,0x20,0x1f,0xe0,0x02,0x00,0x16,0x80,0x19,0x80,0x10,0x80,0x00,0x00,
119
  /* ASCII 108 */  0x00,0x00,0x10,0x00,0x10,0x20,0x1f,0xe0,0x10,0x00,0x10,0x00,0x00,0x00,
120
  /* ASCII 109 */  0x10,0x80,0x1f,0x80,0x10,0x80,0x1f,0x00,0x10,0x80,0x1f,0x00,0x10,0x00,
121
  /* ASCII 110 */  0x10,0x80,0x1f,0x80,0x11,0x00,0x00,0x80,0x10,0x80,0x1f,0x00,0x10,0x00,
122
  /* ASCII 111 */  0x00,0x00,0x0f,0x00,0x10,0x80,0x10,0x80,0x10,0x80,0x0f,0x00,0x00,0x00,
123
  /* ASCII 112 */  0x40,0x80,0x7f,0x80,0x51,0x00,0x10,0x80,0x10,0x80,0x0f,0x00,0x00,0x00,
124
  /* ASCII 113 */  0x00,0x00,0x0f,0x00,0x10,0x80,0x10,0x80,0x51,0x00,0x7f,0x80,0x40,0x80,
125
  /* ASCII 114 */  0x00,0x00,0x10,0x80,0x1f,0x80,0x11,0x00,0x10,0x80,0x10,0x80,0x00,0x00,
126
  /* ASCII 115 */  0x00,0x00,0x19,0x00,0x12,0x80,0x12,0x80,0x12,0x80,0x0d,0x80,0x00,0x00,
127
  /* ASCII 116 */  0x00,0x00,0x00,0x80,0x0f,0xc0,0x10,0x80,0x10,0x80,0x10,0x80,0x08,0x00,
128
  /* ASCII 117 */  0x00,0x80,0x0f,0x80,0x10,0x00,0x10,0x00,0x08,0x80,0x1f,0x80,0x10,0x00,
129
  /* ASCII 118 */  0x00,0x80,0x03,0x80,0x0c,0x80,0x10,0x00,0x0c,0x80,0x03,0x80,0x00,0x80,
130
  /* ASCII 119 */  0x00,0x80,0x0f,0x80,0x10,0x80,0x0e,0x00,0x10,0x80,0x0f,0x80,0x00,0x80,
131
  /* ASCII 120 */  0x10,0x80,0x19,0x80,0x06,0x00,0x06,0x00,0x19,0x80,0x10,0x80,0x00,0x00,
132
  /* ASCII 121 */  0x00,0x80,0x41,0x80,0x46,0x80,0x78,0x00,0x4c,0x80,0x03,0x80,0x00,0x80,
133
  /* ASCII 122 */  0x00,0x00,0x19,0x80,0x14,0x80,0x12,0x80,0x11,0x80,0x18,0x80,0x00,0x00,
134
  /* ASCII 123 */  0x00,0x00,0x00,0x00,0x04,0x00,0x3b,0xc0,0x40,0x20,0x00,0x00,0x00,0x00,
135
  /* ASCII 124 */  0x00,0x00,0x00,0x00,0x00,0x00,0x3f,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,
136
  /* ASCII 125 */  0x00,0x00,0x00,0x00,0x40,0x20,0x3b,0xc0,0x04,0x00,0x00,0x00,0x00,0x00,
137
  /* ASCII 126 */  0x00,0x00,0x04,0x00,0x02,0x00,0x04,0x00,0x04,0x00,0x02,0x00,0x00,0x00};
138
 
139
int OrientationOffsetX [] = { 0 /* V12*/,0 /* V3*/,+4 /* V6*/,+4 /* V9*/ };
140
int OrientationOffsetY [] = { +4 /* V12*/,0 /* V3*/,0 /* V6*/,+4 /* V9*/ };
141
 
142
/* Private function prototypes -----------------------------------------------*/
143
static void LCD_7637_Controller( void );
144
static void LCD_DrawChar( u8 x, u8 y, u8 width, const u8 *bmp, u16 textColor, u16 bGndColor, u16 charMagniCoeff );
145
static void LCD_BackLightChange( void );
146
static void LCD_BackLightConfig( void );
147
static void LCD_CtrlLinesWrite( GPIO_TypeDef* GPIOx, u32 CtrlPins, BitAction BitVal );
148
 
149
/* Private functions ---------------------------------------------------------*/
150
 
151
/*******************************************************************************
152
*
153
*                                LCD_DataLinesConfig
154
*
155
*******************************************************************************/
156
/**
157
*  Configure data lines D0~D7 in Input Floating mode for read from LCD or in
158
*  Output Push-Pull mode for write on LCD
159
*
160
*  @param[in]  Mode Specifies the configuration mode for data lines D0~D7.
161
*                @n @c Input: configure in Input Floating mode
162
*                @n @c Output: configure in Output Push-Pul mode
163
*
164
**/
165
/******************************************************************************/
166
static void LCD_DataLinesConfig( DataConfigMode_TypeDef Mode )
167
   {
168
   GPIO_InitTypeDef             GPIO_InitStructure;
169
 
170
   GPIO_InitStructure.GPIO_Pin   =  LCD_DATA_PINS;
171
   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
172
 
173
   if( Mode == Input )
174
      {
175
      /* Configure D0~D7 lines as Input */
176
      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
177
      }
178
   else
179
      {
180
      /* Configure D0~D7 lines in Output Push-Pull mode */
181
      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
182
      }
183
 
184
   GPIO_Init( GPIOx_D_LCD, &GPIO_InitStructure );
185
   }
186
 
187
/*******************************************************************************
188
*
189
*                                LCD_DataLinesWrite
190
*
191
*******************************************************************************/
192
/**
193
*  Write a value on D0~D7
194
*
195
*  @param[in]  GPIOx    GPIO port to write on.
196
*  @param[in]  PortVal  The value to write. Only the lowest 8 bits are taken into
197
*                       account.
198
*
199
**/
200
/******************************************************************************/
201
static void LCD_DataLinesWrite( GPIO_TypeDef* GPIOx, u32 PortVal )
202
   {
203
   // Write only the lowest 8 bits!
204
   GPIOx->ODR = ( (GPIOx->ODR) & 0xFF00 ) | (u8)PortVal;
205
   }
206
 
207
/*******************************************************************************
208
*
209
*                                LCD_CtrlLinesConfig
210
*
211
*******************************************************************************/
212
/**
213
*  Configure control lines in Output Push-Pull mode.
214
*
215
**/
216
/******************************************************************************/
217
static void LCD_CtrlLinesConfig( void )
218
   {
219
   GPIO_InitTypeDef             GPIO_InitStructure;
220
 
221
   GPIO_InitStructure.GPIO_Pin   =  LCD_CTRL_PINS;
222
   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
223
   GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_Out_PP;
224
 
225
   GPIO_Init( GPIOx_CTRL_LCD, &GPIO_InitStructure );
226
 
227
   GPIO_InitStructure.GPIO_Pin   =  CtrlPin_CS;
228
   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
229
   GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_Out_PP;
230
 
231
   GPIO_Init( GPIOx_CS_LCD, &GPIO_InitStructure );
232
 
233
   LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RS,  Bit_SET );    /* RS = 1   */
234
   LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RD,  Bit_SET );    /* RD = 1   */
235
   LCD_CtrlLinesWrite( GPIOx_CS_LCD,   CtrlPin_CS,  Bit_SET );    /* CS = 1   */
236
   LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_WR,  Bit_SET );    /* WR = 1   */
237
   LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RST, Bit_RESET );  /* RST = 0  */
238
   }
239
 
240
/*******************************************************************************
241
*
242
*                                LCD_CtrlLinesWrite
243
*
244
*******************************************************************************/
245
/**
246
*  Set or reset control lines.
247
*
248
*  @param[in]  GPIOx       Where x can be 0, 1 or 2 to select the GPIO peripheral.
249
*  @param[in]  CtrlPins    The Control line.
250
*  @param[in]  BitVal
251
*
252
**/
253
/******************************************************************************/
254
static void LCD_CtrlLinesWrite( GPIO_TypeDef* GPIOx, u32 CtrlPins, BitAction BitVal )
255
   {
256
   /* Set or Reset the control line */
257
   GPIO_WriteBit( GPIOx, CtrlPins, BitVal );
258
   }
259
 
260
/*******************************************************************************
261
*
262
*                                LCD_CheckLCDStatus
263
*
264
*******************************************************************************/
265
/**
266
*  Check whether LCD LCD is busy or not.
267
*
268
**/
269
/******************************************************************************/
270
static void LCD_CheckLCDStatus( void )
271
   {
272
   unsigned char ID1;
273
   unsigned char ID2;
274
   unsigned char ID3;
275
 
276
   LCD_SendLCDCmd( ST7637_RDDID );
277
 
278
   /* Configure Data lines as Input */
279
   LCD_DataLinesConfig (Input );
280
 
281
   /* Start the LCD send data sequence */
282
   LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RS, Bit_RESET );     /* RS = 0 */
283
   LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RD, Bit_RESET );     /* RD = 0 */
284
   LCD_CtrlLinesWrite( GPIOx_CS_LCD,   CtrlPin_CS, Bit_RESET );     /* CS = 0 */
285
   LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_WR, Bit_SET );       /* WR = 1 */
286
 
287
   /* Read data to the LCD */
288
   GPIO_ReadInputData( GPIOx_D_LCD );
289
   LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RD, Bit_SET );       /* RD = 1 */
290
   LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RD, Bit_RESET );     /* RD = 0 */
291
 
292
   ID1 = GPIO_ReadInputData( GPIOx_D_LCD );
293
 
294
   LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RD, Bit_SET );       /* RD = 1 */
295
   LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RD, Bit_RESET );     /* RD = 0 */
296
 
297
   ID2 = GPIO_ReadInputData( GPIOx_D_LCD );
298
 
299
   LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RD, Bit_SET );       /* RD = 1 */
300
   LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RD, Bit_RESET );     /* RD = 0 */
301
 
302
   ID3 = GPIO_ReadInputData( GPIOx_D_LCD );
303
 
304
   LCD_DataLinesConfig( Output );
305
   }
306
 
307
/*******************************************************************************
308
*
309
*                                LCD_DrawChar
310
*
311
*******************************************************************************/
312
/**
313
*  Draw a character on the LCD screen.
314
*
315
*  @param[in]  x           The line where to display the character shape.
316
*  @param[in]  y           The column start address.
317
*  @param[in]  width       The number of columns (dots) in a character width.
318
*  @param[in]  bmp         The character (monochrome) bitmap. A pointer of the dot matrix data.
319
*  @param[in]  textColor   The character color.
320
*  @param[in]  bGndColor   The character background color.
321
*  @param[in]  charMagniCoeff The character magnifying coefficient.
322
*
323
*  @warning    The (0x0) point in on the low left corner.
324
*
325
**/
326
/******************************************************************************/
327
static void LCD_DrawChar( u8 x, u8 y, u8 width, const u8* bmp, u16 textColor, u16 bGndColor, u16 charMagniCoeff )
328
   {
329
   int i;
330
   int j;
331
   int k1;
332
   int k2;
333
 
334
   // Select the area for LCD output.
335
   LCD_SetRect_For_Cmd( x, y, 7 * charMagniCoeff, 14 * charMagniCoeff );
336
 
337
   // Select LCD output mode.
338
   LCD_SendLCDCmd( ST7637_RAMWR );
339
 
340
   for( i = 0; i < 7; i++ )
341
      {
342
      for( k1 = 0; k1 < charMagniCoeff; k1++ )
343
         {
344
         for( j = 0x80; j; j >>= 1 ) // 8
345
            {
346
            for( k2 = 0; k2 < charMagniCoeff; k2++ )
347
               {
348
               LCD_SendLCDData( ( bmp[2*i] & j ) ? ( textColor & 255 ) : ( bGndColor &  255 ) );
349
               LCD_SendLCDData( ( bmp[2*i] & j ) ? ( textColor >> 8  ) : ( bGndColor >> 8 ) );
350
               }
351
            }
352
 
353
         for( j = 0x80; j > 2; j >>= 1 )  // 8
354
            {
355
            for( k2 = 0; k2 < charMagniCoeff; k2++ )
356
               {
357
               LCD_SendLCDData( ( bmp[2*i+1] & j ) ? ( textColor & 255 ) : ( bGndColor & 255 ) );
358
               LCD_SendLCDData( ( bmp[2*i+1] & j ) ? ( textColor >> 8  ) : ( bGndColor >> 8 ) );
359
               }
360
            }
361
         }
362
      }
363
   }
364
 
365
/*******************************************************************************
366
*
367
*                                LCD_DisplayRotate
368
*
369
*******************************************************************************/
370
/**
371
*  Configure the LCD controller for a given orientation.
372
*
373
*  @param[in]  H12 The new screen orientation.
374
*
375
**/
376
/******************************************************************************/
377
static void LCD_DisplayRotate( Rotate_H12_V_Match_TypeDef H12 )
378
   {
379
   // Memory Access Control 0x36
380
   LCD_SendLCDCmd( ST7637_MADCTR );
381
 
382
   switch( H12 )
383
      {
384
      case V3  :
385
         LCD_SendLCDData( V3_MADCTRVAL );
386
         break;
387
 
388
      case V6  :
389
         LCD_SendLCDData( V6_MADCTRVAL );
390
         break;
391
 
392
      case V9  :
393
         LCD_SendLCDData( V9_MADCTRVAL );
394
         break;
395
 
396
      case V12 :
397
      default  :
398
         LCD_SendLCDData( V12_MADCTRVAL );
399
         break;
400
      }
401
   }
402
 
403
/*******************************************************************************
404
*
405
*                                LCD_7637_Controller
406
*
407
*******************************************************************************/
408
/**
409
*  Initialization of the controller registers.
410
*
411
*  @note See ST7637.PDF for more information.
412
*
413
**/
414
/******************************************************************************/
415
static void LCD_7637_Controller( void )
416
   {
417
   extern void starting_delay ( long unsigned  );
418
 
419
   /** Apply hardware reset **/
420
   LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RST, Bit_SET );    /* RST = 1  */
421
   LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RST, Bit_RESET );  /* RST = 0  */
422
   starting_delay( 0x500 );
423
 
424
   LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RST, Bit_SET );    /* RST = 1  */
425
   starting_delay( 0x500 );
426
 
427
   //default mode is output
428
   LCD_DataLinesConfig( Output );
429
 
430
   LCD_CheckLCDStatus();
431
 
432
   LCD_SendLCDCmd( ST7637_SWRESET );
433
 
434
   //-----------disable autoread + Manual read once ----------------------------
435
   LCD_SendLCDCmd( ST7637_AUTOLOADSET );  // Auto Load Set 0xD7
436
   LCD_SendLCDData( 0xBF );               // Auto Load Disable
437
 
438
   LCD_SendLCDCmd( ST7637_EPCTIN );       // EE Read/write mode 0xE0
439
   LCD_SendLCDData( 0x00 );               // Set read mode
440
 
441
   LCD_SendLCDCmd( ST7637_EPMRD );        // Read active 0xE3
442
   LCD_SendLCDCmd( ST7637_EPCTOUT );      // Cancel control 0xE1
443
 
444
   //---------------------------------- Sleep OUT ------------------------------
445
   LCD_SendLCDCmd( ST7637_DISPOFF );      // display off 0x28
446
   LCD_SendLCDCmd( ST7637_SLPOUT );       // Sleep Out 0x11
447
 
448
   //--------------------------------Vop setting--------------------------------
449
   LCD_SendLCDCmd( ST7637_VOPSET );       // Set Vop by initial Module 0xC0
450
   LCD_SendLCDData( 0xFB );               // Vop = 13.64
451
   LCD_SendLCDData( 0x00 );               // base on Module
452
 
453
   //----------------------------Set Register-----------------------------------
454
   LCD_SendLCDCmd( ST7637_BIASSEL );      // Bias select 0xC3
455
   LCD_SendLCDData( 0x00 );               // 1/12 Bias, base on Module
456
 
457
   LCD_SendLCDCmd( ST7637_BSTBMPXSEL );   // Setting Booster times 0xC4
458
   LCD_SendLCDData( 0x05 );               // Booster X 8
459
 
460
   LCD_SendLCDCmd( ST7637_BSTEFFSEL );    // Booster eff 0xC5
461
   LCD_SendLCDData( 0x11 );               // BE = 0x01 (Level 2)
462
 
463
   LCD_SendLCDCmd( ST7637_VGSORCSEL );    // Vg with booster x2 control 0xcb
464
   LCD_SendLCDData( 0x01 );               // Vg from Vdd2
465
 
466
   LCD_SendLCDCmd( ST7637_ID1SET );       // ID1 = 00 0xcc
467
   LCD_SendLCDData( 0x00 );               //
468
 
469
   LCD_SendLCDCmd( ST7637_ID3SET );       // ID3 = 00 0xce
470
   LCD_SendLCDData( 0x00 );               //
471
 
472
   LCD_SendLCDCmd( 0xB7 );                // Glass direction
473
   LCD_SendLCDData( 0xC0 );               //
474
 
475
   LCD_SendLCDCmd( ST7637_ANASET );       // Analog circuit setting 0xd0
476
   LCD_SendLCDData( 0x1D );               //
477
 
478
   LCD_SendLCDCmd( 0xB4 );                // PTL mode set
479
   LCD_SendLCDData( 0x18 );               // power normal mode
480
   LCD_SendLCDCmd( ST7637_INVOFF );       // Display Inversion OFF 0x20
481
 
482
   LCD_SendLCDCmd( 0x2A );                // column range
483
   LCD_SendLCDData( 0x04 );               //
484
   LCD_SendLCDData( 0x83 );               //
485
 
486
   LCD_SendLCDCmd( 0x2B );                // raw range
487
   LCD_SendLCDData( 0x04 );               //
488
   LCD_SendLCDData( 0x83 );               //
489
 
490
 
491
   LCD_SendLCDCmd( ST7637_COLMOD );       // Color mode = 65k 0x3A
492
   LCD_SendLCDData( 0x05 );               //
493
 
494
   LCD_SendLCDCmd( ST7637_MADCTR );       // Memory Access Control 0x36
495
   LCD_SendLCDData( V9_MADCTRVAL );
496
 
497
   LCD_SendLCDCmd( ST7637_DUTYSET );      // Duty = 132 duty 0xb0
498
   LCD_SendLCDData( 0x7F );
499
 
500
   LCD_SendLCDCmd( 0x29 );                // Display ON
501
   LCD_SendLCDCmd( 0xF9 );                // Gamma
502
   LCD_SendLCDData( 0x00 );               //
503
   LCD_SendLCDData( 0x03 );               //
504
   LCD_SendLCDData( 0x05 );               //
505
   LCD_SendLCDData( 0x07 );               //
506
   LCD_SendLCDData( 0x09 );               //
507
   LCD_SendLCDData( 0x0B );               //
508
   LCD_SendLCDData( 0x0D );               //
509
   LCD_SendLCDData( 0x0F );               //
510
   LCD_SendLCDData( 0x11 );               //
511
   LCD_SendLCDData( 0x13 );               //
512
   LCD_SendLCDData( 0x15 );               //
513
   LCD_SendLCDData( 0x17 );               //
514
   LCD_SendLCDData( 0x19 );               //
515
   LCD_SendLCDData( 0x1B );               //
516
   LCD_SendLCDData( 0x1D );               //
517
   LCD_SendLCDData( 0x1F );               //
518
   }
519
 
520
/*******************************************************************************
521
*
522
*                                LCD_BackLightConfig
523
*
524
*******************************************************************************/
525
/**
526
*  Setting of the PWM that drives the backlight intensity.
527
*
528
**/
529
/******************************************************************************/
530
static void LCD_BackLightConfig( void )
531
   {
532
   GPIO_InitTypeDef GPIO_InitStructure;
533
 
534
   /* Enable GPIOB clock  */
535
   RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB, ENABLE );
536
 
537
   /* GPIOB Configuration:TIM4 2 in Output */
538
   GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_7;
539
   GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF_PP;
540
   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
541
 
542
   GPIO_Init( GPIOB, &GPIO_InitStructure );
543
 
544
   /* TIM4 Configuration -----------------------------------------------------*/
545
   /* TIM4CLK = 12 MHz, Prescaler = 0x0 */
546
 
547
   /* Enable TIM4 clock */
548
   RCC_APB1PeriphClockCmd( RCC_APB1Periph_TIM4, ENABLE );
549
 
550
   TIM_DeInit( TIM4 );
551
   TIM_TimeBaseStructInit( &TIM_TimeBaseStructure );
552
   TIM_OCStructInit( &TIM_OCInitStructure );
553
 
554
   /* Time base configuration */
555
   TIM_TimeBaseStructure.TIM_Period          = 0xFFFF;
556
   TIM_TimeBaseStructure.TIM_Prescaler       = 0x0;
557
   TIM_TimeBaseStructure.TIM_ClockDivision   = 0x0;
558
   TIM_TimeBaseStructure.TIM_CounterMode     = TIM_CounterMode_Up;
559
 
560
   TIM_TimeBaseInit( TIM4, &TIM_TimeBaseStructure );
561
 
562
   /* Output Compare Toggle Mode configuration: Channel2 */
563
   TIM_OCInitStructure.TIM_OCMode   = TIM_OCMode_PWM1;
564
   TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
565
   TIM_OCInitStructure.TIM_Pulse    = Current_CCR_BackLightStart;
566
 
567
   TIM_OC2Init( TIM4, &TIM_OCInitStructure );
568
   TIM_OC4PreloadConfig( TIM4, TIM_OCPreload_Disable );
569
 
570
   TIM_ARRPreloadConfig( TIM4, ENABLE );
571
 
572
   /* Enable TIM4 IT */
573
   TIM_ITConfig( TIM4, TIM_IT_CC2, ENABLE );
574
 
575
   // Go !!!
576
   TIM_Cmd( TIM4, ENABLE );
577
   }
578
 
579
/*******************************************************************************
580
*
581
*                                LCD_BackLightChange
582
*
583
*******************************************************************************/
584
/**
585
*  Modify the PWM rate.
586
*
587
**/
588
/******************************************************************************/
589
static void LCD_BackLightChange( void )
590
   {
591
   /* Output Compare Toggle Mode configuration: Channel2 */
592
   TIM_OCInitStructure.TIM_Pulse = Current_CCR_BackLightStart;
593
 
594
   TIM_OCInit( TIM4, &TIM_OCInitStructure );
595
   }
596
 
597
/* Public functions for CircleOS ---------------------------------------------*/
598
 
599
/*******************************************************************************
600
*
601
*                                LCD_Init
602
*
603
*******************************************************************************/
604
/**
605
*
606
*  Initialize LCD. Called at CircleOS startup.
607
*
608
*  @attention  This function must <b>NOT</b> be called by the user.
609
*
610
**/
611
/******************************************************************************/
612
void LCD_Init( void )
613
   {
614
   LCD_SetBackLight( UTIL_ReadBackupRegister( BKP_BKLIGHT ) );
615
 
616
   /* Do some gpio configs*/
617
   GPIO_InitTypeDef GPIO_InitStructure;
618
 
619
   /* Enable GPIO clock for LCD */
620
   RCC_APB2PeriphClockCmd( GPIO_LCD_CTRL_PERIPH, ENABLE );
621
   RCC_APB2PeriphClockCmd( GPIO_LCD_D_PERIPH, ENABLE );
622
   RCC_APB2PeriphClockCmd( GPIO_LCD_CS_PERIPH, ENABLE );
623
 
624
   /* Enable GPIOC clock */
625
   RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOC, ENABLE );
626
 
627
   /* Init BackLight*/
628
   LCD_BackLightConfig();
629
 
630
   /* Configure control lines signals as output mode */
631
   LCD_CtrlLinesConfig();
632
 
633
   /* LCD LCD Init */
634
   LCD_7637_Controller();
635
   }
636
 
637
/*******************************************************************************
638
*
639
*                                LCD_Handler
640
*
641
*******************************************************************************/
642
/**
643
*
644
*  Called by the CircleOS scheduler to manage LCD tasks.
645
*
646
*  @attention  This function must <b>NOT</b> be called by the user.
647
*
648
**/
649
/******************************************************************************/
650
void LCD_Handler( void )
651
   {
652
   if( ++HandlerDivider % BACKLIGHT_DIVIDER )
653
      {
654
      return;
655
      }
656
 
657
   LCD_BackLightChange();
658
   }
659
 
660
 
661
/// @endcond
662
 
663
/* Public functions ----------------------------------------------------------*/
664
 
665
/*******************************************************************************
666
*
667
*                                LCD_SendLCDCmd
668
*
669
*******************************************************************************/
670
/**
671
*
672
*  Send on command byte to the LCD.
673
*
674
*  @param[in]  Cmd   An unsigned char containing the user command to send to the LCD.
675
*
676
**/
677
/******************************************************************************/
678
void LCD_SendLCDCmd( u8 Cmd )
679
   {
680
   /* Start the LCD send data sequence */
681
   LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RS, Bit_RESET );     /* RS = 0 */
682
   LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RD, Bit_SET );       /* RD = 1 */
683
   LCD_CtrlLinesWrite( GPIOx_CS_LCD,   CtrlPin_CS, Bit_RESET );     /* CS = 0 */
684
   LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_WR, Bit_RESET );     /* WR = 0 */
685
 
686
   /* Write data to the LCD */
687
   LCD_DataLinesWrite( GPIOx_D_LCD, (u32)Cmd );
688
   LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_WR, Bit_SET );       /* WR = 1 */
689
   }
690
 
691
/*******************************************************************************
692
*
693
*                                LCD_SendLCDData
694
*
695
*******************************************************************************/
696
/**
697
*
698
*  Send one data byte to the LCD.
699
*
700
*  @param[in]  Data  An unsigned character containing the data to send to the LCD.
701
*  @pre        An LCD_SendLCDCmd was done with a command waiting for data.
702
*
703
*
704
**/
705
/******************************************************************************/
706
void LCD_SendLCDData( u8 Data )
707
   {
708
   /* Configure Data lines as Output */
709
   LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RS, Bit_SET );
710
   LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RD, Bit_SET );
711
   LCD_CtrlLinesWrite( GPIOx_CS_LCD,   CtrlPin_CS, Bit_RESET );
712
   LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_WR, Bit_RESET );
713
 
714
   /* Write data to the LCD */
715
   LCD_DataLinesWrite( GPIOx_D_LCD,(u32)Data );
716
   LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_WR, Bit_SET );
717
   }
718
 
719
/***********************************************************************************
720
*
721
*                                LCD_ReadLCDData
722
*
723
************************************************************************************/
724
/**
725
*
726
*  Read one data byte from the LCD.
727
*
728
*  @return     An unsigned 32 bit word containing the data returned by a LCD command.
729
*  @pre        An LCD_SendLCDCmd was done with a command returning data.
730
*
731
**/
732
/********************************************************************************/
733
u32 LCD_ReadLCDData( void )
734
   {
735
   u32 LCDData = 0;
736
 
737
   /* Configure Data lines as Input */
738
   LCD_DataLinesConfig(Input);
739
 
740
   /* Start the LCD send data sequence */
741
   LCD_CtrlLinesWrite( GPIOx_D_LCD,  CtrlPin_RS, Bit_SET );         /* RS = 1 */
742
   LCD_CtrlLinesWrite( GPIOx_D_LCD,  CtrlPin_WR, Bit_SET );         /* WR = 1 */
743
   LCD_CtrlLinesWrite( GPIOx_CS_LCD, CtrlPin_CS, Bit_RESET );       /* CS = 0 */
744
   LCD_CtrlLinesWrite( GPIOx_D_LCD,  CtrlPin_RD, Bit_RESET );       /* RD = 0 */
745
 
746
   /* Read data from the LCD */
747
   LCDData = (GPIO_ReadInputData( GPIOx_D_LCD ) & LCD_DATA_PINS );
748
 
749
   LCD_CtrlLinesWrite( GPIOx_D_LCD, CtrlPin_RD, Bit_SET );          /* RD = 1 */
750
 
751
   /* Read the LCD returned data */
752
   LCD_DataLinesConfig( Output );
753
 
754
   return LCDData;
755
   }
756
 
757
/*******************************************************************************
758
*
759
*                                LCD_FillRect
760
*
761
*******************************************************************************/
762
/**
763
*
764
*  Fill a rectangle with a provided color.
765
*
766
*  @param[in]  x        The horizontal coordinate of the rectangle low left corner.
767
*  @param[in]  y        The vertical coordinate of the rectangle low left corner.
768
*  @param[in]  width    The rectangle width in pixels.
769
*  @param[in]  height   The rectangle height in pixels.
770
*  @param[in]  color    The RGB color to fill the rectangle with.
771
*
772
*  @warning    The (0x0) point in on the low left corner.
773
*
774
**/
775
/******************************************************************************/
776
void LCD_FillRect( u16 x, u16 y, u16 width, u16 height, u16 color )
777
   {
778
   u8 Line;
779
   u8 Column;
780
 
781
   /* Select LCD screen area. */
782
   LCD_SetRect_For_Cmd( x, y, width, height );
783
 
784
   /* Send LCD RAM write command. */
785
   LCD_SendLCDCmd( ST7637_RAMWR );
786
 
787
   /* Fill selected LCD screen area with provided color. */
788
   for( Line = 0; Line < width; Line++ )
789
      {
790
      for( Column = 0; Column < height; Column++ )
791
         {
792
         LCD_SendLCDData( color & 0xff );
793
         LCD_SendLCDData( ( color >> 8 ) & 0xff );
794
         }
795
      }
796
 
797
   #ifdef TESTLCD
798
   /* Configure Data lines as Input */
799
   LCD_DataLinesConfig( Input );
800
 
801
   LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RST, Bit_SET );    /* RST = 1  */
802
   LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RST, Bit_RESET );  /* RST = 0  */
803
   LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RST, Bit_SET );    /* RST = 1  */
804
 
805
   /* Start the LCD send data sequence */
806
   LCD_CtrlLinesWrite( GPIOx_D_LCD,  CtrlPin_RS, Bit_SET );       /* RS = 1   */
807
   LCD_CtrlLinesWrite( GPIOx_D_LCD,  CtrlPin_RS, Bit_RESET );     /* RS = 0   */
808
   LCD_CtrlLinesWrite( GPIOx_D_LCD,  CtrlPin_RS, Bit_SET );       /* RS = 1   */
809
 
810
   LCD_CtrlLinesWrite( GPIOx_D_LCD,  CtrlPin_RS, Bit_SET );       /* RS = 1   */
811
   LCD_CtrlLinesWrite( GPIOx_D_LCD,  CtrlPin_RS, Bit_RESET );     /* RS = 0   */
812
   LCD_CtrlLinesWrite( GPIOx_D_LCD,  CtrlPin_RS, Bit_SET );       /* RS = 1   */
813
 
814
   LCD_CtrlLinesWrite( GPIOx_D_LCD,  CtrlPin_WR, Bit_SET );       /* WR = 1   */
815
   LCD_CtrlLinesWrite( GPIOx_D_LCD,  CtrlPin_WR, Bit_RESET );     /* WR = 1   */
816
   LCD_CtrlLinesWrite( GPIOx_D_LCD,  CtrlPin_WR, Bit_SET );       /* WR = 1   */
817
 
818
   LCD_CtrlLinesWrite( GPIOx_D_LCD,  CtrlPin_RD, Bit_SET );       /* RD = 1   */
819
   LCD_CtrlLinesWrite( GPIOx_D_LCD,  CtrlPin_RD, Bit_RESET );     /* RD = 0   */
820
   LCD_CtrlLinesWrite( GPIOx_D_LCD,  CtrlPin_RD, Bit_SET );       /* RD = 1   */
821
 
822
   LCD_CtrlLinesWrite( GPIOx_D_LCD,  CtrlPin_RD, Bit_SET );       /* RD = 1   */
823
   LCD_CtrlLinesWrite( GPIOx_D_LCD,  CtrlPin_RD, Bit_RESET );     /* RD = 0   */
824
   LCD_CtrlLinesWrite( GPIOx_D_LCD,  CtrlPin_RD, Bit_SET );       /* RD = 1   */
825
 
826
   /* Configure Data lines as Input */
827
   LCD_DataLinesConfig( Output );
828
 
829
   LCD_DataLinesWrite( GPIOx_D_LCD, ~0 );
830
   LCD_DataLinesWrite( GPIOx_D_LCD, 0 );
831
   LCD_DataLinesWrite( GPIOx_D_LCD, ~1 );
832
   LCD_DataLinesWrite( GPIOx_D_LCD, 1 );
833
   LCD_DataLinesWrite( GPIOx_D_LCD, ~2 );
834
   LCD_DataLinesWrite( GPIOx_D_LCD, 2 );
835
   LCD_DataLinesWrite( GPIOx_D_LCD, ~4 );
836
   LCD_DataLinesWrite( GPIOx_D_LCD, 4 );
837
   LCD_DataLinesWrite( GPIOx_D_LCD, ~8 );
838
   LCD_DataLinesWrite( GPIOx_D_LCD, 8 );
839
   LCD_DataLinesWrite( GPIOx_D_LCD, ~0x10 );
840
   LCD_DataLinesWrite( GPIOx_D_LCD, 0x10 );
841
   LCD_DataLinesWrite( GPIOx_D_LCD, ~0x20 );
842
   LCD_DataLinesWrite( GPIOx_D_LCD, 0x20 );
843
   LCD_DataLinesWrite( GPIOx_D_LCD, ~0x40 );
844
   LCD_DataLinesWrite( GPIOx_D_LCD, 0x40 );
845
   LCD_DataLinesWrite( GPIOx_D_LCD, ~0x80 );
846
   LCD_DataLinesWrite( GPIOx_D_LCD, 0x80 );
847
 
848
   LCD_DataLinesConfig( Input );
849
 
850
   #endif
851
   }
852
 
853
/*******************************************************************************
854
*
855
*                                LCD_DrawRect
856
*
857
*******************************************************************************/
858
/**
859
*
860
*  Draw a rectangle with a provided color.
861
*
862
*  @param[in]  x        The horizontal coordinate of the rectangle low left corner.
863
*  @param[in]  y        The vertical coordinate of the rectangle low left corner.
864
*  @param[in]  width    The rectangle width in pixels.
865
*  @param[in]  height   The rectangle height in pixels.
866
*  @param[in]  color    The RGB color to draw the rectangle with.
867
*
868
*  @warning    The (0x0) point in on the low left corner.
869
*
870
**/
871
/******************************************************************************/
872
void LCD_DrawRect( u16 x, u16 y, u16 width, u16 height, u16 color )
873
   {
874
   // Draw horizontal sides.
875
   LCD_FillRect( x, y,              width, 1, color );
876
   LCD_FillRect( x, y + height - 1, width, 1, color );
877
 
878
   // Draw vertical sides.
879
   LCD_FillRect( x,              y, 1, height, color );
880
   LCD_FillRect( x + width - 1,  y, 1, height, color );
881
   }
882
 
883
/*******************************************************************************
884
*
885
*                                LCD_DrawPixel
886
*
887
*******************************************************************************/
888
/**
889
*
890
*  Draw a pixel on the LCD with the provided color.
891
*
892
*  @param[in]  XPos     The horizontal coordinate of the pixel.
893
*  @param[in]  YPos     The vertical coordinate of the pixel.
894
*  @param[in]  Color    The RGB color to draw the pixel with.
895
*
896
*  @warning    The (0x0) point in on the low left corner.
897
*
898
**/
899
/******************************************************************************/
900
void LCD_DrawPixel( u8 XPos, u8 YPos, u16 Color )
901
   {
902
   /* Select LCD screen area. */
903
   LCD_SetRect_For_Cmd( XPos, YPos, 1, 1 );
904
 
905
   /* Send LCD RAM write command. */
906
   LCD_SendLCDCmd( ST7637_RAMWR );
907
 
908
   // Draw pixel.
909
   LCD_SendLCDData( Color );
910
   LCD_SendLCDData( Color >> 8 );
911
   }
912
 
913
/*******************************************************************************
914
*
915
*                                LCD_RectRead
916
*
917
*******************************************************************************/
918
/**
919
*
920
*  Save the pixels of a rectangle part of the LCD into a RAM variable.
921
*
922
*  @param[in]  x        The horizontal coordinate of the rectangle low left corner.
923
*  @param[in]  y        The vertical coordinate of the rectangle low left corner.
924
*  @param[in]  width    The rectangle width in pixels.
925
*  @param[in]  height   The rectangle height in pixels.
926
*  @param[out] bmp      The variable to store the read data into.
927
*
928
*  @warning    One pixel weights 2 bytes.
929
*  @warning    The (0x0) point in on the low left corner.
930
*
931
**/
932
/******************************************************************************/
933
void LCD_RectRead( u16 x, u16 y, u16 width, u16 height, u8* bmp )
934
   {
935
   int i;
936
   int bytesize = (width * height) *2; // 2 bytes per pixel.
937
 
938
   /* Select LCD screen area. */
939
   LCD_SetRect_For_Cmd( x, y, width, height );
940
 
941
   /* Send LCD RAM write command. */
942
   LCD_SendLCDCmd(ST7637_RAMRD);
943
 
944
   // First read byte is dummy!
945
   LCD_ReadLCDData();
946
 
947
   // Read pixels from LCD screen.
948
   for( i = 0; i < bytesize; i++ )
949
      {
950
      *bmp++ = LCD_ReadLCDData();
951
      }
952
   }
953
 
954
/*******************************************************************************
955
*
956
*                                LCD_GetPixel
957
*
958
*******************************************************************************/
959
/**
960
*
961
*  Read the RGB color of the pixel the coordinate are provided in parameter.
962
*
963
*  @param[in]  x        The horizontal coordinate of the pixel.
964
*  @param[in]  y        The vertical coordinate of the pixel.
965
*  @return              An unsigned 16 bit word containing the RGB color of the pixel.
966
*
967
*  @warning    The (0x0) point in on the low left corner.
968
*  @see        LCD_RectRead
969
*
970
**/
971
/******************************************************************************/
972
u16 LCD_GetPixel( u8 x, u8 y )
973
   {
974
   u16 val;
975
 
976
   LCD_RectRead( x, y, 1, 1, (u8*)&val );
977
 
978
   return val;
979
   }
980
 
981
/*******************************************************************************
982
*
983
*                                LCD_DisplayChar
984
*
985
*******************************************************************************/
986
/**
987
*
988
*  Display at provided coordinates the provided ASCII character with the provided
989
*  text and background colors and with the provided magnify coefficient.
990
*
991
*  @param[in]  x              The horizontal coordinate of the character.
992
*  @param[in]  y              The vertical coordinate of the character.
993
*  @param[in]  Ascii          The ASCII code of the character to display.
994
*                             @n Ascii must be higher than 31 and lower than 127.
995
*  @param[in]  TextColor      The color used to draw the character.
996
*  @param[in]  BGndColor      The background color of the drawn character.
997
*  @param[in]  CharMagniCoeff The magnify coefficient used to draw the character.
998
*
999
*  @warning    The (0x0) point in on the low left corner.
1000
*
1001
**/
1002
/******************************************************************************/
1003
void LCD_DisplayChar( u8 x, u8 y, u8 Ascii, u16 TextColor, u16 BGndColor, u16 CharMagniCoeff)
1004
   {
1005
   // Display the selected bitmap according to the provided ASCII character.
1006
   LCD_DrawChar( x, y, 7, (u8*)&AsciiDotsTable[ (Ascii-32) * 14 ], TextColor, BGndColor, CharMagniCoeff );
1007
   }
1008
 
1009
/*******************************************************************************
1010
*
1011
*                                LCD_SetRect_For_Cmd
1012
*
1013
*******************************************************************************/
1014
/**
1015
*
1016
*  Define the rectangle for the next command to be applied.
1017
*
1018
*  @param[in]  x        The horizontal coordinate of the rectangle low left corner.
1019
*  @param[in]  y        The vertical coordinate of the rectangle low left corner.
1020
*  @param[in]  width    The rectangle width in pixels.
1021
*  @param[in]  height   The rectangle height in pixels.
1022
*
1023
*  @warning    The (0x0) point in on the low left corner.
1024
*
1025
**/
1026
/******************************************************************************/
1027
void LCD_SetRect_For_Cmd( s16 x, s16 y, s16 width, s16 height )
1028
   {
1029
   LCD_SendLCDCmd( ST7637_CASET );
1030
   LCD_SendLCDData( y + OrientationOffsetX[ CurrentScreenOrientation ] );
1031
   LCD_SendLCDData( y + OrientationOffsetX[ CurrentScreenOrientation ] + height - 1 );
1032
 
1033
   LCD_SendLCDCmd( ST7637_RASET );
1034
   LCD_SendLCDData( x + OrientationOffsetY[ CurrentScreenOrientation ] );
1035
   LCD_SendLCDData( x + OrientationOffsetY[ CurrentScreenOrientation ] + width - 1 );
1036
   }
1037
 
1038
/*******************************************************************************
1039
*
1040
*                                LCD_SetBackLight
1041
*
1042
*******************************************************************************/
1043
/**
1044
*
1045
*  Modify the PWM rate. Any value below BACKLIGHTMIN reset the value to the
1046
*  default value (DEFAULT_CCR_BACKLIGHTSTART).
1047
*
1048
*  @param[in]  newBacklightStart The new PWM rate.
1049
*
1050
**/
1051
/******************************************************************************/
1052
void LCD_SetBackLight( u32 newBacklightStart )
1053
   {
1054
   if( newBacklightStart >= BACKLIGHTMIN )
1055
      {
1056
      Current_CCR_BackLightStart = newBacklightStart;
1057
      }
1058
   else
1059
      {
1060
      Current_CCR_BackLightStart = DEFAULT_CCR_BACKLIGHTSTART;
1061
      }
1062
   }
1063
 
1064
/*******************************************************************************
1065
*
1066
*                                LCD_SetBackLightOff
1067
*
1068
*******************************************************************************/
1069
/**
1070
*
1071
*  Switch the LCD back light off.
1072
*
1073
**/
1074
/******************************************************************************/
1075
void LCD_SetBackLightOff( void )
1076
   {
1077
   Current_CCR_BackLightStart = 0;
1078
   }
1079
 
1080
/*******************************************************************************
1081
*
1082
*                                LCD_SetBackLightOn
1083
*
1084
*******************************************************************************/
1085
/**
1086
*
1087
*  Switch the LCD back light on.
1088
*
1089
**/
1090
/******************************************************************************/
1091
void LCD_SetBackLightOn( void )
1092
   {
1093
   Current_CCR_BackLightStart = DEFAULT_CCR_BACKLIGHTSTART;
1094
   }
1095
 
1096
/*******************************************************************************
1097
*
1098
*                                LCD_GetBackLight
1099
*
1100
*******************************************************************************/
1101
/**
1102
*
1103
*  Returns le LCD PWM rate.
1104
*
1105
*  @return The current LCD PWM rate.
1106
*
1107
**/
1108
/******************************************************************************/
1109
u32 LCD_GetBackLight( void )
1110
   {
1111
   return Current_CCR_BackLightStart;
1112
   }
1113
 
1114
/*******************************************************************************
1115
*
1116
*                                LCD_SetRotateScreen
1117
*
1118
*******************************************************************************/
1119
/**
1120
*
1121
*  Enable or disable the ability of the screen display to rotate according to
1122
*  the MEMs information.
1123
*
1124
*  @param[in]  RotateScreen 0 to disable screen rotation and 1 to enable.
1125
*
1126
**/
1127
/******************************************************************************/
1128
void LCD_SetRotateScreen( u8 RotateScreen)
1129
   {
1130
   CurrentRotateScreen = RotateScreen;
1131
   }
1132
 
1133
/*******************************************************************************
1134
*
1135
*                                LCD_GetRotateScreen
1136
*
1137
*******************************************************************************/
1138
/**
1139
*
1140
*  Return the screen rotation mode.
1141
*
1142
*  @retval 0 screen rotation is disabled.
1143
*  @retval 1 screen rotation is enabled.
1144
*
1145
**/
1146
/******************************************************************************/
1147
u8 LCD_GetRotateScreen( void )
1148
   {
1149
   return CurrentRotateScreen;
1150
   }
1151
 
1152
/*******************************************************************************
1153
*
1154
*                                LCD_SetScreenOrientation
1155
*
1156
*******************************************************************************/
1157
/**
1158
*
1159
*  Set the screen orientation.
1160
*
1161
*  @param[in]  ScreenOrientation The new screen orientation.
1162
*
1163
**/
1164
/******************************************************************************/
1165
void LCD_SetScreenOrientation( Rotate_H12_V_Match_TypeDef ScreenOrientation )
1166
   {
1167
   CurrentScreenOrientation = ScreenOrientation;
1168
 
1169
   LCD_DisplayRotate( CurrentScreenOrientation );
1170
   }
1171
 
1172
/*******************************************************************************
1173
*
1174
*                                LCD_GetScreenOrientation
1175
*
1176
*******************************************************************************/
1177
/**
1178
*
1179
*  Return current screen orientation.
1180
*
1181
*  @return   A Rotate_H12_V_Match_TypeDef telling the current screen orientation.
1182
*
1183
**/
1184
/******************************************************************************/
1185
Rotate_H12_V_Match_TypeDef LCD_GetScreenOrientation( void )
1186
   {
1187
   return CurrentScreenOrientation;
1188
   }
1189
 

powered by: WebSVN 2.1.0

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