diff --git a/components/lcd_touch/esp_lcd_touch/idf_component.yml b/components/lcd_touch/esp_lcd_touch/idf_component.yml index 75c218d9..2441f18f 100644 --- a/components/lcd_touch/esp_lcd_touch/idf_component.yml +++ b/components/lcd_touch/esp_lcd_touch/idf_component.yml @@ -1,4 +1,4 @@ -version: "1.1.1" +version: "1.1.2" description: ESP LCD Touch - main component for using touch screen controllers url: https://github.com/espressif/esp-bsp/tree/master/components/lcd_touch/esp_lcd_touch dependencies: diff --git a/components/lcd_touch/esp_lcd_touch/include/esp_lcd_touch.h b/components/lcd_touch/esp_lcd_touch/include/esp_lcd_touch.h index db39f1f0..d0b26763 100644 --- a/components/lcd_touch/esp_lcd_touch/include/esp_lcd_touch.h +++ b/components/lcd_touch/esp_lcd_touch/include/esp_lcd_touch.h @@ -64,6 +64,8 @@ typedef struct { esp_lcd_touch_interrupt_callback_t interrupt_callback; /*!< User data passed to callback */ void *user_data; + /*!< User data passed to driver */ + void *driver_data; } esp_lcd_touch_config_t; typedef struct { diff --git a/components/lcd_touch/esp_lcd_touch_gt911/README.md b/components/lcd_touch/esp_lcd_touch_gt911/README.md index 21459408..37b19890 100644 --- a/components/lcd_touch/esp_lcd_touch_gt911/README.md +++ b/components/lcd_touch/esp_lcd_touch_gt911/README.md @@ -25,6 +25,10 @@ Initialization of the touch component. ``` esp_lcd_panel_io_i2c_config_t io_config = ESP_LCD_TOUCH_IO_I2C_GT911_CONFIG(); + esp_lcd_touch_io_gt911_config_t tp_gt911_config = { + .dev_addr = io_config.dev_addr, + }; + esp_lcd_touch_config_t tp_cfg = { .x_max = CONFIG_LCD_HRES, .y_max = CONFIG_LCD_VRES, @@ -39,6 +43,7 @@ Initialization of the touch component. .mirror_x = 0, .mirror_y = 0, }, + .driver_data = &tp_gt911_config, }; esp_lcd_touch_handle_t tp; diff --git a/components/lcd_touch/esp_lcd_touch_gt911/esp_lcd_touch_gt911.c b/components/lcd_touch/esp_lcd_touch_gt911/esp_lcd_touch_gt911.c index 1f1d9b2e..5e5e625e 100644 --- a/components/lcd_touch/esp_lcd_touch_gt911/esp_lcd_touch_gt911.c +++ b/components/lcd_touch/esp_lcd_touch_gt911/esp_lcd_touch_gt911.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -16,6 +16,7 @@ #include "driver/i2c.h" #include "esp_lcd_panel_io.h" #include "esp_lcd_touch.h" +#include "esp_lcd_touch_gt911.h" static const char *TAG = "GT911"; @@ -86,6 +87,57 @@ esp_err_t esp_lcd_touch_new_i2c_gt911(const esp_lcd_panel_io_handle_t io, const /* Save config */ memcpy(&esp_lcd_touch_gt911->config, config, sizeof(esp_lcd_touch_config_t)); + esp_lcd_touch_io_gt911_config_t *gt911_config = (esp_lcd_touch_io_gt911_config_t *)esp_lcd_touch_gt911->config.driver_data; + + /* Prepare pin for touch controller reset */ + if (esp_lcd_touch_gt911->config.rst_gpio_num != GPIO_NUM_NC) { + const gpio_config_t rst_gpio_config = { + .mode = GPIO_MODE_OUTPUT, + .pin_bit_mask = BIT64(esp_lcd_touch_gt911->config.rst_gpio_num) + }; + ret = gpio_config(&rst_gpio_config); + ESP_GOTO_ON_ERROR(ret, err, TAG, "GPIO config failed"); + } + + if (gt911_config && esp_lcd_touch_gt911->config.rst_gpio_num != GPIO_NUM_NC && esp_lcd_touch_gt911->config.int_gpio_num != GPIO_NUM_NC) { + /* Prepare pin for touch controller int */ + const gpio_config_t int_gpio_config = { + .mode = GPIO_MODE_OUTPUT, + .intr_type = GPIO_INTR_DISABLE, + .pull_down_en = 0, + .pull_up_en = 1, + .pin_bit_mask = BIT64(esp_lcd_touch_gt911->config.int_gpio_num), + }; + ret = gpio_config(&int_gpio_config); + ESP_GOTO_ON_ERROR(ret, err, TAG, "GPIO config failed"); + + ESP_RETURN_ON_ERROR(gpio_set_level(esp_lcd_touch_gt911->config.rst_gpio_num, esp_lcd_touch_gt911->config.levels.reset), TAG, "GPIO set level error!"); + ESP_RETURN_ON_ERROR(gpio_set_level(esp_lcd_touch_gt911->config.int_gpio_num, 0), TAG, "GPIO set level error!"); + vTaskDelay(pdMS_TO_TICKS(10)); + + /* Select I2C addr, set output high or low */ + uint32_t gpio_level; + if (ESP_LCD_TOUCH_IO_I2C_GT911_ADDRESS_BACKUP == gt911_config->dev_addr) { + gpio_level = 1; + } else if (ESP_LCD_TOUCH_IO_I2C_GT911_ADDRESS == gt911_config->dev_addr) { + gpio_level = 0; + } else { + gpio_level = 0; + ESP_LOGE(TAG, "Addr (0x%X) is invalid", gt911_config->dev_addr); + } + ESP_RETURN_ON_ERROR(gpio_set_level(esp_lcd_touch_gt911->config.int_gpio_num, gpio_level), TAG, "GPIO set level error!"); + vTaskDelay(pdMS_TO_TICKS(1)); + + ESP_RETURN_ON_ERROR(gpio_set_level(esp_lcd_touch_gt911->config.rst_gpio_num, !esp_lcd_touch_gt911->config.levels.reset), TAG, "GPIO set level error!"); + vTaskDelay(pdMS_TO_TICKS(10)); + + vTaskDelay(pdMS_TO_TICKS(50)); + } else { + ESP_LOGW(TAG, "Unable to initialize the I2C address"); + /* Reset controller */ + ret = touch_gt911_reset(esp_lcd_touch_gt911); + ESP_GOTO_ON_ERROR(ret, err, TAG, "GT911 reset failed"); + } /* Prepare pin for touch interrupt */ if (esp_lcd_touch_gt911->config.int_gpio_num != GPIO_NUM_NC) { @@ -103,20 +155,6 @@ esp_err_t esp_lcd_touch_new_i2c_gt911(const esp_lcd_panel_io_handle_t io, const } } - /* Prepare pin for touch controller reset */ - if (esp_lcd_touch_gt911->config.rst_gpio_num != GPIO_NUM_NC) { - const gpio_config_t rst_gpio_config = { - .mode = GPIO_MODE_OUTPUT, - .pin_bit_mask = BIT64(esp_lcd_touch_gt911->config.rst_gpio_num) - }; - ret = gpio_config(&rst_gpio_config); - ESP_GOTO_ON_ERROR(ret, err, TAG, "GPIO config failed"); - } - - /* Reset controller */ - ret = touch_gt911_reset(esp_lcd_touch_gt911); - ESP_GOTO_ON_ERROR(ret, err, TAG, "GT911 reset failed"); - /* Read status and config info */ ret = touch_gt911_read_cfg(esp_lcd_touch_gt911); ESP_GOTO_ON_ERROR(ret, err, TAG, "GT911 init failed"); diff --git a/components/lcd_touch/esp_lcd_touch_gt911/idf_component.yml b/components/lcd_touch/esp_lcd_touch_gt911/idf_component.yml index c9e9957c..37de956e 100644 --- a/components/lcd_touch/esp_lcd_touch_gt911/idf_component.yml +++ b/components/lcd_touch/esp_lcd_touch_gt911/idf_component.yml @@ -1,4 +1,4 @@ -version: "1.1.0" +version: "1.1.1" description: ESP LCD Touch GT911 - touch controller GT911 url: https://github.com/espressif/esp-bsp/tree/master/components/lcd_touch/esp_lcd_touch_gt911 dependencies: diff --git a/components/lcd_touch/esp_lcd_touch_gt911/include/esp_lcd_touch_gt911.h b/components/lcd_touch/esp_lcd_touch_gt911/include/esp_lcd_touch_gt911.h index 0b10949d..0349b37e 100644 --- a/components/lcd_touch/esp_lcd_touch_gt911/include/esp_lcd_touch_gt911.h +++ b/components/lcd_touch/esp_lcd_touch_gt911/include/esp_lcd_touch_gt911.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -41,6 +41,14 @@ esp_err_t esp_lcd_touch_new_i2c_gt911(const esp_lcd_panel_io_handle_t io, const #define ESP_LCD_TOUCH_IO_I2C_GT911_ADDRESS (0x5D) #define ESP_LCD_TOUCH_IO_I2C_GT911_ADDRESS_BACKUP (0x14) +/** + * @brief GT911 Configuration Type + * + */ +typedef struct { + uint8_t dev_addr; /*!< I2C device address */ +} esp_lcd_touch_io_gt911_config_t; + /** * @brief Touch IO configuration structure *