diff options
| author | Scott Shawcroft <scott@adafruit.com> | 2020-11-30 16:03:16 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-11-30 16:03:16 -0800 |
| commit | 5b3c930e384ef6440f0f7b5167bb54ea68a8be76 (patch) | |
| tree | 1dc8b0cf3e88bb09ef297276e1e269a9dc4c263f /ports | |
| parent | a975ef497162297fa80658170481f6d3fcfc25bc (diff) | |
| parent | e90cb3ad866d418803768f3a58154e0039478e56 (diff) | |
Merge pull request #3738 from microDev1/fix-touch
ESP32S2: Fix multiple touchpad don't work simultaneously
Diffstat (limited to 'ports')
| -rw-r--r-- | ports/esp32s2/common-hal/touchio/TouchIn.c | 26 | ||||
| -rw-r--r-- | ports/esp32s2/supervisor/port.c | 5 |
2 files changed, 23 insertions, 8 deletions
diff --git a/ports/esp32s2/common-hal/touchio/TouchIn.c b/ports/esp32s2/common-hal/touchio/TouchIn.c index b44234775..b27cbcf86 100644 --- a/ports/esp32s2/common-hal/touchio/TouchIn.c +++ b/ports/esp32s2/common-hal/touchio/TouchIn.c @@ -25,10 +25,19 @@ */ #include "shared-bindings/touchio/TouchIn.h" -#include "py/runtime.h" +#include "py/runtime.h" #include "driver/touch_pad.h" +bool touch_inited = false; + +void touchin_reset(void) { + if (touch_inited) { + touch_pad_deinit(); + touch_inited = false; + } +} + static uint16_t get_raw_reading(touchio_touchin_obj_t *self) { uint32_t touch_value; touch_pad_read_raw_data((touch_pad_t)self->pin->touch_channel, &touch_value); @@ -45,11 +54,14 @@ void common_hal_touchio_touchin_construct(touchio_touchin_obj_t* self, } claim_pin(pin); - touch_pad_init(); - touch_pad_config((touch_pad_t)pin->touch_channel); + if (!touch_inited) { + touch_pad_init(); + touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER); + touch_pad_fsm_start(); + touch_inited = true; + } - touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER); - touch_pad_fsm_start(); + touch_pad_config((touch_pad_t)pin->touch_channel); // wait for "raw data" to reset mp_hal_delay_ms(10); @@ -73,14 +85,12 @@ void common_hal_touchio_touchin_deinit(touchio_touchin_obj_t* self) { if (common_hal_touchio_touchin_deinited(self)) { return; } - touch_pad_deinit(); reset_pin_number(self->pin->touch_channel); self->pin = NULL; } bool common_hal_touchio_touchin_get_value(touchio_touchin_obj_t *self) { - uint16_t reading = get_raw_reading(self); - return reading > self->threshold; + return get_raw_reading(self) > self->threshold; } uint16_t common_hal_touchio_touchin_get_raw_value(touchio_touchin_obj_t *self) { diff --git a/ports/esp32s2/supervisor/port.c b/ports/esp32s2/supervisor/port.c index 264bdee97..0841081de 100644 --- a/ports/esp32s2/supervisor/port.c +++ b/ports/esp32s2/supervisor/port.c @@ -44,6 +44,7 @@ #include "common-hal/ps2io/Ps2.h" #include "common-hal/pulseio/PulseIn.h" #include "common-hal/pwmio/PWMOut.h" +#include "common-hal/touchio/TouchIn.h" #include "common-hal/watchdog/WatchDogTimer.h" #include "common-hal/wifi/__init__.h" #include "supervisor/memory.h" @@ -146,6 +147,10 @@ void reset_port(void) { rtc_reset(); #endif +#if CIRCUITPY_TOUCHIO_USE_NATIVE + touchin_reset(); +#endif + #if CIRCUITPY_WATCHDOG watchdog_reset(); #endif |
