wip
This commit is contained in:
parent
3e75c9a45e
commit
9307b62ad5
42
main.c
42
main.c
@ -132,7 +132,7 @@ static void reset_devices(void) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC void start_mp(supervisor_allocation *heap, bool first_run) {
|
STATIC void start_mp(supervisor_allocation *heap) {
|
||||||
supervisor_workflow_reset();
|
supervisor_workflow_reset();
|
||||||
|
|
||||||
// Stack limit should be less than real stack size, so we have a chance
|
// Stack limit should be less than real stack size, so we have a chance
|
||||||
@ -176,14 +176,6 @@ STATIC void start_mp(supervisor_allocation *heap, bool first_run) {
|
|||||||
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_lib));
|
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_lib));
|
||||||
|
|
||||||
mp_obj_list_init((mp_obj_list_t *)mp_sys_argv, 0);
|
mp_obj_list_init((mp_obj_list_t *)mp_sys_argv, 0);
|
||||||
|
|
||||||
#if CIRCUITPY_ALARM
|
|
||||||
// Record which alarm woke us up, if any. An object may be created so the heap must be functional.
|
|
||||||
// There is no alarm if this is not the first time code.py or the REPL has been run.
|
|
||||||
shared_alarm_save_wake_alarm(first_run ? common_hal_alarm_create_wake_alarm() : mp_const_none);
|
|
||||||
// Reset alarm module only after we retrieved the wakeup alarm.
|
|
||||||
alarm_reset();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC void stop_mp(void) {
|
STATIC void stop_mp(void) {
|
||||||
@ -373,7 +365,7 @@ STATIC void print_code_py_status_message(safe_mode_t safe_mode) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC bool run_code_py(safe_mode_t safe_mode, bool first_run, bool *simulate_reset) {
|
STATIC bool run_code_py(safe_mode_t safe_mode, bool *simulate_reset) {
|
||||||
bool serial_connected_at_start = serial_connected();
|
bool serial_connected_at_start = serial_connected();
|
||||||
bool printed_safe_mode_message = false;
|
bool printed_safe_mode_message = false;
|
||||||
#if CIRCUITPY_AUTORELOAD_DELAY_MS > 0
|
#if CIRCUITPY_AUTORELOAD_DELAY_MS > 0
|
||||||
@ -409,8 +401,8 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool first_run, bool *simulate_re
|
|||||||
|
|
||||||
supervisor_allocation *heap = allocate_remaining_memory();
|
supervisor_allocation *heap = allocate_remaining_memory();
|
||||||
|
|
||||||
// Prepare the VM state. Includes an alarm check/reset for sleep.
|
// Prepare the VM state.
|
||||||
start_mp(heap, first_run);
|
start_mp(heap);
|
||||||
|
|
||||||
#if CIRCUITPY_USB
|
#if CIRCUITPY_USB
|
||||||
usb_setup_with_vm();
|
usb_setup_with_vm();
|
||||||
@ -853,12 +845,12 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC int run_repl(bool first_run) {
|
STATIC int run_repl(void) {
|
||||||
int exit_code = PYEXEC_FORCED_EXIT;
|
int exit_code = PYEXEC_FORCED_EXIT;
|
||||||
stack_resize();
|
stack_resize();
|
||||||
filesystem_flush();
|
filesystem_flush();
|
||||||
supervisor_allocation *heap = allocate_remaining_memory();
|
supervisor_allocation *heap = allocate_remaining_memory();
|
||||||
start_mp(heap, first_run);
|
start_mp(heap);
|
||||||
|
|
||||||
#if CIRCUITPY_USB
|
#if CIRCUITPY_USB
|
||||||
usb_setup_with_vm();
|
usb_setup_with_vm();
|
||||||
@ -968,6 +960,12 @@ int __attribute__((used)) main(void) {
|
|||||||
safe_mode = NO_CIRCUITPY;
|
safe_mode = NO_CIRCUITPY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if CIRCUITPY_ALARM
|
||||||
|
// Record which alarm woke us up, if any.
|
||||||
|
// common_hal_alarm_record_wake_alarm() should return a static, non-heap object
|
||||||
|
shared_alarm_save_wake_alarm(common_hal_alarm_record_wake_alarm());
|
||||||
|
#endif
|
||||||
|
|
||||||
// Reset everything and prep MicroPython to run boot.py.
|
// Reset everything and prep MicroPython to run boot.py.
|
||||||
reset_port();
|
reset_port();
|
||||||
// Port-independent devices, like CIRCUITPY_BLEIO_HCI.
|
// Port-independent devices, like CIRCUITPY_BLEIO_HCI.
|
||||||
@ -1001,20 +999,18 @@ int __attribute__((used)) main(void) {
|
|||||||
// Boot script is finished, so now go into REPL or run code.py.
|
// Boot script is finished, so now go into REPL or run code.py.
|
||||||
int exit_code = PYEXEC_FORCED_EXIT;
|
int exit_code = PYEXEC_FORCED_EXIT;
|
||||||
bool skip_repl = true;
|
bool skip_repl = true;
|
||||||
bool first_run = true;
|
bool simulate_reset = true;
|
||||||
bool simulate_reset;
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
simulate_reset = false;
|
|
||||||
if (!skip_repl) {
|
if (!skip_repl) {
|
||||||
exit_code = run_repl(first_run);
|
exit_code = run_repl();
|
||||||
supervisor_set_run_reason(RUN_REASON_REPL_RELOAD);
|
supervisor_set_run_reason(RUN_REASON_REPL_RELOAD);
|
||||||
}
|
}
|
||||||
if (exit_code == PYEXEC_FORCED_EXIT) {
|
if (exit_code == PYEXEC_FORCED_EXIT) {
|
||||||
if (!first_run) {
|
if (!simulate_reset) {
|
||||||
serial_write_compressed(translate("soft reboot\n"));
|
serial_write_compressed(translate("soft reboot\n"));
|
||||||
}
|
}
|
||||||
if (pyexec_mode_kind == PYEXEC_MODE_FRIENDLY_REPL) {
|
if (pyexec_mode_kind == PYEXEC_MODE_FRIENDLY_REPL) {
|
||||||
skip_repl = run_code_py(safe_mode, first_run, &simulate_reset);
|
skip_repl = run_code_py(safe_mode, &simulate_reset);
|
||||||
} else {
|
} else {
|
||||||
skip_repl = false;
|
skip_repl = false;
|
||||||
}
|
}
|
||||||
@ -1025,7 +1021,11 @@ int __attribute__((used)) main(void) {
|
|||||||
// Either the REPL or code.py has run and finished.
|
// Either the REPL or code.py has run and finished.
|
||||||
// If code.py did a fake deep sleep, pretend that we are running code.py for
|
// If code.py did a fake deep sleep, pretend that we are running code.py for
|
||||||
// the first time after a hard reset. This will preserve any alarm information.
|
// the first time after a hard reset. This will preserve any alarm information.
|
||||||
first_run = simulate_reset;
|
if (!simulate_reset) {
|
||||||
|
#if CIRCUITPY_ALARM
|
||||||
|
shared_alarm_save_wake_alarm(mp_const_none);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
mp_deinit();
|
mp_deinit();
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -48,6 +48,13 @@ const alarm_sleep_memory_obj_t alarm_sleep_memory_obj = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Static alarm object recording alarm (if any) that woke up CircuitPython after light or deep sleep.
|
||||||
|
// This object lives across VM instantiations, so none of these objects can contain references to the heap.
|
||||||
|
static union {
|
||||||
|
alarm_pin_pinalarm_obj_t pin_alarm;
|
||||||
|
alarm_time_timealarm_obj_t time_alarm;
|
||||||
|
} wake_alarm;
|
||||||
|
|
||||||
void alarm_reset(void) {
|
void alarm_reset(void) {
|
||||||
// Reset the alarm flag
|
// Reset the alarm flag
|
||||||
alarm_pin_pinalarm_reset();
|
alarm_pin_pinalarm_reset();
|
||||||
@ -57,7 +64,7 @@ void alarm_reset(void) {
|
|||||||
void alarm_get_wakeup_cause(void) {
|
void alarm_get_wakeup_cause(void) {
|
||||||
// Called from rtc_init, just before SWRST of RTC. It is called
|
// Called from rtc_init, just before SWRST of RTC. It is called
|
||||||
// at an early stage of main(), to save TAMPID from SWRST. Later,
|
// at an early stage of main(), to save TAMPID from SWRST. Later,
|
||||||
// common_hal_alarm_create_wake_alarm is called to make a wakeup
|
// common_hal_alarm_record_wake_alarm is called to make a wakeup
|
||||||
// alarm from the deep sleep.
|
// alarm from the deep sleep.
|
||||||
|
|
||||||
TAMPID = RTC->MODE0.TAMPID.reg;
|
TAMPID = RTC->MODE0.TAMPID.reg;
|
||||||
@ -67,7 +74,7 @@ bool common_hal_alarm_woken_from_sleep(void) {
|
|||||||
return alarm_pin_pinalarm_woke_this_cycle() || alarm_time_timealarm_woke_this_cycle();
|
return alarm_pin_pinalarm_woke_this_cycle() || alarm_time_timealarm_woke_this_cycle();
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_obj_t common_hal_alarm_create_wake_alarm(void) {
|
mp_obj_t common_hal_alarm_record_wake_alarm(void) {
|
||||||
// Called from main.c on the first start up, just before alarm_reset.
|
// Called from main.c on the first start up, just before alarm_reset.
|
||||||
// Return a copy of wakeup alarm from deep sleep / fake deep sleep.
|
// Return a copy of wakeup alarm from deep sleep / fake deep sleep.
|
||||||
// In case of fake sleep, status should be left in TimeAlarm/PinAlarm.
|
// In case of fake sleep, status should be left in TimeAlarm/PinAlarm.
|
||||||
@ -76,13 +83,13 @@ mp_obj_t common_hal_alarm_create_wake_alarm(void) {
|
|||||||
if (alarm_pin_pinalarm_woke_this_cycle()) {
|
if (alarm_pin_pinalarm_woke_this_cycle()) {
|
||||||
TAMPID = RTC->MODE0.TAMPID.reg;
|
TAMPID = RTC->MODE0.TAMPID.reg;
|
||||||
RTC->MODE0.TAMPID.reg = TAMPID; // clear register
|
RTC->MODE0.TAMPID.reg = TAMPID; // clear register
|
||||||
return alarm_pin_pinalarm_create_wakeup_alarm(TAMPID);
|
return alarm_pin_pinalarm_record_wakeup_alarm(&wake_alarm.pin_alarm, TAMPID);
|
||||||
}
|
}
|
||||||
if (alarm_time_timealarm_woke_this_cycle() || (true_deep && TAMPID == 0)) {
|
if (alarm_time_timealarm_woke_this_cycle() || (true_deep && TAMPID == 0)) {
|
||||||
return alarm_time_timealarm_create_wakeup_alarm();
|
return alarm_time_timealarm_record_wakeup_alarm(&wake_alarm.time_alarm);
|
||||||
}
|
}
|
||||||
if (true_deep) {
|
if (true_deep) {
|
||||||
return alarm_pin_pinalarm_create_wakeup_alarm(TAMPID);
|
return alarm_pin_pinalarm_record_wakeup_alarm(&wake_alarm.pin_alarm, TAMPID);
|
||||||
}
|
}
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
@ -128,12 +128,11 @@ mp_obj_t alarm_pin_pinalarm_find_triggered_alarm(size_t n_alarms, const mp_obj_t
|
|||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_obj_t alarm_pin_pinalarm_create_wakeup_alarm(uint32_t TAMPID) {
|
mp_obj_t alarm_pin_pinalarm_record_wakeup_alarm(alarm_pin_pinalarm_obj_t *alarm, uint32_t TAMPID) {
|
||||||
// Create tamper alarm that caused wakeup from deep sleep
|
// Create tamper alarm that caused wakeup from deep sleep
|
||||||
|
|
||||||
for (samd_tamper_pin_t *t = TAMPER_PINS; t->n >= 0; t++) {
|
for (samd_tamper_pin_t *t = TAMPER_PINS; t->n >= 0; t++) {
|
||||||
if (TAMPID & (1 << t->n)) {
|
if (TAMPID & (1 << t->n)) {
|
||||||
alarm_pin_pinalarm_obj_t *alarm = m_new_obj(alarm_pin_pinalarm_obj_t);
|
|
||||||
alarm->base.type = &alarm_pin_pinalarm_type;
|
alarm->base.type = &alarm_pin_pinalarm_type;
|
||||||
alarm->pin = t->pin;
|
alarm->pin = t->pin;
|
||||||
return alarm;
|
return alarm;
|
||||||
|
@ -39,7 +39,7 @@ typedef struct {
|
|||||||
} alarm_pin_pinalarm_obj_t;
|
} alarm_pin_pinalarm_obj_t;
|
||||||
|
|
||||||
mp_obj_t alarm_pin_pinalarm_find_triggered_alarm(size_t n_alarms, const mp_obj_t *alarms);
|
mp_obj_t alarm_pin_pinalarm_find_triggered_alarm(size_t n_alarms, const mp_obj_t *alarms);
|
||||||
mp_obj_t alarm_pin_pinalarm_create_wakeup_alarm(uint32_t TAMPID);
|
mp_obj_t alarm_pin_pinalarm_record_wakeup_alarm(alarm_pin_pinalarm_obj_t *alarm, uint32_t TAMPID);
|
||||||
|
|
||||||
void pin_alarm_callback(uint8_t num);
|
void pin_alarm_callback(uint8_t num);
|
||||||
void alarm_pin_pinalarm_reset(void);
|
void alarm_pin_pinalarm_reset(void);
|
||||||
|
@ -58,13 +58,12 @@ mp_obj_t alarm_time_timealarm_find_triggered_alarm(size_t n_alarms, const mp_obj
|
|||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_obj_t alarm_time_timealarm_create_wakeup_alarm(void) {
|
mp_obj_t alarm_time_timealarm_record_wakeup_alarm(alarm_time_timealarm_obj_t *alarm) {
|
||||||
alarm_time_timealarm_obj_t *timer = m_new_obj(alarm_time_timealarm_obj_t);
|
alarm->base.type = &alarm_time_timealarm_type;
|
||||||
timer->base.type = &alarm_time_timealarm_type;
|
|
||||||
// TODO: Set monotonic_time based on the RTC state.
|
// TODO: Set monotonic_time based on the RTC state.
|
||||||
// Or don't, most of the other ports don't have this either.
|
// Or don't, most of the other ports don't have this either.
|
||||||
timer->monotonic_time = 0.0f;
|
alarm->monotonic_time = 0.0f;
|
||||||
return timer;
|
return alarm;
|
||||||
}
|
}
|
||||||
|
|
||||||
void time_alarm_callback(void) {
|
void time_alarm_callback(void) {
|
||||||
|
@ -35,7 +35,7 @@ typedef struct {
|
|||||||
} alarm_time_timealarm_obj_t;
|
} alarm_time_timealarm_obj_t;
|
||||||
|
|
||||||
mp_obj_t alarm_time_timealarm_find_triggered_alarm(size_t n_alarms, const mp_obj_t *alarms);
|
mp_obj_t alarm_time_timealarm_find_triggered_alarm(size_t n_alarms, const mp_obj_t *alarms);
|
||||||
mp_obj_t alarm_time_timealarm_create_wakeup_alarm(void);
|
mp_obj_t alarm_time_timealarm_record_wakeup_alarm(alarm_time_timealarm_obj_t *alarm);
|
||||||
void time_alarm_callback(void);
|
void time_alarm_callback(void);
|
||||||
bool alarm_time_timealarm_woke_this_cycle(void);
|
bool alarm_time_timealarm_woke_this_cycle(void);
|
||||||
void alarm_time_timealarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_obj_t *alarms);
|
void alarm_time_timealarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_obj_t *alarms);
|
||||||
|
@ -385,6 +385,10 @@ safe_mode_t port_init(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void reset_port(void) {
|
void reset_port(void) {
|
||||||
|
#if CIRCUITPY_ALARM
|
||||||
|
alarm_reset();
|
||||||
|
#endif
|
||||||
|
|
||||||
#if CIRCUITPY_BUSIO
|
#if CIRCUITPY_BUSIO
|
||||||
reset_sercoms();
|
reset_sercoms();
|
||||||
#endif
|
#endif
|
||||||
|
@ -58,6 +58,15 @@ const alarm_sleep_memory_obj_t alarm_sleep_memory_obj = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Static alarm object recording alarm (if any) that woke up CircuitPython after light or deep sleep.
|
||||||
|
// This object lives across VM instantiations, so none of these objects can contain references to the heap.
|
||||||
|
static union {
|
||||||
|
alarm_pin_pinalarm_obj_t pin_alarm;
|
||||||
|
alarm_time_timealarm_obj_t time_alarm;
|
||||||
|
alarm_touch_touchalarm_obj_t touch_alarm;
|
||||||
|
alarm_coproc_coprocalarm_obj_t coproc_alarm;
|
||||||
|
} wake_alarm;
|
||||||
|
|
||||||
void alarm_reset(void) {
|
void alarm_reset(void) {
|
||||||
alarm_sleep_memory_reset();
|
alarm_sleep_memory_reset();
|
||||||
alarm_pin_pinalarm_reset();
|
alarm_pin_pinalarm_reset();
|
||||||
@ -90,27 +99,27 @@ bool common_hal_alarm_woken_from_sleep(void) {
|
|||||||
return _get_wakeup_cause() != ESP_SLEEP_WAKEUP_UNDEFINED;
|
return _get_wakeup_cause() != ESP_SLEEP_WAKEUP_UNDEFINED;
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_obj_t common_hal_alarm_create_wake_alarm(void) {
|
mp_obj_t common_hal_alarm_record_wake_alarm(void) {
|
||||||
// If woken from deep sleep, create a copy alarm similar to what would have
|
// If woken from deep sleep, create a copy alarm similar to what would have
|
||||||
// been passed in originally. Otherwise, just return none
|
// been passed in originally. Otherwise, just return none
|
||||||
esp_sleep_wakeup_cause_t cause = _get_wakeup_cause();
|
esp_sleep_wakeup_cause_t cause = _get_wakeup_cause();
|
||||||
switch (cause) {
|
switch (cause) {
|
||||||
case ESP_SLEEP_WAKEUP_TIMER: {
|
case ESP_SLEEP_WAKEUP_TIMER: {
|
||||||
return alarm_time_timealarm_create_wakeup_alarm();
|
return alarm_time_timealarm_record_wakeup_alarm(&wake_alarm.time_alarm);
|
||||||
}
|
}
|
||||||
|
|
||||||
case ESP_SLEEP_WAKEUP_GPIO:
|
case ESP_SLEEP_WAKEUP_GPIO:
|
||||||
case ESP_SLEEP_WAKEUP_EXT0:
|
case ESP_SLEEP_WAKEUP_EXT0:
|
||||||
case ESP_SLEEP_WAKEUP_EXT1: {
|
case ESP_SLEEP_WAKEUP_EXT1: {
|
||||||
return alarm_pin_pinalarm_create_wakeup_alarm();
|
return alarm_pin_pinalarm_record_wakeup_alarm(&wake_alarm.pin_alarm);
|
||||||
}
|
}
|
||||||
|
|
||||||
case ESP_SLEEP_WAKEUP_TOUCHPAD: {
|
case ESP_SLEEP_WAKEUP_TOUCHPAD: {
|
||||||
return alarm_touch_touchalarm_create_wakeup_alarm();
|
return alarm_touch_touchalarm_record_wakeup_alarm(&wake_alarm.touch_alarm);
|
||||||
}
|
}
|
||||||
|
|
||||||
case ESP_SLEEP_WAKEUP_ULP: {
|
case ESP_SLEEP_WAKEUP_ULP: {
|
||||||
return alarm_coproc_coprocalarm_create_wakeup_alarm();
|
return alarm_coproc_coprocalarm_record_wakeup_alarm(&wake_alarm.coproc_alarm);
|
||||||
}
|
}
|
||||||
|
|
||||||
case ESP_SLEEP_WAKEUP_UNDEFINED:
|
case ESP_SLEEP_WAKEUP_UNDEFINED:
|
||||||
|
@ -47,9 +47,7 @@ mp_obj_t alarm_coproc_coprocalarm_find_triggered_alarm(const size_t n_alarms, co
|
|||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_obj_t alarm_coproc_coprocalarm_create_wakeup_alarm(void) {
|
mp_obj_t alarm_coproc_coprocalarm_record_wakeup_alarm(alarm_coproc_coprocalarm_obj_t *alarm) {
|
||||||
// Create CoprocAlarm object.
|
|
||||||
alarm_coproc_coprocalarm_obj_t *alarm = m_new_obj(alarm_coproc_coprocalarm_obj_t);
|
|
||||||
alarm->base.type = &alarm_coproc_coprocalarm_type;
|
alarm->base.type = &alarm_coproc_coprocalarm_type;
|
||||||
return alarm;
|
return alarm;
|
||||||
}
|
}
|
||||||
@ -111,7 +109,7 @@ mp_obj_t alarm_coproc_coprocalarm_find_triggered_alarm(const size_t n_alarms, co
|
|||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_obj_t alarm_coproc_coprocalarm_create_wakeup_alarm(void) {
|
mp_obj_t alarm_coproc_coprocalarm_record_wakeup_alarm(void) {
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ typedef struct {
|
|||||||
} alarm_coproc_coprocalarm_obj_t;
|
} alarm_coproc_coprocalarm_obj_t;
|
||||||
|
|
||||||
mp_obj_t alarm_coproc_coprocalarm_find_triggered_alarm(const size_t n_alarms, const mp_obj_t *alarms);
|
mp_obj_t alarm_coproc_coprocalarm_find_triggered_alarm(const size_t n_alarms, const mp_obj_t *alarms);
|
||||||
mp_obj_t alarm_coproc_coprocalarm_create_wakeup_alarm(void);
|
mp_obj_t alarm_coproc_coprocalarm_record_wakeup_alarm(void);
|
||||||
|
|
||||||
void alarm_coproc_coprocalarm_prepare_for_deep_sleep(void);
|
void alarm_coproc_coprocalarm_prepare_for_deep_sleep(void);
|
||||||
void alarm_coproc_coprocalarm_reset(void);
|
void alarm_coproc_coprocalarm_reset(void);
|
||||||
|
@ -111,7 +111,7 @@ mp_obj_t alarm_pin_pinalarm_find_triggered_alarm(size_t n_alarms, const mp_obj_t
|
|||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_obj_t alarm_pin_pinalarm_create_wakeup_alarm(void) {
|
mp_obj_t alarm_pin_pinalarm_record_wakeup_alarm(alarm_pin_pinalarm_obj_t *alarm) {
|
||||||
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
|
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
|
||||||
|
|
||||||
// Pin status will persist into a fake deep sleep
|
// Pin status will persist into a fake deep sleep
|
||||||
@ -135,7 +135,6 @@ mp_obj_t alarm_pin_pinalarm_create_wakeup_alarm(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
alarm_pin_pinalarm_obj_t *alarm = m_new_obj(alarm_pin_pinalarm_obj_t);
|
|
||||||
alarm->base.type = &alarm_pin_pinalarm_type;
|
alarm->base.type = &alarm_pin_pinalarm_type;
|
||||||
alarm->pin = NULL;
|
alarm->pin = NULL;
|
||||||
// Map the pin number back to a pin object.
|
// Map the pin number back to a pin object.
|
||||||
|
@ -35,7 +35,7 @@ typedef struct {
|
|||||||
} alarm_pin_pinalarm_obj_t;
|
} alarm_pin_pinalarm_obj_t;
|
||||||
|
|
||||||
mp_obj_t alarm_pin_pinalarm_find_triggered_alarm(size_t n_alarms, const mp_obj_t *alarms);
|
mp_obj_t alarm_pin_pinalarm_find_triggered_alarm(size_t n_alarms, const mp_obj_t *alarms);
|
||||||
mp_obj_t alarm_pin_pinalarm_create_wakeup_alarm(void);
|
mp_obj_t alarm_pin_pinalarm_record_wakeup_alarm(void);
|
||||||
|
|
||||||
void alarm_pin_pinalarm_prepare_for_deep_sleep(void);
|
void alarm_pin_pinalarm_prepare_for_deep_sleep(void);
|
||||||
void alarm_pin_pinalarm_reset(void);
|
void alarm_pin_pinalarm_reset(void);
|
||||||
|
@ -51,12 +51,11 @@ mp_obj_t alarm_time_timealarm_find_triggered_alarm(size_t n_alarms, const mp_obj
|
|||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_obj_t alarm_time_timealarm_create_wakeup_alarm(void) {
|
mp_obj_t alarm_time_timealarm_record_wakeup_alarm(alarm_time_timealarm_obj_t *alarm) {
|
||||||
alarm_time_timealarm_obj_t *timer = m_new_obj(alarm_time_timealarm_obj_t);
|
alarm->base.type = &alarm_time_timealarm_type;
|
||||||
timer->base.type = &alarm_time_timealarm_type;
|
|
||||||
// TODO: Set monotonic_time based on the RTC state.
|
// TODO: Set monotonic_time based on the RTC state.
|
||||||
timer->monotonic_time = 0.0f;
|
alarm->monotonic_time = 0.0f;
|
||||||
return timer;
|
return alarm;
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_timer_handle_t pretend_sleep_timer;
|
esp_timer_handle_t pretend_sleep_timer;
|
||||||
|
@ -33,7 +33,7 @@ typedef struct {
|
|||||||
} alarm_time_timealarm_obj_t;
|
} alarm_time_timealarm_obj_t;
|
||||||
|
|
||||||
mp_obj_t alarm_time_timealarm_find_triggered_alarm(size_t n_alarms, const mp_obj_t *alarms);
|
mp_obj_t alarm_time_timealarm_find_triggered_alarm(size_t n_alarms, const mp_obj_t *alarms);
|
||||||
mp_obj_t alarm_time_timealarm_create_wakeup_alarm(void);
|
mp_obj_t alarm_time_timealarm_record_wakeup_alarm(alarm_time_timealarm_obj_t *alarm);
|
||||||
|
|
||||||
void alarm_time_timealarm_reset(void);
|
void alarm_time_timealarm_reset(void);
|
||||||
void alarm_time_timealarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_obj_t *alarms);
|
void alarm_time_timealarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_obj_t *alarms);
|
||||||
|
@ -52,9 +52,8 @@ mp_obj_t alarm_touch_touchalarm_find_triggered_alarm(const size_t n_alarms, cons
|
|||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_obj_t alarm_touch_touchalarm_create_wakeup_alarm(void) {
|
mp_obj_t alarm_touch_touchalarm_record_wakeup_alarm(alarm_touch_touchalarm_obj_t *alarm) {
|
||||||
// Create TouchAlarm object.
|
// Create TouchAlarm object.
|
||||||
alarm_touch_touchalarm_obj_t *alarm = m_new_obj(alarm_touch_touchalarm_obj_t);
|
|
||||||
alarm->base.type = &alarm_touch_touchalarm_type;
|
alarm->base.type = &alarm_touch_touchalarm_type;
|
||||||
alarm->pin = NULL;
|
alarm->pin = NULL;
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ typedef struct {
|
|||||||
} alarm_touch_touchalarm_obj_t;
|
} alarm_touch_touchalarm_obj_t;
|
||||||
|
|
||||||
mp_obj_t alarm_touch_touchalarm_find_triggered_alarm(const size_t n_alarms, const mp_obj_t *alarms);
|
mp_obj_t alarm_touch_touchalarm_find_triggered_alarm(const size_t n_alarms, const mp_obj_t *alarms);
|
||||||
mp_obj_t alarm_touch_touchalarm_create_wakeup_alarm(void);
|
mp_obj_t alarm_touch_touchalarm_record_wakeup_alarm(alarm_touch_touchalarm_obj_t *alarm);
|
||||||
|
|
||||||
void alarm_touch_touchalarm_prepare_for_deep_sleep(void);
|
void alarm_touch_touchalarm_prepare_for_deep_sleep(void);
|
||||||
void alarm_touch_touchalarm_reset(void);
|
void alarm_touch_touchalarm_reset(void);
|
||||||
|
@ -60,6 +60,10 @@
|
|||||||
#include "peripherals/rmt.h"
|
#include "peripherals/rmt.h"
|
||||||
#include "peripherals/timer.h"
|
#include "peripherals/timer.h"
|
||||||
|
|
||||||
|
#if CIRCUITPY_ALARM
|
||||||
|
#include "common-hal/alarm/__init__.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#if CIRCUITPY_COUNTIO || CIRCUITPY_ROTARYIO || CIRCUITPY_FREQUENCYIO
|
#if CIRCUITPY_COUNTIO || CIRCUITPY_ROTARYIO || CIRCUITPY_FREQUENCYIO
|
||||||
#include "peripherals/pcnt.h"
|
#include "peripherals/pcnt.h"
|
||||||
#endif
|
#endif
|
||||||
@ -338,6 +342,10 @@ safe_mode_t port_init(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void reset_port(void) {
|
void reset_port(void) {
|
||||||
|
#if CIRCUITPY_ALARM
|
||||||
|
alarm_reset();
|
||||||
|
#endif
|
||||||
|
|
||||||
// TODO deinit for esp32-camera
|
// TODO deinit for esp32-camera
|
||||||
#if CIRCUITPY_ESP32_CAMERA
|
#if CIRCUITPY_ESP32_CAMERA
|
||||||
esp_camera_deinit();
|
esp_camera_deinit();
|
||||||
|
@ -56,6 +56,14 @@ const alarm_sleep_memory_obj_t alarm_sleep_memory_obj = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Static alarm object recording alarm (if any) that woke up CircuitPython after light or deep sleep.
|
||||||
|
// This object lives across VM instantiations, so none of these objects can contain references to the heap.
|
||||||
|
static union {
|
||||||
|
alarm_pin_pinalarm_obj_t pin_alarm;
|
||||||
|
alarm_time_timealarm_obj_t time_alarm;
|
||||||
|
alarm_touch_touchalarm_obj_t touch_alarm;
|
||||||
|
} wake_alarm;
|
||||||
|
|
||||||
void alarm_reset(void) {
|
void alarm_reset(void) {
|
||||||
alarm_sleep_memory_reset();
|
alarm_sleep_memory_reset();
|
||||||
alarm_pin_pinalarm_reset();
|
alarm_pin_pinalarm_reset();
|
||||||
@ -115,19 +123,19 @@ bool common_hal_alarm_woken_from_sleep(void) {
|
|||||||
|| cause == NRF_SLEEP_WAKEUP_TOUCHPAD;
|
|| cause == NRF_SLEEP_WAKEUP_TOUCHPAD;
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_obj_t common_hal_alarm_create_wake_alarm(void) {
|
mp_obj_t common_hal_alarm_record_wake_alarm(void) {
|
||||||
// If woken from deep sleep, create a copy alarm similar to what would have
|
// If woken from deep sleep, create a copy alarm similar to what would have
|
||||||
// been passed in originally. Otherwise, just return none
|
// been passed in originally. Otherwise, just return none
|
||||||
nrf_sleep_source_t cause = _get_wakeup_cause();
|
nrf_sleep_source_t cause = _get_wakeup_cause();
|
||||||
switch (cause) {
|
switch (cause) {
|
||||||
case NRF_SLEEP_WAKEUP_TIMER: {
|
case NRF_SLEEP_WAKEUP_TIMER: {
|
||||||
return alarm_time_timealarm_create_wakeup_alarm();
|
return alarm_time_timealarm_record_wakeup_alarm(&wake_alarm.time_alarm);
|
||||||
}
|
}
|
||||||
case NRF_SLEEP_WAKEUP_TOUCHPAD: {
|
case NRF_SLEEP_WAKEUP_TOUCHPAD: {
|
||||||
return alarm_touch_touchalarm_create_wakeup_alarm();
|
return alarm_touch_touchalarm_record_wakeup_alarm(&wake_alarm.touch_alarm);
|
||||||
}
|
}
|
||||||
case NRF_SLEEP_WAKEUP_GPIO: {
|
case NRF_SLEEP_WAKEUP_GPIO: {
|
||||||
return alarm_pin_pinalarm_create_wakeup_alarm();
|
return alarm_pin_pinalarm_record_wakeup_alarm(&wake_alarm.pin_alarm);
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -101,8 +101,7 @@ mp_obj_t alarm_pin_pinalarm_find_triggered_alarm(size_t n_alarms, const mp_obj_t
|
|||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_obj_t alarm_pin_pinalarm_create_wakeup_alarm(void) {
|
mp_obj_t alarm_pin_pinalarm_record_wakeup_alarm(alarm_pin_pinalarm_obj_t *alarm) {
|
||||||
alarm_pin_pinalarm_obj_t *alarm = m_new_obj(alarm_pin_pinalarm_obj_t);
|
|
||||||
alarm->base.type = &alarm_pin_pinalarm_type;
|
alarm->base.type = &alarm_pin_pinalarm_type;
|
||||||
alarm->pin = NULL;
|
alarm->pin = NULL;
|
||||||
// Map the pin number back to a pin object.
|
// Map the pin number back to a pin object.
|
||||||
|
@ -35,7 +35,7 @@ typedef struct {
|
|||||||
} alarm_pin_pinalarm_obj_t;
|
} alarm_pin_pinalarm_obj_t;
|
||||||
|
|
||||||
mp_obj_t alarm_pin_pinalarm_find_triggered_alarm(size_t n_alarms, const mp_obj_t *alarms);
|
mp_obj_t alarm_pin_pinalarm_find_triggered_alarm(size_t n_alarms, const mp_obj_t *alarms);
|
||||||
mp_obj_t alarm_pin_pinalarm_create_wakeup_alarm(void);
|
mp_obj_t alarm_pin_pinalarm_record_wakeup_alarm(alarm_pin_pinalarm_obj_t *alarm);
|
||||||
|
|
||||||
void alarm_pin_pinalarm_reset(void);
|
void alarm_pin_pinalarm_reset(void);
|
||||||
void alarm_pin_pinalarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_obj_t *alarms);
|
void alarm_pin_pinalarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_obj_t *alarms);
|
||||||
|
@ -49,12 +49,11 @@ mp_obj_t alarm_time_timealarm_find_triggered_alarm(size_t n_alarms, const mp_obj
|
|||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_obj_t alarm_time_timealarm_create_wakeup_alarm(void) {
|
mp_obj_t alarm_time_timealarm_record_wakeup_alarm(alarm_time_timealarm_obj_t *alarm) {
|
||||||
alarm_time_timealarm_obj_t *timer = m_new_obj(alarm_time_timealarm_obj_t);
|
alarm->base.type = &alarm_time_timealarm_type;
|
||||||
timer->base.type = &alarm_time_timealarm_type;
|
|
||||||
// TODO: Set monotonic_time based on the RTC state.
|
// TODO: Set monotonic_time based on the RTC state.
|
||||||
timer->monotonic_time = 0.0f;
|
alarm->monotonic_time = 0.0f;
|
||||||
return timer;
|
return alarm;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool alarm_time_timealarm_woke_this_cycle(void) {
|
bool alarm_time_timealarm_woke_this_cycle(void) {
|
||||||
|
@ -37,7 +37,7 @@ extern void port_disable_interrupt_after_ticks_ch(uint32_t channel);
|
|||||||
extern void port_interrupt_after_ticks_ch(uint32_t channel, uint32_t ticks);
|
extern void port_interrupt_after_ticks_ch(uint32_t channel, uint32_t ticks);
|
||||||
|
|
||||||
mp_obj_t alarm_time_timealarm_find_triggered_alarm(size_t n_alarms, const mp_obj_t *alarms);
|
mp_obj_t alarm_time_timealarm_find_triggered_alarm(size_t n_alarms, const mp_obj_t *alarms);
|
||||||
mp_obj_t alarm_time_timealarm_create_wakeup_alarm(void);
|
mp_obj_t alarm_time_timealarm_record_wakeup_alarm(alarm_time_timealarm_obj_t *alarm);
|
||||||
|
|
||||||
bool alarm_time_timealarm_woke_this_cycle(void);
|
bool alarm_time_timealarm_woke_this_cycle(void);
|
||||||
void alarm_time_timealarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_obj_t *alarms);
|
void alarm_time_timealarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_obj_t *alarms);
|
||||||
|
@ -39,7 +39,7 @@ mp_obj_t alarm_touch_touchalarm_find_triggered_alarm(const size_t n_alarms, cons
|
|||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_obj_t alarm_touch_touchalarm_create_wakeup_alarm(void) {
|
mp_obj_t alarm_touch_touchalarm_record_wakeup_alarm(alarm_touch_touchalarm_obj_t *alarm) {
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ typedef struct {
|
|||||||
|
|
||||||
// Find the alarm object that caused us to wake up or create an equivalent one.
|
// Find the alarm object that caused us to wake up or create an equivalent one.
|
||||||
mp_obj_t alarm_touch_touchalarm_find_triggered_alarm(const size_t n_alarms, const mp_obj_t *alarms);
|
mp_obj_t alarm_touch_touchalarm_find_triggered_alarm(const size_t n_alarms, const mp_obj_t *alarms);
|
||||||
mp_obj_t alarm_touch_touchalarm_create_wakeup_alarm(void);
|
mp_obj_t alarm_touch_touchalarm_record_wakeup_alarm(void);
|
||||||
// Check for the wake up alarm from pretend deep sleep.
|
// Check for the wake up alarm from pretend deep sleep.
|
||||||
void alarm_touch_touchalarm_set_alarm(const bool deep_sleep, const size_t n_alarms, const mp_obj_t *alarms);
|
void alarm_touch_touchalarm_set_alarm(const bool deep_sleep, const size_t n_alarms, const mp_obj_t *alarms);
|
||||||
void alarm_touch_touchalarm_prepare_for_deep_sleep(void);
|
void alarm_touch_touchalarm_prepare_for_deep_sleep(void);
|
||||||
|
@ -64,6 +64,10 @@
|
|||||||
|
|
||||||
#include "lib/tinyusb/src/device/usbd.h"
|
#include "lib/tinyusb/src/device/usbd.h"
|
||||||
|
|
||||||
|
#if CIRCUITPY_ALARM
|
||||||
|
#include "common-hal/alarm/__init__.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef CIRCUITPY_AUDIOBUSIO
|
#ifdef CIRCUITPY_AUDIOBUSIO
|
||||||
#include "common-hal/audiobusio/I2SOut.h"
|
#include "common-hal/audiobusio/I2SOut.h"
|
||||||
#endif
|
#endif
|
||||||
@ -212,6 +216,10 @@ safe_mode_t port_init(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void reset_port(void) {
|
void reset_port(void) {
|
||||||
|
#if CIRCUITPY_ALARM
|
||||||
|
alarm_reset();
|
||||||
|
#endif
|
||||||
|
|
||||||
#if CIRCUITPY_BUSIO
|
#if CIRCUITPY_BUSIO
|
||||||
i2c_reset();
|
i2c_reset();
|
||||||
spi_reset();
|
spi_reset();
|
||||||
|
@ -96,6 +96,13 @@ const alarm_sleep_memory_obj_t alarm_sleep_memory_obj = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Static alarm object recording alarm (if any) that woke up CircuitPython after light or deep sleep.
|
||||||
|
// This object lives across VM instantiations, so none of these objects can contain references to the heap.
|
||||||
|
static union {
|
||||||
|
alarm_pin_pinalarm_obj_t pin_alarm;
|
||||||
|
alarm_time_timealarm_obj_t time_alarm;
|
||||||
|
} wake_alarm;
|
||||||
|
|
||||||
void alarm_reset(void) {
|
void alarm_reset(void) {
|
||||||
alarm_sleep_memory_reset();
|
alarm_sleep_memory_reset();
|
||||||
alarm_pin_pinalarm_reset();
|
alarm_pin_pinalarm_reset();
|
||||||
@ -131,17 +138,17 @@ bool common_hal_alarm_woken_from_sleep(void) {
|
|||||||
return _get_wakeup_cause() != RP_SLEEP_WAKEUP_UNDEF;
|
return _get_wakeup_cause() != RP_SLEEP_WAKEUP_UNDEF;
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_obj_t common_hal_alarm_create_wake_alarm(void) {
|
mp_obj_t common_hal_alarm_record_wake_alarm(void) {
|
||||||
// If woken from deep sleep, create a copy alarm similar to what would have
|
// If woken from deep sleep, create a copy alarm similar to what would have
|
||||||
// been passed in originally. Otherwise, just return none
|
// been passed in originally. Otherwise, just return none
|
||||||
uint8_t cause = _get_wakeup_cause();
|
uint8_t cause = _get_wakeup_cause();
|
||||||
switch (cause) {
|
switch (cause) {
|
||||||
case RP_SLEEP_WAKEUP_RTC: {
|
case RP_SLEEP_WAKEUP_RTC: {
|
||||||
return alarm_time_timealarm_create_wakeup_alarm();
|
return alarm_time_timealarm_record_wakeup_alarm(&wake_alarm.time_alarm);
|
||||||
}
|
}
|
||||||
|
|
||||||
case RP_SLEEP_WAKEUP_GPIO: {
|
case RP_SLEEP_WAKEUP_GPIO: {
|
||||||
return alarm_pin_pinalarm_create_wakeup_alarm();
|
return alarm_pin_pinalarm_record_wakeup_alarm(&wake_alarm.pin_alarm);
|
||||||
}
|
}
|
||||||
|
|
||||||
case RP_SLEEP_WAKEUP_UNDEF:
|
case RP_SLEEP_WAKEUP_UNDEF:
|
||||||
|
@ -94,10 +94,10 @@ mp_obj_t alarm_pin_pinalarm_find_triggered_alarm(size_t n_alarms, const mp_obj_t
|
|||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_obj_t alarm_pin_pinalarm_create_wakeup_alarm(void) {
|
mp_obj_t alarm_pin_pinalarm_record_wakeup_alarm(alarm_pin_pinalarm_obj_t *alarm) {
|
||||||
alarm_pin_pinalarm_obj_t *alarm = m_new_obj(alarm_pin_pinalarm_obj_t);
|
|
||||||
alarm->base.type = &alarm_pin_pinalarm_type;
|
alarm->base.type = &alarm_pin_pinalarm_type;
|
||||||
// TODO: how to obtain the correct pin from memory?
|
// TODO: how to obtain the correct pin from memory?
|
||||||
|
alarm->pin = NULL;
|
||||||
return alarm;
|
return alarm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ typedef struct {
|
|||||||
} alarm_pin_pinalarm_obj_t;
|
} alarm_pin_pinalarm_obj_t;
|
||||||
|
|
||||||
mp_obj_t alarm_pin_pinalarm_find_triggered_alarm(size_t n_alarms, const mp_obj_t *alarms);
|
mp_obj_t alarm_pin_pinalarm_find_triggered_alarm(size_t n_alarms, const mp_obj_t *alarms);
|
||||||
mp_obj_t alarm_pin_pinalarm_create_wakeup_alarm(void);
|
mp_obj_t alarm_pin_pinalarm_record_wakeup_alarm(alarm_pin_pinalarm_obj_t *alarm);
|
||||||
|
|
||||||
void alarm_pin_pinalarm_reset(void);
|
void alarm_pin_pinalarm_reset(void);
|
||||||
void alarm_pin_pinalarm_light_reset(void);
|
void alarm_pin_pinalarm_light_reset(void);
|
||||||
|
@ -58,12 +58,11 @@ mp_obj_t alarm_time_timealarm_find_triggered_alarm(size_t n_alarms, const mp_obj
|
|||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_obj_t alarm_time_timealarm_create_wakeup_alarm(void) {
|
mp_obj_t alarm_time_timealarm_record_wakeup_alarm(alarm_time_timealarm_obj_t *alarm) {
|
||||||
alarm_time_timealarm_obj_t *timer = m_new_obj(alarm_time_timealarm_obj_t);
|
alarm->base.type = &alarm_time_timealarm_type;
|
||||||
timer->base.type = &alarm_time_timealarm_type;
|
|
||||||
// TODO: Set monotonic_time based on the RTC state.
|
// TODO: Set monotonic_time based on the RTC state.
|
||||||
timer->monotonic_time = 0.0f;
|
alarm->monotonic_time = 0.0f;
|
||||||
return timer;
|
return alarm;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool alarm_time_timealarm_woke_this_cycle(void) {
|
bool alarm_time_timealarm_woke_this_cycle(void) {
|
||||||
|
@ -33,7 +33,7 @@ typedef struct {
|
|||||||
} alarm_time_timealarm_obj_t;
|
} alarm_time_timealarm_obj_t;
|
||||||
|
|
||||||
mp_obj_t alarm_time_timealarm_find_triggered_alarm(size_t n_alarms, const mp_obj_t *alarms);
|
mp_obj_t alarm_time_timealarm_find_triggered_alarm(size_t n_alarms, const mp_obj_t *alarms);
|
||||||
mp_obj_t alarm_time_timealarm_create_wakeup_alarm(void);
|
mp_obj_t alarm_time_timealarm_record_wakeup_alarm(alarm_time_timealarm_obj_t *alarm);
|
||||||
|
|
||||||
void alarm_time_timealarm_reset(void);
|
void alarm_time_timealarm_reset(void);
|
||||||
void alarm_time_timealarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_obj_t *alarms);
|
void alarm_time_timealarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_obj_t *alarms);
|
||||||
|
@ -41,6 +41,10 @@
|
|||||||
#include "shared-bindings/rtc/__init__.h"
|
#include "shared-bindings/rtc/__init__.h"
|
||||||
#include "shared-bindings/pwmio/PWMOut.h"
|
#include "shared-bindings/pwmio/PWMOut.h"
|
||||||
|
|
||||||
|
#if CIRCUITPY_ALARM
|
||||||
|
#include "common-hal/alarm/__init__.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#if CIRCUITPY_SSL
|
#if CIRCUITPY_SSL
|
||||||
#include "common-hal/ssl/__init__.h"
|
#include "common-hal/ssl/__init__.h"
|
||||||
#endif
|
#endif
|
||||||
@ -154,6 +158,10 @@ safe_mode_t port_init(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void reset_port(void) {
|
void reset_port(void) {
|
||||||
|
#if CIRCUITPY_ALARM
|
||||||
|
alarm_reset();
|
||||||
|
#endif
|
||||||
|
|
||||||
#if CIRCUITPY_BUSIO
|
#if CIRCUITPY_BUSIO
|
||||||
reset_i2c();
|
reset_i2c();
|
||||||
reset_spi();
|
reset_spi();
|
||||||
|
@ -47,6 +47,13 @@ const alarm_sleep_memory_obj_t alarm_sleep_memory_obj = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Static alarm object recording alarm (if any) that woke up CircuitPython after light or deep sleep.
|
||||||
|
// This object lives across VM instantiations, so none of these objects can contain references to the heap.
|
||||||
|
static union {
|
||||||
|
alarm_pin_pinalarm_obj_t pin_alarm;
|
||||||
|
alarm_time_timealarm_obj_t time_alarm;
|
||||||
|
} wake_alarm;
|
||||||
|
|
||||||
STATIC stm_sleep_source_t true_deep_wake_reason;
|
STATIC stm_sleep_source_t true_deep_wake_reason;
|
||||||
|
|
||||||
void alarm_reset(void) {
|
void alarm_reset(void) {
|
||||||
@ -81,16 +88,16 @@ bool common_hal_alarm_woken_from_sleep(void) {
|
|||||||
return alarm_get_wakeup_cause() != STM_WAKEUP_UNDEF;
|
return alarm_get_wakeup_cause() != STM_WAKEUP_UNDEF;
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_obj_t common_hal_alarm_create_wake_alarm(void) {
|
mp_obj_t common_hal_alarm_record_wake_alarm(void) {
|
||||||
// If woken from deep sleep, create a copy alarm similar to what would have
|
// If woken from deep sleep, create a copy alarm similar to what would have
|
||||||
// been passed in originally. Otherwise, just return none
|
// been passed in originally. Otherwise, just return none
|
||||||
stm_sleep_source_t cause = alarm_get_wakeup_cause();
|
stm_sleep_source_t cause = alarm_get_wakeup_cause();
|
||||||
switch (cause) {
|
switch (cause) {
|
||||||
case STM_WAKEUP_RTC: {
|
case STM_WAKEUP_RTC: {
|
||||||
return alarm_time_timealarm_create_wakeup_alarm();
|
return alarm_time_timealarm_record_wakeup_alarm(&wake_alarm.time_alarm);
|
||||||
}
|
}
|
||||||
case STM_WAKEUP_GPIO: {
|
case STM_WAKEUP_GPIO: {
|
||||||
return alarm_pin_pinalarm_create_wakeup_alarm();
|
return alarm_pin_pinalarm_record_wakeup_alarm(&wake_alarm.pin_alarm);
|
||||||
}
|
}
|
||||||
case STM_WAKEUP_UNDEF:
|
case STM_WAKEUP_UNDEF:
|
||||||
default:
|
default:
|
||||||
|
@ -100,8 +100,7 @@ mp_obj_t alarm_pin_pinalarm_find_triggered_alarm(size_t n_alarms, const mp_obj_t
|
|||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_obj_t alarm_pin_pinalarm_create_wakeup_alarm(void) {
|
mp_obj_t alarm_pin_pinalarm_record_wakeup_alarm(alarm_pin_pinalarm_obj_t *alarm) {
|
||||||
alarm_pin_pinalarm_obj_t *alarm = m_new_obj(alarm_pin_pinalarm_obj_t);
|
|
||||||
alarm->base.type = &alarm_pin_pinalarm_type;
|
alarm->base.type = &alarm_pin_pinalarm_type;
|
||||||
// TODO: replace this if/when other WKUP pins are supported
|
// TODO: replace this if/when other WKUP pins are supported
|
||||||
alarm->pin = &pin_PA00;
|
alarm->pin = &pin_PA00;
|
||||||
|
@ -38,7 +38,7 @@ typedef struct {
|
|||||||
} alarm_pin_pinalarm_obj_t;
|
} alarm_pin_pinalarm_obj_t;
|
||||||
|
|
||||||
mp_obj_t alarm_pin_pinalarm_find_triggered_alarm(size_t n_alarms, const mp_obj_t *alarms);
|
mp_obj_t alarm_pin_pinalarm_find_triggered_alarm(size_t n_alarms, const mp_obj_t *alarms);
|
||||||
mp_obj_t alarm_pin_pinalarm_create_wakeup_alarm(void);
|
mp_obj_t alarm_pin_pinalarm_record_wakeup_alarm(alarm_pin_pinalarm_obj_t *alarm);
|
||||||
|
|
||||||
void alarm_pin_pinalarm_reset(void);
|
void alarm_pin_pinalarm_reset(void);
|
||||||
void alarm_pin_pinalarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_obj_t *alarms);
|
void alarm_pin_pinalarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_obj_t *alarms);
|
||||||
|
@ -53,12 +53,11 @@ mp_obj_t alarm_time_timealarm_find_triggered_alarm(size_t n_alarms, const mp_obj
|
|||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_obj_t alarm_time_timealarm_create_wakeup_alarm(void) {
|
mp_obj_t alarm_time_timealarm_record_wakeup_alarm(alarm_time_timealarm_obj_t *alarm) {
|
||||||
alarm_time_timealarm_obj_t *timer = m_new_obj(alarm_time_timealarm_obj_t);
|
alarm->base.type = &alarm_time_timealarm_type;
|
||||||
timer->base.type = &alarm_time_timealarm_type;
|
|
||||||
// TODO: Set monotonic_time based on the RTC state.
|
// TODO: Set monotonic_time based on the RTC state.
|
||||||
timer->monotonic_time = 0.0f;
|
alarm->monotonic_time = 0.0f;
|
||||||
return timer;
|
return alarm;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is run in the timer task. We use it to wake the main CircuitPython task.
|
// This is run in the timer task. We use it to wake the main CircuitPython task.
|
||||||
|
@ -35,7 +35,7 @@ typedef struct {
|
|||||||
} alarm_time_timealarm_obj_t;
|
} alarm_time_timealarm_obj_t;
|
||||||
|
|
||||||
mp_obj_t alarm_time_timealarm_find_triggered_alarm(size_t n_alarms, const mp_obj_t *alarms);
|
mp_obj_t alarm_time_timealarm_find_triggered_alarm(size_t n_alarms, const mp_obj_t *alarms);
|
||||||
mp_obj_t alarm_time_timealarm_create_wakeup_alarm(void);
|
mp_obj_t alarm_time_timealarm_record_wakeup_alarm(alarm_time_timealarm_obj_t *alarm);
|
||||||
|
|
||||||
bool alarm_time_timealarm_woke_this_cycle(void);
|
bool alarm_time_timealarm_woke_this_cycle(void);
|
||||||
void alarm_time_timealarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_obj_t *alarms);
|
void alarm_time_timealarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_obj_t *alarms);
|
||||||
|
@ -33,7 +33,10 @@
|
|||||||
#include "common-hal/microcontroller/Pin.h"
|
#include "common-hal/microcontroller/Pin.h"
|
||||||
#include "shared-bindings/microcontroller/__init__.h"
|
#include "shared-bindings/microcontroller/__init__.h"
|
||||||
|
|
||||||
#ifdef CIRCUITPY_AUDIOPWMIO
|
#if CIRCUITPY_ALARM
|
||||||
|
#include "common-hal/alarm/__init__.h"
|
||||||
|
#endif
|
||||||
|
#if CIRCUITPY_AUDIOPWMIO
|
||||||
#include "common-hal/audiopwmio/PWMAudioOut.h"
|
#include "common-hal/audiopwmio/PWMAudioOut.h"
|
||||||
#endif
|
#endif
|
||||||
#if CIRCUITPY_BUSIO
|
#if CIRCUITPY_BUSIO
|
||||||
@ -57,9 +60,6 @@
|
|||||||
#if CIRCUITPY_PULSEIO || CIRCUITPY_ALARM
|
#if CIRCUITPY_PULSEIO || CIRCUITPY_ALARM
|
||||||
#include "peripherals/exti.h"
|
#include "peripherals/exti.h"
|
||||||
#endif
|
#endif
|
||||||
#if CIRCUITPY_ALARM
|
|
||||||
#include "common-hal/alarm/__init__.h"
|
|
||||||
#endif
|
|
||||||
#if CIRCUITPY_RTC
|
#if CIRCUITPY_RTC
|
||||||
#include "shared-bindings/rtc/__init__.h"
|
#include "shared-bindings/rtc/__init__.h"
|
||||||
#endif
|
#endif
|
||||||
@ -244,6 +244,10 @@ void SysTick_Handler(void) {
|
|||||||
void reset_port(void) {
|
void reset_port(void) {
|
||||||
reset_all_pins();
|
reset_all_pins();
|
||||||
|
|
||||||
|
#if CIRCUITPY_ALARM
|
||||||
|
alarm_reset();
|
||||||
|
#endif
|
||||||
|
|
||||||
#if CIRCUITPY_RTC
|
#if CIRCUITPY_RTC
|
||||||
rtc_reset();
|
rtc_reset();
|
||||||
#endif
|
#endif
|
||||||
|
@ -55,7 +55,7 @@ extern void common_hal_alarm_pretending_deep_sleep(void);
|
|||||||
extern mp_obj_t shared_alarm_get_wake_alarm(void);
|
extern mp_obj_t shared_alarm_get_wake_alarm(void);
|
||||||
|
|
||||||
// Creates a new alarm object after exiting deep sleep (real or fake)
|
// Creates a new alarm object after exiting deep sleep (real or fake)
|
||||||
extern mp_obj_t common_hal_alarm_create_wake_alarm(void);
|
extern mp_obj_t common_hal_alarm_record_wake_alarm(void);
|
||||||
|
|
||||||
// Saves alarm to global array
|
// Saves alarm to global array
|
||||||
void shared_alarm_save_wake_alarm(mp_obj_t alarm);
|
void shared_alarm_save_wake_alarm(mp_obj_t alarm);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user