Skip to content

Commit f8ed889

Browse files
arturo182tannewt
authored andcommitted
raspberrypi: Properly support GPIOS > 32
Oops, turns out that shifting a variable more than its type's number of bits is undefined behaviour...
1 parent 4b4773e commit f8ed889

File tree

1 file changed

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

1 file changed

+9
-9
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ bool cyw_ever_init;
2121
static uint32_t cyw_pin_claimed;
2222

2323
void reset_pin_number_cyw(uint8_t pin_no) {
24-
cyw_pin_claimed &= ~(1 << pin_no);
24+
cyw_pin_claimed &= ~(1LL << pin_no);
2525
}
2626
#endif
2727

2828
static uint64_t never_reset_pins;
2929

3030
void reset_all_pins(void) {
3131
for (size_t i = 0; i < NUM_BANK0_GPIOS; i++) {
32-
if ((never_reset_pins & (1 << i)) != 0) {
32+
if ((never_reset_pins & (1LL << i)) != 0) {
3333
continue;
3434
}
3535
reset_pin_number(i);
@@ -50,7 +50,7 @@ void never_reset_pin_number(uint8_t pin_number) {
5050
return;
5151
}
5252

53-
never_reset_pins |= 1 << pin_number;
53+
never_reset_pins |= 1LL << pin_number;
5454
}
5555

5656
// By default, all pins get reset in the same way
@@ -63,8 +63,8 @@ void reset_pin_number(uint8_t pin_number) {
6363
return;
6464
}
6565

66-
gpio_bank0_pin_claimed &= ~(1 << pin_number);
67-
never_reset_pins &= ~(1 << pin_number);
66+
gpio_bank0_pin_claimed &= ~(1LL << pin_number);
67+
never_reset_pins &= ~(1LL << pin_number);
6868

6969
// Allow the board to override the reset state of any pin
7070
if (board_reset_pin_number(pin_number)) {
@@ -97,27 +97,27 @@ void common_hal_reset_pin(const mcu_pin_obj_t *pin) {
9797
void claim_pin(const mcu_pin_obj_t *pin) {
9898
#if CIRCUITPY_CYW43
9999
if (pin->base.type == &cyw43_pin_type) {
100-
cyw_pin_claimed |= (1 << pin->number);
100+
cyw_pin_claimed |= (1LL << pin->number);
101101
return;
102102
}
103103
#endif
104104
if (pin->number >= NUM_BANK0_GPIOS) {
105105
return;
106106
}
107-
gpio_bank0_pin_claimed |= (1 << pin->number);
107+
gpio_bank0_pin_claimed |= (1LL << pin->number);
108108
}
109109

110110
bool pin_number_is_free(uint8_t pin_number) {
111111
if (pin_number >= NUM_BANK0_GPIOS) {
112112
return false;
113113
}
114-
return !(gpio_bank0_pin_claimed & (1 << pin_number));
114+
return !(gpio_bank0_pin_claimed & (1LL << pin_number));
115115
}
116116

117117
bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t *pin) {
118118
#if CIRCUITPY_CYW43
119119
if (pin->base.type == &cyw43_pin_type) {
120-
return !(cyw_pin_claimed & (1 << pin->number));
120+
return !(cyw_pin_claimed & (1LL << pin->number));
121121
}
122122
#endif
123123
return pin_number_is_free(pin->number);

0 commit comments

Comments
 (0)