From ba35f4c753ec5b0a1da9907fa4057d0bb6a3973b Mon Sep 17 00:00:00 2001 From: AlexAls Date: Wed, 29 Oct 2025 16:20:21 +0300 Subject: [PATCH 1/2] Fix issues on starting touch sensor and attaching interrupt --- cores/esp32/esp32-hal-touch-ng.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cores/esp32/esp32-hal-touch-ng.c b/cores/esp32/esp32-hal-touch-ng.c index 44bde091be8..cc66944c4ff 100644 --- a/cores/esp32/esp32-hal-touch-ng.c +++ b/cores/esp32/esp32-hal-touch-ng.c @@ -129,7 +129,7 @@ bool touchStart() { if (running) { // Already running return true; } - if (enabled && (touch_sensor_start_continuous_scanning(touch_sensor_handle) != ESP_OK)) { + if (!enabled && (touch_sensor_start_continuous_scanning(touch_sensor_handle) != ESP_OK)) { log_e("Touch sensor not enabled or failed to start continuous scanning failed!"); return false; } @@ -395,7 +395,7 @@ static void __touchConfigInterrupt(uint8_t pin, void (*userFunc)(void), void *Ar return; } - touch_channel_config_t chan_cfg = {}; + touch_channel_config_t chan_cfg = TOUCH_CHANNEL_DEFAULT_CONFIG(); for (int i = 0; i < _sample_num; i++) { #if SOC_TOUCH_SENSOR_VERSION == 1 // ESP32 chan_cfg.abs_active_thresh[i] = threshold; @@ -416,17 +416,17 @@ static void __touchConfigInterrupt(uint8_t pin, void (*userFunc)(void), void *Ar // it keeps backwards compatibility static void __touchAttachInterrupt(uint8_t pin, void (*userFunc)(void), touch_value_t threshold) { - __touchConfigInterrupt(pin, userFunc, NULL, threshold, false); + __touchConfigInterrupt(pin, userFunc, NULL, false, threshold); } // new additional version of the API with User Args static void __touchAttachArgsInterrupt(uint8_t pin, void (*userFunc)(void), void *args, touch_value_t threshold) { - __touchConfigInterrupt(pin, userFunc, args, threshold, true); + __touchConfigInterrupt(pin, userFunc, args, true, threshold); } // new additional API to detach touch ISR static void __touchDettachInterrupt(uint8_t pin) { - __touchConfigInterrupt(pin, NULL, NULL, 0, false); // userFunc as NULL acts as detaching + __touchConfigInterrupt(pin, NULL, NULL, false, 0); // userFunc as NULL acts as detaching } // /* From 73e097b179d0a85cb2e80a5275effa99d9029599 Mon Sep 17 00:00:00 2001 From: AlexAls Date: Fri, 31 Oct 2025 03:29:56 +0300 Subject: [PATCH 2/2] Fix logical issues --- cores/esp32/esp32-hal-touch-ng.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/cores/esp32/esp32-hal-touch-ng.c b/cores/esp32/esp32-hal-touch-ng.c index cc66944c4ff..a28ee4994c4 100644 --- a/cores/esp32/esp32-hal-touch-ng.c +++ b/cores/esp32/esp32-hal-touch-ng.c @@ -117,8 +117,12 @@ bool touchDisable() { if (!enabled) { // Already disabled return true; } - if (!running && (touch_sensor_disable(touch_sensor_handle) != ESP_OK)) { - log_e("Touch sensor still running or disable failed!"); + if (running) { + log_e("Touch sensor still running!"); + return false; + } + if (touch_sensor_disable(touch_sensor_handle) != ESP_OK) { + log_e("Touch sensor disable failed!"); return false; } enabled = false; @@ -129,8 +133,12 @@ bool touchStart() { if (running) { // Already running return true; } - if (!enabled && (touch_sensor_start_continuous_scanning(touch_sensor_handle) != ESP_OK)) { - log_e("Touch sensor not enabled or failed to start continuous scanning failed!"); + if (!enabled) { + log_e("Touch sensor not enabled!"); + return false; + } + if (touch_sensor_start_continuous_scanning(touch_sensor_handle) != ESP_OK) { + log_e("Touch sensor failed to start continuous scanning!"); return false; } running = true;