Skip to content
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

Changed the order of enabling interrupts #196

Merged
merged 1 commit into from
Oct 30, 2024
Merged
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
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