Skip to content

Commit e06b3da

Browse files
committed
don't use pad state to track if a pin is in use
this interferes with the desire to allow a pin to be a non-default state when it "is reset"
1 parent 721b7d8 commit e06b3da

File tree

1 file changed

+9
-5
lines changed
  • ports/raspberrypi/common-hal/microcontroller

1 file changed

+9
-5
lines changed

ports/raspberrypi/common-hal/microcontroller/Pin.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131

3232
#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h"
3333

34+
static uint32_t gpio_bank0_pin_claimed;
35+
3436
#if CIRCUITPY_CYW43
3537
#include "bindings/cyw43/__init__.h"
3638
#include "pico/cyw43_arch.h"
@@ -76,6 +78,7 @@ void reset_pin_number(uint8_t pin_number) {
7678
return;
7779
}
7880

81+
gpio_bank0_pin_claimed &= ~(1 << pin_number);
7982
never_reset_pins &= ~(1 << pin_number);
8083

8184
// We are very aggressive in shutting down the pad fully. Both pulls are
@@ -105,19 +108,20 @@ void claim_pin(const mcu_pin_obj_t *pin) {
105108
#if CIRCUITPY_CYW43
106109
if (pin->base.type == &cyw43_pin_type) {
107110
cyw_pin_claimed |= (1 << pin->number);
111+
return;
108112
}
109113
#endif
110-
// Nothing to do because all changes will set the GPIO settings.
114+
if (pin->number >= NUM_BANK0_GPIOS) {
115+
return;
116+
}
117+
gpio_bank0_pin_claimed |= (1 << pin->number);
111118
}
112119

113120
bool pin_number_is_free(uint8_t pin_number) {
114121
if (pin_number >= NUM_BANK0_GPIOS) {
115122
return false;
116123
}
117-
118-
uint32_t pad_state = padsbank0_hw->io[pin_number];
119-
return (pad_state & PADS_BANK0_GPIO0_IE_BITS) == 0 &&
120-
(pad_state & PADS_BANK0_GPIO0_OD_BITS) != 0;
124+
return !(gpio_bank0_pin_claimed & (1 << pin_number));
121125
}
122126

123127
bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t *pin) {

0 commit comments

Comments
 (0)