Skip to content

Commit

Permalink
Changed the order of enabling interrupts
Browse files Browse the repository at this point in the history
Corrected interrupts leven pos/neg edge
  • Loading branch information
rzeldent committed Sep 1, 2024
1 parent 4612f81 commit 34f80df
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 62 deletions.
37 changes: 18 additions & 19 deletions src/esp_touch_cst816s.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
}
Expand All @@ -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);
Expand Down
72 changes: 32 additions & 40 deletions src/esp_touch_gt911.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;

Expand Down
5 changes: 2 additions & 3 deletions src/esp_touch_xpt2046.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
}
Expand Down

0 comments on commit 34f80df

Please sign in to comment.