|
31 | 31 |
|
32 | 32 | #include "src/rp2_common/hardware_gpio/include/hardware/gpio.h"
|
33 | 33 |
|
| 34 | +static uint32_t gpio_bank0_pin_claimed; |
| 35 | + |
34 | 36 | #if CIRCUITPY_CYW43
|
35 | 37 | #include "bindings/cyw43/__init__.h"
|
36 | 38 | #include "pico/cyw43_arch.h"
|
@@ -71,13 +73,24 @@ void never_reset_pin_number(uint8_t pin_number) {
|
71 | 73 | never_reset_pins |= 1 << pin_number;
|
72 | 74 | }
|
73 | 75 |
|
| 76 | +// By default, all pins get reset in the same way |
| 77 | +MP_WEAK bool board_reset_pin_number(uint8_t pin_number) { |
| 78 | + return false; |
| 79 | +} |
| 80 | + |
74 | 81 | void reset_pin_number(uint8_t pin_number) {
|
75 | 82 | if (pin_number >= NUM_BANK0_GPIOS) {
|
76 | 83 | return;
|
77 | 84 | }
|
78 | 85 |
|
| 86 | + gpio_bank0_pin_claimed &= ~(1 << pin_number); |
79 | 87 | never_reset_pins &= ~(1 << pin_number);
|
80 | 88 |
|
| 89 | + // Allow the board to override the reset state of any pin |
| 90 | + if (board_reset_pin_number(pin_number)) { |
| 91 | + return; |
| 92 | + } |
| 93 | + |
81 | 94 | // We are very aggressive in shutting down the pad fully. Both pulls are
|
82 | 95 | // disabled and both buffers are as well.
|
83 | 96 | gpio_init(pin_number);
|
@@ -105,19 +118,20 @@ void claim_pin(const mcu_pin_obj_t *pin) {
|
105 | 118 | #if CIRCUITPY_CYW43
|
106 | 119 | if (pin->base.type == &cyw43_pin_type) {
|
107 | 120 | cyw_pin_claimed |= (1 << pin->number);
|
| 121 | + return; |
108 | 122 | }
|
109 | 123 | #endif
|
110 |
| - // Nothing to do because all changes will set the GPIO settings. |
| 124 | + if (pin->number >= NUM_BANK0_GPIOS) { |
| 125 | + return; |
| 126 | + } |
| 127 | + gpio_bank0_pin_claimed |= (1 << pin->number); |
111 | 128 | }
|
112 | 129 |
|
113 | 130 | bool pin_number_is_free(uint8_t pin_number) {
|
114 | 131 | if (pin_number >= NUM_BANK0_GPIOS) {
|
115 | 132 | return false;
|
116 | 133 | }
|
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; |
| 134 | + return !(gpio_bank0_pin_claimed & (1 << pin_number)); |
121 | 135 | }
|
122 | 136 |
|
123 | 137 | bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t *pin) {
|
|
0 commit comments