Wed, 26 Jun 2024 21:48:49 +0200
Reverted gpio_pad_select_gpio() calls, added the correct include. Starting the unit works better now. Reverted some other small changes. In some parts the controller is very slow, possible spiffs issue?
0 | 1 | /* |
2 | * Author: LoBo (loboris@gmail.com, loboris.github) | |
3 | * | |
4 | * Module supporting SPI TFT displays based on ILI9341 & ILI9488 controllers | |
5 | * | |
6 | * HIGH SPEED LOW LEVEL DISPLAY FUNCTIONS | |
7 | * USING DIRECT or DMA SPI TRANSFER MODEs | |
8 | * | |
9 | */ | |
10 | ||
11 | #include <string.h> | |
12 | #include "tftspi.h" | |
13 | #include "esp_system.h" | |
34
5c92103c5e72
Version 0.2.10. Fixed spelling error in websocket component. Updated esp-idf to v4.0-dev-459-gba1ff1692 and adjusted several sources for changed headers. Finalized keeping the AP running at all times. Increased websocket server stack depth from 6000 to 7000.
Michiel Broek <mbroek@mbse.eu>
parents:
0
diff
changeset
|
14 | #include "driver/gpio.h" |
0 | 15 | #include "freertos/task.h" |
16 | #include "esp_heap_caps.h" | |
17 | #include "soc/spi_reg.h" | |
136
89fc3c57282e
Reverted gpio_pad_select_gpio() calls, added the correct include. Starting the unit works better now. Reverted some other small changes. In some parts the controller is very slow, possible spiffs issue?
Michiel Broek <mbroek@mbse.eu>
parents:
129
diff
changeset
|
18 | #include "rom/gpio.h" |
0 | 19 | |
20 | // ==================================================== | |
21 | // ==== Global variables, default values ============== | |
22 | ||
23 | // Converts colors to grayscale if set to 1 | |
24 | uint8_t gray_scale = 0; | |
25 | // Spi clock for reading data from display memory in Hz | |
26 | uint32_t max_rdclock = 8000000; | |
27 | ||
28 | // Default display dimensions | |
29 | int _width = DEFAULT_TFT_DISPLAY_WIDTH; | |
30 | int _height = DEFAULT_TFT_DISPLAY_HEIGHT; | |
31 | ||
32 | // Display type, DISP_TYPE_ILI9488 or DISP_TYPE_ILI9341 | |
33 | uint8_t tft_disp_type = DEFAULT_DISP_TYPE; | |
34 | ||
35 | // Spi device handles for display and touch screen | |
36 | spi_lobo_device_handle_t disp_spi = NULL; | |
37 | spi_lobo_device_handle_t ts_spi = NULL; | |
38 | ||
39 | // ==================================================== | |
40 | ||
41 | ||
42 | static color_t *trans_cline = NULL; | |
43 | static uint8_t _dma_sending = 0; | |
44 | ||
45 | // RGB to GRAYSCALE constants | |
46 | // 0.2989 0.5870 0.1140 | |
47 | #define GS_FACT_R 0.2989 | |
48 | #define GS_FACT_G 0.4870 | |
49 | #define GS_FACT_B 0.2140 | |
50 | ||
51 | ||
52 | ||
53 | // ==== Functions ===================== | |
54 | ||
55 | //------------------------------------------------------ | |
56 | esp_err_t IRAM_ATTR wait_trans_finish(uint8_t free_line) | |
57 | { | |
58 | // Wait for SPI bus ready | |
59 | while (disp_spi->host->hw->cmd.usr); | |
60 | if ((free_line) && (trans_cline)) { | |
61 | free(trans_cline); | |
62 | trans_cline = NULL; | |
63 | } | |
64 | if (_dma_sending) { | |
65 | //Tell common code DMA workaround that our DMA channel is idle. If needed, the code will do a DMA reset. | |
66 | if (disp_spi->host->dma_chan) spi_lobo_dmaworkaround_idle(disp_spi->host->dma_chan); | |
67 | ||
68 | // Reset DMA | |
69 | disp_spi->host->hw->dma_conf.val |= SPI_OUT_RST|SPI_IN_RST|SPI_AHBM_RST|SPI_AHBM_FIFO_RST; | |
70 | disp_spi->host->hw->dma_out_link.start=0; | |
71 | disp_spi->host->hw->dma_in_link.start=0; | |
72 | disp_spi->host->hw->dma_conf.val &= ~(SPI_OUT_RST|SPI_IN_RST|SPI_AHBM_RST|SPI_AHBM_FIFO_RST); | |
73 | disp_spi->host->hw->dma_conf.out_data_burst_en=1; | |
74 | _dma_sending = 0; | |
75 | } | |
76 | return ESP_OK; | |
77 | } | |
78 | ||
79 | //------------------------------- | |
80 | esp_err_t IRAM_ATTR disp_select() | |
81 | { | |
82 | wait_trans_finish(1); | |
83 | return spi_lobo_device_select(disp_spi, 0); | |
84 | } | |
85 | ||
86 | //--------------------------------- | |
87 | esp_err_t IRAM_ATTR disp_deselect() | |
88 | { | |
89 | wait_trans_finish(1); | |
90 | return spi_lobo_device_deselect(disp_spi); | |
91 | } | |
92 | ||
93 | //--------------------------------------------------------------------------------------------------- | |
94 | static void IRAM_ATTR _spi_transfer_start(spi_lobo_device_handle_t spi_dev, int wrbits, int rdbits) { | |
95 | // Load send buffer | |
96 | spi_dev->host->hw->user.usr_mosi_highpart = 0; | |
97 | spi_dev->host->hw->mosi_dlen.usr_mosi_dbitlen = wrbits-1; | |
98 | spi_dev->host->hw->user.usr_mosi = 1; | |
99 | if (rdbits) { | |
100 | spi_dev->host->hw->miso_dlen.usr_miso_dbitlen = rdbits; | |
101 | spi_dev->host->hw->user.usr_miso = 1; | |
102 | } | |
103 | else { | |
104 | spi_dev->host->hw->miso_dlen.usr_miso_dbitlen = 0; | |
105 | spi_dev->host->hw->user.usr_miso = 0; | |
106 | } | |
107 | // Start transfer | |
108 | spi_dev->host->hw->cmd.usr = 1; | |
109 | // Wait for SPI bus ready | |
110 | while (spi_dev->host->hw->cmd.usr); | |
111 | } | |
112 | ||
113 | // Send 1 byte display command, display must be selected | |
114 | //------------------------------------------------ | |
115 | void IRAM_ATTR disp_spi_transfer_cmd(int8_t cmd) { | |
116 | // Wait for SPI bus ready | |
117 | while (disp_spi->host->hw->cmd.usr); | |
118 | ||
119 | // Set DC to 0 (command mode); | |
120 | gpio_set_level(PIN_NUM_DC, 0); | |
121 | ||
122 | disp_spi->host->hw->data_buf[0] = (uint32_t)cmd; | |
123 | _spi_transfer_start(disp_spi, 8, 0); | |
124 | } | |
125 | ||
126 | // Send command with data to display, display must be selected | |
127 | //---------------------------------------------------------------------------------- | |
128 | void IRAM_ATTR disp_spi_transfer_cmd_data(int8_t cmd, uint8_t *data, uint32_t len) { | |
129 | // Wait for SPI bus ready | |
130 | while (disp_spi->host->hw->cmd.usr); | |
131 | ||
132 | // Set DC to 0 (command mode); | |
133 | gpio_set_level(PIN_NUM_DC, 0); | |
134 | ||
135 | disp_spi->host->hw->data_buf[0] = (uint32_t)cmd; | |
136 | _spi_transfer_start(disp_spi, 8, 0); | |
137 | ||
138 | if ((len == 0) || (data == NULL)) return; | |
139 | ||
140 | // Set DC to 1 (data mode); | |
141 | gpio_set_level(PIN_NUM_DC, 1); | |
142 | ||
143 | uint8_t idx=0, bidx=0; | |
144 | uint32_t bits=0; | |
145 | uint32_t count=0; | |
146 | uint32_t wd = 0; | |
147 | while (count < len) { | |
148 | // get data byte from buffer | |
149 | wd |= (uint32_t)data[count] << bidx; | |
150 | count++; | |
151 | bits += 8; | |
152 | bidx += 8; | |
153 | if (count == len) { | |
154 | disp_spi->host->hw->data_buf[idx] = wd; | |
155 | break; | |
156 | } | |
157 | if (bidx == 32) { | |
158 | disp_spi->host->hw->data_buf[idx] = wd; | |
159 | idx++; | |
160 | bidx = 0; | |
161 | wd = 0; | |
162 | } | |
163 | if (idx == 16) { | |
164 | // SPI buffer full, send data | |
165 | _spi_transfer_start(disp_spi, bits, 0); | |
166 | ||
167 | bits = 0; | |
168 | idx = 0; | |
169 | bidx = 0; | |
170 | } | |
171 | } | |
172 | if (bits > 0) _spi_transfer_start(disp_spi, bits, 0); | |
173 | } | |
174 | ||
175 | // Set the address window for display write & read commands, display must be selected | |
176 | //--------------------------------------------------------------------------------------------------- | |
177 | static void IRAM_ATTR disp_spi_transfer_addrwin(uint16_t x1, uint16_t x2, uint16_t y1, uint16_t y2) { | |
178 | uint32_t wd; | |
179 | ||
180 | taskDISABLE_INTERRUPTS(); | |
181 | // Wait for SPI bus ready | |
182 | while (disp_spi->host->hw->cmd.usr); | |
183 | gpio_set_level(PIN_NUM_DC, 0); | |
184 | ||
185 | disp_spi->host->hw->data_buf[0] = (uint32_t)TFT_CASET; | |
186 | disp_spi->host->hw->user.usr_mosi_highpart = 0; | |
187 | disp_spi->host->hw->mosi_dlen.usr_mosi_dbitlen = 7; | |
188 | disp_spi->host->hw->user.usr_mosi = 1; | |
189 | disp_spi->host->hw->miso_dlen.usr_miso_dbitlen = 0; | |
190 | disp_spi->host->hw->user.usr_miso = 0; | |
191 | ||
192 | disp_spi->host->hw->cmd.usr = 1; // Start transfer | |
193 | ||
194 | wd = (uint32_t)(x1>>8); | |
195 | wd |= (uint32_t)(x1&0xff) << 8; | |
196 | wd |= (uint32_t)(x2>>8) << 16; | |
197 | wd |= (uint32_t)(x2&0xff) << 24; | |
198 | ||
199 | while (disp_spi->host->hw->cmd.usr); // wait transfer end | |
200 | gpio_set_level(PIN_NUM_DC, 1); | |
201 | disp_spi->host->hw->data_buf[0] = wd; | |
202 | disp_spi->host->hw->mosi_dlen.usr_mosi_dbitlen = 31; | |
203 | disp_spi->host->hw->cmd.usr = 1; // Start transfer | |
204 | ||
205 | while (disp_spi->host->hw->cmd.usr); | |
206 | gpio_set_level(PIN_NUM_DC, 0); | |
207 | disp_spi->host->hw->data_buf[0] = (uint32_t)TFT_PASET; | |
208 | disp_spi->host->hw->mosi_dlen.usr_mosi_dbitlen = 7; | |
209 | disp_spi->host->hw->cmd.usr = 1; // Start transfer | |
210 | ||
211 | wd = (uint32_t)(y1>>8); | |
212 | wd |= (uint32_t)(y1&0xff) << 8; | |
213 | wd |= (uint32_t)(y2>>8) << 16; | |
214 | wd |= (uint32_t)(y2&0xff) << 24; | |
215 | ||
216 | while (disp_spi->host->hw->cmd.usr); | |
217 | gpio_set_level(PIN_NUM_DC, 1); | |
218 | ||
219 | disp_spi->host->hw->data_buf[0] = wd; | |
220 | disp_spi->host->hw->mosi_dlen.usr_mosi_dbitlen = 31; | |
221 | disp_spi->host->hw->cmd.usr = 1; // Start transfer | |
222 | while (disp_spi->host->hw->cmd.usr); | |
223 | taskENABLE_INTERRUPTS(); | |
224 | } | |
225 | ||
226 | // Convert color to gray scale | |
227 | //---------------------------------------------- | |
228 | static color_t IRAM_ATTR color2gs(color_t color) | |
229 | { | |
230 | color_t _color; | |
231 | float gs_clr = GS_FACT_R * color.r + GS_FACT_G * color.g + GS_FACT_B * color.b; | |
232 | if (gs_clr > 255) gs_clr = 255; | |
233 | ||
234 | _color.r = (uint8_t)gs_clr; | |
235 | _color.g = (uint8_t)gs_clr; | |
236 | _color.b = (uint8_t)gs_clr; | |
237 | ||
238 | return _color; | |
239 | } | |
240 | ||
241 | // Set display pixel at given coordinates to given color | |
242 | //------------------------------------------------------------------------ | |
243 | void IRAM_ATTR drawPixel(int16_t x, int16_t y, color_t color, uint8_t sel) | |
244 | { | |
245 | if (!(disp_spi->cfg.flags & LB_SPI_DEVICE_HALFDUPLEX)) return; | |
246 | ||
247 | if (sel) { | |
248 | if (disp_select()) return; | |
249 | } | |
250 | else wait_trans_finish(1); | |
251 | ||
252 | uint32_t wd = 0; | |
253 | color_t _color = color; | |
254 | if (gray_scale) _color = color2gs(color); | |
255 | ||
256 | taskDISABLE_INTERRUPTS(); | |
257 | disp_spi_transfer_addrwin(x, x+1, y, y+1); | |
258 | ||
259 | // Send RAM WRITE command | |
260 | gpio_set_level(PIN_NUM_DC, 0); | |
261 | disp_spi->host->hw->data_buf[0] = (uint32_t)TFT_RAMWR; | |
262 | disp_spi->host->hw->mosi_dlen.usr_mosi_dbitlen = 7; | |
263 | disp_spi->host->hw->cmd.usr = 1; // Start transfer | |
264 | while (disp_spi->host->hw->cmd.usr); // Wait for SPI bus ready | |
265 | ||
266 | wd = (uint32_t)_color.r; | |
267 | wd |= (uint32_t)_color.g << 8; | |
268 | wd |= (uint32_t)_color.b << 16; | |
269 | ||
270 | // Set DC to 1 (data mode); | |
271 | gpio_set_level(PIN_NUM_DC, 1); | |
272 | ||
273 | disp_spi->host->hw->data_buf[0] = wd; | |
274 | disp_spi->host->hw->mosi_dlen.usr_mosi_dbitlen = 23; | |
275 | disp_spi->host->hw->cmd.usr = 1; // Start transfer | |
276 | while (disp_spi->host->hw->cmd.usr); // Wait for SPI bus ready | |
277 | ||
278 | taskENABLE_INTERRUPTS(); | |
279 | if (sel) disp_deselect(); | |
280 | } | |
281 | ||
282 | //----------------------------------------------------------- | |
283 | static void IRAM_ATTR _dma_send(uint8_t *data, uint32_t size) | |
284 | { | |
285 | //Fill DMA descriptors | |
286 | spi_lobo_dmaworkaround_transfer_active(disp_spi->host->dma_chan); //mark channel as active | |
287 | spi_lobo_setup_dma_desc_links(disp_spi->host->dmadesc_tx, size, data, false); | |
288 | disp_spi->host->hw->user.usr_mosi_highpart=0; | |
289 | disp_spi->host->hw->dma_out_link.addr=(int)(&disp_spi->host->dmadesc_tx[0]) & 0xFFFFF; | |
290 | disp_spi->host->hw->dma_out_link.start=1; | |
291 | disp_spi->host->hw->user.usr_mosi_highpart=0; | |
292 | ||
293 | disp_spi->host->hw->mosi_dlen.usr_mosi_dbitlen = (size * 8) - 1; | |
294 | ||
295 | _dma_sending = 1; | |
296 | // Start transfer | |
297 | disp_spi->host->hw->cmd.usr = 1; | |
298 | } | |
299 | ||
300 | //--------------------------------------------------------------------------- | |
301 | static void IRAM_ATTR _direct_send(color_t *color, uint32_t len, uint8_t rep) | |
302 | { | |
303 | uint32_t cidx = 0; // color buffer index | |
304 | uint32_t wd = 0; | |
305 | int idx = 0; | |
306 | int bits = 0; | |
307 | int wbits = 0; | |
308 | ||
309 | taskDISABLE_INTERRUPTS(); | |
310 | color_t _color = color[0]; | |
311 | if ((rep) && (gray_scale)) _color = color2gs(color[0]); | |
312 | ||
313 | while (len) { | |
314 | // ** Get color data from color buffer ** | |
315 | if (rep == 0) { | |
316 | if (gray_scale) _color = color2gs(color[cidx]); | |
317 | else _color = color[cidx]; | |
318 | } | |
319 | ||
320 | wd |= (uint32_t)_color.r << wbits; | |
321 | wbits += 8; | |
322 | if (wbits == 32) { | |
323 | bits += wbits; | |
324 | wbits = 0; | |
325 | disp_spi->host->hw->data_buf[idx++] = wd; | |
326 | wd = 0; | |
327 | } | |
328 | wd |= (uint32_t)_color.g << wbits; | |
329 | wbits += 8; | |
330 | if (wbits == 32) { | |
331 | bits += wbits; | |
332 | wbits = 0; | |
333 | disp_spi->host->hw->data_buf[idx++] = wd; | |
334 | wd = 0; | |
335 | } | |
336 | wd |= (uint32_t)_color.b << wbits; | |
337 | wbits += 8; | |
338 | if (wbits == 32) { | |
339 | bits += wbits; | |
340 | wbits = 0; | |
341 | disp_spi->host->hw->data_buf[idx++] = wd; | |
342 | wd = 0; | |
343 | } | |
344 | len--; // Decrement colors counter | |
345 | if (rep == 0) cidx++; // if not repeating color, increment color buffer index | |
346 | } | |
347 | if (bits) { | |
348 | while (disp_spi->host->hw->cmd.usr); // Wait for SPI bus ready | |
349 | disp_spi->host->hw->mosi_dlen.usr_mosi_dbitlen = bits-1; // set number of bits to be sent | |
350 | disp_spi->host->hw->cmd.usr = 1; // Start transfer | |
351 | } | |
352 | taskENABLE_INTERRUPTS(); | |
353 | } | |
354 | ||
355 | // ================================================================ | |
356 | // === Main function to send data to display ====================== | |
357 | // If rep==true: repeat sending color data to display 'len' times | |
358 | // If rep==false: send 'len' color data from color buffer to display | |
359 | // ** Device must already be selected and address window set ** | |
360 | // ================================================================ | |
361 | //---------------------------------------------------------------------------------------------- | |
362 | static void IRAM_ATTR _TFT_pushColorRep(color_t *color, uint32_t len, uint8_t rep, uint8_t wait) | |
363 | { | |
364 | if (len == 0) return; | |
365 | if (!(disp_spi->cfg.flags & LB_SPI_DEVICE_HALFDUPLEX)) return; | |
366 | ||
367 | // Send RAM WRITE command | |
368 | gpio_set_level(PIN_NUM_DC, 0); | |
369 | disp_spi->host->hw->data_buf[0] = (uint32_t)TFT_RAMWR; | |
370 | disp_spi->host->hw->mosi_dlen.usr_mosi_dbitlen = 7; | |
371 | disp_spi->host->hw->cmd.usr = 1; // Start transfer | |
372 | while (disp_spi->host->hw->cmd.usr); // Wait for SPI bus ready | |
373 | ||
374 | gpio_set_level(PIN_NUM_DC, 1); // Set DC to 1 (data mode); | |
375 | ||
376 | if ((len*24) <= 512) { | |
377 | ||
378 | _direct_send(color, len, rep); | |
379 | ||
380 | } | |
381 | else if (rep == 0) { | |
382 | // ==== use DMA transfer ==== | |
383 | // ** Prepare data | |
384 | if (gray_scale) { | |
385 | for (int n=0; n<len; n++) { | |
386 | color[n] = color2gs(color[n]); | |
387 | } | |
388 | } | |
389 | ||
390 | _dma_send((uint8_t *)color, len*3); | |
391 | } | |
392 | else { | |
393 | // ==== Repeat color, more than 512 bits total ==== | |
394 | ||
395 | color_t _color; | |
396 | uint32_t buf_colors; | |
397 | int buf_bytes, to_send; | |
398 | ||
399 | /* | |
400 | to_send = len; | |
401 | while (to_send > 0) { | |
402 | wait_trans_finish(0); | |
403 | _direct_send(color, ((to_send > 21) ? 21 : to_send), rep); | |
404 | to_send -= 21; | |
405 | } | |
406 | */ | |
407 | ||
408 | buf_colors = ((len > (_width*2)) ? (_width*2) : len); | |
409 | buf_bytes = buf_colors * 3; | |
410 | ||
411 | // Prepare color buffer of maximum 2 color lines | |
412 | trans_cline = heap_caps_malloc(buf_bytes, MALLOC_CAP_DMA); | |
413 | if (trans_cline == NULL) return; | |
414 | ||
415 | // Prepare fill color | |
416 | if (gray_scale) _color = color2gs(color[0]); | |
417 | else _color = color[0]; | |
418 | ||
419 | // Fill color buffer with fill color | |
420 | for (uint32_t i=0; i<buf_colors; i++) { | |
421 | trans_cline[i] = _color; | |
422 | } | |
423 | ||
424 | // Send 'len' colors | |
425 | to_send = len; | |
426 | while (to_send > 0) { | |
427 | wait_trans_finish(0); | |
428 | _dma_send((uint8_t *)trans_cline, ((to_send > buf_colors) ? buf_bytes : (to_send*3))); | |
429 | to_send -= buf_colors; | |
430 | } | |
431 | } | |
432 | ||
433 | if (wait) wait_trans_finish(1); | |
434 | } | |
435 | ||
436 | // Write 'len' color data to TFT 'window' (x1,y2),(x2,y2) | |
437 | //------------------------------------------------------------------------------------------- | |
438 | void IRAM_ATTR TFT_pushColorRep(int x1, int y1, int x2, int y2, color_t color, uint32_t len) | |
439 | { | |
440 | if (disp_select() != ESP_OK) return; | |
441 | ||
442 | // ** Send address window ** | |
443 | disp_spi_transfer_addrwin(x1, x2, y1, y2); | |
444 | ||
445 | _TFT_pushColorRep(&color, len, 1, 1); | |
446 | ||
447 | disp_deselect(); | |
448 | } | |
449 | ||
450 | // Write 'len' color data to TFT 'window' (x1,y2),(x2,y2) from given buffer | |
451 | // ** Device must already be selected ** | |
452 | //----------------------------------------------------------------------------------- | |
453 | void IRAM_ATTR send_data(int x1, int y1, int x2, int y2, uint32_t len, color_t *buf) | |
454 | { | |
455 | // ** Send address window ** | |
456 | disp_spi_transfer_addrwin(x1, x2, y1, y2); | |
457 | _TFT_pushColorRep(buf, len, 0, 0); | |
458 | } | |
459 | ||
460 | // Reads 'len' pixels/colors from the TFT's GRAM 'window' | |
461 | // 'buf' is an array of bytes with 1st byte reserved for reading 1 dummy byte | |
462 | // and the rest is actually an array of color_t values | |
463 | //-------------------------------------------------------------------------------------------- | |
464 | int IRAM_ATTR read_data(int x1, int y1, int x2, int y2, int len, uint8_t *buf, uint8_t set_sp) | |
465 | { | |
466 | spi_lobo_transaction_t t; | |
467 | uint32_t current_clock = 0; | |
468 | ||
469 | memset(&t, 0, sizeof(t)); //Zero out the transaction | |
470 | memset(buf, 0, len*sizeof(color_t)); | |
471 | ||
472 | if (set_sp) { | |
473 | if (disp_deselect() != ESP_OK) return -1; | |
474 | // Change spi clock if needed | |
475 | current_clock = spi_lobo_get_speed(disp_spi); | |
476 | if (max_rdclock < current_clock) spi_lobo_set_speed(disp_spi, max_rdclock); | |
477 | } | |
478 | ||
479 | if (disp_select() != ESP_OK) return -2; | |
480 | ||
481 | // ** Send address window ** | |
482 | disp_spi_transfer_addrwin(x1, x2, y1, y2); | |
483 | ||
484 | // ** GET pixels/colors ** | |
485 | disp_spi_transfer_cmd(TFT_RAMRD); | |
486 | ||
487 | t.length=0; //Send nothing | |
488 | t.tx_buffer=NULL; | |
489 | t.rxlength=8*((len*3)+1); //Receive size in bits | |
490 | t.rx_buffer=buf; | |
491 | //t.user = (void*)1; | |
492 | ||
493 | esp_err_t res = spi_lobo_transfer_data(disp_spi, &t); // Receive using direct mode | |
494 | ||
495 | disp_deselect(); | |
496 | ||
497 | if (set_sp) { | |
498 | // Restore spi clock if needed | |
499 | if (max_rdclock < current_clock) spi_lobo_set_speed(disp_spi, current_clock); | |
500 | } | |
501 | ||
502 | return res; | |
503 | } | |
504 | ||
505 | // Reads one pixel/color from the TFT's GRAM at position (x,y) | |
506 | //----------------------------------------------- | |
507 | color_t IRAM_ATTR readPixel(int16_t x, int16_t y) | |
508 | { | |
509 | uint8_t color_buf[sizeof(color_t)+1] = {0}; | |
510 | ||
511 | read_data(x, y, x+1, y+1, 1, color_buf, 1); | |
512 | ||
513 | color_t color; | |
514 | color.r = color_buf[1]; | |
515 | color.g = color_buf[2]; | |
516 | color.b = color_buf[3]; | |
517 | return color; | |
518 | } | |
519 | ||
520 | // get 16-bit data from touch controller for specified type | |
521 | // ** Touch device must already be selected ** | |
522 | //---------------------------------------- | |
523 | int IRAM_ATTR touch_get_data(uint8_t type) | |
524 | { | |
525 | /* | |
526 | esp_err_t ret; | |
527 | spi_lobo_transaction_t t; | |
528 | memset(&t, 0, sizeof(t)); //Zero out the transaction | |
529 | uint8_t rxdata[2] = {0}; | |
530 | ||
531 | // send command byte & receive 2 byte response | |
532 | t.rxlength=8*2; | |
533 | t.rx_buffer=&rxdata; | |
534 | t.command = type; | |
535 | ||
536 | ret = spi_lobo_transfer_data(ts_spi, &t); // Transmit using direct mode | |
537 | ||
538 | if (ret != ESP_OK) res = -1; | |
539 | res = (((int)(rxdata[0] << 8) | (int)(rxdata[1])) >> 4); | |
540 | */ | |
541 | // spi_lobo_device_select(ts_spi, 0); | |
542 | ||
543 | ts_spi->host->hw->data_buf[0] = type; | |
544 | _spi_transfer_start(ts_spi, 24, 24); | |
545 | ||
546 | // printf("touch_get_data(%02X) %06x %02x %02x %02x ", type, ts_spi->host->hw->data_buf[0], | |
547 | // (ts_spi->host->hw->data_buf[0] & 0x0ff), | |
548 | // (ts_spi->host->hw->data_buf[0] >> 11 & 0x0ff), | |
549 | // (ts_spi->host->hw->data_buf[0] >> 19 & 0x0ff) ); | |
550 | uint16_t res = (uint16_t)(((ts_spi->host->hw->data_buf[0] >> 11 & 0x0ff) << 8) | (ts_spi->host->hw->data_buf[0] >> 19 & 0x0ff)); | |
551 | // printf("res=%d %04x\n", res, res); | |
552 | // spi_lobo_device_deselect(ts_spi); | |
553 | return res; | |
554 | } | |
555 | ||
556 | // ==== STMPE610 =============================================================== | |
557 | ||
558 | ||
559 | // ----- STMPE610 -------------------------------------------------------------------------- | |
560 | ||
561 | // Send 1 byte display command, display must be selected | |
562 | //--------------------------------------------------------- | |
563 | static void IRAM_ATTR stmpe610_write_reg(uint8_t reg, uint8_t val) { | |
564 | ||
565 | spi_lobo_device_select(ts_spi, 0); | |
566 | ||
567 | ts_spi->host->hw->data_buf[0] = (val << 8) | reg; | |
568 | _spi_transfer_start(ts_spi, 16, 0); | |
569 | ||
570 | spi_lobo_device_deselect(ts_spi); | |
571 | } | |
572 | ||
573 | //----------------------------------------------- | |
574 | static uint8_t IRAM_ATTR stmpe610_read_byte(uint8_t reg) { | |
575 | spi_lobo_device_select(ts_spi, 0); | |
576 | ||
577 | ts_spi->host->hw->data_buf[0] = (reg << 8) | (reg | 0x80); | |
578 | _spi_transfer_start(ts_spi, 16, 16); | |
579 | uint8_t res = ts_spi->host->hw->data_buf[0] >> 8; | |
580 | ||
581 | spi_lobo_device_deselect(ts_spi); | |
582 | return res; | |
583 | } | |
584 | ||
585 | //----------------------------------------- | |
586 | static uint16_t IRAM_ATTR stmpe610_read_word(uint8_t reg) { | |
587 | spi_lobo_device_select(ts_spi, 0); | |
588 | ||
589 | ts_spi->host->hw->data_buf[0] = ((((reg+1) << 8) | ((reg+1) | 0x80)) << 16) | (reg << 8) | (reg | 0x80); | |
590 | _spi_transfer_start(ts_spi, 32, 32); | |
591 | uint16_t res = (uint16_t)(ts_spi->host->hw->data_buf[0] & 0xFF00); | |
592 | res |= (uint16_t)(ts_spi->host->hw->data_buf[0] >> 24); | |
593 | ||
594 | spi_lobo_device_deselect(ts_spi); | |
595 | return res; | |
596 | } | |
597 | ||
598 | //----------------------- | |
599 | uint32_t stmpe610_getID() | |
600 | { | |
601 | uint16_t tid = stmpe610_read_word(0); | |
602 | uint8_t tver = stmpe610_read_byte(2); | |
603 | return (tid << 8) | tver; | |
604 | } | |
605 | ||
606 | //================== | |
607 | void stmpe610_Init() | |
608 | { | |
609 | stmpe610_write_reg(STMPE610_REG_SYS_CTRL1, 0x02); // Software chip reset | |
129 | 610 | vTaskDelay(10 / portTICK_PERIOD_MS); |
0 | 611 | |
612 | stmpe610_write_reg(STMPE610_REG_SYS_CTRL2, 0x04); // Temperature sensor clock off, GPIO clock off, touch clock on, ADC clock on | |
613 | ||
614 | stmpe610_write_reg(STMPE610_REG_INT_EN, 0x00); // Don't Interrupt on INT pin | |
615 | ||
616 | stmpe610_write_reg(STMPE610_REG_ADC_CTRL1, 0x48); // ADC conversion time = 80 clock ticks, 12-bit ADC, internal voltage refernce | |
129 | 617 | vTaskDelay(2 / portTICK_PERIOD_MS); |
0 | 618 | stmpe610_write_reg(STMPE610_REG_ADC_CTRL2, 0x01); // ADC speed 3.25MHz |
619 | stmpe610_write_reg(STMPE610_REG_GPIO_AF, 0x00); // GPIO alternate function - OFF | |
620 | stmpe610_write_reg(STMPE610_REG_TSC_CFG, 0xE3); // Averaging 8, touch detect delay 1ms, panel driver settling time 1ms | |
621 | stmpe610_write_reg(STMPE610_REG_FIFO_TH, 0x01); // FIFO threshold = 1 | |
622 | stmpe610_write_reg(STMPE610_REG_FIFO_STA, 0x01); // FIFO reset enable | |
623 | stmpe610_write_reg(STMPE610_REG_FIFO_STA, 0x00); // FIFO reset disable | |
624 | stmpe610_write_reg(STMPE610_REG_TSC_FRACT_XYZ, 0x07); // Z axis data format | |
625 | stmpe610_write_reg(STMPE610_REG_TSC_I_DRIVE, 0x01); // max 50mA touchscreen line current | |
626 | stmpe610_write_reg(STMPE610_REG_TSC_CTRL, 0x30); // X&Y&Z, 16 reading window | |
627 | stmpe610_write_reg(STMPE610_REG_TSC_CTRL, 0x31); // X&Y&Z, 16 reading window, TSC enable | |
628 | stmpe610_write_reg(STMPE610_REG_INT_STA, 0xFF); // Clear all interrupts | |
629 | stmpe610_write_reg(STMPE610_REG_INT_CTRL, 0x00); // Level interrupt, disable interrupts | |
630 | } | |
631 | ||
632 | //=========================================================== | |
633 | int stmpe610_get_touch(uint16_t *x, uint16_t *y, uint16_t *z) | |
634 | { | |
635 | if (!(stmpe610_read_byte(STMPE610_REG_TSC_CTRL) & 0x80)) return 0; | |
636 | ||
637 | // Get touch data | |
638 | uint8_t fifo_size = stmpe610_read_byte(STMPE610_REG_FIFO_SIZE); | |
639 | while (fifo_size < 2) { | |
640 | if (!(stmpe610_read_byte(STMPE610_REG_TSC_CTRL) & 0x80)) return 0; | |
641 | fifo_size = stmpe610_read_byte(STMPE610_REG_FIFO_SIZE); | |
642 | } | |
643 | while (fifo_size > 120) { | |
644 | if (!(stmpe610_read_byte(STMPE610_REG_TSC_CTRL) & 0x80)) return 0; | |
645 | *x = stmpe610_read_word(STMPE610_REG_TSC_DATA_X); | |
646 | *y = stmpe610_read_word(STMPE610_REG_TSC_DATA_Y); | |
647 | *z = stmpe610_read_byte(STMPE610_REG_TSC_DATA_Z); | |
648 | fifo_size = stmpe610_read_byte(STMPE610_REG_FIFO_SIZE); | |
649 | } | |
650 | for (uint8_t i=0; i < (fifo_size-1); i++) { | |
651 | *x = stmpe610_read_word(STMPE610_REG_TSC_DATA_X); | |
652 | *y = stmpe610_read_word(STMPE610_REG_TSC_DATA_Y); | |
653 | *z = stmpe610_read_byte(STMPE610_REG_TSC_DATA_Z); | |
654 | } | |
655 | ||
656 | *x = 4096 - *x; | |
657 | /* | |
658 | // Clear the rest of the fifo | |
659 | { | |
660 | stmpe610_write_reg(STMPE610_REG_FIFO_STA, 0x01); // FIFO reset enable | |
661 | stmpe610_write_reg(STMPE610_REG_FIFO_STA, 0x00); // FIFO reset disable | |
662 | } | |
663 | */ | |
664 | return 1; | |
665 | } | |
666 | ||
667 | // ==== STMPE610 =========================================================================== | |
668 | ||
669 | ||
670 | // Find maximum spi clock for successful read from display RAM | |
671 | // ** Must be used AFTER the display is initialized ** | |
672 | //====================== | |
673 | uint32_t find_rd_speed() | |
674 | { | |
675 | esp_err_t ret; | |
676 | color_t color; | |
677 | uint32_t max_speed = 1000000; | |
678 | uint32_t change_speed, cur_speed; | |
679 | int line_check; | |
680 | color_t *color_line = NULL; | |
681 | uint8_t *line_rdbuf = NULL; | |
682 | uint8_t gs = gray_scale; | |
683 | ||
684 | gray_scale = 0; | |
685 | cur_speed = spi_lobo_get_speed(disp_spi); | |
686 | ||
687 | color_line = malloc(_width*3); | |
688 | if (color_line == NULL) goto exit; | |
689 | ||
690 | line_rdbuf = malloc((_width*3)+1); | |
691 | if (line_rdbuf == NULL) goto exit; | |
692 | ||
693 | color_t *rdline = (color_t *)(line_rdbuf+1); | |
694 | ||
695 | // Fill test line with colors | |
696 | color = (color_t){0xEC,0xA8,0x74}; | |
697 | for (int x=0; x<_width; x++) { | |
698 | color_line[x] = color; | |
699 | } | |
700 | ||
701 | // Find maximum read spi clock | |
702 | for (uint32_t speed=2000000; speed<=cur_speed; speed += 1000000) { | |
703 | change_speed = spi_lobo_set_speed(disp_spi, speed); | |
704 | if (change_speed == 0) goto exit; | |
705 | ||
706 | memset(line_rdbuf, 0, _width*sizeof(color_t)+1); | |
707 | ||
708 | if (disp_select()) goto exit; | |
709 | // Write color line | |
710 | send_data(0, _height/2, _width-1, _height/2, _width, color_line); | |
711 | if (disp_deselect()) goto exit; | |
712 | ||
713 | // Read color line | |
714 | ret = read_data(0, _height/2, _width-1, _height/2, _width, line_rdbuf, 0); | |
715 | ||
716 | // Compare | |
717 | line_check = 0; | |
718 | if (ret == ESP_OK) { | |
719 | for (int y=0; y<_width; y++) { | |
720 | if ((color_line[y].r & 0xFC) != (rdline[y].r & 0xFC)) line_check = 1; | |
721 | else if ((color_line[y].g & 0xFC) != (rdline[y].g & 0xFC)) line_check = 1; | |
722 | else if ((color_line[y].b & 0xFC) != (rdline[y].b & 0xFC)) line_check = 1; | |
723 | if (line_check) break; | |
724 | } | |
725 | } | |
726 | else line_check = ret; | |
727 | ||
728 | if (line_check) break; | |
729 | max_speed = speed; | |
730 | } | |
731 | ||
732 | exit: | |
733 | gray_scale = gs; | |
734 | if (line_rdbuf) free(line_rdbuf); | |
735 | if (color_line) free(color_line); | |
736 | ||
737 | // restore spi clk | |
738 | change_speed = spi_lobo_set_speed(disp_spi, cur_speed); | |
739 | ||
740 | return max_speed; | |
741 | } | |
742 | ||
743 | //--------------------------------------------------------------------------- | |
744 | // Companion code to the initialization table. | |
745 | // Reads and issues a series of LCD commands stored in byte array | |
746 | //--------------------------------------------------------------------------- | |
747 | static void commandList(spi_lobo_device_handle_t spi, const uint8_t *addr) { | |
748 | uint8_t numCommands, numArgs, cmd; | |
749 | uint16_t ms; | |
750 | ||
751 | numCommands = *addr++; // Number of commands to follow | |
752 | while(numCommands--) { // For each command... | |
753 | cmd = *addr++; // save command | |
754 | numArgs = *addr++; // Number of args to follow | |
755 | ms = numArgs & TFT_CMD_DELAY; // If high bit set, delay follows args | |
756 | numArgs &= ~TFT_CMD_DELAY; // Mask out delay bit | |
757 | ||
758 | disp_spi_transfer_cmd_data(cmd, (uint8_t *)addr, numArgs); | |
759 | ||
760 | addr += numArgs; | |
761 | ||
762 | if(ms) { | |
763 | ms = *addr++; // Read post-command delay time (ms) | |
764 | if(ms == 255) ms = 500; // If 255, delay for 500 ms | |
129 | 765 | vTaskDelay(ms / portTICK_PERIOD_MS); |
0 | 766 | } |
767 | } | |
768 | } | |
769 | ||
770 | //================================== | |
771 | void _tft_setRotation(uint8_t rot) { | |
772 | uint8_t rotation = rot & 3; // can't be higher than 3 | |
773 | uint8_t send = 1; | |
774 | uint8_t madctl = 0; | |
775 | uint16_t tmp; | |
776 | ||
777 | if ((rotation & 1)) { | |
778 | // in landscape modes must be width > height | |
779 | if (_width < _height) { | |
780 | tmp = _width; | |
781 | _width = _height; | |
782 | _height = tmp; | |
783 | } | |
784 | } | |
785 | else { | |
786 | // in portrait modes must be width < height | |
787 | if (_width > _height) { | |
788 | tmp = _width; | |
789 | _width = _height; | |
790 | _height = tmp; | |
791 | } | |
792 | } | |
793 | #if TFT_INVERT_ROTATION | |
794 | switch (rotation) { | |
795 | case PORTRAIT: | |
796 | madctl = (MADCTL_MV | TFT_RGB_BGR); | |
797 | break; | |
798 | case LANDSCAPE: | |
799 | madctl = (MADCTL_MX | TFT_RGB_BGR); | |
800 | break; | |
801 | case PORTRAIT_FLIP: | |
802 | madctl = (MADCTL_MV | TFT_RGB_BGR); | |
803 | break; | |
804 | case LANDSCAPE_FLIP: | |
805 | madctl = (MADCTL_MY | TFT_RGB_BGR); | |
806 | break; | |
807 | } | |
808 | #elif TFT_INVERT_ROTATION1 | |
809 | switch (rotation) { | |
810 | case PORTRAIT: | |
811 | madctl = (MADCTL_MY | MADCTL_MX | TFT_RGB_BGR); | |
812 | break; | |
813 | case LANDSCAPE: | |
814 | madctl = (MADCTL_MY | MADCTL_MV | TFT_RGB_BGR); | |
815 | break; | |
816 | case PORTRAIT_FLIP: | |
817 | madctl = (TFT_RGB_BGR); | |
818 | break; | |
819 | case LANDSCAPE_FLIP: | |
820 | madctl = (MADCTL_MX | MADCTL_MV | TFT_RGB_BGR); | |
821 | break; | |
822 | } | |
823 | #elif TFT_INVERT_ROTATION2 | |
824 | switch (rotation) { | |
825 | case PORTRAIT: | |
826 | madctl = (MADCTL_MX | MADCTL_MV | TFT_RGB_BGR); | |
827 | break; | |
828 | case LANDSCAPE: | |
829 | madctl = (TFT_RGB_BGR); | |
830 | break; | |
831 | case PORTRAIT_FLIP: | |
832 | madctl = (MADCTL_MY | MADCTL_MV | TFT_RGB_BGR); | |
833 | break; | |
834 | case LANDSCAPE_FLIP: | |
835 | madctl = (MADCTL_MY | MADCTL_MX | TFT_RGB_BGR); | |
836 | break; | |
837 | } | |
838 | #else | |
839 | switch (rotation) { | |
840 | case PORTRAIT: | |
841 | madctl = (MADCTL_MX | TFT_RGB_BGR); | |
842 | break; | |
843 | case LANDSCAPE: | |
844 | madctl = (MADCTL_MV | TFT_RGB_BGR); | |
845 | break; | |
846 | case PORTRAIT_FLIP: | |
847 | madctl = (MADCTL_MY | TFT_RGB_BGR); | |
848 | break; | |
849 | case LANDSCAPE_FLIP: | |
850 | madctl = (MADCTL_MX | MADCTL_MY | MADCTL_MV | TFT_RGB_BGR); | |
851 | break; | |
852 | } | |
853 | #endif | |
854 | if (send) { | |
855 | if (disp_select() == ESP_OK) { | |
856 | disp_spi_transfer_cmd_data(TFT_MADCTL, &madctl, 1); | |
857 | disp_deselect(); | |
858 | } | |
859 | } | |
860 | ||
861 | } | |
862 | ||
863 | //================= | |
864 | void TFT_PinsInit() | |
865 | { | |
866 | // Route all used pins to GPIO control | |
136
89fc3c57282e
Reverted gpio_pad_select_gpio() calls, added the correct include. Starting the unit works better now. Reverted some other small changes. In some parts the controller is very slow, possible spiffs issue?
Michiel Broek <mbroek@mbse.eu>
parents:
129
diff
changeset
|
867 | gpio_pad_select_gpio(PIN_NUM_CS); |
89fc3c57282e
Reverted gpio_pad_select_gpio() calls, added the correct include. Starting the unit works better now. Reverted some other small changes. In some parts the controller is very slow, possible spiffs issue?
Michiel Broek <mbroek@mbse.eu>
parents:
129
diff
changeset
|
868 | gpio_pad_select_gpio(PIN_NUM_MISO); |
89fc3c57282e
Reverted gpio_pad_select_gpio() calls, added the correct include. Starting the unit works better now. Reverted some other small changes. In some parts the controller is very slow, possible spiffs issue?
Michiel Broek <mbroek@mbse.eu>
parents:
129
diff
changeset
|
869 | gpio_pad_select_gpio(PIN_NUM_MOSI); |
89fc3c57282e
Reverted gpio_pad_select_gpio() calls, added the correct include. Starting the unit works better now. Reverted some other small changes. In some parts the controller is very slow, possible spiffs issue?
Michiel Broek <mbroek@mbse.eu>
parents:
129
diff
changeset
|
870 | gpio_pad_select_gpio(PIN_NUM_CLK); |
89fc3c57282e
Reverted gpio_pad_select_gpio() calls, added the correct include. Starting the unit works better now. Reverted some other small changes. In some parts the controller is very slow, possible spiffs issue?
Michiel Broek <mbroek@mbse.eu>
parents:
129
diff
changeset
|
871 | gpio_pad_select_gpio(PIN_NUM_DC); |
0 | 872 | |
873 | gpio_set_direction(PIN_NUM_MISO, GPIO_MODE_INPUT); | |
874 | gpio_set_pull_mode(PIN_NUM_MISO, GPIO_PULLUP_ONLY); | |
875 | gpio_set_direction(PIN_NUM_CS, GPIO_MODE_OUTPUT); | |
876 | gpio_set_direction(PIN_NUM_MOSI, GPIO_MODE_OUTPUT); | |
877 | gpio_set_direction(PIN_NUM_CLK, GPIO_MODE_OUTPUT); | |
878 | gpio_set_direction(PIN_NUM_DC, GPIO_MODE_OUTPUT); | |
879 | gpio_set_level(PIN_NUM_DC, 0); | |
880 | #if USE_TOUCH | |
136
89fc3c57282e
Reverted gpio_pad_select_gpio() calls, added the correct include. Starting the unit works better now. Reverted some other small changes. In some parts the controller is very slow, possible spiffs issue?
Michiel Broek <mbroek@mbse.eu>
parents:
129
diff
changeset
|
881 | gpio_pad_select_gpio(PIN_NUM_TCS); |
0 | 882 | gpio_set_direction(PIN_NUM_TCS, GPIO_MODE_OUTPUT); |
883 | #endif | |
884 | #if PIN_NUM_BCKL | |
136
89fc3c57282e
Reverted gpio_pad_select_gpio() calls, added the correct include. Starting the unit works better now. Reverted some other small changes. In some parts the controller is very slow, possible spiffs issue?
Michiel Broek <mbroek@mbse.eu>
parents:
129
diff
changeset
|
885 | gpio_pad_select_gpio(PIN_NUM_BCKL); |
0 | 886 | gpio_set_direction(PIN_NUM_BCKL, GPIO_MODE_OUTPUT); |
887 | gpio_set_level(PIN_NUM_BCKL, PIN_BCKL_OFF); | |
888 | #endif | |
889 | ||
890 | #if PIN_NUM_RST | |
136
89fc3c57282e
Reverted gpio_pad_select_gpio() calls, added the correct include. Starting the unit works better now. Reverted some other small changes. In some parts the controller is very slow, possible spiffs issue?
Michiel Broek <mbroek@mbse.eu>
parents:
129
diff
changeset
|
891 | gpio_pad_select_gpio(PIN_NUM_RST); |
0 | 892 | gpio_set_direction(PIN_NUM_RST, GPIO_MODE_OUTPUT); |
893 | gpio_set_level(PIN_NUM_RST, 0); | |
894 | #endif | |
895 | } | |
896 | ||
897 | // Initialize the display | |
898 | // ==================== | |
899 | void TFT_display_init() | |
900 | { | |
901 | esp_err_t ret; | |
902 | ||
903 | #if PIN_NUM_RST | |
904 | //Reset the display | |
905 | gpio_set_level(PIN_NUM_RST, 0); | |
906 | vTaskDelay(20 / portTICK_RATE_MS); | |
907 | gpio_set_level(PIN_NUM_RST, 1); | |
908 | vTaskDelay(150 / portTICK_RATE_MS); | |
909 | #endif | |
910 | ||
911 | ret = disp_select(); | |
912 | assert(ret==ESP_OK); | |
913 | //Send all the initialization commands | |
914 | if (tft_disp_type == DISP_TYPE_ILI9341) { | |
915 | commandList(disp_spi, ILI9341_init); | |
916 | } | |
917 | else if (tft_disp_type == DISP_TYPE_ILI9488) { | |
918 | commandList(disp_spi, ILI9488_init); | |
919 | } | |
920 | else if (tft_disp_type == DISP_TYPE_ST7789V) { | |
921 | commandList(disp_spi, ST7789V_init); | |
922 | } | |
923 | else if (tft_disp_type == DISP_TYPE_ST7735) { | |
924 | commandList(disp_spi, STP7735_init); | |
925 | } | |
926 | else if (tft_disp_type == DISP_TYPE_ST7735R) { | |
927 | commandList(disp_spi, STP7735R_init); | |
928 | commandList(disp_spi, Rcmd2green); | |
929 | commandList(disp_spi, Rcmd3); | |
930 | } | |
931 | else if (tft_disp_type == DISP_TYPE_ST7735B) { | |
932 | commandList(disp_spi, STP7735R_init); | |
933 | commandList(disp_spi, Rcmd2red); | |
934 | commandList(disp_spi, Rcmd3); | |
935 | uint8_t dt = 0xC0; | |
936 | disp_spi_transfer_cmd_data(TFT_MADCTL, &dt, 1); | |
937 | } | |
938 | else assert(0); | |
939 | ||
940 | ret = disp_deselect(); | |
941 | assert(ret==ESP_OK); | |
942 | ||
943 | // Clear screen | |
944 | _tft_setRotation(PORTRAIT); | |
945 | TFT_pushColorRep(0, 0, _width-1, _height-1, (color_t){0,0,0}, (uint32_t)(_height*_width)); | |
946 | ||
947 | ///Enable backlight | |
948 | #if PIN_NUM_BCKL | |
949 | gpio_set_level(PIN_NUM_BCKL, PIN_BCKL_ON); | |
950 | #endif | |
951 | } | |
952 | ||
953 |