From 4a6c2460083607ba05ab8af13a31889767c2ce98 Mon Sep 17 00:00:00 2001 From: Peter Harper Date: Wed, 9 Oct 2024 18:03:55 +0100 Subject: [PATCH] rp2/mphalport: Add mp_hal_is_pin_reserved() function. As cyw43 pins might be dynamic, add a function that returns if a pin is reserved. This is used by `MICROPY_HW_PIN_RESERVED` to prevent the pin IRQ from being reset across a soft-reset. Signed-off-by: Peter Harper --- ports/rp2/boards/RPI_PICO_W/mpconfigboard.h | 4 +++- ports/rp2/mphalport.c | 8 ++++++++ ports/rp2/mphalport.h | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/ports/rp2/boards/RPI_PICO_W/mpconfigboard.h b/ports/rp2/boards/RPI_PICO_W/mpconfigboard.h index ef812b6301..45ad6107ba 100644 --- a/ports/rp2/boards/RPI_PICO_W/mpconfigboard.h +++ b/ports/rp2/boards/RPI_PICO_W/mpconfigboard.h @@ -20,4 +20,6 @@ #define MICROPY_HW_PIN_EXT_COUNT CYW43_WL_GPIO_COUNT -#define MICROPY_HW_PIN_RESERVED(i) ((i) == CYW43_PIN_WL_HOST_WAKE || (i) == CYW43_PIN_WL_REG_ON) +// If this returns true for a pin then its irq will not be disabled on a soft reboot +int mp_hal_is_pin_reserved(int n); +#define MICROPY_HW_PIN_RESERVED(i) mp_hal_is_pin_reserved(i) diff --git a/ports/rp2/mphalport.c b/ports/rp2/mphalport.c index 3f50151620..caecb69509 100644 --- a/ports/rp2/mphalport.c +++ b/ports/rp2/mphalport.c @@ -278,3 +278,11 @@ void mp_wfe_or_timeout(uint32_t timeout_ms) { // Clean up the timer node if it's not already soft_timer_remove(&timer); } + +int mp_hal_is_pin_reserved(int n) { + #if MICROPY_PY_NETWORK_CYW43 + return n == CYW43_PIN_WL_HOST_WAKE; + #else + return false; + #endif +} diff --git a/ports/rp2/mphalport.h b/ports/rp2/mphalport.h index da865fb7e8..33a1073e1d 100644 --- a/ports/rp2/mphalport.h +++ b/ports/rp2/mphalport.h @@ -210,5 +210,6 @@ enum { void mp_hal_get_mac(int idx, uint8_t buf[6]); void mp_hal_get_mac_ascii(int idx, size_t chr_off, size_t chr_len, char *dest); void mp_hal_generate_laa_mac(int idx, uint8_t buf[6]); +int mp_hal_is_pin_reserved(int n); #endif // MICROPY_INCLUDED_RP2_MPHALPORT_H