File tree Expand file tree Collapse file tree
ports/raspberrypi/common-hal/microcontroller Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
113120bool 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
123127bool common_hal_mcu_pin_is_free (const mcu_pin_obj_t * pin ) {
You can’t perform that action at this time.
0 commit comments