diff --git a/Dockerfile b/Dockerfile index 8c314638..cb3045cb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -27,7 +27,7 @@ COPY container.gitconfig /root/.gitconfig ENV PATH="$PATH:/willow/.local/bin" WORKDIR /willow -ENV ADF_VER="willow-main-2023092800" +ENV ADF_VER="willow-main-2023102800" RUN \ cd /opt/esp/idf && \ curl https://raw.githubusercontent.com/toverainc/esp-adf/$ADF_VER/idf_patches/idf_v5.1_freertos.patch | patch -p1 diff --git a/dependencies.lock b/dependencies.lock index 06004ca1..52c5a38c 100644 --- a/dependencies.lock +++ b/dependencies.lock @@ -11,6 +11,12 @@ dependencies: service_url: https://api.components.espressif.com/ type: service version: 1.1.0 + espressif/esp_lcd_touch_gt911: + component_hash: 20ac25d1439dbe177764dbed9cd868388fecb052380b5349f2e9e370013ca76a + source: + service_url: https://api.components.espressif.com/ + type: service + version: 1.1.0 espressif/esp_lcd_touch_tt21100: component_hash: 3670f6f3d68c120d680d70ffdf2dc10f6c2a5bea8c0e87521fb92ac2af1f94c5 source: @@ -46,6 +52,6 @@ dependencies: service_url: https://api.components.espressif.com/ type: service version: 8.3.9 -manifest_hash: 16e419349385001148c6e6d82b3ab837b2e2869753a81d6fe4ea5f77b9ec754e +manifest_hash: 026d2c1ee13599f6e9792b979b276491d4aacc16c125a234ca36a647dda816a1 target: esp32s3 version: 1.0.0 diff --git a/main/idf_component.yml b/main/idf_component.yml index 8235229c..308a1fc6 100644 --- a/main/idf_component.yml +++ b/main/idf_component.yml @@ -1,5 +1,6 @@ ## IDF Component Manager Manifest File dependencies: + espressif/esp_lcd_touch_gt911: "1.1.0" lvgl/lvgl: "8.3.9" espressif/esp_websocket_client: "1.1.0" espressif/nghttp: "1.52.0" diff --git a/main/slvgl.c b/main/slvgl.c index b4a2d3b1..4eba763c 100644 --- a/main/slvgl.c +++ b/main/slvgl.c @@ -2,10 +2,12 @@ #include "driver/ledc.h" #include "esp_err.h" #include "esp_lcd_panel_ops.h" +#include "esp_lcd_touch_gt911.h" #include "esp_lcd_touch_tt21100.h" #include "esp_log.h" #include "esp_lvgl_port.h" #include "esp_timer.h" +#include "i2c_bus.h" #include "lvgl.h" #include "periph_lcd.h" @@ -38,6 +40,10 @@ typedef struct periph_lcd { bool lcd_color_invert; } periph_lcd_t; +enum esp32_s3_box_touch_t { + TOUCH_GT911, + TOUCH_TT21100, +}; esp_lcd_panel_handle_t hdl_lcd = NULL; int lvgl_lock_timeout; lv_disp_t *ld; @@ -122,8 +128,24 @@ esp_err_t init_lvgl_display(void) return ret; } +static esp_lcd_panel_io_i2c_config_t cfg_lpiic_gt911(int addr) +{ + esp_lcd_panel_io_i2c_config_t cfg_io_lt = ESP_LCD_TOUCH_IO_I2C_GT911_CONFIG(); + cfg_io_lt.dev_addr = addr; + + return cfg_io_lt; +} + +static esp_lcd_panel_io_i2c_config_t cfg_lpiic_tt21100(void) +{ + esp_lcd_panel_io_i2c_config_t cfg_io_lt = ESP_LCD_TOUCH_IO_I2C_TT21100_CONFIG(); + + return cfg_io_lt; +} + esp_err_t init_lvgl_touch(void) { + enum esp32_s3_box_touch_t touch_type; esp_err_t ret = ESP_OK; switch (hw_type) { @@ -138,7 +160,7 @@ esp_err_t init_lvgl_touch(void) esp_lcd_touch_config_t cfg_lt = { .flags = { - .mirror_x = true, + .mirror_x = false, .mirror_y = false, .swap_xy = LCD_SWAP_XY, }, @@ -152,7 +174,23 @@ esp_err_t init_lvgl_touch(void) .y_max = LCD_V_RES, }; - esp_lcd_panel_io_i2c_config_t cfg_io_lt = ESP_LCD_TOUCH_IO_I2C_TT21100_CONFIG(); + esp_lcd_panel_io_i2c_config_t cfg_io_lt; + + if (i2c_bus_probe_addr(hdl_i2c_bus, ESP_LCD_TOUCH_IO_I2C_GT911_ADDRESS << 1) == ESP_OK) { + cfg_io_lt = cfg_lpiic_gt911(ESP_LCD_TOUCH_IO_I2C_GT911_ADDRESS); + touch_type = TOUCH_GT911; + } else if (i2c_bus_probe_addr(hdl_i2c_bus, ESP_LCD_TOUCH_IO_I2C_GT911_ADDRESS_BACKUP << 1) == ESP_OK) { + cfg_io_lt = cfg_lpiic_gt911(ESP_LCD_TOUCH_IO_I2C_GT911_ADDRESS_BACKUP); + touch_type = TOUCH_GT911; + } else if (i2c_bus_probe_addr(hdl_i2c_bus, ESP_LCD_TOUCH_IO_I2C_TT21100_ADDRESS << 1) == ESP_OK) { + cfg_io_lt = cfg_lpiic_tt21100(); + cfg_lt.flags.mirror_x = true; + touch_type = TOUCH_TT21100; + } else { + ESP_LOGE(TAG, "touch screen not detected"); + return ESP_ERR_NOT_FOUND; + } + ret = esp_lcd_new_panel_io_i2c((esp_lcd_i2c_bus_handle_t)0, &cfg_io_lt, &lcdp->lcd_io_handle); if (ret != ESP_OK) { ESP_LOGE(TAG, "failed to initialize display panel IO: %s", esp_err_to_name(ret)); @@ -160,12 +198,20 @@ esp_err_t init_lvgl_touch(void) } esp_lcd_touch_handle_t hdl_lt = NULL; - ret = esp_lcd_touch_new_i2c_tt21100(lcdp->lcd_io_handle, &cfg_lt, &hdl_lt); - if (ret != ESP_OK) { - ESP_LOGE(TAG, "failed to initialize touch screen: %s", esp_err_to_name(ret)); - return ret; - } + if (touch_type == TOUCH_GT911) { + ret = esp_lcd_touch_new_i2c_gt911(lcdp->lcd_io_handle, &cfg_lt, &hdl_lt); + if (ret != ESP_OK) { + ESP_LOGE(TAG, "failed to initialize GT911 touch screen: %s", esp_err_to_name(ret)); + return ret; + } + } else if (touch_type == TOUCH_TT21100) { + ret = esp_lcd_touch_new_i2c_tt21100(lcdp->lcd_io_handle, &cfg_lt, &hdl_lt); + if (ret != ESP_OK) { + ESP_LOGE(TAG, "failed to initialize TT21100 touch screen: %s", esp_err_to_name(ret)); + return ret; + } + } const lvgl_port_touch_cfg_t cfg_pt = { .disp = ld, .handle = hdl_lt,