Skip to content

Commit f096f43

Browse files
authored
fix(esp32): issues on starting touch sensor and attaching interrupt (#11967)
* Fix issues on starting touch sensor and attaching interrupt * Fix logical issues
1 parent 66fd111 commit f096f43

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

cores/esp32/esp32-hal-touch-ng.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,12 @@ bool touchDisable() {
117117
if (!enabled) { // Already disabled
118118
return true;
119119
}
120-
if (!running && (touch_sensor_disable(touch_sensor_handle) != ESP_OK)) {
121-
log_e("Touch sensor still running or disable failed!");
120+
if (running) {
121+
log_e("Touch sensor still running!");
122+
return false;
123+
}
124+
if (touch_sensor_disable(touch_sensor_handle) != ESP_OK) {
125+
log_e("Touch sensor disable failed!");
122126
return false;
123127
}
124128
enabled = false;
@@ -129,8 +133,12 @@ bool touchStart() {
129133
if (running) { // Already running
130134
return true;
131135
}
132-
if (enabled && (touch_sensor_start_continuous_scanning(touch_sensor_handle) != ESP_OK)) {
133-
log_e("Touch sensor not enabled or failed to start continuous scanning failed!");
136+
if (!enabled) {
137+
log_e("Touch sensor not enabled!");
138+
return false;
139+
}
140+
if (touch_sensor_start_continuous_scanning(touch_sensor_handle) != ESP_OK) {
141+
log_e("Touch sensor failed to start continuous scanning!");
134142
return false;
135143
}
136144
running = true;
@@ -395,7 +403,7 @@ static void __touchConfigInterrupt(uint8_t pin, void (*userFunc)(void), void *Ar
395403
return;
396404
}
397405

398-
touch_channel_config_t chan_cfg = {};
406+
touch_channel_config_t chan_cfg = TOUCH_CHANNEL_DEFAULT_CONFIG();
399407
for (int i = 0; i < _sample_num; i++) {
400408
#if SOC_TOUCH_SENSOR_VERSION == 1 // ESP32
401409
chan_cfg.abs_active_thresh[i] = threshold;
@@ -416,17 +424,17 @@ static void __touchConfigInterrupt(uint8_t pin, void (*userFunc)(void), void *Ar
416424

417425
// it keeps backwards compatibility
418426
static void __touchAttachInterrupt(uint8_t pin, void (*userFunc)(void), touch_value_t threshold) {
419-
__touchConfigInterrupt(pin, userFunc, NULL, threshold, false);
427+
__touchConfigInterrupt(pin, userFunc, NULL, false, threshold);
420428
}
421429

422430
// new additional version of the API with User Args
423431
static void __touchAttachArgsInterrupt(uint8_t pin, void (*userFunc)(void), void *args, touch_value_t threshold) {
424-
__touchConfigInterrupt(pin, userFunc, args, threshold, true);
432+
__touchConfigInterrupt(pin, userFunc, args, true, threshold);
425433
}
426434

427435
// new additional API to detach touch ISR
428436
static void __touchDettachInterrupt(uint8_t pin) {
429-
__touchConfigInterrupt(pin, NULL, NULL, 0, false); // userFunc as NULL acts as detaching
437+
__touchConfigInterrupt(pin, NULL, NULL, false, 0); // userFunc as NULL acts as detaching
430438
}
431439

432440
// /*

0 commit comments

Comments
 (0)