diff --git a/src/esp_touch_cst816s.c b/src/esp_touch_cst816s.c index 1ca139b..3432a2c 100644 --- a/src/esp_touch_cst816s.c +++ b/src/esp_touch_cst816s.c @@ -259,14 +259,29 @@ esp_err_t esp_lcd_touch_new_i2c_cst816s(const esp_lcd_panel_io_handle_t io, cons memcpy(&th->config, config, sizeof(esp_lcd_touch_config_t)); portMUX_INITIALIZE(&th->data.lock); + // Reset controller + if ((res = cst816s_reset(th)) != ESP_OK) + { + log_e("GT911 reset failed"); + cst816s_del(th); + return res; + } + + // Read type and resolution + if ((res = cst816s_read_info(th)) != ESP_OK) + { + log_e("GT911 read info failed"); + cst816s_del(th); + return res; + } + if (config->int_gpio_num != GPIO_NUM_NC) { esp_rom_gpio_pad_select_gpio(config->int_gpio_num); const gpio_config_t cfg = { .pin_bit_mask = BIT64(config->int_gpio_num), .mode = GPIO_MODE_INPUT, - // If the user has provided a callback routine for the interrupt enable the interrupt mode on the negative edge. - .intr_type = config->interrupt_callback ? GPIO_INTR_NEGEDGE : GPIO_INTR_DISABLE}; + .intr_type = config->levels.interrupt ? GPIO_INTR_POSEDGE : GPIO_INTR_NEGEDGE}; if ((res = gpio_config(&cfg)) != ESP_OK) { free(th); @@ -280,7 +295,7 @@ esp_err_t esp_lcd_touch_new_i2c_cst816s(const esp_lcd_panel_io_handle_t io, cons { gpio_reset_pin(th->config.int_gpio_num); free(th); - log_e("Registering INT callback failed"); + log_e("Registering interrupt callback failed"); return res; } } @@ -306,22 +321,6 @@ esp_err_t esp_lcd_touch_new_i2c_cst816s(const esp_lcd_panel_io_handle_t io, cons return res; } } - - // Reset controller - if ((res = cst816s_reset(th)) != ESP_OK) - { - log_e("GT911 reset failed"); - cst816s_del(th); - return res; - } - - // Read type and resolution - if ((res = cst816s_read_info(th)) != ESP_OK) - { - log_e("GT911 read info failed"); - cst816s_del(th); - return res; - } } log_d("handle:0x%08x", th); diff --git a/src/esp_touch_gt911.c b/src/esp_touch_gt911.c index d79930c..33322c8 100644 --- a/src/esp_touch_gt911.c +++ b/src/esp_touch_gt911.c @@ -397,53 +397,19 @@ esp_err_t esp_lcd_touch_new_i2c_gt911(const esp_lcd_panel_io_handle_t io, const memcpy(&th->config, config, sizeof(esp_lcd_touch_config_t)); portMUX_INITIALIZE(&th->data.lock); - if (config->int_gpio_num != GPIO_NUM_NC) + // Initialize RST pin + if (config->rst_gpio_num != GPIO_NUM_NC) { - esp_rom_gpio_pad_select_gpio(config->int_gpio_num); + esp_rom_gpio_pad_select_gpio(config->rst_gpio_num); const gpio_config_t cfg = { - .pin_bit_mask = BIT64(config->int_gpio_num), - .mode = GPIO_MODE_INPUT, - // If the user has provided a callback routine for the interrupt enable the interrupt mode on the negative edge. - .intr_type = config->interrupt_callback ? GPIO_INTR_NEGEDGE : GPIO_INTR_DISABLE}; + .pin_bit_mask = BIT64(config->rst_gpio_num), + .mode = GPIO_MODE_OUTPUT}; if ((res = gpio_config(&cfg)) != ESP_OK) { free(th); - log_e("Configuring GPIO for INT failed"); + log_e("Configuring or setting GPIO for RST failed"); return res; } - - if (config->interrupt_callback != NULL) - { - if ((res = esp_lcd_touch_register_interrupt_callback(th, config->interrupt_callback)) != ESP_OK) - { - gpio_reset_pin(th->config.int_gpio_num); - free(th); - log_e("Registering INT callback failed"); - return res; - } - } - - if (config->rst_gpio_num != GPIO_NUM_NC) - { - esp_rom_gpio_pad_select_gpio(config->rst_gpio_num); - const gpio_config_t cfg = { - .pin_bit_mask = BIT64(config->rst_gpio_num), - .mode = GPIO_MODE_OUTPUT}; - if ((res = gpio_config(&cfg)) != ESP_OK) - { - if (th->config.int_gpio_num != GPIO_NUM_NC) - { - if (config->interrupt_callback != NULL) - gpio_isr_handler_remove(th->config.int_gpio_num); - - gpio_reset_pin(th->config.int_gpio_num); - } - - free(th); - log_e("Configuring or setting GPIO for RST failed"); - return res; - } - } } // Reset controller @@ -462,6 +428,32 @@ esp_err_t esp_lcd_touch_new_i2c_gt911(const esp_lcd_panel_io_handle_t io, const return res; } + if (config->int_gpio_num != GPIO_NUM_NC) + { + esp_rom_gpio_pad_select_gpio(config->int_gpio_num); + const gpio_config_t cfg = { + .pin_bit_mask = BIT64(config->int_gpio_num), + .mode = GPIO_MODE_INPUT, + .intr_type = config->levels.interrupt ? GPIO_INTR_POSEDGE : GPIO_INTR_NEGEDGE}; + if ((res = gpio_config(&cfg)) != ESP_OK) + { + free(th); + log_e("Configuring GPIO for INT failed"); + return res; + } + + if (config->interrupt_callback != NULL) + { + if ((res = esp_lcd_touch_register_interrupt_callback(th, config->interrupt_callback)) != ESP_OK) + { + gpio_reset_pin(th->config.int_gpio_num); + free(th); + log_e("Registering interrupt callback failed"); + return res; + } + } + } + log_d("handle:0x%08x", th); *handle = th; diff --git a/src/esp_touch_xpt2046.c b/src/esp_touch_xpt2046.c index 27ff477..8c52434 100644 --- a/src/esp_touch_xpt2046.c +++ b/src/esp_touch_xpt2046.c @@ -204,8 +204,7 @@ esp_err_t esp_lcd_touch_new_spi_xpt2046(const esp_lcd_panel_io_handle_t io, cons const gpio_config_t cfg = { .pin_bit_mask = BIT64(config->int_gpio_num), .mode = GPIO_MODE_INPUT, - // If the user has provided a callback routine for the interrupt enable the interrupt mode on the negative edge. - .intr_type = config->interrupt_callback ? GPIO_INTR_NEGEDGE : GPIO_INTR_DISABLE}; + .intr_type = config->levels.interrupt ? GPIO_INTR_POSEDGE : GPIO_INTR_NEGEDGE}; if ((res = gpio_config(&cfg)) != ESP_OK) { free(th); @@ -219,7 +218,7 @@ esp_err_t esp_lcd_touch_new_spi_xpt2046(const esp_lcd_panel_io_handle_t io, cons { gpio_reset_pin(th->config.int_gpio_num); free(th); - log_e("Registering INT callback failed"); + log_e("Registering interrupt callback failed"); return res; } }