@@ -100,7 +100,9 @@ static const uint64_t pin_mask_reset_forbidden =
100
100
101
101
102
102
void never_reset_pin_number (gpio_num_t pin_number ) {
103
- if (pin_number == NO_PIN ) {
103
+ // Some CircuitPython APIs deal in uint8_t pin numbers, but NO_PIN is -1.
104
+ // Also allow pin 255 to be treated as NO_PIN to avoid crashes
105
+ if (pin_number == NO_PIN || pin_number == (uint8_t )NO_PIN ) {
104
106
return ;
105
107
}
106
108
never_reset_pins |= PIN_BIT (pin_number );
@@ -141,7 +143,9 @@ STATIC void _reset_pin(gpio_num_t pin_number) {
141
143
142
144
// Mark pin as free and return it to a quiescent state.
143
145
void reset_pin_number (gpio_num_t pin_number ) {
144
- if (pin_number == NO_PIN ) {
146
+ // Some CircuitPython APIs deal in uint8_t pin numbers, but NO_PIN is -1.
147
+ // Also allow pin 255 to be treated as NO_PIN to avoid crashes
148
+ if (pin_number == NO_PIN || pin_number == (uint8_t )NO_PIN ) {
145
149
return ;
146
150
}
147
151
never_reset_pins &= ~PIN_BIT (pin_number );
@@ -174,7 +178,9 @@ void reset_all_pins(void) {
174
178
}
175
179
176
180
void claim_pin_number (gpio_num_t pin_number ) {
177
- if (pin_number == NO_PIN ) {
181
+ // Some CircuitPython APIs deal in uint8_t pin numbers, but NO_PIN is -1.
182
+ // Also allow pin 255 to be treated as NO_PIN to avoid crashes
183
+ if (pin_number == NO_PIN || pin_number == (uint8_t )NO_PIN ) {
178
184
return ;
179
185
}
180
186
in_use |= PIN_BIT (pin_number );
0 commit comments