Skip to content

Commit

Permalink
GT911: add driver_data for GT911
Browse files Browse the repository at this point in the history
  • Loading branch information
espressif2022 committed Jun 12, 2024
1 parent 7942f2c commit 9d58aa6
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 18 deletions.
2 changes: 2 additions & 0 deletions components/lcd_touch/esp_lcd_touch/include/esp_lcd_touch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 2 additions & 4 deletions components/lcd_touch/esp_lcd_touch_gt911/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ 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,
};
uint8_t gt911_addr = io_config.dev_addr;
esp_lcd_touch_config_t tp_cfg = {
.x_max = CONFIG_LCD_HRES,
Expand All @@ -43,7 +41,7 @@ Initialization of the touch component.
.mirror_x = 0,
.mirror_y = 0,
},
.user_data = &tp_gt911_config,
.driver_data = &gt911_addr,
};
esp_lcd_touch_handle_t tp;
Expand Down
10 changes: 5 additions & 5 deletions components/lcd_touch/esp_lcd_touch_gt911/esp_lcd_touch_gt911.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ 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.user_data;
uint8_t *gt911_addr = (uint8_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) {
Expand All @@ -99,7 +99,7 @@ esp_err_t esp_lcd_touch_new_i2c_gt911(const esp_lcd_panel_io_handle_t io, const
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) {
if (gt911_addr && 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,
Expand All @@ -117,13 +117,13 @@ esp_err_t esp_lcd_touch_new_i2c_gt911(const esp_lcd_panel_io_handle_t io, const

/* 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) {
if (ESP_LCD_TOUCH_IO_I2C_GT911_ADDRESS_BACKUP == *gt911_addr) {
gpio_level = 1;
} else if (ESP_LCD_TOUCH_IO_I2C_GT911_ADDRESS == gt911_config->dev_addr) {
} else if (ESP_LCD_TOUCH_IO_I2C_GT911_ADDRESS == *gt911_addr) {
gpio_level = 0;
} else {
gpio_level = 0;
ESP_LOGE(TAG, "Addr (0x%X) is invalid", (unsigned int)gt911_config->dev_addr);
ESP_LOGE(TAG, "Addr (0x%X) is invalid", *gt911_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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,6 @@ 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 {
uint32_t dev_addr; /*!< I2C device address */
void *user_data; /*!< User data passed to callback */
} esp_lcd_touch_io_gt911_config_t;

/**
* @brief Touch IO configuration structure
*
Expand Down

0 comments on commit 9d58aa6

Please sign in to comment.