From 8a917ad2529ea3df5f47e2be5b4edf362d2d03f6 Mon Sep 17 00:00:00 2001 From: Jonathan Hogg Date: Mon, 9 Nov 2020 13:11:52 +0000 Subject: [PATCH] esp32/machine_pin: Reset pin if init sets mode. This will forcibly grab the pin back from the ADC if it has previously been associated with it. Fixes #5771. --- ports/esp32/machine_pin.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ports/esp32/machine_pin.c b/ports/esp32/machine_pin.c index a55cc1f4ab..dcdd53be92 100644 --- a/ports/esp32/machine_pin.c +++ b/ports/esp32/machine_pin.c @@ -150,6 +150,11 @@ STATIC mp_obj_t machine_pin_obj_init_helper(const machine_pin_obj_t *self, size_ mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + // reset the pin first if this is a mode-setting init (grab it back from ADC) + if (args[ARG_mode].u_obj != mp_const_none) { + gpio_reset_pin(self->id); + } + // configure the pin for gpio gpio_pad_select_gpio(self->id);