Skip to content

Commit

Permalink
Merge pull request #329 from espressif2022/feature/update_GT911_init
Browse files Browse the repository at this point in the history
feat(GT911): added I2C addr set support. (BSP-496)
  • Loading branch information
espzav authored Jun 12, 2024
2 parents 5c7b366 + d118a01 commit 54e9ba5
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 18 deletions.
2 changes: 1 addition & 1 deletion components/lcd_touch/esp_lcd_touch/idf_component.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
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
5 changes: 5 additions & 0 deletions components/lcd_touch/esp_lcd_touch_gt911/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down
68 changes: 53 additions & 15 deletions components/lcd_touch/esp_lcd_touch_gt911/esp_lcd_touch_gt911.c
Original file line number Diff line number Diff line change
@@ -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
*/
Expand All @@ -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";

Expand Down Expand Up @@ -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) {
Expand All @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion components/lcd_touch/esp_lcd_touch_gt911/idf_component.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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
*/
Expand Down Expand Up @@ -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
*
Expand Down

0 comments on commit 54e9ba5

Please sign in to comment.