Skip to content

Commit

Permalink
treewide: support GT911 touch controller in final Box-3
Browse files Browse the repository at this point in the history
The pre-production units of the ESP32-S3-Box-3 uses a different touch
controller than the final model. Detect the model to make sure the touch
controller works on both versions.

This requires a change to ESP-ADF to allow probing the I2C address on
the I2C bus.
  • Loading branch information
stintel authored and kristiankielhofner committed Oct 28, 2023
1 parent 37f99d6 commit 126c4d0
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 7 additions & 1 deletion dependencies.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions main/idf_component.yml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
60 changes: 53 additions & 7 deletions main/slvgl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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,
},
Expand All @@ -152,20 +174,44 @@ 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));
return ret;
}

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,
Expand Down

0 comments on commit 126c4d0

Please sign in to comment.