@@ -81,13 +81,21 @@ static const char *TAG = "platform Lilygo T-Display S3";
8181#define LILYGO_TDISPLAY_S3_LCD_V_RES (170)
8282#define LILYGO_TDISPLAY_S3_LCD_PIXEL_CLOCK_HZ (10 * 1000 * 1000)
8383
84+ enum TouchChips
85+ {
86+ UNKNOWN ,
87+ CST8165S ,
88+ CST328
89+ };
90+
8491static lv_disp_draw_buf_t disp_buf ;
8592static lv_disp_drv_t * disp_drv ;
8693static esp_lcd_panel_io_handle_t lcd_io = NULL ;
8794static esp_lcd_panel_handle_t lcd_panel = NULL ;
8895static esp_lcd_touch_handle_t tp = NULL ;
8996static esp_lcd_panel_io_handle_t tp_io_handle = NULL ;
9097static lv_indev_drv_t indev_drv ; // Input device driver (Touch)
98+ static uint8_t touch_chip_type = UNKNOWN ;
9199
92100typedef struct {
93101 uint32_t addr ;
@@ -123,8 +131,11 @@ __attribute__((unused)) void platform_adjust_touch_coords(lv_coord_t* x, lv_coor
123131{
124132 lv_coord_t xpos = * x ;
125133
126- // 1.9 in landscape mode needs the co-ordinates adjusted
127- * x = LILYGO_TDISPLAY_S3_LCD_H_RES - xpos ;
134+ if (touch_chip_type == CST8165S )
135+ {
136+ // CST8165S in landscape mode needs the co-ordinates adjusted
137+ * x = LILYGO_TDISPLAY_S3_LCD_H_RES - xpos ;
138+ }
128139
129140 if (* x < 0 )
130141 {
@@ -340,11 +351,12 @@ void platform_init(i2c_master_bus_handle_t bus_handle, SemaphoreHandle_t I2CMute
340351 vTaskDelay (pdMS_TO_TICKS (20 ));
341352 gpio_set_level (TOUCH_RESET , 1 );
342353 vTaskDelay (pdMS_TO_TICKS (50 ));
343-
354+
344355 // some early boards had CST328 touch chip, and later has CST816. They use different I2C addresses,
345356 // so probe for which one is present
346357 if (i2c_master_probe (bus_handle , ESP_LCD_TOUCH_IO_I2C_CST816S_ADDRESS , 50 ) == ESP_OK )
347358 {
359+ touch_chip_type = CST8165S ;
348360 const esp_lcd_panel_io_i2c_config_t tp_io_config = ESP_LCD_TOUCH_IO_I2C_CST816S_CONFIG ();
349361
350362 // Touch IO handle
@@ -378,6 +390,7 @@ void platform_init(i2c_master_bus_handle_t bus_handle, SemaphoreHandle_t I2CMute
378390 }
379391 else if (i2c_master_probe (bus_handle , ESP_LCD_TOUCH_IO_I2C_CST328_ADDRESS , 50 ) == ESP_OK )
380392 {
393+ touch_chip_type = CST328 ;
381394 const esp_lcd_panel_io_i2c_config_t tp_io_config = ESP_LCD_TOUCH_IO_I2C_CST328_CONFIG ();
382395
383396 // Touch IO handle
0 commit comments