Skip to content
Open
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
6 changes: 6 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,12 @@ static bool __attribute__((noinline)) run_code_py(safe_mode_t safe_mode, bool *s
#if CIRCUITPY_DISPLAYIO
common_hal_displayio_auto_primary_display();
#endif
// Undo any preserve_dios.
#if CIRCUITPY_ALARM_PRESERVE_DIOS
common_hal_alarm_clear_pin_preservations();
#endif
// Reset pins, as if there was a hard reset.
reset_all_pins();
// Pretend that the next run is the first run, as if we were reset.
*simulate_reset = true;
}
Expand Down
3 changes: 0 additions & 3 deletions ports/atmel-samd/common-hal/alarm/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,6 @@ mp_obj_t common_hal_alarm_light_sleep_until_alarms(size_t n_alarms, const mp_obj
}

void common_hal_alarm_set_deep_sleep_alarms(size_t n_alarms, const mp_obj_t *alarms, size_t n_dios, digitalio_digitalinout_obj_t **preserve_dios) {
if (n_dios > 0) {
mp_raise_NotImplementedError_varg(MP_ERROR_TEXT("%q"), MP_QSTR_preserve_dios);
}
_setup_sleep_alarms(true, n_alarms, alarms);
}

Expand Down
2 changes: 1 addition & 1 deletion ports/espressif/common-hal/alarm/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ void MP_NORETURN common_hal_alarm_enter_deep_sleep(void) {
#endif

// We no longer need to remember the pin preservations, since any pin resets are all done.
clear_pin_preservations();
common_hal_alarm_clear_pin_preservations();

// The ESP-IDF caches the deep sleep settings and applies them before sleep.
// We don't need to worry about resetting them in the interim.
Expand Down
3 changes: 2 additions & 1 deletion ports/espressif/common-hal/microcontroller/Pin.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "shared-bindings/microcontroller/Pin.h"
#include "shared-bindings/digitalio/DigitalInOut.h"
#include "shared-bindings/alarm/__init__.h"

#include "py/mphal.h"

Expand Down Expand Up @@ -368,7 +369,7 @@ void preserve_pin_number(gpio_num_t pin_number) {
}
}

