Skip to content

fix GT911 show error the first time #238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lvgl_touch/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,22 @@ menu "LVGL Touch controller"
prompt "Invert Y coordinate value."
default y

config GT911_INT_PIN
int
prompt "GPIO for GT911 Interrupt"

default 40
help
Configure the touchpanel MISO pin here.

config GT911_RST_PIN
int
prompt "GPIO for GT911 Reset"

default 39
help
Configure the touchpanel MOSI pin here.

endmenu

choice
Expand Down
36 changes: 35 additions & 1 deletion lvgl_touch/gt911.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,38 @@ esp_err_t gt911_i2c_write8(uint8_t slave_addr, uint16_t register_addr, uint8_t d
return lvgl_i2c_write(CONFIG_LV_I2C_TOUCH_PORT, slave_addr, register_addr | I2C_REG_16, &buffer, 1);
}

/**
* @brief set GT911 slave address via RST and INT pin
* @param dev_addr: Device address on communication Bus (I2C slave address of GT911).
* @retval None
*/
void gt911_set_addr(uint8_t dev_addr){
//fix show error the first time
gpio_config_t io_conf;
io_conf.intr_type = GPIO_INTR_DISABLE;
io_conf.mode = GPIO_MODE_OUTPUT;
io_conf.pin_bit_mask = (1ULL << CONFIG_GT911_INT_PIN)|(1ULL << CONFIG_GT911_RST_PIN);
io_conf.pull_down_en = 0;
io_conf.pull_up_en = 0;
gpio_config(&io_conf);
gpio_pad_select_gpio(CONFIG_GT911_INT_PIN);
gpio_set_direction(CONFIG_GT911_INT_PIN, GPIO_MODE_OUTPUT);
gpio_pad_select_gpio(CONFIG_GT911_RST_PIN);
gpio_set_direction(CONFIG_GT911_RST_PIN, GPIO_MODE_OUTPUT);

// 设置引脚电平
gpio_set_level(CONFIG_GT911_INT_PIN, 0);
gpio_set_level(CONFIG_GT911_RST_PIN, 0);
vTaskDelay(pdMS_TO_TICKS(10));
gpio_set_level(CONFIG_GT911_INT_PIN, GT911_I2C_SLAVE_ADDR==0x29);
vTaskDelay(pdMS_TO_TICKS(1));
gpio_set_level(CONFIG_GT911_RST_PIN, 1);
vTaskDelay(pdMS_TO_TICKS(5));
gpio_set_level(CONFIG_GT911_INT_PIN, 0);
vTaskDelay(pdMS_TO_TICKS(50));
vTaskDelay(pdMS_TO_TICKS(50));
}

/**
* @brief Initialize for GT911 communication via I2C
* @param dev_addr: Device address on communication Bus (I2C slave address of GT911).
Expand All @@ -53,10 +85,12 @@ void gt911_init(uint8_t dev_addr) {
uint8_t data_buf;
esp_err_t ret;

gt911_set_addr(dev_addr);//fix show error the first time

ESP_LOGI(TAG, "Checking for GT911 Touch Controller");
if ((ret = gt911_i2c_read(dev_addr, GT911_PRODUCT_ID1, &data_buf, 1) != ESP_OK)) {
ESP_LOGE(TAG, "Error reading from device: %s",
esp_err_to_name(ret)); // Only show error the first time
esp_err_to_name(ret));
return;
}

Expand Down