53
53
54
54
55
55
#define WAIT_CYCLE 0U
56
- #define LCD_X_MAX 240
57
- #define LCD_Y_MAX 320
56
+ #define LCD_X_MAX 320
57
+ #define LCD_Y_MAX 240
58
58
#define TFT_BGR 8
59
59
// RGB to GRAYSCALE constants
60
60
// 0.2989 0.5870 0.1140
63
63
#define GS_FACT_B 0.2140
64
64
65
65
#define SPI_CHANNEL (0)
66
- #define DCX_IO (38)
67
- #define TFT_RST (37)
66
+ #define LCD_CS (36)
67
+ #define LCD_RST (39)
68
+ #define LCD_DC (38)
69
+ #define LCD_WR (37)
68
70
69
71
enum _instruction_length
70
72
{
@@ -115,7 +117,7 @@ static mp_fpioa_cfg_item_t disp_pin_func[DISP_NUM_FUNC];
115
117
static uint32_t tft_spi_speed = SPI_DEFAULT_SPEED ;
116
118
117
119
static const char TAG [] = "[TFTSPI]" ;
118
- static uint8_t invertrot = 1 ;
120
+ static uint8_t invertrot = 0 ;
119
121
120
122
// ==== Functions =====================
121
123
@@ -186,10 +188,10 @@ static bool tft_hard_init(void)
186
188
return false;
187
189
}
188
190
189
- disp_pin_func [0 ] = (mp_fpioa_cfg_item_t ){tft_dc_gpionum , DCX_IO , GPIO_USEDAS_DCX , FUNC_GPIOHS0 + tft_dc_gpionum };
190
- disp_pin_func [1 ] = (mp_fpioa_cfg_item_t ){-1 , 36 , GPIO_USEDAS_CS , FUNC_SPI0_SS3 };
191
- disp_pin_func [2 ] = (mp_fpioa_cfg_item_t ){-1 , 39 , GPIO_USEDAS_CLK , FUNC_SPI0_SCLK };
192
- disp_pin_func [3 ] = (mp_fpioa_cfg_item_t ){tft_rst_gpionum , TFT_RST , GPIO_USEDAS_RST , FUNC_GPIOHS0 + tft_rst_gpionum };
191
+ disp_pin_func [0 ] = (mp_fpioa_cfg_item_t ){tft_dc_gpionum , LCD_DC , GPIO_USEDAS_DCX , FUNC_GPIOHS0 + tft_dc_gpionum };
192
+ disp_pin_func [1 ] = (mp_fpioa_cfg_item_t ){-1 , LCD_CS , GPIO_USEDAS_CS , FUNC_SPI0_SS3 };
193
+ disp_pin_func [2 ] = (mp_fpioa_cfg_item_t ){-1 , LCD_WR , GPIO_USEDAS_CLK , FUNC_SPI0_SCLK };
194
+ disp_pin_func [3 ] = (mp_fpioa_cfg_item_t ){tft_rst_gpionum , LCD_RST , GPIO_USEDAS_RST , FUNC_GPIOHS0 + tft_rst_gpionum };
193
195
194
196
if (!fpioa_check_pins (DISP_NUM_FUNC , disp_pin_func , GPIO_FUNC_DISP )) {
195
197
gpiohs_set_free (tft_dc_gpionum );
@@ -256,6 +258,7 @@ static void tft_write_rgb565(uint16_t* data_buf, uint32_t length)
256
258
{
257
259
set_dcx_data ();
258
260
io_write (spi_dfs16 , (const uint8_t * )(data_buf ), length * 2 );
261
+ //io_write(spi_dfs8, (const uint8_t *)(data_buf), length * 2);
259
262
}
260
263
261
264
/*
@@ -271,8 +274,12 @@ static void tft_write_32bit(uint32_t* data_buf, uint32_t length)
271
274
//-------------------------------------------------------
272
275
static void tft_fill_data (uint32_t data , uint32_t length )
273
276
{
277
+ uint32_t len = 0 ;
278
+ LOGV (TAG , "tft_fill_data length = 0x%X" , length );
279
+ if (length > 1 ) len = length /2 - 1 ;
280
+ else len = length ;
274
281
set_dcx_data ();
275
- spi_dev_fill (spi_dfs32 , 0 , data , data , length / 2 - 1 );
282
+ spi_dev_fill (spi_dfs32 , 0 , data , data , len );
276
283
}
277
284
278
285
@@ -301,6 +308,41 @@ static bool tft_init(uint8_t hw_sw)
301
308
tft_write_command (PIXEL_FORMAT_SET );
302
309
data = 0x55 ;
303
310
tft_write_byte (& data , 1 );
311
+
312
+ /*
313
+ // aibit LCM init
314
+ tft_write_command(NORMAL_DISPALY_ON);
315
+ mp_hal_delay_ms(10);
316
+ tft_write_command(BACKLIGHT_CTL2);
317
+ tft_write_byte((uint8_t *)"\xFF\x93\x42", 3);
318
+ mp_hal_delay_ms(10);
319
+ tft_write_command(INVERSION_DISPALY_ON);
320
+ mp_hal_delay_ms(10);
321
+ tft_write_command(MEMORY_ACCESS_CTL);
322
+ tft_write_byte((uint8_t *)"\x01",1);
323
+ mp_hal_delay_ms(10);
324
+ tft_write_command(POWER_CTL1);
325
+ tft_write_byte((uint8_t *)"\x1D\x0A", 2);
326
+ mp_hal_delay_ms(10);
327
+ tft_write_command(POWER_CTL2);
328
+ tft_write_byte((uint8_t *)"\x02", 1);
329
+ mp_hal_delay_ms(10);
330
+ tft_write_command(VCOM_CTL1);
331
+ tft_write_byte((uint8_t *)"\x2F\x27", 2);
332
+ mp_hal_delay_ms(10);
333
+ tft_write_command(VCOM_CTL2);
334
+ tft_write_byte((uint8_t *)"\xA4", 1);
335
+ tft_write_command(BACKLIGHT_CTL1);
336
+ tft_write_byte((uint8_t *)"\x0B", 1);
337
+ mp_hal_delay_ms(10);
338
+ tft_write_command(POSITIVE_GAMMA_CORRECT);
339
+ tft_write_byte((uint8_t *)"\x0F\x24\x21\x0C\x0F\x06\x50\x75\x3F\x07\x12\x05\x11\x0B\x08", 15);
340
+ mp_hal_delay_ms(10);
341
+ tft_write_command(NEGATIVE_GAMMA_CORRECT);
342
+ tft_write_byte((uint8_t *)"\x08\x1D\x20\x02\x0E\x04\x31\x24\x42\x03\x0B\x09\x30\x36\x0F", 15);
343
+ mp_hal_delay_ms(10);
344
+ */
345
+
304
346
tft_write_command (DISPALY_ON );
305
347
return true;
306
348
}
@@ -455,6 +497,7 @@ void send_frame_buffer()
455
497
{
456
498
if ((active_dstate -> use_frame_buffer ) && active_dstate -> tft_frame_buffer ) {
457
499
LOGV (TAG , "Send frame buffer at %p" , active_dstate -> tft_frame_buffer );
500
+ LOGV (TAG , "width:%d height:%d" , active_dstate -> _width , active_dstate -> _height );
458
501
// ** Send address window **
459
502
disp_spi_transfer_addrwin (0 , active_dstate -> _width - 1 , 0 , active_dstate -> _height - 1 );
460
503
// Send color buffer
@@ -519,12 +562,21 @@ void _tft_setRotation(uint8_t rot) {
519
562
}
520
563
else if (invertrot == 1 ) {
521
564
switch (rotation ) {
565
+ /* ILI9341
522
566
case PORTRAIT:
523
567
madctl = (MADCTL_MY | MADCTL_MX | active_dstate->TFT_RGB_BGR);
524
568
break;
525
569
case LANDSCAPE:
526
570
madctl = (MADCTL_MY | MADCTL_MV | active_dstate->TFT_RGB_BGR);
527
571
break;
572
+ */
573
+ // ILI9342
574
+ case LANDSCAPE :
575
+ madctl = (MADCTL_MY | MADCTL_MX | active_dstate -> TFT_RGB_BGR );
576
+ break ;
577
+ case PORTRAIT :
578
+ madctl = (MADCTL_MY | MADCTL_MV | active_dstate -> TFT_RGB_BGR );
579
+ break ;
528
580
case PORTRAIT_FLIP :
529
581
madctl = (active_dstate -> TFT_RGB_BGR );
530
582
break ;
@@ -575,7 +627,7 @@ int TFT_display_init(display_config_t *dconfig)
575
627
{
576
628
TFT_display_setvars (dconfig );
577
629
578
- if (!tft_init (3 )) return -1 ;
630
+ if (!tft_init (1 )) return -1 ; // 0x01 soft reset, 0x2 hard reset, 0x3 both reset
579
631
vTaskDelay (100 );
580
632
581
633
return 0 ;
0 commit comments