1 /********************* (C) COPYRIGHT 2007 RAISONANCE S.A.S. *******************/
\r
5 * @brief The LCD driver for the ST7637.
\r
10 /******************************************************************************/
\r
12 /* Includes ------------------------------------------------------------------*/
\r
18 /* Private define ------------------------------------------------------------*/
\r
19 #define V9_MADCTRVAL 0x90 /*!< Left orientation value. */
\r
20 #define V12_MADCTRVAL 0x30 /*!< Up orientation value. */
\r
21 #define V3_MADCTRVAL 0x50 /*!< Right orientation value. */
\r
22 #define V6_MADCTRVAL 0xF0 /*!< Bottom orientation value. */
\r
23 #define BACKLIGHT_DIVIDER 500 /*!< LCD handler step. */
\r
25 /* Private variables ---------------------------------------------------------*/
\r
27 // vars for timer dedicated for lcd backlight
\r
28 static TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
\r
29 static TIM_OCInitTypeDef TIM_OCInitStructure;
\r
30 static int HandlerDivider = 0;
\r
32 int Current_CCR_BackLightStart = DEFAULT_CCR_BACKLIGHTSTART;
\r
34 /* External variable ---------------------------------------------------------*/
\r
35 extern GPIO_InitTypeDef GPIO_InitStructure;
\r
36 extern u16 CCR_BackLight_Tab[5];
\r
37 extern int CurrentRotateScreen;
\r
38 extern Rotate_H12_V_Match_TypeDef CurrentScreenOrientation;
\r
40 /*! ASCII Table. Each character is 7 column (7dots large) on two pages (16dots high)
\r
41 7 column character: Two 8 bit data to display one column*/
\r
42 static const u8 AsciiDotsTable[95 * 14 ] = {
\r
43 /* ASCII 32 */ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
\r
44 /* ASCII 33 */ 0x00,0x00,0x00,0x00,0x00,0x00,0x13,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,
\r
45 /* ASCII 34 */ 0x00,0x00,0x00,0xe0,0x00,0x20,0x00,0x00,0x00,0xe0,0x00,0x20,0x00,0x00,
\r
46 /* ASCII 35 */ 0x00,0x00,0x35,0x00,0x0f,0x80,0x35,0x60,0x0f,0x80,0x05,0x60,0x00,0x00,
\r
47 /* ASCII 36 */ 0x00,0x00,0x0d,0x80,0x0a,0x40,0x3a,0x60,0x06,0x40,0x00,0x00,0x00,0x00,
\r
48 /* ASCII 37 */ 0x00,0x00,0x02,0x40,0x02,0xa0,0x0a,0x40,0x15,0x00,0x09,0x00,0x00,0x00,
\r
49 /* ASCII 38 */ 0x00,0x00,0x0c,0x00,0x13,0x00,0x14,0x80,0x08,0x80,0x14,0x00,0x00,0x00,
\r
50 /* ASCII 39 */ 0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,
\r
51 /* ASCII 40 */ 0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0x80,0x60,0x60,0x00,0x00,0x00,0x00,
\r
52 /* ASCII 41 */ 0x00,0x00,0x00,0x00,0x60,0x60,0x1f,0x80,0x00,0x00,0x00,0x00,0x00,0x00,
\r
53 /* ASCII 42 */ 0x00,0x00,0x00,0x40,0x03,0x40,0x00,0xe0,0x03,0x40,0x00,0x40,0x00,0x00,
\r
54 /* ASCII 43 */ 0x02,0x00,0x02,0x00,0x02,0x00,0x1f,0xc0,0x02,0x00,0x02,0x00,0x02,0x00,
\r
55 /* ASCII 44 */ 0x00,0x00,0x00,0x00,0x60,0x00,0x38,0x00,0x08,0x00,0x00,0x00,0x00,0x00,
\r
56 /* ASCII 45 */ 0x00,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x02,0x00,0x00,0x00,
\r
57 /* ASCII 46 */ 0x00,0x00,0x00,0x00,0x18,0x00,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
\r
58 /* ASCII 47 */ 0x00,0x00,0x20,0x00,0x18,0x00,0x06,0x00,0x01,0x80,0x00,0x60,0x00,0x00,
\r
59 /* ASCII 48 */ 0x00,0x00,0x0f,0xc0,0x10,0x20,0x10,0x20,0x10,0x20,0x0f,0xc0,0x00,0x00,
\r
60 /* ASCII 49 */ 0x00,0x00,0x10,0x00,0x10,0x20,0x1f,0xe0,0x10,0x00,0x10,0x00,0x00,0x00,
\r
61 /* ASCII 50 */ 0x00,0x00,0x18,0x40,0x14,0x20,0x12,0x20,0x11,0x20,0x18,0xc0,0x00,0x00,
\r
62 /* ASCII 51 */ 0x00,0x00,0x08,0x40,0x10,0x20,0x11,0x20,0x11,0x20,0x0e,0xc0,0x00,0x00,
\r
63 /* ASCII 52 */ 0x00,0x00,0x06,0x00,0x05,0x00,0x04,0xc0,0x14,0x20,0x1f,0xe0,0x14,0x00,
\r
64 /* ASCII 53 */ 0x00,0x00,0x08,0x00,0x11,0xe0,0x11,0x20,0x11,0x20,0x0e,0x20,0x00,0x00,
\r
65 /* ASCII 54 */ 0x00,0x00,0x0f,0x80,0x11,0x40,0x11,0x20,0x11,0x20,0x0e,0x20,0x00,0x00,
\r
66 /* ASCII 55 */ 0x00,0x00,0x00,0x60,0x00,0x20,0x18,0x20,0x07,0x20,0x00,0xe0,0x00,0x00,
\r
67 /* ASCII 56 */ 0x00,0x00,0x0e,0xc0,0x11,0x20,0x11,0x20,0x11,0x20,0x0e,0xc0,0x00,0x00,
\r
68 /* ASCII 57 */ 0x00,0x00,0x11,0xc0,0x12,0x20,0x12,0x20,0x0a,0x20,0x07,0xc0,0x00,0x00,
\r
69 /* ASCII 58 */ 0x00,0x00,0x00,0x00,0x19,0x80,0x19,0x80,0x00,0x00,0x00,0x00,0x00,0x00,
\r
70 /* ASCII 59 */ 0x00,0x00,0x00,0x00,0x30,0x00,0x19,0x80,0x09,0x80,0x00,0x00,0x00,0x00,
\r
71 /* ASCII 60 */ 0x02,0x00,0x05,0x00,0x05,0x00,0x08,0x80,0x10,0x40,0x10,0x40,0x00,0x00,
\r
72 /* ASCII 61 */ 0x00,0x00,0x05,0x00,0x05,0x00,0x05,0x00,0x05,0x00,0x05,0x00,0x00,0x00,
\r
73 /* ASCII 62 */ 0x10,0x40,0x10,0x40,0x08,0x80,0x05,0x00,0x05,0x00,0x02,0x00,0x00,0x00,
\r
74 /* ASCII 63 */ 0x00,0x00,0x00,0x00,0x10,0x80,0x14,0x40,0x02,0x40,0x01,0x80,0x00,0x00,
\r
75 /* ASCII 64 */ 0x00,0x00,0x1f,0xe0,0x20,0x10,0x23,0x10,0x24,0x90,0x17,0xe0,0x00,0x00,
\r
76 /* ASCII 65 */ 0x10,0x00,0x1c,0x00,0x17,0xa0,0x04,0x60,0x17,0x80,0x1c,0x00,0x10,0x00,
\r
77 /* ASCII 66 */ 0x10,0x20,0x1f,0xe0,0x11,0x20,0x11,0x20,0x11,0x20,0x0e,0xc0,0x00,0x00,
\r
78 /* ASCII 67 */ 0x00,0x00,0x0f,0xc0,0x10,0x20,0x10,0x20,0x10,0x20,0x08,0x60,0x00,0x00,
\r
79 /* ASCII 68 */ 0x10,0x20,0x1f,0xe0,0x10,0x20,0x10,0x20,0x08,0x40,0x07,0x80,0x00,0x00,
\r
80 /* ASCII 69 */ 0x10,0x20,0x1f,0xe0,0x11,0x20,0x13,0xa0,0x10,0x20,0x18,0x60,0x00,0x00,
\r
81 /* ASCII 70 */ 0x00,0x00,0x10,0x20,0x1f,0xe0,0x11,0x20,0x03,0xa0,0x00,0x20,0x00,0x60,
\r
82 /* ASCII 71 */ 0x00,0x00,0x0f,0xc0,0x10,0x20,0x10,0x20,0x12,0x20,0x0e,0x60,0x02,0x00,
\r
83 /* ASCII 72 */ 0x10,0x20,0x1f,0xe0,0x11,0x20,0x01,0x00,0x11,0x20,0x1f,0xe0,0x10,0x20,
\r
84 /* ASCII 73 */ 0x00,0x00,0x10,0x20,0x10,0x20,0x1f,0xe0,0x10,0x20,0x10,0x20,0x00,0x00,
\r
85 /* ASCII 74 */ 0x00,0x00,0x0e,0x00,0x10,0x20,0x10,0x20,0x0f,0xe0,0x00,0x20,0x00,0x00,
\r
86 /* ASCII 75 */ 0x10,0x20,0x1f,0xe0,0x12,0x20,0x03,0x00,0x04,0xa0,0x18,0x60,0x10,0x20,
\r
87 /* ASCII 76 */ 0x00,0x00,0x10,0x20,0x1f,0xe0,0x10,0x20,0x10,0x00,0x1c,0x00,0x00,0x00,
\r
88 /* ASCII 77 */ 0x10,0x20,0x1f,0xe0,0x10,0xe0,0x03,0x00,0x10,0xe0,0x1f,0xe0,0x10,0x20,
\r
89 /* ASCII 78 */ 0x10,0x20,0x1f,0xe0,0x10,0xe0,0x07,0x00,0x18,0x20,0x1f,0xe0,0x00,0x20,
\r
90 /* ASCII 79 */ 0x00,0x00,0x0f,0xc0,0x10,0x20,0x10,0x20,0x10,0x20,0x0f,0xc0,0x00,0x00,
\r
91 /* ASCII 80 */ 0x00,0x00,0x10,0x20,0x1f,0xe0,0x12,0x20,0x02,0x20,0x01,0xc0,0x00,0x00,
\r
92 /* ASCII 81 */ 0x00,0x00,0x0f,0xc0,0x10,0x20,0x30,0x20,0x30,0x20,0x2f,0xc0,0x00,0x00,
\r
93 /* ASCII 82 */ 0x10,0x20,0x1f,0xe0,0x12,0x20,0x02,0x20,0x06,0x20,0x09,0xc0,0x10,0x00,
\r
94 /* ASCII 83 */ 0x00,0x00,0x18,0xc0,0x09,0x20,0x11,0x20,0x11,0x40,0x0e,0x60,0x00,0x00,
\r
95 /* ASCII 84 */ 0x00,0x60,0x00,0x20,0x10,0x20,0x1f,0xe0,0x10,0x20,0x00,0x20,0x00,0x60,
\r
96 /* ASCII 85 */ 0x00,0x20,0x0f,0xe0,0x10,0x20,0x10,0x00,0x10,0x20,0x0f,0xe0,0x00,0x20,
\r
97 /* ASCII 86 */ 0x00,0x20,0x00,0xe0,0x07,0x20,0x18,0x00,0x07,0x20,0x00,0xe0,0x00,0x20,
\r
98 /* ASCII 87 */ 0x00,0x20,0x0f,0xe0,0x10,0x20,0x0f,0x00,0x10,0x20,0x0f,0xe0,0x00,0x20,
\r
99 /* ASCII 88 */ 0x10,0x20,0x18,0x60,0x04,0x80,0x03,0x00,0x04,0x80,0x18,0x60,0x10,0x20,
\r
100 /* ASCII 89 */ 0x00,0x20,0x00,0x60,0x11,0xa0,0x1e,0x00,0x11,0xa0,0x00,0x60,0x00,0x20,
\r
101 /* ASCII 90 */ 0x00,0x00,0x18,0x60,0x14,0x20,0x13,0x20,0x10,0xa0,0x18,0x60,0x00,0x00,
\r
102 /* ASCII 91 */ 0x00,0x00,0x00,0x00,0x7f,0xe0,0x40,0x20,0x40,0x20,0x00,0x00,0x00,0x00,
\r
103 /* ASCII 92 */ 0x00,0x00,0x00,0x20,0x01,0xc0,0x06,0x00,0x38,0x00,0x00,0x00,0x00,0x00,
\r
104 /* ASCII 93 */ 0x00,0x00,0x00,0x00,0x40,0x20,0x40,0x20,0x7f,0xe0,0x00,0x00,0x00,0x00,
\r
105 /* ASCII 94 */ 0x00,0x00,0x01,0x00,0x00,0x80,0x00,0x60,0x00,0x80,0x01,0x00,0x00,0x00,
\r
106 /* ASCII 95 */ 0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,
\r
107 /* ASCII 96 */ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x40,0x00,0x00,0x00,0x00,
\r
108 /* ASCII 97 */ 0x00,0x00,0x0d,0x00,0x12,0x80,0x12,0x80,0x12,0x80,0x1f,0x00,0x10,0x00,
\r
109 /* ASCII 98 */ 0x10,0x20,0x1f,0xe0,0x11,0x00,0x10,0x80,0x10,0x80,0x0f,0x00,0x00,0x00,
\r
110 /* ASCII 99 */ 0x00,0x00,0x0f,0x00,0x10,0x80,0x10,0x80,0x10,0x80,0x09,0x80,0x00,0x00,
\r
111 /* ASCII 100 */ 0x00,0x00,0x0f,0x00,0x10,0x80,0x10,0x80,0x11,0x20,0x1f,0xe0,0x10,0x00,
\r
112 /* ASCII 101 */ 0x00,0x00,0x0f,0x00,0x12,0x80,0x12,0x80,0x12,0x80,0x13,0x00,0x00,0x00,
\r
113 /* ASCII 102 */ 0x00,0x00,0x10,0x80,0x1f,0xc0,0x10,0xa0,0x10,0xa0,0x10,0xa0,0x00,0x00,
\r
114 /* ASCII 103 */ 0x00,0x00,0x0f,0x00,0x50,0x80,0x50,0x80,0x51,0x00,0x3f,0x80,0x00,0x80,
\r
115 /* ASCII 104 */ 0x10,0x20,0x1f,0xe0,0x11,0x00,0x00,0x80,0x10,0x80,0x1f,0x00,0x10,0x00,
\r
116 /* ASCII 105 */ 0x00,0x00,0x10,0x80,0x10,0x80,0x1f,0xa0,0x10,0x00,0x10,0x00,0x00,0x00,
\r
117 /* ASCII 106 */ 0x00,0x00,0x40,0x80,0x40,0x80,0x40,0xa0,0x3f,0x80,0x00,0x00,0x00,0x00,
\r
118 /* ASCII 107 */ 0x10,0x20,0x1f,0xe0,0x02,0x00,0x16,0x80,0x19,0x80,0x10,0x80,0x00,0x00,
\r
119 /* ASCII 108 */ 0x00,0x00,0x10,0x00,0x10,0x20,0x1f,0xe0,0x10,0x00,0x10,0x00,0x00,0x00,
\r
120 /* ASCII 109 */ 0x10,0x80,0x1f,0x80,0x10,0x80,0x1f,0x00,0x10,0x80,0x1f,0x00,0x10,0x00,
\r
121 /* ASCII 110 */ 0x10,0x80,0x1f,0x80,0x11,0x00,0x00,0x80,0x10,0x80,0x1f,0x00,0x10,0x00,
\r
122 /* ASCII 111 */ 0x00,0x00,0x0f,0x00,0x10,0x80,0x10,0x80,0x10,0x80,0x0f,0x00,0x00,0x00,
\r
123 /* ASCII 112 */ 0x40,0x80,0x7f,0x80,0x51,0x00,0x10,0x80,0x10,0x80,0x0f,0x00,0x00,0x00,
\r
124 /* ASCII 113 */ 0x00,0x00,0x0f,0x00,0x10,0x80,0x10,0x80,0x51,0x00,0x7f,0x80,0x40,0x80,
\r
125 /* ASCII 114 */ 0x00,0x00,0x10,0x80,0x1f,0x80,0x11,0x00,0x10,0x80,0x10,0x80,0x00,0x00,
\r
126 /* ASCII 115 */ 0x00,0x00,0x19,0x00,0x12,0x80,0x12,0x80,0x12,0x80,0x0d,0x80,0x00,0x00,
\r
127 /* ASCII 116 */ 0x00,0x00,0x00,0x80,0x0f,0xc0,0x10,0x80,0x10,0x80,0x10,0x80,0x08,0x00,
\r
128 /* ASCII 117 */ 0x00,0x80,0x0f,0x80,0x10,0x00,0x10,0x00,0x08,0x80,0x1f,0x80,0x10,0x00,
\r
129 /* ASCII 118 */ 0x00,0x80,0x03,0x80,0x0c,0x80,0x10,0x00,0x0c,0x80,0x03,0x80,0x00,0x80,
\r
130 /* ASCII 119 */ 0x00,0x80,0x0f,0x80,0x10,0x80,0x0e,0x00,0x10,0x80,0x0f,0x80,0x00,0x80,
\r
131 /* ASCII 120 */ 0x10,0x80,0x19,0x80,0x06,0x00,0x06,0x00,0x19,0x80,0x10,0x80,0x00,0x00,
\r
132 /* ASCII 121 */ 0x00,0x80,0x41,0x80,0x46,0x80,0x78,0x00,0x4c,0x80,0x03,0x80,0x00,0x80,
\r
133 /* ASCII 122 */ 0x00,0x00,0x19,0x80,0x14,0x80,0x12,0x80,0x11,0x80,0x18,0x80,0x00,0x00,
\r
134 /* ASCII 123 */ 0x00,0x00,0x00,0x00,0x04,0x00,0x3b,0xc0,0x40,0x20,0x00,0x00,0x00,0x00,
\r
135 /* ASCII 124 */ 0x00,0x00,0x00,0x00,0x00,0x00,0x3f,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,
\r
136 /* ASCII 125 */ 0x00,0x00,0x00,0x00,0x40,0x20,0x3b,0xc0,0x04,0x00,0x00,0x00,0x00,0x00,
\r
137 /* ASCII 126 */ 0x00,0x00,0x04,0x00,0x02,0x00,0x04,0x00,0x04,0x00,0x02,0x00,0x00,0x00};
\r
139 int OrientationOffsetX [] = { 0 /* V12*/,0 /* V3*/,+4 /* V6*/,+4 /* V9*/ };
\r
140 int OrientationOffsetY [] = { +4 /* V12*/,0 /* V3*/,0 /* V6*/,+4 /* V9*/ };
\r
142 /* Private function prototypes -----------------------------------------------*/
\r
143 static void LCD_7637_Controller( void );
\r
144 static void LCD_DrawChar( u8 x, u8 y, u8 width, const u8 *bmp, u16 textColor, u16 bGndColor, u16 charMagniCoeff );
\r
145 static void LCD_BackLightChange( void );
\r
146 static void LCD_BackLightConfig( void );
\r
147 static void LCD_CtrlLinesWrite( GPIO_TypeDef* GPIOx, u32 CtrlPins, BitAction BitVal );
\r
149 /* Private functions ---------------------------------------------------------*/
\r
151 /*******************************************************************************
\r
153 * LCD_DataLinesConfig
\r
155 *******************************************************************************/
\r
157 * Configure data lines D0~D7 in Input Floating mode for read from LCD or in
\r
158 * Output Push-Pull mode for write on LCD
\r
160 * @param[in] Mode Specifies the configuration mode for data lines D0~D7.
\r
161 * @n @c Input: configure in Input Floating mode
\r
162 * @n @c Output: configure in Output Push-Pul mode
\r
165 /******************************************************************************/
\r
166 static void LCD_DataLinesConfig( DataConfigMode_TypeDef Mode )
\r
168 GPIO_InitTypeDef GPIO_InitStructure;
\r
170 GPIO_InitStructure.GPIO_Pin = LCD_DATA_PINS;
\r
171 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
\r
173 if( Mode == Input )
\r
175 /* Configure D0~D7 lines as Input */
\r
176 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
\r
180 /* Configure D0~D7 lines in Output Push-Pull mode */
\r
181 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
\r
184 GPIO_Init( GPIOx_D_LCD, &GPIO_InitStructure );
\r
187 /*******************************************************************************
\r
189 * LCD_DataLinesWrite
\r
191 *******************************************************************************/
\r
193 * Write a value on D0~D7
\r
195 * @param[in] GPIOx GPIO port to write on.
\r
196 * @param[in] PortVal The value to write. Only the lowest 8 bits are taken into
\r
200 /******************************************************************************/
\r
201 static void LCD_DataLinesWrite( GPIO_TypeDef* GPIOx, u32 PortVal )
\r
203 // Write only the lowest 8 bits!
\r
204 GPIOx->ODR = ( (GPIOx->ODR) & 0xFF00 ) | (u8)PortVal;
\r
207 /*******************************************************************************
\r
209 * LCD_CtrlLinesConfig
\r
211 *******************************************************************************/
\r
213 * Configure control lines in Output Push-Pull mode.
\r
216 /******************************************************************************/
\r
217 static void LCD_CtrlLinesConfig( void )
\r
219 GPIO_InitTypeDef GPIO_InitStructure;
\r
221 GPIO_InitStructure.GPIO_Pin = LCD_CTRL_PINS;
\r
222 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
\r
223 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
\r
225 GPIO_Init( GPIOx_CTRL_LCD, &GPIO_InitStructure );
\r
227 GPIO_InitStructure.GPIO_Pin = CtrlPin_CS;
\r
228 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
\r
229 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
\r
231 GPIO_Init( GPIOx_CS_LCD, &GPIO_InitStructure );
\r
233 LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RS, Bit_SET ); /* RS = 1 */
\r
234 LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RD, Bit_SET ); /* RD = 1 */
\r
235 LCD_CtrlLinesWrite( GPIOx_CS_LCD, CtrlPin_CS, Bit_SET ); /* CS = 1 */
\r
236 LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_WR, Bit_SET ); /* WR = 1 */
\r
237 LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RST, Bit_RESET ); /* RST = 0 */
\r
240 /*******************************************************************************
\r
242 * LCD_CtrlLinesWrite
\r
244 *******************************************************************************/
\r
246 * Set or reset control lines.
\r
248 * @param[in] GPIOx Where x can be 0, 1 or 2 to select the GPIO peripheral.
\r
249 * @param[in] CtrlPins The Control line.
\r
250 * @param[in] BitVal
\r
253 /******************************************************************************/
\r
254 static void LCD_CtrlLinesWrite( GPIO_TypeDef* GPIOx, u32 CtrlPins, BitAction BitVal )
\r
256 /* Set or Reset the control line */
\r
257 GPIO_WriteBit( GPIOx, CtrlPins, BitVal );
\r
260 /*******************************************************************************
\r
262 * LCD_CheckLCDStatus
\r
264 *******************************************************************************/
\r
266 * Check whether LCD LCD is busy or not.
\r
269 /******************************************************************************/
\r
270 static void LCD_CheckLCDStatus( void )
\r
276 LCD_SendLCDCmd( ST7637_RDDID );
\r
278 /* Configure Data lines as Input */
\r
279 LCD_DataLinesConfig (Input );
\r
281 /* Start the LCD send data sequence */
\r
282 LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RS, Bit_RESET ); /* RS = 0 */
\r
283 LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RD, Bit_RESET ); /* RD = 0 */
\r
284 LCD_CtrlLinesWrite( GPIOx_CS_LCD, CtrlPin_CS, Bit_RESET ); /* CS = 0 */
\r
285 LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_WR, Bit_SET ); /* WR = 1 */
\r
287 /* Read data to the LCD */
\r
288 GPIO_ReadInputData( GPIOx_D_LCD );
\r
289 LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RD, Bit_SET ); /* RD = 1 */
\r
290 LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RD, Bit_RESET ); /* RD = 0 */
\r
292 ID1 = GPIO_ReadInputData( GPIOx_D_LCD );
\r
294 LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RD, Bit_SET ); /* RD = 1 */
\r
295 LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RD, Bit_RESET ); /* RD = 0 */
\r
297 ID2 = GPIO_ReadInputData( GPIOx_D_LCD );
\r
299 LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RD, Bit_SET ); /* RD = 1 */
\r
300 LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RD, Bit_RESET ); /* RD = 0 */
\r
302 ID3 = GPIO_ReadInputData( GPIOx_D_LCD );
\r
304 LCD_DataLinesConfig( Output );
\r
307 /*******************************************************************************
\r
311 *******************************************************************************/
\r
313 * Draw a character on the LCD screen.
\r
315 * @param[in] x The line where to display the character shape.
\r
316 * @param[in] y The column start address.
\r
317 * @param[in] width The number of columns (dots) in a character width.
\r
318 * @param[in] bmp The character (monochrome) bitmap. A pointer of the dot matrix data.
\r
319 * @param[in] textColor The character color.
\r
320 * @param[in] bGndColor The character background color.
\r
321 * @param[in] charMagniCoeff The character magnifying coefficient.
\r
323 * @warning The (0x0) point in on the low left corner.
\r
326 /******************************************************************************/
\r
327 static void LCD_DrawChar( u8 x, u8 y, u8 width, const u8* bmp, u16 textColor, u16 bGndColor, u16 charMagniCoeff )
\r
334 // Select the area for LCD output.
\r
335 LCD_SetRect_For_Cmd( x, y, 7 * charMagniCoeff, 14 * charMagniCoeff );
\r
337 // Select LCD output mode.
\r
338 LCD_SendLCDCmd( ST7637_RAMWR );
\r
340 for( i = 0; i < 7; i++ )
\r
342 for( k1 = 0; k1 < charMagniCoeff; k1++ )
\r
344 for( j = 0x80; j; j >>= 1 ) // 8
\r
346 for( k2 = 0; k2 < charMagniCoeff; k2++ )
\r
348 LCD_SendLCDData( ( bmp[2*i] & j ) ? ( textColor & 255 ) : ( bGndColor & 255 ) );
\r
349 LCD_SendLCDData( ( bmp[2*i] & j ) ? ( textColor >> 8 ) : ( bGndColor >> 8 ) );
\r
353 for( j = 0x80; j > 2; j >>= 1 ) // 8
\r
355 for( k2 = 0; k2 < charMagniCoeff; k2++ )
\r
357 LCD_SendLCDData( ( bmp[2*i+1] & j ) ? ( textColor & 255 ) : ( bGndColor & 255 ) );
\r
358 LCD_SendLCDData( ( bmp[2*i+1] & j ) ? ( textColor >> 8 ) : ( bGndColor >> 8 ) );
\r
365 /*******************************************************************************
\r
367 * LCD_DisplayRotate
\r
369 *******************************************************************************/
\r
371 * Configure the LCD controller for a given orientation.
\r
373 * @param[in] H12 The new screen orientation.
\r
376 /******************************************************************************/
\r
377 static void LCD_DisplayRotate( Rotate_H12_V_Match_TypeDef H12 )
\r
379 // Memory Access Control 0x36
\r
380 LCD_SendLCDCmd( ST7637_MADCTR );
\r
385 LCD_SendLCDData( V3_MADCTRVAL );
\r
389 LCD_SendLCDData( V6_MADCTRVAL );
\r
393 LCD_SendLCDData( V9_MADCTRVAL );
\r
398 LCD_SendLCDData( V12_MADCTRVAL );
\r
403 /*******************************************************************************
\r
405 * LCD_7637_Controller
\r
407 *******************************************************************************/
\r
409 * Initialization of the controller registers.
\r
411 * @note See ST7637.PDF for more information.
\r
414 /******************************************************************************/
\r
415 static void LCD_7637_Controller( void )
\r
417 extern void starting_delay ( long unsigned );
\r
419 /** Apply hardware reset **/
\r
420 LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RST, Bit_SET ); /* RST = 1 */
\r
421 LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RST, Bit_RESET ); /* RST = 0 */
\r
422 starting_delay( 0x500 );
\r
424 LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RST, Bit_SET ); /* RST = 1 */
\r
425 starting_delay( 0x500 );
\r
427 //default mode is output
\r
428 LCD_DataLinesConfig( Output );
\r
430 LCD_CheckLCDStatus();
\r
432 LCD_SendLCDCmd( ST7637_SWRESET );
\r
434 //-----------disable autoread + Manual read once ----------------------------
\r
435 LCD_SendLCDCmd( ST7637_AUTOLOADSET ); // Auto Load Set 0xD7
\r
436 LCD_SendLCDData( 0xBF ); // Auto Load Disable
\r
438 LCD_SendLCDCmd( ST7637_EPCTIN ); // EE Read/write mode 0xE0
\r
439 LCD_SendLCDData( 0x00 ); // Set read mode
\r
441 LCD_SendLCDCmd( ST7637_EPMRD ); // Read active 0xE3
\r
442 LCD_SendLCDCmd( ST7637_EPCTOUT ); // Cancel control 0xE1
\r
444 //---------------------------------- Sleep OUT ------------------------------
\r
445 LCD_SendLCDCmd( ST7637_DISPOFF ); // display off 0x28
\r
446 LCD_SendLCDCmd( ST7637_SLPOUT ); // Sleep Out 0x11
\r
448 //--------------------------------Vop setting--------------------------------
\r
449 LCD_SendLCDCmd( ST7637_VOPSET ); // Set Vop by initial Module 0xC0
\r
450 LCD_SendLCDData( 0xFB ); // Vop = 13.64
\r
451 LCD_SendLCDData( 0x00 ); // base on Module
\r
453 //----------------------------Set Register-----------------------------------
\r
454 LCD_SendLCDCmd( ST7637_BIASSEL ); // Bias select 0xC3
\r
455 LCD_SendLCDData( 0x00 ); // 1/12 Bias, base on Module
\r
457 LCD_SendLCDCmd( ST7637_BSTBMPXSEL ); // Setting Booster times 0xC4
\r
458 LCD_SendLCDData( 0x05 ); // Booster X 8
\r
460 LCD_SendLCDCmd( ST7637_BSTEFFSEL ); // Booster eff 0xC5
\r
461 LCD_SendLCDData( 0x11 ); // BE = 0x01 (Level 2)
\r
463 LCD_SendLCDCmd( ST7637_VGSORCSEL ); // Vg with booster x2 control 0xcb
\r
464 LCD_SendLCDData( 0x01 ); // Vg from Vdd2
\r
466 LCD_SendLCDCmd( ST7637_ID1SET ); // ID1 = 00 0xcc
\r
467 LCD_SendLCDData( 0x00 ); //
\r
469 LCD_SendLCDCmd( ST7637_ID3SET ); // ID3 = 00 0xce
\r
470 LCD_SendLCDData( 0x00 ); //
\r
472 LCD_SendLCDCmd( 0xB7 ); // Glass direction
\r
473 LCD_SendLCDData( 0xC0 ); //
\r
475 LCD_SendLCDCmd( ST7637_ANASET ); // Analog circuit setting 0xd0
\r
476 LCD_SendLCDData( 0x1D ); //
\r
478 LCD_SendLCDCmd( 0xB4 ); // PTL mode set
\r
479 LCD_SendLCDData( 0x18 ); // power normal mode
\r
480 LCD_SendLCDCmd( ST7637_INVOFF ); // Display Inversion OFF 0x20
\r
482 LCD_SendLCDCmd( 0x2A ); // column range
\r
483 LCD_SendLCDData( 0x04 ); //
\r
484 LCD_SendLCDData( 0x83 ); //
\r
486 LCD_SendLCDCmd( 0x2B ); // raw range
\r
487 LCD_SendLCDData( 0x04 ); //
\r
488 LCD_SendLCDData( 0x83 ); //
\r
491 LCD_SendLCDCmd( ST7637_COLMOD ); // Color mode = 65k 0x3A
\r
492 LCD_SendLCDData( 0x05 ); //
\r
494 LCD_SendLCDCmd( ST7637_MADCTR ); // Memory Access Control 0x36
\r
495 LCD_SendLCDData( V9_MADCTRVAL );
\r
497 LCD_SendLCDCmd( ST7637_DUTYSET ); // Duty = 132 duty 0xb0
\r
498 LCD_SendLCDData( 0x7F );
\r
500 LCD_SendLCDCmd( 0x29 ); // Display ON
\r
501 LCD_SendLCDCmd( 0xF9 ); // Gamma
\r
502 LCD_SendLCDData( 0x00 ); //
\r
503 LCD_SendLCDData( 0x03 ); //
\r
504 LCD_SendLCDData( 0x05 ); //
\r
505 LCD_SendLCDData( 0x07 ); //
\r
506 LCD_SendLCDData( 0x09 ); //
\r
507 LCD_SendLCDData( 0x0B ); //
\r
508 LCD_SendLCDData( 0x0D ); //
\r
509 LCD_SendLCDData( 0x0F ); //
\r
510 LCD_SendLCDData( 0x11 ); //
\r
511 LCD_SendLCDData( 0x13 ); //
\r
512 LCD_SendLCDData( 0x15 ); //
\r
513 LCD_SendLCDData( 0x17 ); //
\r
514 LCD_SendLCDData( 0x19 ); //
\r
515 LCD_SendLCDData( 0x1B ); //
\r
516 LCD_SendLCDData( 0x1D ); //
\r
517 LCD_SendLCDData( 0x1F ); //
\r
520 /*******************************************************************************
\r
522 * LCD_BackLightConfig
\r
524 *******************************************************************************/
\r
526 * Setting of the PWM that drives the backlight intensity.
\r
529 /******************************************************************************/
\r
530 static void LCD_BackLightConfig( void )
\r
532 GPIO_InitTypeDef GPIO_InitStructure;
\r
534 /* Enable GPIOB clock */
\r
535 RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB, ENABLE );
\r
537 /* GPIOB Configuration:TIM4 2 in Output */
\r
538 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
\r
539 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
\r
540 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
\r
542 GPIO_Init( GPIOB, &GPIO_InitStructure );
\r
544 /* TIM4 Configuration -----------------------------------------------------*/
\r
545 /* TIM4CLK = 12 MHz, Prescaler = 0x0 */
\r
547 /* Enable TIM4 clock */
\r
548 RCC_APB1PeriphClockCmd( RCC_APB1Periph_TIM4, ENABLE );
\r
550 TIM_DeInit( TIM4 );
\r
551 TIM_TimeBaseStructInit( &TIM_TimeBaseStructure );
\r
552 TIM_OCStructInit( &TIM_OCInitStructure );
\r
554 /* Time base configuration */
\r
555 TIM_TimeBaseStructure.TIM_Period = 0xFFFF;
\r
556 TIM_TimeBaseStructure.TIM_Prescaler = 0x0;
\r
557 TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
\r
558 TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
\r
560 TIM_TimeBaseInit( TIM4, &TIM_TimeBaseStructure );
\r
562 /* Output Compare Toggle Mode configuration: Channel2 */
\r
563 TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
\r
564 TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
\r
565 TIM_OCInitStructure.TIM_Pulse = Current_CCR_BackLightStart;
\r
567 TIM_OC2Init( TIM4, &TIM_OCInitStructure );
\r
568 TIM_OC4PreloadConfig( TIM4, TIM_OCPreload_Disable );
\r
570 TIM_ARRPreloadConfig( TIM4, ENABLE );
\r
572 /* Enable TIM4 IT */
\r
573 TIM_ITConfig( TIM4, TIM_IT_CC2, ENABLE );
\r
576 TIM_Cmd( TIM4, ENABLE );
\r
579 /*******************************************************************************
\r
581 * LCD_BackLightChange
\r
583 *******************************************************************************/
\r
585 * Modify the PWM rate.
\r
588 /******************************************************************************/
\r
589 static void LCD_BackLightChange( void )
\r
591 /* Output Compare Toggle Mode configuration: Channel2 */
\r
592 TIM_OCInitStructure.TIM_Pulse = Current_CCR_BackLightStart;
\r
594 TIM_OCInit( TIM4, &TIM_OCInitStructure );
\r
597 /* Public functions for CircleOS ---------------------------------------------*/
\r
599 /*******************************************************************************
\r
603 *******************************************************************************/
\r
606 * Initialize LCD. Called at CircleOS startup.
\r
608 * @attention This function must <b>NOT</b> be called by the user.
\r
611 /******************************************************************************/
\r
612 void LCD_Init( void )
\r
614 LCD_SetBackLight( UTIL_ReadBackupRegister( BKP_BKLIGHT ) );
\r
616 /* Do some gpio configs*/
\r
617 GPIO_InitTypeDef GPIO_InitStructure;
\r
619 /* Enable GPIO clock for LCD */
\r
620 RCC_APB2PeriphClockCmd( GPIO_LCD_CTRL_PERIPH, ENABLE );
\r
621 RCC_APB2PeriphClockCmd( GPIO_LCD_D_PERIPH, ENABLE );
\r
622 RCC_APB2PeriphClockCmd( GPIO_LCD_CS_PERIPH, ENABLE );
\r
624 /* Enable GPIOC clock */
\r
625 RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOC, ENABLE );
\r
627 /* Init BackLight*/
\r
628 LCD_BackLightConfig();
\r
630 /* Configure control lines signals as output mode */
\r
631 LCD_CtrlLinesConfig();
\r
634 LCD_7637_Controller();
\r
637 /*******************************************************************************
\r
641 *******************************************************************************/
\r
644 * Called by the CircleOS scheduler to manage LCD tasks.
\r
646 * @attention This function must <b>NOT</b> be called by the user.
\r
649 /******************************************************************************/
\r
650 void LCD_Handler( void )
\r
652 if( ++HandlerDivider % BACKLIGHT_DIVIDER )
\r
657 LCD_BackLightChange();
\r
663 /* Public functions ----------------------------------------------------------*/
\r
665 /*******************************************************************************
\r
669 *******************************************************************************/
\r
672 * Send on command byte to the LCD.
\r
674 * @param[in] Cmd An unsigned char containing the user command to send to the LCD.
\r
677 /******************************************************************************/
\r
678 void LCD_SendLCDCmd( u8 Cmd )
\r
680 /* Start the LCD send data sequence */
\r
681 LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RS, Bit_RESET ); /* RS = 0 */
\r
682 LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RD, Bit_SET ); /* RD = 1 */
\r
683 LCD_CtrlLinesWrite( GPIOx_CS_LCD, CtrlPin_CS, Bit_RESET ); /* CS = 0 */
\r
684 LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_WR, Bit_RESET ); /* WR = 0 */
\r
686 /* Write data to the LCD */
\r
687 LCD_DataLinesWrite( GPIOx_D_LCD, (u32)Cmd );
\r
688 LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_WR, Bit_SET ); /* WR = 1 */
\r
691 /*******************************************************************************
\r
695 *******************************************************************************/
\r
698 * Send one data byte to the LCD.
\r
700 * @param[in] Data An unsigned character containing the data to send to the LCD.
\r
701 * @pre An LCD_SendLCDCmd was done with a command waiting for data.
\r
705 /******************************************************************************/
\r
706 void LCD_SendLCDData( u8 Data )
\r
708 /* Configure Data lines as Output */
\r
709 LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RS, Bit_SET );
\r
710 LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RD, Bit_SET );
\r
711 LCD_CtrlLinesWrite( GPIOx_CS_LCD, CtrlPin_CS, Bit_RESET );
\r
712 LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_WR, Bit_RESET );
\r
714 /* Write data to the LCD */
\r
715 LCD_DataLinesWrite( GPIOx_D_LCD,(u32)Data );
\r
716 LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_WR, Bit_SET );
\r
719 /***********************************************************************************
\r
723 ************************************************************************************/
\r
726 * Read one data byte from the LCD.
\r
728 * @return An unsigned 32 bit word containing the data returned by a LCD command.
\r
729 * @pre An LCD_SendLCDCmd was done with a command returning data.
\r
732 /********************************************************************************/
\r
733 u32 LCD_ReadLCDData( void )
\r
737 /* Configure Data lines as Input */
\r
738 LCD_DataLinesConfig(Input);
\r
740 /* Start the LCD send data sequence */
\r
741 LCD_CtrlLinesWrite( GPIOx_D_LCD, CtrlPin_RS, Bit_SET ); /* RS = 1 */
\r
742 LCD_CtrlLinesWrite( GPIOx_D_LCD, CtrlPin_WR, Bit_SET ); /* WR = 1 */
\r
743 LCD_CtrlLinesWrite( GPIOx_CS_LCD, CtrlPin_CS, Bit_RESET ); /* CS = 0 */
\r
744 LCD_CtrlLinesWrite( GPIOx_D_LCD, CtrlPin_RD, Bit_RESET ); /* RD = 0 */
\r
746 /* Read data from the LCD */
\r
747 LCDData = (GPIO_ReadInputData( GPIOx_D_LCD ) & LCD_DATA_PINS );
\r
749 LCD_CtrlLinesWrite( GPIOx_D_LCD, CtrlPin_RD, Bit_SET ); /* RD = 1 */
\r
751 /* Read the LCD returned data */
\r
752 LCD_DataLinesConfig( Output );
\r
757 /*******************************************************************************
\r
761 *******************************************************************************/
\r
764 * Fill a rectangle with a provided color.
\r
766 * @param[in] x The horizontal coordinate of the rectangle low left corner.
\r
767 * @param[in] y The vertical coordinate of the rectangle low left corner.
\r
768 * @param[in] width The rectangle width in pixels.
\r
769 * @param[in] height The rectangle height in pixels.
\r
770 * @param[in] color The RGB color to fill the rectangle with.
\r
772 * @warning The (0x0) point in on the low left corner.
\r
775 /******************************************************************************/
\r
776 void LCD_FillRect( u16 x, u16 y, u16 width, u16 height, u16 color )
\r
781 /* Select LCD screen area. */
\r
782 LCD_SetRect_For_Cmd( x, y, width, height );
\r
784 /* Send LCD RAM write command. */
\r
785 LCD_SendLCDCmd( ST7637_RAMWR );
\r
787 /* Fill selected LCD screen area with provided color. */
\r
788 for( Line = 0; Line < width; Line++ )
\r
790 for( Column = 0; Column < height; Column++ )
\r
792 LCD_SendLCDData( color & 0xff );
\r
793 LCD_SendLCDData( ( color >> 8 ) & 0xff );
\r
798 /* Configure Data lines as Input */
\r
799 LCD_DataLinesConfig( Input );
\r
801 LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RST, Bit_SET ); /* RST = 1 */
\r
802 LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RST, Bit_RESET ); /* RST = 0 */
\r
803 LCD_CtrlLinesWrite( GPIOx_CTRL_LCD, CtrlPin_RST, Bit_SET ); /* RST = 1 */
\r
805 /* Start the LCD send data sequence */
\r
806 LCD_CtrlLinesWrite( GPIOx_D_LCD, CtrlPin_RS, Bit_SET ); /* RS = 1 */
\r
807 LCD_CtrlLinesWrite( GPIOx_D_LCD, CtrlPin_RS, Bit_RESET ); /* RS = 0 */
\r
808 LCD_CtrlLinesWrite( GPIOx_D_LCD, CtrlPin_RS, Bit_SET ); /* RS = 1 */
\r
810 LCD_CtrlLinesWrite( GPIOx_D_LCD, CtrlPin_RS, Bit_SET ); /* RS = 1 */
\r
811 LCD_CtrlLinesWrite( GPIOx_D_LCD, CtrlPin_RS, Bit_RESET ); /* RS = 0 */
\r
812 LCD_CtrlLinesWrite( GPIOx_D_LCD, CtrlPin_RS, Bit_SET ); /* RS = 1 */
\r
814 LCD_CtrlLinesWrite( GPIOx_D_LCD, CtrlPin_WR, Bit_SET ); /* WR = 1 */
\r
815 LCD_CtrlLinesWrite( GPIOx_D_LCD, CtrlPin_WR, Bit_RESET ); /* WR = 1 */
\r
816 LCD_CtrlLinesWrite( GPIOx_D_LCD, CtrlPin_WR, Bit_SET ); /* WR = 1 */
\r
818 LCD_CtrlLinesWrite( GPIOx_D_LCD, CtrlPin_RD, Bit_SET ); /* RD = 1 */
\r
819 LCD_CtrlLinesWrite( GPIOx_D_LCD, CtrlPin_RD, Bit_RESET ); /* RD = 0 */
\r
820 LCD_CtrlLinesWrite( GPIOx_D_LCD, CtrlPin_RD, Bit_SET ); /* RD = 1 */
\r
822 LCD_CtrlLinesWrite( GPIOx_D_LCD, CtrlPin_RD, Bit_SET ); /* RD = 1 */
\r
823 LCD_CtrlLinesWrite( GPIOx_D_LCD, CtrlPin_RD, Bit_RESET ); /* RD = 0 */
\r
824 LCD_CtrlLinesWrite( GPIOx_D_LCD, CtrlPin_RD, Bit_SET ); /* RD = 1 */
\r
826 /* Configure Data lines as Input */
\r
827 LCD_DataLinesConfig( Output );
\r
829 LCD_DataLinesWrite( GPIOx_D_LCD, ~0 );
\r
830 LCD_DataLinesWrite( GPIOx_D_LCD, 0 );
\r
831 LCD_DataLinesWrite( GPIOx_D_LCD, ~1 );
\r
832 LCD_DataLinesWrite( GPIOx_D_LCD, 1 );
\r
833 LCD_DataLinesWrite( GPIOx_D_LCD, ~2 );
\r
834 LCD_DataLinesWrite( GPIOx_D_LCD, 2 );
\r
835 LCD_DataLinesWrite( GPIOx_D_LCD, ~4 );
\r
836 LCD_DataLinesWrite( GPIOx_D_LCD, 4 );
\r
837 LCD_DataLinesWrite( GPIOx_D_LCD, ~8 );
\r
838 LCD_DataLinesWrite( GPIOx_D_LCD, 8 );
\r
839 LCD_DataLinesWrite( GPIOx_D_LCD, ~0x10 );
\r
840 LCD_DataLinesWrite( GPIOx_D_LCD, 0x10 );
\r
841 LCD_DataLinesWrite( GPIOx_D_LCD, ~0x20 );
\r
842 LCD_DataLinesWrite( GPIOx_D_LCD, 0x20 );
\r
843 LCD_DataLinesWrite( GPIOx_D_LCD, ~0x40 );
\r
844 LCD_DataLinesWrite( GPIOx_D_LCD, 0x40 );
\r
845 LCD_DataLinesWrite( GPIOx_D_LCD, ~0x80 );
\r
846 LCD_DataLinesWrite( GPIOx_D_LCD, 0x80 );
\r
848 LCD_DataLinesConfig( Input );
\r
853 /*******************************************************************************
\r
857 *******************************************************************************/
\r
860 * Draw a rectangle with a provided color.
\r
862 * @param[in] x The horizontal coordinate of the rectangle low left corner.
\r
863 * @param[in] y The vertical coordinate of the rectangle low left corner.
\r
864 * @param[in] width The rectangle width in pixels.
\r
865 * @param[in] height The rectangle height in pixels.
\r
866 * @param[in] color The RGB color to draw the rectangle with.
\r
868 * @warning The (0x0) point in on the low left corner.
\r
871 /******************************************************************************/
\r
872 void LCD_DrawRect( u16 x, u16 y, u16 width, u16 height, u16 color )
\r
874 // Draw horizontal sides.
\r
875 LCD_FillRect( x, y, width, 1, color );
\r
876 LCD_FillRect( x, y + height - 1, width, 1, color );
\r
878 // Draw vertical sides.
\r
879 LCD_FillRect( x, y, 1, height, color );
\r
880 LCD_FillRect( x + width - 1, y, 1, height, color );
\r
883 /*******************************************************************************
\r
887 *******************************************************************************/
\r
890 * Draw a pixel on the LCD with the provided color.
\r
892 * @param[in] XPos The horizontal coordinate of the pixel.
\r
893 * @param[in] YPos The vertical coordinate of the pixel.
\r
894 * @param[in] Color The RGB color to draw the pixel with.
\r
896 * @warning The (0x0) point in on the low left corner.
\r
899 /******************************************************************************/
\r
900 void LCD_DrawPixel( u8 XPos, u8 YPos, u16 Color )
\r
902 /* Select LCD screen area. */
\r
903 LCD_SetRect_For_Cmd( XPos, YPos, 1, 1 );
\r
905 /* Send LCD RAM write command. */
\r
906 LCD_SendLCDCmd( ST7637_RAMWR );
\r
909 LCD_SendLCDData( Color );
\r
910 LCD_SendLCDData( Color >> 8 );
\r
913 /*******************************************************************************
\r
917 *******************************************************************************/
\r
920 * Save the pixels of a rectangle part of the LCD into a RAM variable.
\r
922 * @param[in] x The horizontal coordinate of the rectangle low left corner.
\r
923 * @param[in] y The vertical coordinate of the rectangle low left corner.
\r
924 * @param[in] width The rectangle width in pixels.
\r
925 * @param[in] height The rectangle height in pixels.
\r
926 * @param[out] bmp The variable to store the read data into.
\r
928 * @warning One pixel weights 2 bytes.
\r
929 * @warning The (0x0) point in on the low left corner.
\r
932 /******************************************************************************/
\r
933 void LCD_RectRead( u16 x, u16 y, u16 width, u16 height, u8* bmp )
\r
936 int bytesize = (width * height) *2; // 2 bytes per pixel.
\r
938 /* Select LCD screen area. */
\r
939 LCD_SetRect_For_Cmd( x, y, width, height );
\r
941 /* Send LCD RAM write command. */
\r
942 LCD_SendLCDCmd(ST7637_RAMRD);
\r
944 // First read byte is dummy!
\r
947 // Read pixels from LCD screen.
\r
948 for( i = 0; i < bytesize; i++ )
\r
950 *bmp++ = LCD_ReadLCDData();
\r
954 /*******************************************************************************
\r
958 *******************************************************************************/
\r
961 * Read the RGB color of the pixel the coordinate are provided in parameter.
\r
963 * @param[in] x The horizontal coordinate of the pixel.
\r
964 * @param[in] y The vertical coordinate of the pixel.
\r
965 * @return An unsigned 16 bit word containing the RGB color of the pixel.
\r
967 * @warning The (0x0) point in on the low left corner.
\r
968 * @see LCD_RectRead
\r
971 /******************************************************************************/
\r
972 u16 LCD_GetPixel( u8 x, u8 y )
\r
976 LCD_RectRead( x, y, 1, 1, (u8*)&val );
\r
981 /*******************************************************************************
\r
985 *******************************************************************************/
\r
988 * Display at provided coordinates the provided ASCII character with the provided
\r
989 * text and background colors and with the provided magnify coefficient.
\r
991 * @param[in] x The horizontal coordinate of the character.
\r
992 * @param[in] y The vertical coordinate of the character.
\r
993 * @param[in] Ascii The ASCII code of the character to display.
\r
994 * @n Ascii must be higher than 31 and lower than 127.
\r
995 * @param[in] TextColor The color used to draw the character.
\r
996 * @param[in] BGndColor The background color of the drawn character.
\r
997 * @param[in] CharMagniCoeff The magnify coefficient used to draw the character.
\r
999 * @warning The (0x0) point in on the low left corner.
\r
1002 /******************************************************************************/
\r
1003 void LCD_DisplayChar( u8 x, u8 y, u8 Ascii, u16 TextColor, u16 BGndColor, u16 CharMagniCoeff)
\r
1005 // Display the selected bitmap according to the provided ASCII character.
\r
1006 LCD_DrawChar( x, y, 7, (u8*)&AsciiDotsTable[ (Ascii-32) * 14 ], TextColor, BGndColor, CharMagniCoeff );
\r
1009 /*******************************************************************************
\r
1011 * LCD_SetRect_For_Cmd
\r
1013 *******************************************************************************/
\r
1016 * Define the rectangle for the next command to be applied.
\r
1018 * @param[in] x The horizontal coordinate of the rectangle low left corner.
\r
1019 * @param[in] y The vertical coordinate of the rectangle low left corner.
\r
1020 * @param[in] width The rectangle width in pixels.
\r
1021 * @param[in] height The rectangle height in pixels.
\r
1023 * @warning The (0x0) point in on the low left corner.
\r
1026 /******************************************************************************/
\r
1027 void LCD_SetRect_For_Cmd( s16 x, s16 y, s16 width, s16 height )
\r
1029 LCD_SendLCDCmd( ST7637_CASET );
\r
1030 LCD_SendLCDData( y + OrientationOffsetX[ CurrentScreenOrientation ] );
\r
1031 LCD_SendLCDData( y + OrientationOffsetX[ CurrentScreenOrientation ] + height - 1 );
\r
1033 LCD_SendLCDCmd( ST7637_RASET );
\r
1034 LCD_SendLCDData( x + OrientationOffsetY[ CurrentScreenOrientation ] );
\r
1035 LCD_SendLCDData( x + OrientationOffsetY[ CurrentScreenOrientation ] + width - 1 );
\r
1038 /*******************************************************************************
\r
1040 * LCD_SetBackLight
\r
1042 *******************************************************************************/
\r
1045 * Modify the PWM rate. Any value below BACKLIGHTMIN reset the value to the
\r
1046 * default value (DEFAULT_CCR_BACKLIGHTSTART).
\r
1048 * @param[in] newBacklightStart The new PWM rate.
\r
1051 /******************************************************************************/
\r
1052 void LCD_SetBackLight( u32 newBacklightStart )
\r
1054 if( newBacklightStart >= BACKLIGHTMIN )
\r
1056 Current_CCR_BackLightStart = newBacklightStart;
\r
1060 Current_CCR_BackLightStart = DEFAULT_CCR_BACKLIGHTSTART;
\r
1064 /*******************************************************************************
\r
1066 * LCD_SetBackLightOff
\r
1068 *******************************************************************************/
\r
1071 * Switch the LCD back light off.
\r
1074 /******************************************************************************/
\r
1075 void LCD_SetBackLightOff( void )
\r
1077 Current_CCR_BackLightStart = 0;
\r
1080 /*******************************************************************************
\r
1082 * LCD_SetBackLightOn
\r
1084 *******************************************************************************/
\r
1087 * Switch the LCD back light on.
\r
1090 /******************************************************************************/
\r
1091 void LCD_SetBackLightOn( void )
\r
1093 Current_CCR_BackLightStart = DEFAULT_CCR_BACKLIGHTSTART;
\r
1096 /*******************************************************************************
\r
1098 * LCD_GetBackLight
\r
1100 *******************************************************************************/
\r
1103 * Returns le LCD PWM rate.
\r
1105 * @return The current LCD PWM rate.
\r
1108 /******************************************************************************/
\r
1109 u32 LCD_GetBackLight( void )
\r
1111 return Current_CCR_BackLightStart;
\r
1114 /*******************************************************************************
\r
1116 * LCD_SetRotateScreen
\r
1118 *******************************************************************************/
\r
1121 * Enable or disable the ability of the screen display to rotate according to
\r
1122 * the MEMs information.
\r
1124 * @param[in] RotateScreen 0 to disable screen rotation and 1 to enable.
\r
1127 /******************************************************************************/
\r
1128 void LCD_SetRotateScreen( u8 RotateScreen)
\r
1130 CurrentRotateScreen = RotateScreen;
\r
1133 /*******************************************************************************
\r
1135 * LCD_GetRotateScreen
\r
1137 *******************************************************************************/
\r
1140 * Return the screen rotation mode.
\r
1142 * @retval 0 screen rotation is disabled.
\r
1143 * @retval 1 screen rotation is enabled.
\r
1146 /******************************************************************************/
\r
1147 u8 LCD_GetRotateScreen( void )
\r
1149 return CurrentRotateScreen;
\r
1152 /*******************************************************************************
\r
1154 * LCD_SetScreenOrientation
\r
1156 *******************************************************************************/
\r
1159 * Set the screen orientation.
\r
1161 * @param[in] ScreenOrientation The new screen orientation.
\r
1164 /******************************************************************************/
\r
1165 void LCD_SetScreenOrientation( Rotate_H12_V_Match_TypeDef ScreenOrientation )
\r
1167 CurrentScreenOrientation = ScreenOrientation;
\r
1169 LCD_DisplayRotate( CurrentScreenOrientation );
\r
1172 /*******************************************************************************
\r
1174 * LCD_GetScreenOrientation
\r
1176 *******************************************************************************/
\r
1179 * Return current screen orientation.
\r
1181 * @return A Rotate_H12_V_Match_TypeDef telling the current screen orientation.
\r
1184 /******************************************************************************/
\r
1185 Rotate_H12_V_Match_TypeDef LCD_GetScreenOrientation( void )
\r
1187 return CurrentScreenOrientation;
\r