micropython: fix bug

This commit is contained in:
KY-zhang-X
2022-10-12 13:58:50 +08:00
parent 3e4ceb8afe
commit ed310f51bf
3 changed files with 8 additions and 6 deletions

View File

@@ -155,14 +155,14 @@ STATIC mp_obj_t machine_pin_obj_init_helper(machine_pin_obj_t *self, size_t n_ar
mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("invalid pin mode: %d"), mode);
}
// if given, set the pin value before initialising to prevent glitches
// configure the GPIO as requested
mp_hal_pin_config(self, mode);
// set the pin value
if (args[ARG_value].u_obj != MP_OBJ_NULL) {
mp_hal_pin_write(self, mp_obj_is_true(args[ARG_value].u_obj));
}
// configure the GPIO as requested
mp_hal_pin_config(self, mode);
return mp_const_none;
}