@@ -43,21 +43,14 @@ uint8_t TOUCH_GPIOS[] = {2, 3, 4, 5, 6 /*, 7, 8, 9, 10, 11, 12 ,13, 14, 15*/};
4343#define NO_TOUCH_GPIO 17
4444#endif
4545
46+ #define INTERRUPT_THRESHOLD 0 // Use benchmarked threshold
47+
4648#if CONFIG_IDF_TARGET_ESP32
47- #define RELEASED_VALUE 75 // 75+ read value to pass test
48- #define PRESSED_VALUE 20 // 20- read value to pass test
49- #define INTERRUPT_THRESHOLD 40
50- #elif CONFIG_IDF_TARGET_ESP32S2
51- #define RELEASED_VALUE 10000 // 10000- read value to pass test
52- #define PRESSED_VALUE 42000 // 40000+ read value to pass test
53- #define INTERRUPT_THRESHOLD 30000
54- #elif CONFIG_IDF_TARGET_ESP32S3
55- #define RELEASED_VALUE 25000 // 25000- read value to pass test
56- #define PRESSED_VALUE 90000 // 90000+ read value to pass test
57- #define INTERRUPT_THRESHOLD 80000
58- #elif CONFIG_IDF_TARGET_ESP32P4
49+ #define PRESSED_VALUE_DIFFERENCE 200 // -200 read value difference against the unpressed value
50+ #elif CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32S2
51+ #define PRESSED_VALUE_DIFFERENCE 2000 // 2000+ read value difference against the unpressed value
52+ #elif CONFIG_IDF_TARGET_ESP32P4 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
5953#define PRESSED_VALUE_DIFFERENCE 200 // 200+ read value difference against the unpressed value
60- #define INTERRUPT_THRESHOLD 0 // Use benchmarked threshold
6154#else
6255#error Test not currently supported on this chip. Please adjust and try again!
6356#endif
@@ -109,31 +102,6 @@ void tearDown(void) {
109102 * Test Touch read on all available channels - compare values if reading is right
110103 */
111104void test_touch_read (void ) {
112-
113- #if SOC_TOUCH_SENSOR_VERSION <= 2
114- // TEST RELEASE STATE
115- for (int i = 0 ; i < sizeof (TOUCH_GPIOS); i++) {
116- #ifdef CONFIG_IDF_TARGET_ESP32
117- TEST_ASSERT_GREATER_THAN (RELEASED_VALUE, touchRead (TOUCH_GPIOS[i]));
118- #else
119- TEST_ASSERT_LESS_THAN (RELEASED_VALUE, touchRead (TOUCH_GPIOS[i]));
120- #endif
121- }
122-
123- // TEST PRESS STATE
124- for (int j = 0 ; j < TEST_TOUCH_CHANNEL; j++) {
125- test_press_fake (touch_list[j]);
126- }
127- delay (100 );
128-
129- for (int k = 0 ; k < sizeof (TOUCH_GPIOS); k++) {
130- #ifdef CONFIG_IDF_TARGET_ESP32
131- TEST_ASSERT_LESS_THAN (PRESSED_VALUE, touchRead (TOUCH_GPIOS[k]));
132- #else
133- TEST_ASSERT_GREATER_THAN (PRESSED_VALUE, touchRead (TOUCH_GPIOS[k]));
134- #endif
135- }
136- #else // TOUCH V3
137105 // TEST RELEASE STATE
138106 touch_value_t touch_unpressed[sizeof (TOUCH_GPIOS)];
139107 for (int i = 0 ; i < sizeof (TOUCH_GPIOS); i++) {
@@ -151,11 +119,14 @@ void test_touch_read(void) {
151119 touch_pressed[k] = touchRead (TOUCH_GPIOS[k]);
152120 }
153121
154- // COMPARE PRESSED > UNPRESSED
122+ // COMPARE PRESSED <- > UNPRESSED
155123 for (int l = 0 ; l < sizeof (TOUCH_GPIOS); l++) {
124+ #if CONFIG_IDF_TARGET_ESP32
125+ TEST_ASSERT_LESS_THAN ((touch_unpressed[l] - PRESSED_VALUE_DIFFERENCE), touch_pressed[l]);
126+ #else
156127 TEST_ASSERT_GREATER_THAN ((touch_unpressed[l] + PRESSED_VALUE_DIFFERENCE), touch_pressed[l]);
157- }
158128#endif
129+ }
159130}
160131
161132void test_touch_interrtupt (void ) {
@@ -166,7 +137,6 @@ void test_touch_interrtupt(void) {
166137 test_press_fake (touch_list[0 ]);
167138 test_press_fake (touch_list[1 ]);
168139
169- delay (300 );
170140
171141 touchDetachInterrupt (TOUCH_GPIOS[0 ]);
172142 touchDetachInterrupt (TOUCH_GPIOS[1 ]);
0 commit comments