From e8ea9c75a1400c105a4b7bfa3e707a06186b454e Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 30 Nov 2021 19:16:21 -0500 Subject: [PATCH] check for missing pins; deinit txrx leds --- main.c | 2 ++ ports/atmel-samd/boards/pewpew_m4/mpconfigboard.mk | 3 ++- ports/atmel-samd/common-hal/alarm/pin/PinAlarm.c | 12 ++++++++++-- supervisor/shared/status_leds.c | 9 +++++++++ supervisor/shared/status_leds.h | 1 + 5 files changed, 24 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index 413a4f5b12..b1b482f985 100644 --- a/main.c +++ b/main.c @@ -537,6 +537,8 @@ STATIC bool run_code_py(safe_mode_t safe_mode) { common_hal_alarm_pretending_deep_sleep(); } else if (connecting_delay_ticks < 0) { // Entering deep sleep (may be fake or real.) + status_led_deinit(); + deinit_rxtx_leds(); board_deinit(); if (!supervisor_workflow_active()) { // Enter true deep sleep. When we wake up we'll be back at the diff --git a/ports/atmel-samd/boards/pewpew_m4/mpconfigboard.mk b/ports/atmel-samd/boards/pewpew_m4/mpconfigboard.mk index 7c3e7eb3ed..cffbaf619a 100644 --- a/ports/atmel-samd/boards/pewpew_m4/mpconfigboard.mk +++ b/ports/atmel-samd/boards/pewpew_m4/mpconfigboard.mk @@ -11,7 +11,7 @@ LONGINT_IMPL = NONE CIRCUITPY_FULL_BUILD = 0 -CIRCUIPTY_USB_CDC = 0 +CIRCUITPY_ALARM = 0 CIRCUITPY_AUDIOBUSIO = 0 CIRCUITPY_AUDIOMP3 = 0 CIRCUITPY_AUDIOPWMIO = 0 @@ -29,6 +29,7 @@ CIRCUITPY_ROTARYIO = 0 CIRCUITPY_RTC = 0 CIRCUITPY_SAMD = 0 CIRCUITPY_TOUCHIO = 0 +CIRCUITPY_USB_CDC = 0 CIRCUITPY_USB_HID = 0 CIRCUITPY_USB_MIDI = 0 CIRCUITPY_VECTORIO = 0 diff --git a/ports/atmel-samd/common-hal/alarm/pin/PinAlarm.c b/ports/atmel-samd/common-hal/alarm/pin/PinAlarm.c index 2e1d596c39..cfd4a9f893 100644 --- a/ports/atmel-samd/common-hal/alarm/pin/PinAlarm.c +++ b/ports/atmel-samd/common-hal/alarm/pin/PinAlarm.c @@ -198,8 +198,16 @@ void alarm_pin_pinalarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_ob if (deep_sleep) { // Tamper Pins: IN0:PB00; IN1:PB02; IN2:PA02; IN3:PC00; IN4:PC01; OUT:PB01 // Only these pins can do TAMPER - if (alarm->pin != &pin_PB00 && alarm->pin != &pin_PB02 && - alarm->pin != &pin_PA02) { + if ( + #ifdef PIN_PB00 + alarm->pin != &pin_PB00 + #else + true + #endif + #ifdef PIN_PB02 + && alarm->pin != &pin_PB02 + #endif + && alarm->pin != &pin_PA02) { mp_raise_ValueError(translate("Pin cannot wake from Deep Sleep")); } pinalarm_on = true; diff --git a/supervisor/shared/status_leds.c b/supervisor/shared/status_leds.c index 92c9578051..0c433271fc 100644 --- a/supervisor/shared/status_leds.c +++ b/supervisor/shared/status_leds.c @@ -340,6 +340,15 @@ void init_rxtx_leds(void) { #endif } +void deinit_rxtx_leds(void) { + #if CIRCUITPY_DIGITALIO && defined(MICROPY_HW_LED_RX) + common_hal_digitalio_digitalinout_deinit(&rx_led); + #endif + #if CIRCUITPY_DIGITALIO && defined(MICROPY_HW_LED_TX) + common_hal_digitalio_digitalinout_deinit(&tx_led); + #endif +} + void toggle_rx_led(void) { #if CIRCUITPY_DIGITALIO && defined(MICROPY_HW_LED_RX) common_hal_digitalio_digitalinout_set_value(&rx_led, !common_hal_digitalio_digitalinout_get_value(&rx_led)); diff --git a/supervisor/shared/status_leds.h b/supervisor/shared/status_leds.h index f41ff71c68..3d2fa978a8 100644 --- a/supervisor/shared/status_leds.h +++ b/supervisor/shared/status_leds.h @@ -55,6 +55,7 @@ uint32_t color_brightness(uint32_t color, uint8_t brightness); void set_status_brightness(uint8_t level); void init_rxtx_leds(void); +void deinit_rxtx_leds(void); void toggle_rx_led(void); void toggle_tx_led(void);