Skip to content

Commit ea382df

Browse files
Refactor touch pad error logging (#11878)
- Removed duplicated log_e("No touch pad on selected pin!") calls from multiple functions. - Centralized the error log inside digitalPinToTouchChannel(). - Extended the error message to include the pin number for better debugging context. - Added log_e() in digitalPinToTouchChannel() when no touch sensor is available on the chip. Co-authored-by: Me No Dev <me-no-dev@users.noreply.github.com>
1 parent c2bd3c9 commit ea382df

File tree

3 files changed

+5
-10
lines changed

3 files changed

+5
-10
lines changed

cores/esp32/esp32-hal-gpio.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,21 @@
3333
#include "soc/touch_sensor_periph.h"
3434

3535
int8_t digitalPinToTouchChannel(uint8_t pin) {
36-
int8_t ret = -1;
3736
if (pin < SOC_GPIO_PIN_COUNT) {
3837
for (uint8_t i = 0; i < SOC_TOUCH_SENSOR_NUM; i++) {
3938
if (touch_sensor_channel_io_map[i] == pin) {
40-
ret = i;
41-
break;
39+
return i;
4240
}
4341
}
4442
}
45-
return ret;
43+
44+
log_e("No touch pad on selected pin(%u)!", pin);
45+
return -1;
4646
}
4747
#else
4848
// No Touch Sensor available
4949
int8_t digitalPinToTouchChannel(uint8_t pin) {
50+
log_e("Touch sensor not available on this chip");
5051
return -1;
5152
}
5253
#endif

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,6 @@ static void __touchChannelInit(int pad) {
332332
static touch_value_t __touchRead(uint8_t pin) {
333333
int8_t pad = digitalPinToTouchChannel(pin);
334334
if (pad < 0) {
335-
log_e(" No touch pad on selected pin!");
336335
return 0;
337336
}
338337

@@ -360,7 +359,6 @@ static touch_value_t __touchRead(uint8_t pin) {
360359
static void __touchConfigInterrupt(uint8_t pin, void (*userFunc)(void), void *Args, bool callWithArgs, touch_value_t threshold) {
361360
int8_t pad = digitalPinToTouchChannel(pin);
362361
if (pad < 0) {
363-
log_e(" No touch pad on selected pin!");
364362
return;
365363
}
366364

@@ -446,7 +444,6 @@ bool touchInterruptGetLastStatus(uint8_t pin) {
446444
void touchSleepWakeUpEnable(uint8_t pin, touch_value_t threshold) {
447445
int8_t pad = digitalPinToTouchChannel(pin);
448446
if (pad < 0) {
449-
log_e(" No touch pad on selected pin!");
450447
return;
451448
}
452449

cores/esp32/esp32-hal-touch.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,6 @@ static void __touchChannelInit(int pad) {
206206
static touch_value_t __touchRead(uint8_t pin) {
207207
int8_t pad = digitalPinToTouchChannel(pin);
208208
if (pad < 0) {
209-
log_e(" No touch pad on selected pin!");
210209
return 0;
211210
}
212211

@@ -233,7 +232,6 @@ static touch_value_t __touchRead(uint8_t pin) {
233232
static void __touchConfigInterrupt(uint8_t pin, void (*userFunc)(void), void *Args, touch_value_t threshold, bool callWithArgs) {
234233
int8_t pad = digitalPinToTouchChannel(pin);
235234
if (pad < 0) {
236-
log_e(" No touch pad on selected pin!");
237235
return;
238236
}
239237

@@ -295,7 +293,6 @@ bool touchInterruptGetLastStatus(uint8_t pin) {
295293
void touchSleepWakeUpEnable(uint8_t pin, touch_value_t threshold) {
296294
int8_t pad = digitalPinToTouchChannel(pin);
297295
if (pad < 0) {
298-
log_e(" No touch pad on selected pin!");
299296
return;
300297
}
301298

0 commit comments

Comments
 (0)