Mon, 29 Oct 2018 19:37:14 +0100
Swapped MLT and HLT SSR pins to match he real hardware. More doxygen changes.
0 | 1 | /* |
2 | * | |
3 | * HIGH SPEED LOW LEVEL DISPLAY FUNCTIONS USING DIRECT TRANSFER MODE | |
4 | * | |
5 | */ | |
6 | ||
7 | #ifndef _TFTSPI_H_ | |
8 | #define _TFTSPI_H_ | |
9 | ||
10 | #include "tftspi.h" | |
11 | #include "spi_master_lobo.h" | |
12 | #include "sdkconfig.h" | |
13 | #include "stmpe610.h" | |
14 | ||
15 | #define TOUCH_TYPE_NONE 0 | |
16 | #define TOUCH_TYPE_XPT2046 1 | |
17 | #define TOUCH_TYPE_STMPE610 2 | |
18 | ||
19 | //#define TP_CALX_STMPE610 21368532 | |
20 | //#define TP_CALY_STMPE610 11800144 | |
21 | ||
22 | // === Screen orientation constants === | |
23 | #define PORTRAIT 0 | |
24 | #define LANDSCAPE 1 | |
25 | #define PORTRAIT_FLIP 2 | |
26 | #define LANDSCAPE_FLIP 3 | |
27 | ||
28 | #define DISP_TYPE_ILI9341 0 | |
29 | #define DISP_TYPE_ILI9488 1 | |
30 | #define DISP_TYPE_ST7789V 2 | |
31 | #define DISP_TYPE_ST7735 3 | |
32 | #define DISP_TYPE_ST7735R 4 | |
33 | #define DISP_TYPE_ST7735B 5 | |
34 | #define DISP_TYPE_MAX 6 | |
35 | ||
36 | #if CONFIG_EXAMPLE_DISPLAY_TYPE == 1 | |
37 | ||
38 | // ** Set the correct configuration for ESP32-WROVER-KIT v3 | |
39 | // -------------------------------------------------------- | |
40 | #define DEFAULT_DISP_TYPE DISP_TYPE_ST7789V | |
41 | #define DEFAULT_TFT_DISPLAY_WIDTH 240 | |
42 | #define DEFAULT_TFT_DISPLAY_HEIGHT 320 | |
43 | #define DISP_COLOR_BITS_24 0x66 | |
44 | #define DEFAULT_GAMMA_CURVE 0 | |
45 | #define DEFAULT_SPI_CLOCK 26000000 | |
46 | #define TFT_INVERT_ROTATION 0 | |
47 | #define TFT_INVERT_ROTATION1 1 | |
48 | #define TFT_RGB_BGR 0x00 | |
49 | ||
50 | #define USE_TOUCH TOUCH_TYPE_NONE | |
51 | ||
52 | #define PIN_NUM_MISO 25 // SPI MISO | |
53 | #define PIN_NUM_MOSI 23 // SPI MOSI | |
54 | #define PIN_NUM_CLK 19 // SPI CLOCK pin | |
55 | #define PIN_NUM_CS 22 // Display CS pin | |
56 | #define PIN_NUM_DC 21 // Display command/data pin | |
57 | #define PIN_NUM_TCS 0 // Touch screen CS pin | |
58 | ||
59 | #define PIN_NUM_RST 18 // GPIO used for RESET control | |
60 | #define PIN_NUM_BCKL 5 // GPIO used for backlight control | |
61 | #define PIN_BCKL_ON 0 // GPIO value for backlight ON | |
62 | #define PIN_BCKL_OFF 1 // GPIO value for backlight OFF | |
63 | // -------------------------------------------------------- | |
64 | ||
65 | #elif CONFIG_EXAMPLE_DISPLAY_TYPE == 2 | |
66 | ||
67 | // ** Set the correct configuration for Adafruit TFT Feather | |
68 | // --------------------------------------------------------- | |
69 | #define DEFAULT_DISP_TYPE DISP_TYPE_ILI9341 | |
70 | #define DEFAULT_TFT_DISPLAY_WIDTH 240 | |
71 | #define DEFAULT_TFT_DISPLAY_HEIGHT 320 | |
72 | #define DISP_COLOR_BITS_24 0x66 | |
73 | #define DEFAULT_GAMMA_CURVE 0 | |
74 | #define DEFAULT_SPI_CLOCK 26000000 | |
75 | #define TFT_INVERT_ROTATION 0 | |
76 | #define TFT_INVERT_ROTATION1 0 | |
77 | #define TFT_RGB_BGR 0x08 | |
78 | ||
79 | #define USE_TOUCH TOUCH_TYPE_STMPE610 | |
80 | ||
81 | #define PIN_NUM_MISO 19 // SPI MISO | |
82 | #define PIN_NUM_MOSI 18 // SPI MOSI | |
83 | #define PIN_NUM_CLK 5 // SPI CLOCK pin | |
84 | #define PIN_NUM_CS 15 // Display CS pin | |
85 | #define PIN_NUM_DC 33 // Display command/data pin | |
86 | #define PIN_NUM_TCS 32 // Touch screen CS pin (NOT used if USE_TOUCH=0) | |
87 | ||
88 | #define PIN_NUM_RST 0 // GPIO used for RESET control (#16) | |
89 | #define PIN_NUM_BCKL 0 // GPIO used for backlight control | |
90 | #define PIN_BCKL_ON 0 // GPIO value for backlight ON | |
91 | #define PIN_BCKL_OFF 1 // GPIO value for backlight OFF | |
92 | // --------------------------------------------------------- | |
93 | ||
94 | #elif CONFIG_EXAMPLE_DISPLAY_TYPE == 3 | |
95 | ||
96 | // ** Set the correct configuration for M5Stack TFT | |
97 | // --------------------------------------------------------- | |
98 | #define DEFAULT_DISP_TYPE DISP_TYPE_ILI9341 | |
99 | #define DEFAULT_TFT_DISPLAY_WIDTH 320 | |
100 | #define DEFAULT_TFT_DISPLAY_HEIGHT 240 | |
101 | #define DISP_COLOR_BITS_24 0x66 | |
102 | #define DEFAULT_GAMMA_CURVE 0 | |
103 | #define DEFAULT_SPI_CLOCK 26000000 | |
104 | #define TFT_INVERT_ROTATION 0 | |
105 | #define TFT_INVERT_ROTATION1 0 | |
106 | #define TFT_INVERT_ROTATION2 1 // Adapte M5Stack TFT | |
107 | #define TFT_RGB_BGR 0x08 | |
108 | ||
109 | #define USE_TOUCH TOUCH_TYPE_NONE | |
110 | ||
111 | #define PIN_NUM_MISO 19 // SPI MISO | |
112 | #define PIN_NUM_MOSI 23 // SPI MOSI | |
113 | #define PIN_NUM_CLK 18 // SPI CLOCK pin | |
114 | #define PIN_NUM_CS 14 // Display CS pin | |
115 | #define PIN_NUM_DC 27 // Display command/data pin | |
116 | #define PIN_NUM_TCS 0 // Touch screen CS pin (NOT used if USE_TOUCH=0) | |
117 | ||
118 | #define PIN_NUM_RST 33 // GPIO used for RESET control (#16) | |
119 | #define PIN_NUM_BCKL 32 // GPIO used for backlight control | |
120 | #define PIN_BCKL_ON 1 // GPIO value for backlight ON | |
121 | #define PIN_BCKL_OFF 0 // GPIO value for backlight OFF | |
122 | // --------------------------------------------------------- | |
123 | ||
124 | #else | |
125 | ||
126 | // Configuration for other boards, set the correct values for the display used | |
127 | //---------------------------------------------------------------------------- | |
128 | #define DISP_COLOR_BITS_24 0x66 | |
129 | //#define DISP_COLOR_BITS_16 0x55 // Do not use! | |
130 | ||
131 | // ############################################# | |
132 | // ### Set to 1 for some displays, ### | |
133 | // for example the one on ESP-WROWER-KIT ### | |
134 | // ############################################# | |
135 | #define TFT_INVERT_ROTATION 0 | |
136 | #define TFT_INVERT_ROTATION1 0 | |
137 | ||
138 | // ################################################ | |
139 | // ### SET TO 0X00 FOR DISPLAYS WITH RGB MATRIX ### | |
140 | // ### SET TO 0X08 FOR DISPLAYS WITH BGR MATRIX ### | |
141 | // ### For ESP-WROWER-KIT set to 0x00 ### | |
142 | // ################################################ | |
143 | #define TFT_RGB_BGR 0x08 | |
144 | ||
145 | // ############################################################## | |
146 | // ### Define ESP32 SPI pins to which the display is attached ### | |
147 | // ############################################################## | |
148 | ||
149 | // The pins configured here are the native spi pins for HSPI interface | |
150 | // Any other valid pin combination can be used | |
151 | #define PIN_NUM_MISO 19 // SPI MISO | |
152 | #define PIN_NUM_MOSI 23 // SPI MOSI | |
153 | #define PIN_NUM_CLK 18 // SPI CLOCK pin | |
154 | #define PIN_NUM_CS 5 // Display CS pin | |
155 | #define PIN_NUM_DC 4 // Display command/data pin | |
156 | #define PIN_NUM_TCS 22 // Touch screen CS pin (NOT used if USE_TOUCH=0) | |
157 | ||
158 | // -------------------------------------------------------------- | |
159 | // ** Set Reset and Backlight pins to 0 if not used ! | |
160 | // ** If you want to use them, set them to some valid GPIO number | |
161 | #define PIN_NUM_RST 0 // GPIO used for RESET control | |
162 | ||
163 | #define PIN_NUM_BCKL 21 // GPIO used for backlight control | |
164 | #define PIN_BCKL_ON 1 // GPIO value for backlight ON | |
165 | #define PIN_BCKL_OFF 0 // GPIO value for backlight OFF | |
166 | // -------------------------------------------------------------- | |
167 | ||
168 | // ####################################################### | |
169 | // Set this to 1 if you want to use touch screen functions | |
170 | // ####################################################### | |
171 | #define USE_TOUCH TOUCH_TYPE_XPT2046 | |
172 | // ####################################################### | |
173 | ||
174 | // ####################################################################### | |
175 | // Default display width (smaller dimension) and height (larger dimension) | |
176 | // ####################################################################### | |
177 | #define DEFAULT_TFT_DISPLAY_WIDTH 240 | |
178 | #define DEFAULT_TFT_DISPLAY_HEIGHT 320 | |
179 | // ####################################################################### | |
180 | ||
181 | #define DEFAULT_GAMMA_CURVE 0 | |
182 | #define DEFAULT_SPI_CLOCK 26000000 | |
183 | #define DEFAULT_DISP_TYPE DISP_TYPE_ILI9341 | |
184 | //---------------------------------------------------------------------------- | |
185 | ||
186 | #endif // CONFIG_EXAMPLE_ESP_WROVER_KIT | |
187 | ||
188 | ||
189 | // ############################################################## | |
190 | // #### Global variables #### | |
191 | // ############################################################## | |
192 | ||
193 | // ==== Converts colors to grayscale if 1 ======================= | |
194 | extern uint8_t gray_scale; | |
195 | ||
196 | // ==== Spi clock for reading data from display memory in Hz ==== | |
197 | extern uint32_t max_rdclock; | |
198 | ||
199 | // ==== Display dimensions in pixels ============================ | |
200 | extern int _width; | |
201 | extern int _height; | |
202 | ||
203 | // ==== Display type, DISP_TYPE_ILI9488 or DISP_TYPE_ILI9341 ==== | |
204 | extern uint8_t tft_disp_type; | |
205 | ||
206 | // ==== Spi device handles for display and touch screen ========= | |
207 | extern spi_lobo_device_handle_t disp_spi; | |
208 | extern spi_lobo_device_handle_t ts_spi; | |
209 | ||
210 | // ############################################################## | |
211 | ||
212 | // 24-bit color type structure | |
213 | typedef struct __attribute__((__packed__)) { | |
214 | //typedef struct { | |
215 | uint8_t r; | |
216 | uint8_t g; | |
217 | uint8_t b; | |
218 | } color_t ; | |
219 | ||
220 | // ==== Display commands constants ==== | |
221 | #define TFT_INVOFF 0x20 | |
222 | #define TFT_INVONN 0x21 | |
223 | #define TFT_DISPOFF 0x28 | |
224 | #define TFT_DISPON 0x29 | |
225 | #define TFT_MADCTL 0x36 | |
226 | #define TFT_PTLAR 0x30 | |
227 | #define TFT_ENTRYM 0xB7 | |
228 | ||
229 | #define TFT_CMD_NOP 0x00 | |
230 | #define TFT_CMD_SWRESET 0x01 | |
231 | #define TFT_CMD_RDDID 0x04 | |
232 | #define TFT_CMD_RDDST 0x09 | |
233 | ||
234 | #define TFT_CMD_SLPIN 0x10 | |
235 | #define TFT_CMD_SLPOUT 0x11 | |
236 | #define TFT_CMD_PTLON 0x12 | |
237 | #define TFT_CMD_NORON 0x13 | |
238 | ||
239 | #define TFT_CMD_RDMODE 0x0A | |
240 | #define TFT_CMD_RDMADCTL 0x0B | |
241 | #define TFT_CMD_RDPIXFMT 0x0C | |
242 | #define TFT_CMD_RDIMGFMT 0x0D | |
243 | #define TFT_CMD_RDSELFDIAG 0x0F | |
244 | ||
245 | #define TFT_CMD_GAMMASET 0x26 | |
246 | ||
247 | #define TFT_CMD_FRMCTR1 0xB1 | |
248 | #define TFT_CMD_FRMCTR2 0xB2 | |
249 | #define TFT_CMD_FRMCTR3 0xB3 | |
250 | #define TFT_CMD_INVCTR 0xB4 | |
251 | #define TFT_CMD_DFUNCTR 0xB6 | |
252 | ||
253 | #define TFT_CMD_PWCTR1 0xC0 | |
254 | #define TFT_CMD_PWCTR2 0xC1 | |
255 | #define TFT_CMD_PWCTR3 0xC2 | |
256 | #define TFT_CMD_PWCTR4 0xC3 | |
257 | #define TFT_CMD_PWCTR5 0xC4 | |
258 | #define TFT_CMD_VMCTR1 0xC5 | |
259 | #define TFT_CMD_VMCTR2 0xC7 | |
260 | ||
261 | #define TFT_CMD_RDID1 0xDA | |
262 | #define TFT_CMD_RDID2 0xDB | |
263 | #define TFT_CMD_RDID3 0xDC | |
264 | #define TFT_CMD_RDID4 0xDD | |
265 | ||
266 | #define TFT_CMD_GMCTRP1 0xE0 | |
267 | #define TFT_CMD_GMCTRN1 0xE1 | |
268 | ||
269 | #define TFT_CMD_POWERA 0xCB | |
270 | #define TFT_CMD_POWERB 0xCF | |
271 | #define TFT_CMD_POWER_SEQ 0xED | |
272 | #define TFT_CMD_DTCA 0xE8 | |
273 | #define TFT_CMD_DTCB 0xEA | |
274 | #define TFT_CMD_PRC 0xF7 | |
275 | #define TFT_CMD_3GAMMA_EN 0xF2 | |
276 | ||
277 | #define ST_CMD_VCOMS 0xBB | |
278 | #define ST_CMD_FRCTRL2 0xC6 | |
279 | #define ST_CMD_PWCTR1 0xD0 | |
280 | ||
281 | #define ST7735_FRMCTR1 0xB1 | |
282 | #define ST7735_FRMCTR2 0xB2 | |
283 | #define ST7735_FRMCTR3 0xB3 | |
284 | #define ST7735_INVCTR 0xB4 | |
285 | #define ST7735_DISSET5 0xB6 | |
286 | ||
287 | #define ST7735_PWCTR1 0xC0 | |
288 | #define ST7735_PWCTR2 0xC1 | |
289 | #define ST7735_PWCTR3 0xC2 | |
290 | #define ST7735_PWCTR4 0xC3 | |
291 | #define ST7735_PWCTR5 0xC4 | |
292 | #define ST7735_VMCTR1 0xC5 | |
293 | ||
294 | #define ST7735_RDID1 0xDA | |
295 | #define ST7735_RDID2 0xDB | |
296 | #define ST7735_RDID3 0xDC | |
297 | #define ST7735_RDID4 0xDD | |
298 | #define ST7735_NOP 0x00 | |
299 | #define ST7735_SWRESET 0x01 | |
300 | #define ST7735_RDDID 0x04 | |
301 | #define ST7735_RDDST 0x09 | |
302 | ||
303 | #define ST7735_SLPIN 0x10 | |
304 | #define ST7735_SLPOUT 0x11 | |
305 | #define ST7735_PTLON 0x12 | |
306 | #define ST7735_NORON 0x13 | |
307 | #define ST7735_PWCTR6 0xFC | |
308 | #define ST7735_GMCTRP1 0xE0 | |
309 | #define ST7735_GMCTRN1 0xE1 | |
310 | ||
311 | #define MADCTL_MY 0x80 | |
312 | #define MADCTL_MX 0x40 | |
313 | #define MADCTL_MV 0x20 | |
314 | #define MADCTL_ML 0x10 | |
315 | #define MADCTL_MH 0x04 | |
316 | ||
317 | #define TFT_CASET 0x2A | |
318 | #define TFT_PASET 0x2B | |
319 | #define TFT_RAMWR 0x2C | |
320 | #define TFT_RAMRD 0x2E | |
321 | #define TFT_CMD_PIXFMT 0x3A | |
322 | ||
323 | #define TFT_CMD_DELAY 0x80 | |
324 | ||
325 | ||
326 | // Initialization sequence for ILI7749 | |
327 | // ==================================== | |
328 | static const uint8_t ST7789V_init[] = { | |
329 | #if PIN_NUM_RST | |
330 | 15, // 15 commands in list | |
331 | #else | |
332 | 16, // 16 commands in list | |
333 | TFT_CMD_SWRESET, TFT_CMD_DELAY, // 1: Software reset, no args, w/delay | |
334 | 200, // 200 ms delay | |
335 | #endif | |
336 | TFT_CMD_FRMCTR2, 5, 0x0c, 0x0c, 0x00, 0x33, 0x33, | |
337 | TFT_ENTRYM, 1, 0x45, | |
338 | ST_CMD_VCOMS, 1, 0x2B, | |
339 | TFT_CMD_PWCTR1, 1, 0x2C, | |
340 | TFT_CMD_PWCTR3, 2, 0x01, 0xff, | |
341 | TFT_CMD_PWCTR4, 1, 0x11, | |
342 | TFT_CMD_PWCTR5, 1, 0x20, | |
343 | ST_CMD_FRCTRL2, 1, 0x0f, | |
344 | ST_CMD_PWCTR1, 2, 0xA4, 0xA1, | |
345 | TFT_CMD_GMCTRP1, 14, 0xD0, 0x00, 0x05, 0x0E, 0x15, 0x0D, 0x37, 0x43, 0x47, 0x09, 0x15, 0x12, 0x16, 0x19, | |
346 | TFT_CMD_GMCTRN1, 14, 0xD0, 0x00, 0x05, 0x0D, 0x0C, 0x06, 0x2D, 0x44, 0x40, 0x0E, 0x1C, 0x18, 0x16, 0x19, | |
347 | TFT_MADCTL, 1, (MADCTL_MX | TFT_RGB_BGR), // Memory Access Control (orientation) | |
348 | TFT_CMD_PIXFMT, 1, DISP_COLOR_BITS_24, // *** INTERFACE PIXEL FORMAT: 0x66 -> 18 bit; 0x55 -> 16 bit | |
349 | TFT_CMD_SLPOUT, TFT_CMD_DELAY, 120, // Sleep out, // 120 ms delay | |
350 | TFT_DISPON, TFT_CMD_DELAY, 120, | |
351 | }; | |
352 | ||
353 | // Initialization sequence for ILI7341 | |
354 | // ==================================== | |
355 | static const uint8_t ILI9341_init[] = { | |
356 | #if PIN_NUM_RST | |
357 | 23, // 24 commands in list | |
358 | #else | |
359 | 24, // 24 commands in list | |
360 | TFT_CMD_SWRESET, TFT_CMD_DELAY, // 1: Software reset, no args, w/delay | |
361 | 250, // 200 ms delay | |
362 | #endif | |
363 | TFT_CMD_POWERA, 5, 0x39, 0x2C, 0x00, 0x34, 0x02, | |
364 | TFT_CMD_POWERB, 3, 0x00, 0XC1, 0X30, | |
365 | 0xEF, 3, 0x03, 0x80, 0x02, | |
366 | TFT_CMD_DTCA, 3, 0x85, 0x00, 0x78, | |
367 | TFT_CMD_DTCB, 2, 0x00, 0x00, | |
368 | TFT_CMD_POWER_SEQ, 4, 0x64, 0x03, 0X12, 0X81, | |
369 | TFT_CMD_PRC, 1, 0x20, | |
370 | TFT_CMD_PWCTR1, 1, 0x23, //Power control VRH[5:0] | |
371 | TFT_CMD_PWCTR2, 1, 0x10, //Power control SAP[2:0];BT[3:0] | |
372 | TFT_CMD_VMCTR1, 2, 0x3e, 0x28, //VCM control | |
373 | TFT_CMD_VMCTR2, 1, 0x86, //VCM control2 | |
374 | TFT_MADCTL, 1, // Memory Access Control (orientation) | |
375 | (MADCTL_MX | TFT_RGB_BGR), | |
376 | // *** INTERFACE PIXEL FORMAT: 0x66 -> 18 bit; 0x55 -> 16 bit | |
377 | TFT_CMD_PIXFMT, 1, DISP_COLOR_BITS_24, | |
378 | TFT_INVOFF, 0, | |
379 | TFT_CMD_FRMCTR1, 2, 0x00, 0x18, | |
380 | TFT_CMD_DFUNCTR, 4, 0x08, 0x82, 0x27, 0x00, // Display Function Control | |
381 | TFT_PTLAR, 4, 0x00, 0x00, 0x01, 0x3F, | |
382 | TFT_CMD_3GAMMA_EN, 1, 0x00, // 3Gamma Function: Disable (0x02), Enable (0x03) | |
383 | TFT_CMD_GAMMASET, 1, 0x01, //Gamma curve selected (0x01, 0x02, 0x04, 0x08) | |
384 | TFT_CMD_GMCTRP1, 15, //Positive Gamma Correction | |
385 | 0x0F, 0x31, 0x2B, 0x0C, 0x0E, 0x08, 0x4E, 0xF1, 0x37, 0x07, 0x10, 0x03, 0x0E, 0x09, 0x00, | |
386 | TFT_CMD_GMCTRN1, 15, //Negative Gamma Correction | |
387 | 0x00, 0x0E, 0x14, 0x03, 0x11, 0x07, 0x31, 0xC1, 0x48, 0x08, 0x0F, 0x0C, 0x31, 0x36, 0x0F, | |
388 | TFT_CMD_SLPOUT, TFT_CMD_DELAY, // Sleep out | |
389 | 200, // 120 ms delay | |
390 | TFT_DISPON, TFT_CMD_DELAY, 200, | |
391 | }; | |
392 | ||
393 | // Initialization sequence for ILI9488 | |
394 | // ==================================== | |
395 | static const uint8_t ILI9488_init[] = { | |
396 | #if PIN_NUM_RST | |
397 | 17, // 17 commands in list | |
398 | #else | |
399 | 18, // 18 commands in list | |
400 | TFT_CMD_SWRESET, TFT_CMD_DELAY, // 1: Software reset, no args, w/delay | |
401 | 200, // 200 ms delay | |
402 | #endif | |
403 | 0xE0, 15, 0x00, 0x03, 0x09, 0x08, 0x16, 0x0A, 0x3F, 0x78, 0x4C, 0x09, 0x0A, 0x08, 0x16, 0x1A, 0x0F, | |
404 | 0xE1, 15, 0x00, 0x16, 0x19, 0x03, 0x0F, 0x05, 0x32, 0x45, 0x46, 0x04, 0x0E, 0x0D, 0x35, 0x37, 0x0F, | |
405 | 0xC0, 2, //Power Control 1 | |
406 | 0x17, //Vreg1out | |
407 | 0x15, //Verg2out | |
408 | ||
409 | 0xC1, 1, //Power Control 2 | |
410 | 0x41, //VGH,VGL | |
411 | ||
412 | 0xC5, 3, //Power Control 3 | |
413 | 0x00, | |
414 | 0x12, //Vcom | |
415 | 0x80, | |
416 | ||
417 | #if TFT_INVERT_ROTATION | |
418 | TFT_MADCTL, 1, (MADCTL_MV | TFT_RGB_BGR), // Memory Access Control (orientation), set to portrait | |
419 | #else | |
420 | TFT_MADCTL, 1, (MADCTL_MX | TFT_RGB_BGR), // Memory Access Control (orientation), set to portrait | |
421 | #endif | |
422 | ||
423 | // *** INTERFACE PIXEL FORMAT: 0x66 -> 18 bit; | |
424 | TFT_CMD_PIXFMT, 1, DISP_COLOR_BITS_24, | |
425 | ||
426 | 0xB0, 1, // Interface Mode Control | |
427 | 0x00, // 0x80: SDO NOT USE; 0x00 USE SDO | |
428 | ||
429 | 0xB1, 1, //Frame rate | |
430 | 0xA0, //60Hz | |
431 | ||
432 | 0xB4, 1, //Display Inversion Control | |
433 | 0x02, //2-dot | |
434 | ||
435 | 0xB6, 2, //Display Function Control RGB/MCU Interface Control | |
436 | 0x02, //MCU | |
437 | 0x02, //Source,Gate scan direction | |
438 | ||
439 | 0xE9, 1, // Set Image Function | |
440 | 0x00, // Disable 24 bit data | |
441 | ||
442 | 0x53, 1, // Write CTRL Display Value | |
443 | 0x28, // BCTRL && DD on | |
444 | ||
445 | 0x51, 1, // Write Display Brightness Value | |
446 | 0x7F, // | |
447 | ||
448 | 0xF7, 4, // Adjust Control | |
449 | 0xA9, | |
450 | 0x51, | |
451 | 0x2C, | |
452 | 0x02, // D7 stream, loose | |
453 | ||
454 | ||
455 | 0x11, TFT_CMD_DELAY, //Exit Sleep | |
456 | 120, | |
457 | 0x29, 0, //Display on | |
458 | ||
459 | }; | |
460 | ||
461 | ||
462 | // Initialization commands for 7735B screens | |
463 | // ------------------------------------ | |
464 | static const uint8_t STP7735_init[] = { | |
465 | #if PIN_NUM_RST | |
466 | 16, // 17 commands in list | |
467 | #else | |
468 | 17, // 18 commands in list: | |
469 | ST7735_SLPOUT, TFT_CMD_DELAY, // 2: Out of sleep mode, no args, w/delay | |
470 | 255, // 255 = 500 ms delay | |
471 | #endif | |
472 | TFT_CMD_PIXFMT, 1+TFT_CMD_DELAY, // 3: Set color mode, 1 arg + delay: | |
473 | 0x06, // 18-bit color 6-6-6 color format | |
474 | 10, // 10 ms delay | |
475 | ST7735_FRMCTR1, 3+TFT_CMD_DELAY, // 4: Frame rate control, 3 args + delay: | |
476 | 0x00, // fastest refresh | |
477 | 0x06, // 6 lines front porch | |
478 | 0x03, // 3 lines back porch | |
479 | 10, // 10 ms delay | |
480 | TFT_MADCTL , 1 , // 5: Memory access ctrl (directions), 1 arg: | |
481 | 0x08, // Row addr/col addr, bottom to top refresh | |
482 | ST7735_DISSET5, 2 , // 6: Display settings #5, 2 args, no delay: | |
483 | 0x15, // 1 clk cycle nonoverlap, 2 cycle gate | |
484 | // rise, 3 cycle osc equalize | |
485 | 0x02, // Fix on VTL | |
486 | ST7735_INVCTR , 1 , // 7: Display inversion control, 1 arg: | |
487 | 0x0, // Line inversion | |
488 | ST7735_PWCTR1 , 2+TFT_CMD_DELAY, // 8: Power control, 2 args + delay: | |
489 | 0x02, // GVDD = 4.7V | |
490 | 0x70, // 1.0uA | |
491 | 10, // 10 ms delay | |
492 | ST7735_PWCTR2 , 1 , // 9: Power control, 1 arg, no delay: | |
493 | 0x05, // VGH = 14.7V, VGL = -7.35V | |
494 | ST7735_PWCTR3 , 2 , // 10: Power control, 2 args, no delay: | |
495 | 0x01, // Opamp current small | |
496 | 0x02, // Boost frequency | |
497 | ST7735_VMCTR1 , 2+TFT_CMD_DELAY, // 11: Power control, 2 args + delay: | |
498 | 0x3C, // VCOMH = 4V | |
499 | 0x38, // VCOML = -1.1V | |
500 | 10, // 10 ms delay | |
501 | ST7735_PWCTR6 , 2 , // 12: Power control, 2 args, no delay: | |
502 | 0x11, 0x15, | |
503 | ST7735_GMCTRP1,16 , // 13: Magical unicorn dust, 16 args, no delay: | |
504 | 0x09, 0x16, 0x09, 0x20, // (seriously though, not sure what | |
505 | 0x21, 0x1B, 0x13, 0x19, // these config values represent) | |
506 | 0x17, 0x15, 0x1E, 0x2B, | |
507 | 0x04, 0x05, 0x02, 0x0E, | |
508 | ST7735_GMCTRN1,16+TFT_CMD_DELAY, // 14: Sparkles and rainbows, 16 args + delay: | |
509 | 0x0B, 0x14, 0x08, 0x1E, // (ditto) | |
510 | 0x22, 0x1D, 0x18, 0x1E, | |
511 | 0x1B, 0x1A, 0x24, 0x2B, | |
512 | 0x06, 0x06, 0x02, 0x0F, | |
513 | 10, // 10 ms delay | |
514 | TFT_CASET , 4 , // 15: Column addr set, 4 args, no delay: | |
515 | 0x00, 0x02, // XSTART = 2 | |
516 | 0x00, 0x81, // XEND = 129 | |
517 | TFT_PASET , 4 , // 16: Row addr set, 4 args, no delay: | |
518 | 0x00, 0x02, // XSTART = 1 | |
519 | 0x00, 0x81, // XEND = 160 | |
520 | ST7735_NORON , TFT_CMD_DELAY, // 17: Normal display on, no args, w/delay | |
521 | 10, // 10 ms delay | |
522 | TFT_DISPON , TFT_CMD_DELAY, // 18: Main screen turn on, no args, w/delay | |
523 | 255 // 255 = 500 ms delay | |
524 | }; | |
525 | ||
526 | // Init for 7735R, part 1 (red or green tab) | |
527 | // -------------------------------------- | |
528 | static const uint8_t STP7735R_init[] = { | |
529 | #if PIN_NUM_RST | |
530 | 14, // 14 commands in list | |
531 | #else | |
532 | 15, // 15 commands in list: | |
533 | ST7735_SWRESET, TFT_CMD_DELAY, // 1: Software reset, 0 args, w/delay | |
534 | 150, // 150 ms delay | |
535 | #endif | |
536 | ST7735_SLPOUT , TFT_CMD_DELAY, // 2: Out of sleep mode, 0 args, w/delay | |
537 | 255, // 500 ms delay | |
538 | ST7735_FRMCTR1, 3 , // 3: Frame rate ctrl - normal mode, 3 args: | |
539 | 0x01, 0x2C, 0x2D, // Rate = fosc/(1x2+40) * (LINE+2C+2D) | |
540 | ST7735_FRMCTR2, 3 , // 4: Frame rate control - idle mode, 3 args: | |
541 | 0x01, 0x2C, 0x2D, // Rate = fosc/(1x2+40) * (LINE+2C+2D) | |
542 | ST7735_FRMCTR3, 6 , // 5: Frame rate ctrl - partial mode, 6 args: | |
543 | 0x01, 0x2C, 0x2D, // Dot inversion mode | |
544 | 0x01, 0x2C, 0x2D, // Line inversion mode | |
545 | ST7735_INVCTR , 1 , // 6: Display inversion ctrl, 1 arg, no delay: | |
546 | 0x07, // No inversion | |
547 | ST7735_PWCTR1 , 3 , // 7: Power control, 3 args, no delay: | |
548 | 0xA2, | |
549 | 0x02, // -4.6V | |
550 | 0x84, // AUTO mode | |
551 | ST7735_PWCTR2 , 1 , // 8: Power control, 1 arg, no delay: | |
552 | 0xC5, // VGH25 = 2.4C VGSEL = -10 VGH = 3 * AVDD | |
553 | ST7735_PWCTR3 , 2 , // 9: Power control, 2 args, no delay: | |
554 | 0x0A, // Opamp current small | |
555 | 0x00, // Boost frequency | |
556 | ST7735_PWCTR4 , 2 , // 10: Power control, 2 args, no delay: | |
557 | 0x8A, // BCLK/2, Opamp current small & Medium low | |
558 | 0x2A, | |
559 | ST7735_PWCTR5 , 2 , // 11: Power control, 2 args, no delay: | |
560 | 0x8A, 0xEE, | |
561 | ST7735_VMCTR1 , 1 , // 12: Power control, 1 arg, no delay: | |
562 | 0x0E, | |
563 | TFT_INVOFF , 0 , // 13: Don't invert display, no args, no delay | |
564 | TFT_MADCTL , 1 , // 14: Memory access control (directions), 1 arg: | |
565 | 0xC0, // row addr/col addr, bottom to top refresh, RGB order | |
566 | TFT_CMD_PIXFMT , 1+TFT_CMD_DELAY, // 15: Set color mode, 1 arg + delay: | |
567 | 0x06, // 18-bit color 6-6-6 color format | |
568 | 10 // 10 ms delay | |
569 | }; | |
570 | ||
571 | // Init for 7735R, part 2 (green tab only) | |
572 | // --------------------------------------- | |
573 | static const uint8_t Rcmd2green[] = { | |
574 | 2, // 2 commands in list: | |
575 | TFT_CASET , 4 , // 1: Column addr set, 4 args, no delay: | |
576 | 0x00, 0x02, // XSTART = 0 | |
577 | 0x00, 0x7F+0x02, // XEND = 129 | |
578 | TFT_PASET , 4 , // 2: Row addr set, 4 args, no delay: | |
579 | 0x00, 0x01, // XSTART = 0 | |
580 | 0x00, 0x9F+0x01 // XEND = 160 | |
581 | }; | |
582 | ||
583 | // Init for 7735R, part 2 (red tab only) | |
584 | // ------------------------------------- | |
585 | static const uint8_t Rcmd2red[] = { | |
586 | 2, // 2 commands in list: | |
587 | TFT_CASET , 4 , // 1: Column addr set, 4 args, no delay: | |
588 | 0x00, 0x00, // XSTART = 0 | |
589 | 0x00, 0x7F, // XEND = 127 | |
590 | TFT_PASET , 4 , // 2: Row addr set, 4 args, no delay: | |
591 | 0x00, 0x00, // XSTART = 0 | |
592 | 0x00, 0x9F // XEND = 159 | |
593 | }; | |
594 | ||
595 | // Init for 7735R, part 3 (red or green tab) | |
596 | // ----------------------------------------- | |
597 | static const uint8_t Rcmd3[] = { | |
598 | 4, // 4 commands in list: | |
599 | ST7735_GMCTRP1, 16 , // 1: Magical unicorn dust, 16 args, no delay: | |
600 | 0x02, 0x1c, 0x07, 0x12, | |
601 | 0x37, 0x32, 0x29, 0x2d, | |
602 | 0x29, 0x25, 0x2B, 0x39, | |
603 | 0x00, 0x01, 0x03, 0x10, | |
604 | ST7735_GMCTRN1, 16 , // 2: Sparkles and rainbows, 16 args, no delay: | |
605 | 0x03, 0x1d, 0x07, 0x06, | |
606 | 0x2E, 0x2C, 0x29, 0x2D, | |
607 | 0x2E, 0x2E, 0x37, 0x3F, | |
608 | 0x00, 0x00, 0x02, 0x10, | |
609 | ST7735_NORON , TFT_CMD_DELAY, // 3: Normal display on, no args, w/delay | |
610 | 10, // 10 ms delay | |
611 | TFT_DISPON , TFT_CMD_DELAY, // 4: Main screen turn on, no args w/delay | |
612 | 100 // 100 ms delay | |
613 | }; | |
614 | ||
615 | ||
616 | // ==== Public functions ========================================================= | |
617 | ||
618 | // == Low level functions; usually not used directly == | |
619 | esp_err_t wait_trans_finish(uint8_t free_line); | |
620 | void disp_spi_transfer_cmd(int8_t cmd); | |
621 | void disp_spi_transfer_cmd_data(int8_t cmd, uint8_t *data, uint32_t len); | |
622 | void drawPixel(int16_t x, int16_t y, color_t color, uint8_t sel); | |
623 | void send_data(int x1, int y1, int x2, int y2, uint32_t len, color_t *buf); | |
624 | void TFT_pushColorRep(int x1, int y1, int x2, int y2, color_t data, uint32_t len); | |
625 | int read_data(int x1, int y1, int x2, int y2, int len, uint8_t *buf, uint8_t set_sp); | |
626 | color_t readPixel(int16_t x, int16_t y); | |
627 | int touch_get_data(uint8_t type); | |
628 | ||
629 | ||
630 | // Deactivate display's CS line | |
631 | //======================== | |
632 | esp_err_t disp_deselect(); | |
633 | ||
634 | // Activate display's CS line and configure SPI interface if necessary | |
635 | //====================== | |
636 | esp_err_t disp_select(); | |
637 | ||
638 | ||
639 | // Find maximum spi clock for successful read from display RAM | |
640 | // ** Must be used AFTER the display is initialized ** | |
641 | //====================== | |
642 | uint32_t find_rd_speed(); | |
643 | ||
644 | ||
645 | // Change the screen rotation. | |
646 | // Input: m new rotation value (0 to 3) | |
647 | //================================= | |
648 | void _tft_setRotation(uint8_t rot); | |
649 | ||
650 | // Initialize all pins used by display driver | |
651 | // ** MUST be executed before SPI interface initialization | |
652 | //================= | |
653 | void TFT_PinsInit(); | |
654 | ||
655 | // Perform display initialization sequence | |
656 | // Sets orientation to landscape; clears the screen | |
657 | // * All pins must be configured | |
658 | // * SPI interface must already be setup | |
659 | // * 'tft_disp_type', 'COLOR_BITS', '_width', '_height' variables must be set | |
660 | //====================== | |
661 | void TFT_display_init(); | |
662 | ||
663 | //=================== | |
664 | void stmpe610_Init(); | |
665 | ||
666 | //============================================================ | |
667 | int stmpe610_get_touch(uint16_t *x, uint16_t *y, uint16_t *z); | |
668 | ||
669 | //======================== | |
670 | uint32_t stmpe610_getID(); | |
671 | ||
672 | // =============================================================================== | |
673 | ||
674 | #endif |