Skip to content

Commit 8a917ad

Browse files
jonathanhoggdpgeorge
authored andcommitted
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 micropython#5771.
1 parent b04240c commit 8a917ad

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

ports/esp32/machine_pin.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ STATIC mp_obj_t machine_pin_obj_init_helper(const machine_pin_obj_t *self, size_
150150
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
151151
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
152152

153+
// reset the pin first if this is a mode-setting init (grab it back from ADC)
154+
if (args[ARG_mode].u_obj != mp_const_none) {
155+
gpio_reset_pin(self->id);
156+
}
157+
153158
// configure the pin for gpio
154159
gpio_pad_select_gpio(self->id);
155160

0 commit comments

Comments
 (0)