void clear_pin_preservations(void) {
void common_hal_alarm_clear_pin_preservations(void) {
_preserved_pin_mask = 0;
}

Expand Down
1 change: 0 additions & 1 deletion ports/espressif/common-hal/microcontroller/Pin.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ extern bool pin_number_is_free(gpio_num_t pin_number);
extern void never_reset_pin_number(gpio_num_t pin_number);

extern void preserve_pin_number(gpio_num_t pin_number);
extern void clear_pin_preservations(void);

// Allow the board to reset a pin in a board-specific way. This can be used
// for LEDs or enable pins to put them in a state beside the default pull-up.
Expand Down
1 change: 1 addition & 0 deletions ports/espressif/mpconfigport.mk
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ CIRCUITPY_LIBC_STRING0 = 0
# These modules are implemented in ports/<port>/common-hal:
CIRCUITPY__EVE ?= 1
CIRCUITPY_ALARM ?= 1
CIRCUITPY_ALARM_PRESERVE_DIOS ?= 1
CIRCUITPY_ALARM_TOUCH ?= 1
CIRCUITPY_ANALOGBUFIO ?= 1
CIRCUITPY_AUDIOBUSIO ?= 1
Expand Down
3 changes: 0 additions & 3 deletions ports/nordic/common-hal/alarm/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,6 @@ mp_obj_t common_hal_alarm_light_sleep_until_alarms(size_t n_alarms, const mp_obj
}

void common_hal_alarm_set_deep_sleep_alarms(size_t n_alarms, const mp_obj_t *alarms, size_t n_dios, digitalio_digitalinout_obj_t **preserve_dios) {
if (n_dios > 0) {
mp_raise_NotImplementedError_varg(MP_ERROR_TEXT("%q"), MP_QSTR_preserve_dios);
}
_setup_sleep_alarms(true, n_alarms, alarms);
}

Expand Down
3 changes: 0 additions & 3 deletions ports/raspberrypi/common-hal/alarm/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,6 @@ mp_obj_t common_hal_alarm_light_sleep_until_alarms(size_t n_alarms, const mp_obj
}

void common_hal_alarm_set_deep_sleep_alarms(size_t n_alarms, const mp_obj_t *alarms, size_t n_dios, digitalio_digitalinout_obj_t **preserve_dios) {
if (n_dios > 0) {
mp_raise_NotImplementedError_varg(MP_ERROR_TEXT("%q"), MP_QSTR_preserve_dios);
}
_setup_sleep_alarms(true, n_alarms, alarms);
}
Comment thread
dhalbert marked this conversation as resolved.

Expand Down
3 changes: 0 additions & 3 deletions ports/stm/common-hal/alarm/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,6 @@ mp_obj_t common_hal_alarm_light_sleep_until_alarms(size_t n_alarms, const mp_obj
}

void common_hal_alarm_set_deep_sleep_alarms(size_t n_alarms, const mp_obj_t *alarms, size_t n_dios, digitalio_digitalinout_obj_t **preserve_dios) {
if (n_dios > 0) {
mp_raise_NotImplementedError_varg(MP_ERROR_TEXT("%q"), MP_QSTR_preserve_dios);
}
_setup_sleep_alarms(true, n_alarms, alarms);
}

Expand Down
4 changes: 4 additions & 0 deletions py/circuitpy_mpconfig.mk
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ CFLAGS += -DCIRCUITPY_AESIO=$(CIRCUITPY_AESIO)
CIRCUITPY_ALARM ?= 0
CFLAGS += -DCIRCUITPY_ALARM=$(CIRCUITPY_ALARM)

# Whether `alarm.exit_and_deep_sleep_until_alarms()` supports `preserve_dios`.
CIRCUITPY_ALARM_PRESERVE_DIOS ?= 0
CFLAGS += -DCIRCUITPY_ALARM_PRESERVE_DIOS=$(CIRCUITPY_ALARM_PRESERVE_DIOS)

CIRCUITPY_ALARM_TOUCH ?= $(CIRCUITPY_ALARM)
CFLAGS += -DCIRCUITPY_ALARM_TOUCH=$(CIRCUITPY_ALARM_TOUCH)

Expand Down
7 changes: 7 additions & 0 deletions shared-bindings/alarm/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(alarm_light_sleep_until_alarms_obj, 1, MP_OB
//|
//| Preserving `DigitalInOut` states during deep sleep can be used to ensure that
//| external or on-board devices are powered or unpowered during sleep, among other purposes.
//| Once the board wakes up from deep sleep, the `DigitalInOut` states are no longer preserved
//| and must be restored by your code.
//|
//| On some microcontrollers, some pins cannot remain in their original state for hardware reasons.
//|
Expand Down Expand Up @@ -193,6 +195,11 @@ static mp_obj_t alarm_exit_and_deep_sleep_until_alarms(size_t n_args, const mp_o

mp_obj_t preserve_dios = args[ARG_preserve_dios].u_obj;
const size_t num_dios = (size_t)MP_OBJ_SMALL_INT_VALUE(mp_obj_len(preserve_dios));
#if !CIRCUITPY_ALARM_PRESERVE_DIOS
if (num_dios > 0) {
mp_raise_NotImplementedError_varg(MP_ERROR_TEXT("%q"), MP_QSTR_preserve_dios);
}
#endif
digitalio_digitalinout_obj_t *dios_array[num_dios];

for (mp_uint_t i = 0; i < num_dios; i++) {
Expand Down
7 changes: 7 additions & 0 deletions shared-bindings/alarm/__init__.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ extern void common_hal_alarm_set_deep_sleep_alarms(size_t n_alarms, const mp_obj

extern MP_NORETURN void common_hal_alarm_enter_deep_sleep(void);

#if CIRCUITPY_ALARM_PRESERVE_DIOS
// Clear any pin preservations set up for deep sleep (real or fake), releasing
// held pins so they can be reset. Only declared on ports that implement
// `preserve_dios`.
extern void common_hal_alarm_clear_pin_preservations(void);
#endif

// May be used to re-initialize peripherals like GPIO, if the VM reset returned
// them to a default state
extern void common_hal_alarm_pretending_deep_sleep(void);
Expand Down
Loading