Skip to content

Commit 048ca2a

Browse files
committed
get multiple touchpad working
1 parent 2f14609 commit 048ca2a

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

ports/esp32s2/common-hal/touchio/TouchIn.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@
2525
*/
2626

2727
#include "shared-bindings/touchio/TouchIn.h"
28-
#include "py/runtime.h"
2928

29+
#include "py/runtime.h"
3030
#include "driver/touch_pad.h"
3131

32+
bool touch_inited = false;
33+
3234
static uint16_t get_raw_reading(touchio_touchin_obj_t *self) {
3335
uint32_t touch_value;
3436
touch_pad_read_raw_data((touch_pad_t)self->pin->touch_channel, &touch_value);
@@ -45,11 +47,14 @@ void common_hal_touchio_touchin_construct(touchio_touchin_obj_t* self,
4547
}
4648
claim_pin(pin);
4749

48-
touch_pad_init();
49-
touch_pad_config((touch_pad_t)pin->touch_channel);
50+
if (!touch_inited) {
51+
touch_pad_init();
52+
touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER);
53+
touch_pad_fsm_start();
54+
touch_inited = true;
55+
}
5056

51-
touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER);
52-
touch_pad_fsm_start();
57+
touch_pad_config((touch_pad_t)pin->touch_channel);
5358

5459
// wait for "raw data" to reset
5560
mp_hal_delay_ms(10);
@@ -79,8 +84,7 @@ void common_hal_touchio_touchin_deinit(touchio_touchin_obj_t* self) {
7984
}
8085

8186
bool common_hal_touchio_touchin_get_value(touchio_touchin_obj_t *self) {
82-
uint16_t reading = get_raw_reading(self);
83-
return reading > self->threshold;
87+
return get_raw_reading(self) > self->threshold;
8488
}
8589

8690
uint16_t common_hal_touchio_touchin_get_raw_value(touchio_touchin_obj_t *self) {

0 commit comments

Comments
 (0)