Skip to content

Commit 0a36580

Browse files
committed
fix(touch): Update example and fix config
1 parent 41287a3 commit 0a36580

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include "soc/soc_caps.h"
1515

1616
#if SOC_TOUCH_SENSOR_SUPPORTED
17-
//#if SOC_TOUCH_SENSOR_VERSION == 3 // ESP32P4 for now
1817

1918
#include "esp32-hal-touch-ng.h"
2019
#include "esp32-hal-periman.h"
@@ -228,7 +227,7 @@ static void __touchInit() {
228227
#elif SOC_TOUCH_SENSOR_VERSION == 2 // ESP32S2, ESP32S3
229228
touch_sensor_sample_config_t single_sample_cfg = TOUCH_SENSOR_V2_DEFAULT_SAMPLE_CONFIG(_duration_ms, _volt_low, _volt_high);
230229
#elif SOC_TOUCH_SENSOR_VERSION == 3 // ESP32P4
231-
touch_sensor_sample_config_t single_sample_cfg = TOUCH_SENSOR_V3_DEFAULT_SAMPLE_CONFIG(_sample_num, _div_num, _coarse_freq_tune, _fine_freq_tune);
230+
touch_sensor_sample_config_t single_sample_cfg = TOUCH_SENSOR_V3_DEFAULT_SAMPLE_CONFIG(_div_num, _coarse_freq_tune, _fine_freq_tune);
232231
#endif
233232
touch_sensor_sample_config_t sample_cfg[_sample_num] = {};
234233
sample_cfg[0] = single_sample_cfg;
@@ -532,5 +531,4 @@ extern void touchAttachInterrupt(uint8_t, voidFuncPtr, touch_value_t) __attribut
532531
extern void touchAttachInterruptArg(uint8_t, voidArgFuncPtr, void *, touch_value_t) __attribute__((weak, alias("__touchAttachArgsInterrupt")));
533532
extern void touchDetachInterrupt(uint8_t) __attribute__((weak, alias("__touchDettachInterrupt")));
534533

535-
//#endif /* SOC_TOUCH_SENSOR_VERSION == 3 */
536534
#endif /* SOC_TOUCH_SENSOR_SUPPORTED */

libraries/ESP32/examples/Touch/TouchInterrupt/TouchInterrupt.ino

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@ This is an example how to use Touch Intrrerupts
33
The bigger the threshold, the more sensible is the touch
44
*/
55

6-
#if CONFIG_IDF_TARGET_ESP32P4
7-
int threshold = 0; // when 0 is used, the benchmarked value will be used
8-
#else
9-
int threshold = 40;
10-
#endif
6+
int threshold = 0; // if 0 is used, benchmark value is used. Its by default 1,5% change, can be changed by touchSetDefaultThreshold(float percentage)
117

128
bool touch1detected = false;
139
bool touch2detected = false;
@@ -23,6 +19,10 @@ void gotTouch2() {
2319
void setup() {
2420
Serial.begin(115200);
2521
delay(1000); // give me time to bring up serial monitor
22+
23+
//Optional: Set the threshold to 5% of the benchmark value. Only effective if threshold = 0.
24+
touchSetDefaultThreshold(5);
25+
2626
Serial.println("ESP32 Touch Interrupt Test");
2727
touchAttachInterrupt(T2, gotTouch1, threshold);
2828
touchAttachInterrupt(T3, gotTouch2, threshold);
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// ESP32 Touch Test
2-
// Just test touch pin - Touch0 is T0 which is on GPIO 4.
2+
// Just test touch pin - Touch2 is T2 which is on GPIO 2.
33

44
void setup() {
55
Serial.begin(115200);
@@ -8,6 +8,6 @@ void setup() {
88
}
99

1010
void loop() {
11-
Serial.println(touchRead(T1)); // get value using T0
11+
Serial.println(touchRead(T2)); // get value using T2
1212
delay(1000);
1313
}

0 commit comments

Comments
 (0)