Merge pull request #3738 from microDev1/fix-touch
ESP32S2: Fix multiple touchpad don't work simultaneously
This commit is contained in:
commit
5b3c930e38
@ -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) {
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user