Skip to content

RP2040: add GP15 #4063

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ports/raspberrypi/boards/raspberry_pi_pico/pins.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_GP12), MP_ROM_PTR(&pin_GPIO12) },
{ MP_ROM_QSTR(MP_QSTR_GP13), MP_ROM_PTR(&pin_GPIO13) },
{ MP_ROM_QSTR(MP_QSTR_GP14), MP_ROM_PTR(&pin_GPIO14) },
{ MP_ROM_QSTR(MP_QSTR_GP15), MP_ROM_PTR(&pin_GPIO15) },
{ MP_ROM_QSTR(MP_QSTR_GP16), MP_ROM_PTR(&pin_GPIO16) },
{ MP_ROM_QSTR(MP_QSTR_GP17), MP_ROM_PTR(&pin_GPIO17) },
{ MP_ROM_QSTR(MP_QSTR_GP18), MP_ROM_PTR(&pin_GPIO18) },
Expand Down
21 changes: 6 additions & 15 deletions ports/raspberrypi/common-hal/microcontroller/Pin.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include "py/runtime.h"

#include "common-hal/microcontroller/__init__.h"
#include "shared-bindings/microcontroller/Pin.h"

#include "supervisor/shared/rgb_led_status.h"
Expand All @@ -46,7 +47,7 @@ bool speaker_enable_in_use;
STATIC uint32_t never_reset_pins;

void reset_all_pins(void) {
for (size_t i = 0; i < 30; i++) {
for (size_t i = 0; i < TOTAL_GPIO_COUNT; i++) {
if ((never_reset_pins & (1 << i)) != 0) {
continue;
}
Expand All @@ -55,20 +56,15 @@ void reset_all_pins(void) {
}

void never_reset_pin_number(uint8_t pin_number) {
if (pin_number >= 32) {
if (pin_number >= TOTAL_GPIO_COUNT) {
return;
}

never_reset_pins |= 1 << pin_number;
}

void reset_pin_number(uint8_t pin_number) {
if (pin_number >= 32
#if TUD_OPT_RP2040_USB_DEVICE_ENUMERATION_FIX
// Pin 15 is used for Errata so we don't mess with it.
|| pin_number == 15
#endif
) {
if (pin_number >= TOTAL_GPIO_COUNT) {
return;
}

Expand Down Expand Up @@ -139,15 +135,10 @@ void claim_pin(const mcu_pin_obj_t* pin) {
}

bool pin_number_is_free(uint8_t pin_number) {
if (pin_number >= 30) {
if (pin_number >= TOTAL_GPIO_COUNT) {
return false;
}
#if TUD_OPT_RP2040_USB_DEVICE_ENUMERATION_FIX
// Pin 15 is used for Errata so we don't mess with it.
if (pin_number == 15) {
return true;
}
#endif

uint32_t pad_state = padsbank0_hw->io[pin_number];
return (pad_state & PADS_BANK0_GPIO0_IE_BITS) == 0 &&
(pad_state & PADS_BANK0_GPIO0_OD_BITS) != 0;
Expand Down