Browse Source

rp2/mphalport: Change order of pin operations to prevent glitches.

When switching from a special function like SPI to an input or output,
there was a brief period after the function was disabled but before the
pin's I/O state was configured, in which the state would be poorly defined.
This fixes the problem by switching off the special function after fully
configuring the I/O state.

Fixes #10226.

Signed-off-by: Paul Grayson <pdg@alum.mit.edu>
pull/10337/head
Paul Grayson 2 years ago
committed by Damien George
parent
commit
b208cf23e2
  1. 6
      ports/rp2/mphalport.h

6
ports/rp2/mphalport.h

@ -91,22 +91,22 @@ static inline unsigned int mp_hal_pin_name(mp_hal_pin_obj_t pin) {
} }
static inline void mp_hal_pin_input(mp_hal_pin_obj_t pin) { static inline void mp_hal_pin_input(mp_hal_pin_obj_t pin) {
gpio_set_function(pin, GPIO_FUNC_SIO);
gpio_set_dir(pin, GPIO_IN); gpio_set_dir(pin, GPIO_IN);
machine_pin_open_drain_mask &= ~(1 << pin); machine_pin_open_drain_mask &= ~(1 << pin);
gpio_set_function(pin, GPIO_FUNC_SIO);
} }
static inline void mp_hal_pin_output(mp_hal_pin_obj_t pin) { static inline void mp_hal_pin_output(mp_hal_pin_obj_t pin) {
gpio_set_function(pin, GPIO_FUNC_SIO);
gpio_set_dir(pin, GPIO_OUT); gpio_set_dir(pin, GPIO_OUT);
machine_pin_open_drain_mask &= ~(1 << pin); machine_pin_open_drain_mask &= ~(1 << pin);
gpio_set_function(pin, GPIO_FUNC_SIO);
} }
static inline void mp_hal_pin_open_drain(mp_hal_pin_obj_t pin) { static inline void mp_hal_pin_open_drain(mp_hal_pin_obj_t pin) {
gpio_set_function(pin, GPIO_FUNC_SIO);
gpio_set_dir(pin, GPIO_IN); gpio_set_dir(pin, GPIO_IN);
gpio_put(pin, 0); gpio_put(pin, 0);
machine_pin_open_drain_mask |= 1 << pin; machine_pin_open_drain_mask |= 1 << pin;
gpio_set_function(pin, GPIO_FUNC_SIO);
} }
static inline void mp_hal_pin_config(mp_hal_pin_obj_t pin, uint32_t mode, uint32_t pull, uint32_t alt) { static inline void mp_hal_pin_config(mp_hal_pin_obj_t pin, uint32_t mode, uint32_t pull, uint32_t alt) {

Loading…
Cancel
Save