From ee48e4b4528b7cfea7f568d83eb31c0fde1867d8 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Mon, 18 Jan 2021 11:52:03 -0500 Subject: [PATCH] ESP32-S2: Initialize touch in proper order --- ports/esp32s2/peripherals/touch.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ports/esp32s2/peripherals/touch.c b/ports/esp32s2/peripherals/touch.c index 6cf33b2bde..cd895b10be 100644 --- a/ports/esp32s2/peripherals/touch.c +++ b/ports/esp32s2/peripherals/touch.c @@ -46,8 +46,13 @@ void peripherals_touch_init(const touch_pad_t touchpad) { if (!touch_inited) { touch_pad_init(); touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER); + } + // touch_pad_config() must be done before touch_pad_fsm_start() the first time. + // Otherwise the calibration is wrong and we get maximum raw values if there is + // a trace of any significant length on the pin. + touch_pad_config(touchpad); + if (!touch_inited) { touch_pad_fsm_start(); touch_inited = true; } - touch_pad_config(touchpad); }