store wake_alarm in a static object
This commit is contained in:
parent
0221cc8df7
commit
ded134c346
21
main.c
21
main.c
@ -747,8 +747,7 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
|
||||
|
||||
supervisor_allocation *heap = allocate_remaining_memory();
|
||||
|
||||
// true means this is the first set of VM's after a hard reset.
|
||||
start_mp(heap, true);
|
||||
start_mp(heap);
|
||||
|
||||
#if CIRCUITPY_USB
|
||||
// Set up default USB values after boot.py VM starts but before running boot.py.
|
||||
@ -964,6 +963,9 @@ int __attribute__((used)) main(void) {
|
||||
// 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());
|
||||
// Then reset the alarm system. It's not reset in reset_port(), because that's also called
|
||||
// on VM teardown, which would clear any alarm setup.
|
||||
alarm_reset();
|
||||
#endif
|
||||
|
||||
// Reset everything and prep MicroPython to run boot.py.
|
||||
@ -1010,6 +1012,9 @@ int __attribute__((used)) main(void) {
|
||||
serial_write_compressed(translate("soft reboot\n"));
|
||||
}
|
||||
if (pyexec_mode_kind == PYEXEC_MODE_FRIENDLY_REPL) {
|
||||
// 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.
|
||||
skip_repl = run_code_py(safe_mode, &simulate_reset);
|
||||
} else {
|
||||
skip_repl = false;
|
||||
@ -1018,14 +1023,10 @@ int __attribute__((used)) main(void) {
|
||||
break;
|
||||
}
|
||||
|
||||
// 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
|
||||
// the first time after a hard reset. This will preserve any alarm information.
|
||||
if (!simulate_reset) {
|
||||
#if CIRCUITPY_ALARM
|
||||
shared_alarm_save_wake_alarm(mp_const_none);
|
||||
#endif
|
||||
}
|
||||
#if CIRCUITPY_ALARM
|
||||
shared_alarm_save_wake_alarm(simulate_reset ? common_hal_alarm_record_wake_alarm() : mp_const_none);
|
||||
alarm_reset();
|
||||
#endif
|
||||
}
|
||||
mp_deinit();
|
||||
return 0;
|
||||
|
@ -24,8 +24,7 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_ALARM_SLEEPMEMORY_H
|
||||
#define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_ALARM_SLEEPMEMORY_H
|
||||
#pragma once
|
||||
|
||||
#include "py/obj.h"
|
||||
|
||||
@ -34,5 +33,3 @@ typedef struct {
|
||||
} alarm_sleep_memory_obj_t;
|
||||
|
||||
extern void alarm_sleep_memory_reset(void);
|
||||
|
||||
#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_ALARM_SLEEPMEMORY_H
|
||||
|
@ -48,12 +48,9 @@ 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.
|
||||
// Non-heap 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;
|
||||
alarm_wake_alarm_union_t alarm_wake_alarm;
|
||||
|
||||
void alarm_reset(void) {
|
||||
// Reset the alarm flag
|
||||
@ -83,13 +80,13 @@ mp_obj_t common_hal_alarm_record_wake_alarm(void) {
|
||||
if (alarm_pin_pinalarm_woke_this_cycle()) {
|
||||
TAMPID = RTC->MODE0.TAMPID.reg;
|
||||
RTC->MODE0.TAMPID.reg = TAMPID; // clear register
|
||||
return alarm_pin_pinalarm_record_wakeup_alarm(&wake_alarm.pin_alarm, TAMPID);
|
||||
return alarm_pin_pinalarm_record_wake_alarm(TAMPID);
|
||||
}
|
||||
if (alarm_time_timealarm_woke_this_cycle() || (true_deep && TAMPID == 0)) {
|
||||
return alarm_time_timealarm_record_wakeup_alarm(&wake_alarm.time_alarm);
|
||||
return alarm_time_timealarm_record_wake_alarm();
|
||||
}
|
||||
if (true_deep) {
|
||||
return alarm_pin_pinalarm_record_wakeup_alarm(&wake_alarm.pin_alarm, TAMPID);
|
||||
return alarm_pin_pinalarm_record_wake_alarm(TAMPID);
|
||||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
|
@ -24,10 +24,11 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_ALARM__INIT__H
|
||||
#define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_ALARM__INIT__H
|
||||
#pragma once
|
||||
|
||||
#include "common-hal/alarm/SleepMemory.h"
|
||||
#include "common-hal/alarm/pin/PinAlarm.h"
|
||||
#include "common-hal/alarm/time/TimeAlarm.h"
|
||||
|
||||
extern const alarm_sleep_memory_obj_t alarm_sleep_memory_obj;
|
||||
|
||||
@ -53,8 +54,13 @@ typedef enum {
|
||||
SAMD_WAKEUP_RTC
|
||||
} samd_sleep_source_t;
|
||||
|
||||
extern void alarm_set_wakeup_reason(samd_sleep_source_t reason);
|
||||
void alarm_get_wakeup_cause(void);
|
||||
extern void alarm_reset(void);
|
||||
typedef union {
|
||||
alarm_pin_pinalarm_obj_t pin_alarm;
|
||||
alarm_time_timealarm_obj_t time_alarm;
|
||||
} alarm_wake_alarm_union_t;
|
||||
|
||||
#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_ALARM__INIT__H
|
||||
extern alarm_wake_alarm_union_t alarm_wake_alarm;
|
||||
|
||||
extern void alarm_set_wakeup_reason(samd_sleep_source_t reason);
|
||||
extern void alarm_get_wakeup_cause(void);
|
||||
extern void alarm_reset(void);
|
||||
|
@ -31,9 +31,9 @@
|
||||
#include "hal/include/hal_gpio.h"
|
||||
// #include <stdio.h>
|
||||
|
||||
#include "shared-bindings/alarm/__init__.h"
|
||||
#include "shared-bindings/alarm/pin/PinAlarm.h"
|
||||
#include "shared-bindings/microcontroller/__init__.h"
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
#include "common-hal/alarm/__init__.h"
|
||||
|
||||
// This variable stores whether a PinAlarm woke in light sleep or fake deep sleep
|
||||
@ -128,8 +128,8 @@ mp_obj_t alarm_pin_pinalarm_find_triggered_alarm(size_t n_alarms, const mp_obj_t
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
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
|
||||
mp_obj_t alarm_pin_pinalarm_record_wake_alarm(uint32_t TAMPID) {
|
||||
alarm_pin_pinalarm_obj_t *const alarm = &alarm_wake_alarm.pin_alarm;
|
||||
|
||||
for (samd_tamper_pin_t *t = TAMPER_PINS; t->n >= 0; t++) {
|
||||
if (TAMPID & (1 << t->n)) {
|
||||
|
@ -24,12 +24,13 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_ALARM_PINALARM_H
|
||||
#define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_ALARM_PINALARM_H
|
||||
#pragma once
|
||||
|
||||
#include "py/obj.h"
|
||||
#include "py/objtuple.h"
|
||||
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
|
||||
typedef struct {
|
||||
mp_obj_base_t base;
|
||||
const mcu_pin_obj_t *pin;
|
||||
@ -39,7 +40,7 @@ typedef struct {
|
||||
} 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_record_wakeup_alarm(alarm_pin_pinalarm_obj_t *alarm, uint32_t TAMPID);
|
||||
mp_obj_t alarm_pin_pinalarm_record_wake_alarm(uint32_t TAMPID);
|
||||
|
||||
void pin_alarm_callback(uint8_t num);
|
||||
void alarm_pin_pinalarm_reset(void);
|
||||
@ -47,5 +48,3 @@ void alarm_pin_pinalarm_deinit_alarms(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);
|
||||
void alarm_pin_pinalarm_prepare_for_deep_sleep(void);
|
||||
bool alarm_pin_pinalarm_woke_this_cycle(void);
|
||||
|
||||
#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_ALARM_PINALARM_H
|
||||
|
@ -27,9 +27,9 @@
|
||||
#include "py/runtime.h"
|
||||
#include "hpl/pm/hpl_pm_base.h"
|
||||
|
||||
#include "shared-bindings/alarm/__init__.h"
|
||||
#include "shared-bindings/alarm/time/TimeAlarm.h"
|
||||
#include "shared-bindings/time/__init__.h"
|
||||
#include "common-hal/alarm/__init__.h"
|
||||
#include "supervisor/port.h"
|
||||
|
||||
STATIC volatile bool woke_up = false;
|
||||
@ -58,7 +58,9 @@ mp_obj_t alarm_time_timealarm_find_triggered_alarm(size_t n_alarms, const mp_obj
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t alarm_time_timealarm_record_wakeup_alarm(alarm_time_timealarm_obj_t *alarm) {
|
||||
mp_obj_t alarm_time_timealarm_record_wake_alarm(void) {
|
||||
alarm_time_timealarm_obj_t *const alarm = &alarm_wake_alarm.time_alarm;
|
||||
|
||||
alarm->base.type = &alarm_time_timealarm_type;
|
||||
// TODO: Set monotonic_time based on the RTC state.
|
||||
// Or don't, most of the other ports don't have this either.
|
||||
|
@ -24,8 +24,7 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_ALARM_TIMEALARM_H
|
||||
#define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_ALARM_TIMEALARM_H
|
||||
#pragma once
|
||||
|
||||
#include "py/obj.h"
|
||||
|
||||
@ -35,12 +34,10 @@ typedef struct {
|
||||
} 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_record_wakeup_alarm(alarm_time_timealarm_obj_t *alarm);
|
||||
mp_obj_t alarm_time_timealarm_record_wake_alarm(void);
|
||||
void time_alarm_callback(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_reset(void);
|
||||
|
||||
void alarm_time_timealarm_prepare_for_deep_sleep(void);
|
||||
|
||||
#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_ALARM_TIMEALARM_H
|
||||
|
@ -24,12 +24,9 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_ALARM_TOUCHALARM_H
|
||||
#define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_ALARM_TOUCHALARM_H
|
||||
#pragma once
|
||||
|
||||
typedef struct {
|
||||
mp_obj_base_t base;
|
||||
const mcu_pin_obj_t *pin;
|
||||
} alarm_touch_touchalarm_obj_t;
|
||||
|
||||
#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_ALARM_TOUCHALARM_H
|
||||
|
@ -385,10 +385,6 @@ safe_mode_t port_init(void) {
|
||||
}
|
||||
|
||||
void reset_port(void) {
|
||||
#if CIRCUITPY_ALARM
|
||||
alarm_reset();
|
||||
#endif
|
||||
|
||||
#if CIRCUITPY_BUSIO
|
||||
reset_sercoms();
|
||||
#endif
|
||||
|
@ -24,8 +24,7 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_ALARM_SLEEPMEMORY_H
|
||||
#define MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_ALARM_SLEEPMEMORY_H
|
||||
#pragma once
|
||||
|
||||
#include "py/obj.h"
|
||||
|
||||
@ -49,5 +48,3 @@ typedef struct {
|
||||
} alarm_sleep_memory_obj_t;
|
||||
|
||||
extern void alarm_sleep_memory_reset(void);
|
||||
|
||||
#endif // MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_ALARM_SLEEPMEMORY_H
|
||||
|
@ -58,14 +58,9 @@ 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.
|
||||
// Non-heap 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;
|
||||
alarm_wake_alarm_union_t alarm_wake_alarm;
|
||||
|
||||
void alarm_reset(void) {
|
||||
alarm_sleep_memory_reset();
|
||||
@ -105,21 +100,21 @@ mp_obj_t common_hal_alarm_record_wake_alarm(void) {
|
||||
esp_sleep_wakeup_cause_t cause = _get_wakeup_cause();
|
||||
switch (cause) {
|
||||
case ESP_SLEEP_WAKEUP_TIMER: {
|
||||
return alarm_time_timealarm_record_wakeup_alarm(&wake_alarm.time_alarm);
|
||||
return alarm_time_timealarm_record_wake_alarm();
|
||||
}
|
||||
|
||||
case ESP_SLEEP_WAKEUP_GPIO:
|
||||
case ESP_SLEEP_WAKEUP_EXT0:
|
||||
case ESP_SLEEP_WAKEUP_EXT1: {
|
||||
return alarm_pin_pinalarm_record_wakeup_alarm(&wake_alarm.pin_alarm);
|
||||
return alarm_pin_pinalarm_record_wake_alarm();
|
||||
}
|
||||
|
||||
case ESP_SLEEP_WAKEUP_TOUCHPAD: {
|
||||
return alarm_touch_touchalarm_record_wakeup_alarm(&wake_alarm.touch_alarm);
|
||||
return alarm_touch_touchalarm_record_wake_alarm();
|
||||
}
|
||||
|
||||
case ESP_SLEEP_WAKEUP_ULP: {
|
||||
return alarm_coproc_coprocalarm_record_wakeup_alarm(&wake_alarm.coproc_alarm);
|
||||
return alarm_coproc_coprocalarm_record_wake_alarm();
|
||||
}
|
||||
|
||||
case ESP_SLEEP_WAKEUP_UNDEFINED:
|
||||
|
@ -24,13 +24,22 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_ALARM__INIT__H
|
||||
#define MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_ALARM__INIT__H
|
||||
#pragma once
|
||||
|
||||
#include "common-hal/alarm/SleepMemory.h"
|
||||
#include "common-hal/alarm/coproc/CoprocAlarm.h"
|
||||
#include "common-hal/alarm/pin/PinAlarm.h"
|
||||
#include "common-hal/alarm/time/TimeAlarm.h"
|
||||
#include "common-hal/alarm/touch/TouchAlarm.h"
|
||||
|
||||
const alarm_sleep_memory_obj_t alarm_sleep_memory_obj;
|
||||
typedef union {
|
||||
alarm_coproc_coprocalarm_obj_t coproc_alarm;
|
||||
alarm_pin_pinalarm_obj_t pin_alarm;
|
||||
alarm_time_timealarm_obj_t time_alarm;
|
||||
alarm_touch_touchalarm_obj_t touch_alarm;
|
||||
} alarm_wake_alarm_union_t;
|
||||
|
||||
extern alarm_wake_alarm_union_t alarm_wake_alarm;
|
||||
extern const alarm_sleep_memory_obj_t alarm_sleep_memory_obj;
|
||||
|
||||
extern void alarm_reset(void);
|
||||
|
||||
#endif // MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_ALARM__INIT__H
|
||||
|
@ -24,6 +24,7 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "shared-bindings/alarm/__init__.h"
|
||||
#include "shared-bindings/alarm/coproc/CoprocAlarm.h"
|
||||
#include "shared-bindings/coproc/__init__.h"
|
||||
|
||||
@ -47,7 +48,9 @@ mp_obj_t alarm_coproc_coprocalarm_find_triggered_alarm(const size_t n_alarms, co
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t alarm_coproc_coprocalarm_record_wakeup_alarm(alarm_coproc_coprocalarm_obj_t *alarm) {
|
||||
mp_obj_t alarm_coproc_coprocalarm_record_wake_alarm(void) {
|
||||
alarm_coproc_coprocalarm_obj_t *const alarm = &alarm_wake_alarm.coproc_alarm;
|
||||
|
||||
alarm->base.type = &alarm_coproc_coprocalarm_type;
|
||||
return alarm;
|
||||
}
|
||||
@ -109,7 +112,7 @@ mp_obj_t alarm_coproc_coprocalarm_find_triggered_alarm(const size_t n_alarms, co
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t alarm_coproc_coprocalarm_record_wakeup_alarm(void) {
|
||||
mp_obj_t alarm_coproc_coprocalarm_record_wake_alarm(void) {
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
|
@ -24,8 +24,7 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MICROPY_INCLUDED_COMMON_HAL_ALARM_COPROC_COPROCALARM_H
|
||||
#define MICROPY_INCLUDED_COMMON_HAL_ALARM_COPROC_COPROCALARM_H
|
||||
#pragma once
|
||||
|
||||
#include "py/obj.h"
|
||||
#include "py/runtime.h"
|
||||
@ -38,11 +37,9 @@ typedef struct {
|
||||
} 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_record_wakeup_alarm(void);
|
||||
mp_obj_t alarm_coproc_coprocalarm_record_wake_alarm(void);
|
||||
|
||||
void alarm_coproc_coprocalarm_prepare_for_deep_sleep(void);
|
||||
void alarm_coproc_coprocalarm_reset(void);
|
||||
void alarm_coproc_coprocalarm_set_alarm(const bool deep_sleep, const size_t n_alarms, const mp_obj_t *alarms);
|
||||
bool alarm_coproc_coprocalarm_woke_this_cycle(void);
|
||||
|
||||
#endif // MICROPY_INCLUDED_COMMON_HAL_ALARM_COPROC_COPROCALARM_H
|
||||
|
@ -26,10 +26,10 @@
|
||||
*/
|
||||
|
||||
#include "py/runtime.h"
|
||||
|
||||
#include "supervisor/port.h"
|
||||
|
||||
#include "common-hal/alarm/__init__.h"
|
||||
#include "shared-bindings/alarm/pin/PinAlarm.h"
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
#include "shared-bindings/microcontroller/__init__.h"
|
||||
|
||||
#include "esp_sleep.h"
|
||||
@ -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;
|
||||
}
|
||||
|
||||
mp_obj_t alarm_pin_pinalarm_record_wakeup_alarm(alarm_pin_pinalarm_obj_t *alarm) {
|
||||
mp_obj_t alarm_pin_pinalarm_record_wake_alarm(void) {
|
||||
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
|
||||
|
||||
// Pin status will persist into a fake deep sleep
|
||||
@ -135,6 +135,8 @@ mp_obj_t alarm_pin_pinalarm_record_wakeup_alarm(alarm_pin_pinalarm_obj_t *alarm)
|
||||
}
|
||||
}
|
||||
|
||||
alarm_pin_pinalarm_obj_t *const alarm = &alarm_wake_alarm.pin_alarm;
|
||||
|
||||
alarm->base.type = &alarm_pin_pinalarm_type;
|
||||
alarm->pin = NULL;
|
||||
// Map the pin number back to a pin object.
|
||||
|
@ -24,9 +24,13 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "py/obj.h"
|
||||
#include "py/objtuple.h"
|
||||
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
|
||||
typedef struct {
|
||||
mp_obj_base_t base;
|
||||
const mcu_pin_obj_t *pin;
|
||||
@ -35,7 +39,7 @@ typedef struct {
|
||||
} 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_record_wakeup_alarm(void);
|
||||
mp_obj_t alarm_pin_pinalarm_record_wake_alarm(void);
|
||||
|
||||
void alarm_pin_pinalarm_prepare_for_deep_sleep(void);
|
||||
void alarm_pin_pinalarm_reset(void);
|
||||
|
@ -31,6 +31,7 @@
|
||||
|
||||
#include "components/esp_timer/include/esp_timer.h"
|
||||
|
||||
#include "shared-bindings/alarm/__init__.h"
|
||||
#include "shared-bindings/alarm/time/TimeAlarm.h"
|
||||
#include "shared-bindings/time/__init__.h"
|
||||
|
||||
@ -51,7 +52,9 @@ mp_obj_t alarm_time_timealarm_find_triggered_alarm(size_t n_alarms, const mp_obj
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t alarm_time_timealarm_record_wakeup_alarm(alarm_time_timealarm_obj_t *alarm) {
|
||||
mp_obj_t alarm_time_timealarm_record_wake_alarm(void) {
|
||||
alarm_time_timealarm_obj_t *const alarm = &alarm_wake_alarm.time_alarm;
|
||||
|
||||
alarm->base.type = &alarm_time_timealarm_type;
|
||||
// TODO: Set monotonic_time based on the RTC state.
|
||||
alarm->monotonic_time = 0.0f;
|
||||
|
@ -24,6 +24,7 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "py/obj.h"
|
||||
|
||||
@ -33,7 +34,7 @@ typedef struct {
|
||||
} 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_record_wakeup_alarm(alarm_time_timealarm_obj_t *alarm);
|
||||
mp_obj_t alarm_time_timealarm_record_wake_alarm(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);
|
||||
|
@ -24,6 +24,7 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "shared-bindings/alarm/__init__.h"
|
||||
#include "shared-bindings/alarm/touch/TouchAlarm.h"
|
||||
#include "shared-bindings/microcontroller/__init__.h"
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
@ -52,8 +53,9 @@ mp_obj_t alarm_touch_touchalarm_find_triggered_alarm(const size_t n_alarms, cons
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t alarm_touch_touchalarm_record_wakeup_alarm(alarm_touch_touchalarm_obj_t *alarm) {
|
||||
// Create TouchAlarm object.
|
||||
mp_obj_t alarm_touch_touchalarm_record_wake_alarm(void) {
|
||||
alarm_touch_touchalarm_obj_t *const alarm = &alarm_wake_alarm.touch_alarm;
|
||||
|
||||
alarm->base.type = &alarm_touch_touchalarm_type;
|
||||
alarm->pin = NULL;
|
||||
|
||||
|
@ -24,8 +24,7 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MICROPY_INCLUDED_COMMON_HAL_ALARM_TOUCH_TOUCHALARM_H
|
||||
#define MICROPY_INCLUDED_COMMON_HAL_ALARM_TOUCH_TOUCHALARM_H
|
||||
#pragma once
|
||||
|
||||
#include "py/obj.h"
|
||||
#include "common-hal/microcontroller/Pin.h"
|
||||
@ -36,11 +35,9 @@ typedef struct {
|
||||
} 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_record_wakeup_alarm(alarm_touch_touchalarm_obj_t *alarm);
|
||||
mp_obj_t alarm_touch_touchalarm_record_wake_alarm(void);
|
||||
|
||||
void alarm_touch_touchalarm_prepare_for_deep_sleep(void);
|
||||
void alarm_touch_touchalarm_reset(void);
|
||||
void alarm_touch_touchalarm_set_alarm(const bool deep_sleep, const size_t n_alarms, const mp_obj_t *alarms);
|
||||
bool alarm_touch_touchalarm_woke_this_cycle(void);
|
||||
|
||||
#endif // MICROPY_INCLUDED_COMMON_HAL_ALARM_TOUCH_TOUCHALARM_H
|
||||
|
@ -60,10 +60,6 @@
|
||||
#include "peripherals/rmt.h"
|
||||
#include "peripherals/timer.h"
|
||||
|
||||
#if CIRCUITPY_ALARM
|
||||
#include "common-hal/alarm/__init__.h"
|
||||
#endif
|
||||
|
||||
#if CIRCUITPY_COUNTIO || CIRCUITPY_ROTARYIO || CIRCUITPY_FREQUENCYIO
|
||||
#include "peripherals/pcnt.h"
|
||||
#endif
|
||||
@ -342,10 +338,6 @@ safe_mode_t port_init(void) {
|
||||
}
|
||||
|
||||
void reset_port(void) {
|
||||
#if CIRCUITPY_ALARM
|
||||
alarm_reset();
|
||||
#endif
|
||||
|
||||
// TODO deinit for esp32-camera
|
||||
#if CIRCUITPY_ESP32_CAMERA
|
||||
esp_camera_deinit();
|
||||
|
@ -24,8 +24,7 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MICROPY_INCLUDED_NRF_COMMON_HAL_ALARM_SLEEPMEMORY_H
|
||||
#define MICROPY_INCLUDED_NRF_COMMON_HAL_ALARM_SLEEPMEMORY_H
|
||||
#pragma once
|
||||
|
||||
#include "py/obj.h"
|
||||
|
||||
@ -37,5 +36,3 @@ typedef struct {
|
||||
|
||||
extern void set_memory_retention(void);
|
||||
extern void alarm_sleep_memory_reset(void);
|
||||
|
||||
#endif // MICROPY_INCLUDED_NRF_COMMON_HAL_ALARM_SLEEPMEMORY_H
|
||||
|
@ -56,13 +56,9 @@ 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.
|
||||
// Non-heap 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;
|
||||
alarm_wake_alarm_union_t alarm_wake_alarm;
|
||||
|
||||
void alarm_reset(void) {
|
||||
alarm_sleep_memory_reset();
|
||||
@ -129,13 +125,13 @@ mp_obj_t common_hal_alarm_record_wake_alarm(void) {
|
||||
nrf_sleep_source_t cause = _get_wakeup_cause();
|
||||
switch (cause) {
|
||||
case NRF_SLEEP_WAKEUP_TIMER: {
|
||||
return alarm_time_timealarm_record_wakeup_alarm(&wake_alarm.time_alarm);
|
||||
return alarm_time_timealarm_record_wake_alarm();
|
||||
}
|
||||
case NRF_SLEEP_WAKEUP_TOUCHPAD: {
|
||||
return alarm_touch_touchalarm_record_wakeup_alarm(&wake_alarm.touch_alarm);
|
||||
return alarm_touch_touchalarm_record_wake_alarm();
|
||||
}
|
||||
case NRF_SLEEP_WAKEUP_GPIO: {
|
||||
return alarm_pin_pinalarm_record_wakeup_alarm(&wake_alarm.pin_alarm);
|
||||
return alarm_pin_pinalarm_record_wake_alarm();
|
||||
}
|
||||
default:
|
||||
break;
|
||||
|
@ -25,10 +25,12 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MICROPY_INCLUDED_NRF_COMMON_HAL_ALARM__INIT__H
|
||||
#define MICROPY_INCLUDED_NRF_COMMON_HAL_ALARM__INIT__H
|
||||
#pragma once
|
||||
|
||||
#include "common-hal/alarm/SleepMemory.h"
|
||||
#include "common-hal/alarm/pin/PinAlarm.h"
|
||||
#include "common-hal/alarm/time/TimeAlarm.h"
|
||||
#include "common-hal/alarm/touch/TouchAlarm.h"
|
||||
|
||||
typedef enum {
|
||||
NRF_SLEEP_WAKEUP_UNDEFINED,
|
||||
@ -40,6 +42,13 @@ typedef enum {
|
||||
NRF_SLEEP_WAKEUP_ZZZ
|
||||
} nrf_sleep_source_t;
|
||||
|
||||
typedef union {
|
||||
alarm_pin_pinalarm_obj_t pin_alarm;
|
||||
alarm_time_timealarm_obj_t time_alarm;
|
||||
alarm_touch_touchalarm_obj_t touch_alarm;
|
||||
} alarm_wake_alarm_union_t;
|
||||
|
||||
extern alarm_wake_alarm_union_t alarm_wake_alarm;
|
||||
extern const alarm_sleep_memory_obj_t alarm_sleep_memory_obj;
|
||||
|
||||
enum {
|
||||
@ -52,5 +61,3 @@ extern uint8_t sleepmem_wakeup_event;
|
||||
extern uint8_t sleepmem_wakeup_pin;
|
||||
|
||||
extern void alarm_reset(void);
|
||||
|
||||
#endif // MICROPY_INCLUDED_NRF_COMMON_HAL_ALARM__INIT__H
|
||||
|
@ -30,10 +30,9 @@
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "shared-bindings/alarm/__init__.h"
|
||||
#include "shared-bindings/alarm/pin/PinAlarm.h"
|
||||
#include "shared-bindings/microcontroller/__init__.h"
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
#include "common-hal/alarm/__init__.h"
|
||||
|
||||
#include "nrfx.h"
|
||||
#include "nrf_gpio.h"
|
||||
@ -101,7 +100,9 @@ mp_obj_t alarm_pin_pinalarm_find_triggered_alarm(size_t n_alarms, const mp_obj_t
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t alarm_pin_pinalarm_record_wakeup_alarm(alarm_pin_pinalarm_obj_t *alarm) {
|
||||
mp_obj_t alarm_pin_pinalarm_record_wake_alarm(void) {
|
||||
alarm_pin_pinalarm_obj_t *const alarm = &alarm_wake_alarm.pin_alarm;
|
||||
|
||||
alarm->base.type = &alarm_pin_pinalarm_type;
|
||||
alarm->pin = NULL;
|
||||
// Map the pin number back to a pin object.
|
||||
|
@ -24,9 +24,13 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "py/obj.h"
|
||||
#include "py/objtuple.h"
|
||||
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
|
||||
typedef struct {
|
||||
mp_obj_base_t base;
|
||||
const mcu_pin_obj_t *pin;
|
||||
@ -35,7 +39,7 @@ typedef struct {
|
||||
} 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_record_wakeup_alarm(alarm_pin_pinalarm_obj_t *alarm);
|
||||
mp_obj_t alarm_pin_pinalarm_record_wake_alarm(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);
|
||||
|
@ -28,7 +28,7 @@
|
||||
#include "py/runtime.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#include "common-hal/alarm/__init__.h"
|
||||
#include "shared-bindings/alarm/__init__.h"
|
||||
#include "shared-bindings/alarm/time/TimeAlarm.h"
|
||||
#include "shared-bindings/time/__init__.h"
|
||||
|
||||
@ -49,7 +49,9 @@ mp_obj_t alarm_time_timealarm_find_triggered_alarm(size_t n_alarms, const mp_obj
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t alarm_time_timealarm_record_wakeup_alarm(alarm_time_timealarm_obj_t *alarm) {
|
||||
mp_obj_t alarm_time_timealarm_record_wake_alarm(void) {
|
||||
alarm_time_timealarm_obj_t *const alarm = &alarm_wake_alarm.time_alarm;
|
||||
|
||||
alarm->base.type = &alarm_time_timealarm_type;
|
||||
// TODO: Set monotonic_time based on the RTC state.
|
||||
alarm->monotonic_time = 0.0f;
|
||||
|
@ -24,6 +24,7 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "py/obj.h"
|
||||
|
||||
@ -37,7 +38,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);
|
||||
|
||||
mp_obj_t alarm_time_timealarm_find_triggered_alarm(size_t n_alarms, const mp_obj_t *alarms);
|
||||
mp_obj_t alarm_time_timealarm_record_wakeup_alarm(alarm_time_timealarm_obj_t *alarm);
|
||||
mp_obj_t alarm_time_timealarm_record_wake_alarm(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);
|
||||
|
@ -25,6 +25,7 @@
|
||||
*/
|
||||
|
||||
#include "py/runtime.h"
|
||||
|
||||
#include "shared-bindings/alarm/touch/TouchAlarm.h"
|
||||
#include "shared-bindings/microcontroller/__init__.h"
|
||||
|
||||
@ -39,7 +40,7 @@ mp_obj_t alarm_touch_touchalarm_find_triggered_alarm(const size_t n_alarms, cons
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t alarm_touch_touchalarm_record_wakeup_alarm(alarm_touch_touchalarm_obj_t *alarm) {
|
||||
mp_obj_t alarm_touch_touchalarm_record_wake_alarm(void) {
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
|
@ -24,8 +24,7 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MICROPY_INCLUDED_COMMON_HAL_ALARM_TOUCH_TOUCHALARM_H
|
||||
#define MICROPY_INCLUDED_COMMON_HAL_ALARM_TOUCH_TOUCHALARM_H
|
||||
#pragma once
|
||||
|
||||
#include "py/obj.h"
|
||||
#include "common-hal/microcontroller/Pin.h"
|
||||
@ -37,11 +36,9 @@ typedef struct {
|
||||
|
||||
// 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_record_wakeup_alarm(void);
|
||||
mp_obj_t alarm_touch_touchalarm_record_wake_alarm(void);
|
||||
// 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_prepare_for_deep_sleep(void);
|
||||
bool alarm_touch_touchalarm_woke_this_cycle(void);
|
||||
void alarm_touch_touchalarm_reset(void);
|
||||
|
||||
#endif // MICROPY_INCLUDED_COMMON_HAL_ALARM_TOUCH_TOUCHALARM_H
|
||||
|
@ -64,15 +64,11 @@
|
||||
|
||||
#include "lib/tinyusb/src/device/usbd.h"
|
||||
|
||||
#if CIRCUITPY_ALARM
|
||||
#include "common-hal/alarm/__init__.h"
|
||||
#endif
|
||||
|
||||
#ifdef CIRCUITPY_AUDIOBUSIO
|
||||
#if CIRCUITPY_AUDIOBUSIO
|
||||
#include "common-hal/audiobusio/I2SOut.h"
|
||||
#endif
|
||||
|
||||
#ifdef CIRCUITPY_AUDIOPWMIO
|
||||
#if CIRCUITPY_AUDIOPWMIO
|
||||
#include "common-hal/audiopwmio/PWMAudioOut.h"
|
||||
#endif
|
||||
|
||||
@ -216,10 +212,6 @@ safe_mode_t port_init(void) {
|
||||
}
|
||||
|
||||
void reset_port(void) {
|
||||
#if CIRCUITPY_ALARM
|
||||
alarm_reset();
|
||||
#endif
|
||||
|
||||
#if CIRCUITPY_BUSIO
|
||||
i2c_reset();
|
||||
spi_reset();
|
||||
|
@ -24,8 +24,7 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MICROPY_INCLUDED_RASPBERRYPI_COMMON_HAL_ALARM_SLEEPMEMORY_H
|
||||
#define MICROPY_INCLUDED_RASPBERRYPI_COMMON_HAL_ALARM_SLEEPMEMORY_H
|
||||
#pragma once
|
||||
|
||||
#include "py/obj.h"
|
||||
|
||||
@ -34,5 +33,3 @@ typedef struct {
|
||||
} alarm_sleep_memory_obj_t;
|
||||
|
||||
extern void alarm_sleep_memory_reset(void);
|
||||
|
||||
#endif // MICROPY_INCLUDED_RASPBERRYPI_COMMON_HAL_ALARM_SLEEPMEMORY_H
|
||||
|
@ -96,12 +96,9 @@ 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.
|
||||
// Non-heap 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;
|
||||
alarm_wake_alarm_union_t alarm_wake_alarm;
|
||||
|
||||
void alarm_reset(void) {
|
||||
alarm_sleep_memory_reset();
|
||||
@ -144,11 +141,11 @@ mp_obj_t common_hal_alarm_record_wake_alarm(void) {
|
||||
uint8_t cause = _get_wakeup_cause();
|
||||
switch (cause) {
|
||||
case RP_SLEEP_WAKEUP_RTC: {
|
||||
return alarm_time_timealarm_record_wakeup_alarm(&wake_alarm.time_alarm);
|
||||
return alarm_time_timealarm_record_wake_alarm();
|
||||
}
|
||||
|
||||
case RP_SLEEP_WAKEUP_GPIO: {
|
||||
return alarm_pin_pinalarm_record_wakeup_alarm(&wake_alarm.pin_alarm);
|
||||
return alarm_pin_pinalarm_record_wake_alarm();
|
||||
}
|
||||
|
||||
case RP_SLEEP_WAKEUP_UNDEF:
|
||||
|
@ -24,10 +24,11 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MICROPY_INCLUDED_RASPBERRYPI_COMMON_HAL_ALARM__INIT__H
|
||||
#define MICROPY_INCLUDED_RASPBERRYPI_COMMON_HAL_ALARM__INIT__H
|
||||
#pragma once
|
||||
|
||||
#include "common-hal/alarm/SleepMemory.h"
|
||||
#include "common-hal/alarm/pin/PinAlarm.h"
|
||||
#include "common-hal/alarm/time/TimeAlarm.h"
|
||||
|
||||
#include "hardware/regs/clocks.h"
|
||||
|
||||
@ -35,8 +36,12 @@
|
||||
#define RP_SLEEP_WAKEUP_GPIO 1
|
||||
#define RP_SLEEP_WAKEUP_RTC 2
|
||||
|
||||
typedef union {
|
||||
alarm_pin_pinalarm_obj_t pin_alarm;
|
||||
alarm_time_timealarm_obj_t time_alarm;
|
||||
} alarm_wake_alarm_union_t;
|
||||
|
||||
extern alarm_wake_alarm_union_t alarm_wake_alarm;
|
||||
extern const alarm_sleep_memory_obj_t alarm_sleep_memory_obj;
|
||||
|
||||
extern void alarm_reset(void);
|
||||
|
||||
#endif // MICROPY_INCLUDED_RASPBERRYPI_COMMON_HAL_ALARM__INIT__H
|
||||
|
@ -26,10 +26,10 @@
|
||||
|
||||
#include "py/runtime.h"
|
||||
|
||||
#include "shared-bindings/alarm/__init__.h"
|
||||
#include "shared-bindings/alarm/pin/PinAlarm.h"
|
||||
#include "shared-bindings/microcontroller/__init__.h"
|
||||
#include "common-hal/microcontroller/__init__.h"
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
|
||||
#include "pico/stdlib.h"
|
||||
#include "hardware/gpio.h"
|
||||
@ -94,7 +94,9 @@ mp_obj_t alarm_pin_pinalarm_find_triggered_alarm(size_t n_alarms, const mp_obj_t
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t alarm_pin_pinalarm_record_wakeup_alarm(alarm_pin_pinalarm_obj_t *alarm) {
|
||||
mp_obj_t alarm_pin_pinalarm_record_wake_alarm(void) {
|
||||
alarm_pin_pinalarm_obj_t *const alarm = &alarm_wake_alarm.pin_alarm;
|
||||
|
||||
alarm->base.type = &alarm_pin_pinalarm_type;
|
||||
// TODO: how to obtain the correct pin from memory?
|
||||
alarm->pin = NULL;
|
||||
|
@ -24,9 +24,13 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "py/obj.h"
|
||||
#include "py/objtuple.h"
|
||||
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
|
||||
typedef struct {
|
||||
mp_obj_base_t base;
|
||||
const mcu_pin_obj_t *pin;
|
||||
@ -36,7 +40,7 @@ typedef struct {
|
||||
} 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_record_wakeup_alarm(alarm_pin_pinalarm_obj_t *alarm);
|
||||
mp_obj_t alarm_pin_pinalarm_record_wake_alarm(void);
|
||||
|
||||
void alarm_pin_pinalarm_reset(void);
|
||||
void alarm_pin_pinalarm_light_reset(void);
|
||||
|
@ -26,6 +26,7 @@
|
||||
|
||||
#include "py/runtime.h"
|
||||
|
||||
#include "shared-bindings/alarm/__init__.h"
|
||||
#include "shared-bindings/alarm/time/TimeAlarm.h"
|
||||
#include "shared-bindings/time/__init__.h"
|
||||
|
||||
@ -58,7 +59,9 @@ mp_obj_t alarm_time_timealarm_find_triggered_alarm(size_t n_alarms, const mp_obj
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t alarm_time_timealarm_record_wakeup_alarm(alarm_time_timealarm_obj_t *alarm) {
|
||||
mp_obj_t alarm_time_timealarm_record_wake_alarm(void) {
|
||||
alarm_time_timealarm_obj_t *const alarm = &alarm_wake_alarm.time_alarm;
|
||||
|
||||
alarm->base.type = &alarm_time_timealarm_type;
|
||||
// TODO: Set monotonic_time based on the RTC state.
|
||||
alarm->monotonic_time = 0.0f;
|
||||
|
@ -24,6 +24,7 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "py/obj.h"
|
||||
|
||||
@ -33,7 +34,7 @@ typedef struct {
|
||||
} 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_record_wakeup_alarm(alarm_time_timealarm_obj_t *alarm);
|
||||
mp_obj_t alarm_time_timealarm_record_wake_alarm(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);
|
||||
|
@ -24,8 +24,7 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MICROPY_INCLUDED_RASPBERRYPI_COMMON_HAL_ALARM_TOUCH_TOUCHALARM_H
|
||||
#define MICROPY_INCLUDED_RASPBERRYPI_COMMON_HAL_ALARM_TOUCH_TOUCHALARM_H
|
||||
#pragma once
|
||||
|
||||
#include "py/obj.h"
|
||||
#include "common-hal/microcontroller/Pin.h"
|
||||
@ -34,5 +33,3 @@ typedef struct {
|
||||
mp_obj_base_t base;
|
||||
const mcu_pin_obj_t *pin;
|
||||
} alarm_touch_touchalarm_obj_t;
|
||||
|
||||
#endif // MICROPY_INCLUDED_RASPBERRYPI_COMMON_HAL_ALARM_TOUCH_TOUCHALARM_H
|
||||
|
@ -41,10 +41,6 @@
|
||||
#include "shared-bindings/rtc/__init__.h"
|
||||
#include "shared-bindings/pwmio/PWMOut.h"
|
||||
|
||||
#if CIRCUITPY_ALARM
|
||||
#include "common-hal/alarm/__init__.h"
|
||||
#endif
|
||||
|
||||
#if CIRCUITPY_SSL
|
||||
#include "common-hal/ssl/__init__.h"
|
||||
#endif
|
||||
@ -158,10 +154,6 @@ safe_mode_t port_init(void) {
|
||||
}
|
||||
|
||||
void reset_port(void) {
|
||||
#if CIRCUITPY_ALARM
|
||||
alarm_reset();
|
||||
#endif
|
||||
|
||||
#if CIRCUITPY_BUSIO
|
||||
reset_i2c();
|
||||
reset_spi();
|
||||
|
@ -24,8 +24,7 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MICROPY_INCLUDED_STM32_COMMON_HAL_ALARM_SLEEPMEMORY_H
|
||||
#define MICROPY_INCLUDED_STM32_COMMON_HAL_ALARM_SLEEPMEMORY_H
|
||||
#pragma once
|
||||
|
||||
#include "py/obj.h"
|
||||
|
||||
@ -34,5 +33,3 @@ typedef struct {
|
||||
} alarm_sleep_memory_obj_t;
|
||||
|
||||
extern void alarm_sleep_memory_reset(void);
|
||||
|
||||
#endif // MICROPY_INCLUDED_STM32_COMMON_HAL_ALARM_SLEEPMEMORY_H
|
||||
|
@ -47,12 +47,9 @@ 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.
|
||||
// Non-heap 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;
|
||||
alarm_wake_alarm_union_t alarm_wake_alarm;
|
||||
|
||||
STATIC stm_sleep_source_t true_deep_wake_reason;
|
||||
|
||||
@ -94,10 +91,10 @@ mp_obj_t common_hal_alarm_record_wake_alarm(void) {
|
||||
stm_sleep_source_t cause = alarm_get_wakeup_cause();
|
||||
switch (cause) {
|
||||
case STM_WAKEUP_RTC: {
|
||||
return alarm_time_timealarm_record_wakeup_alarm(&wake_alarm.time_alarm);
|
||||
return alarm_time_timealarm_record_wake_alarm();
|
||||
}
|
||||
case STM_WAKEUP_GPIO: {
|
||||
return alarm_pin_pinalarm_record_wakeup_alarm(&wake_alarm.pin_alarm);
|
||||
return alarm_pin_pinalarm_record_wake_alarm();
|
||||
}
|
||||
case STM_WAKEUP_UNDEF:
|
||||
default:
|
||||
|
@ -24,10 +24,11 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MICROPY_INCLUDED_STM32_COMMON_HAL_ALARM__INIT__H
|
||||
#define MICROPY_INCLUDED_STM32_COMMON_HAL_ALARM__INIT__H
|
||||
#pragma once
|
||||
|
||||
#include "common-hal/alarm/SleepMemory.h"
|
||||
#include "common-hal/alarm/pin/PinAlarm.h"
|
||||
#include "common-hal/alarm/time/TimeAlarm.h"
|
||||
|
||||
extern const alarm_sleep_memory_obj_t alarm_sleep_memory_obj;
|
||||
|
||||
@ -37,10 +38,15 @@ typedef enum {
|
||||
STM_WAKEUP_RTC
|
||||
} stm_sleep_source_t;
|
||||
|
||||
typedef union {
|
||||
alarm_pin_pinalarm_obj_t pin_alarm;
|
||||
alarm_time_timealarm_obj_t time_alarm;
|
||||
} alarm_wake_alarm_union_t;
|
||||
|
||||
extern alarm_wake_alarm_union_t alarm_wake_alarm;
|
||||
|
||||
#define STM_ALARM_FLAG (RTC->BKP0R)
|
||||
|
||||
extern void alarm_set_wakeup_reason(stm_sleep_source_t reason);
|
||||
stm_sleep_source_t alarm_get_wakeup_cause(void);
|
||||
extern stm_sleep_source_t alarm_get_wakeup_cause(void);
|
||||
extern void alarm_reset(void);
|
||||
|
||||
#endif // MICROPY_INCLUDED_STM32_COMMON_HAL_ALARM__INIT__H
|
||||
|
@ -26,6 +26,7 @@
|
||||
|
||||
#include "py/runtime.h"
|
||||
|
||||
#include "shared-bindings/alarm/__init__.h"
|
||||
#include "shared-bindings/alarm/pin/PinAlarm.h"
|
||||
|
||||
#include "peripherals/exti.h"
|
||||
@ -100,7 +101,9 @@ mp_obj_t alarm_pin_pinalarm_find_triggered_alarm(size_t n_alarms, const mp_obj_t
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t alarm_pin_pinalarm_record_wakeup_alarm(alarm_pin_pinalarm_obj_t *alarm) {
|
||||
mp_obj_t alarm_pin_pinalarm_record_wake_alarm(void) {
|
||||
alarm_pin_pinalarm_obj_t *const alarm = &alarm_wake_alarm.pin_alarm;
|
||||
|
||||
alarm->base.type = &alarm_pin_pinalarm_type;
|
||||
// TODO: replace this if/when other WKUP pins are supported
|
||||
alarm->pin = &pin_PA00;
|
||||
|
@ -24,12 +24,13 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MICROPY_INCLUDED_STM32_COMMON_HAL_ALARM_PINALARM_H
|
||||
#define MICROPY_INCLUDED_STM32_COMMON_HAL_ALARM_PINALARM_H
|
||||
#pragma once
|
||||
|
||||
#include "py/obj.h"
|
||||
#include "py/objtuple.h"
|
||||
|
||||
#include "shared-bindings/microcontroller/Pin.h"
|
||||
|
||||
typedef struct {
|
||||
mp_obj_base_t base;
|
||||
const mcu_pin_obj_t *pin;
|
||||
@ -38,11 +39,9 @@ typedef struct {
|
||||
} 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_record_wakeup_alarm(alarm_pin_pinalarm_obj_t *alarm);
|
||||
mp_obj_t alarm_pin_pinalarm_record_wake_alarm(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_prepare_for_deep_sleep(void);
|
||||
bool alarm_pin_pinalarm_woke_this_cycle(void);
|
||||
|
||||
#endif // MICROPY_INCLUDED_STM32_COMMON_HAL_ALARM_PINALARM_H
|
||||
|
@ -26,6 +26,7 @@
|
||||
|
||||
#include "py/runtime.h"
|
||||
|
||||
#include "shared-bindings/alarm/__init__.h"
|
||||
#include "shared-bindings/alarm/time/TimeAlarm.h"
|
||||
#include "shared-bindings/time/__init__.h"
|
||||
#include "peripherals/rtc.h"
|
||||
@ -53,7 +54,9 @@ mp_obj_t alarm_time_timealarm_find_triggered_alarm(size_t n_alarms, const mp_obj
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t alarm_time_timealarm_record_wakeup_alarm(alarm_time_timealarm_obj_t *alarm) {
|
||||
mp_obj_t alarm_time_timealarm_record_wake_alarm(void) {
|
||||
alarm_time_timealarm_obj_t *const alarm = &alarm_wake_alarm.time_alarm;
|
||||
|
||||
alarm->base.type = &alarm_time_timealarm_type;
|
||||
// TODO: Set monotonic_time based on the RTC state.
|
||||
alarm->monotonic_time = 0.0f;
|
||||
|
@ -24,8 +24,7 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MICROPY_INCLUDED_STM32_COMMON_HAL_ALARM_TIMEALARM_H
|
||||
#define MICROPY_INCLUDED_STM32_COMMON_HAL_ALARM_TIMEALARM_H
|
||||
#pragma once
|
||||
|
||||
#include "py/obj.h"
|
||||
|
||||
@ -35,12 +34,10 @@ typedef struct {
|
||||
} 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_record_wakeup_alarm(alarm_time_timealarm_obj_t *alarm);
|
||||
mp_obj_t alarm_time_timealarm_record_wake_alarm(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_reset(void);
|
||||
|
||||
void alarm_time_timealarm_prepare_for_deep_sleep(void);
|
||||
|
||||
#endif // MICROPY_INCLUDED_STM32_COMMON_HAL_ALARM_TIMEALARM_H
|
||||
|
@ -24,12 +24,9 @@
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MICROPY_INCLUDED_STM32_COMMON_HAL_ALARM_TOUCHALARM_H
|
||||
#define MICROPY_INCLUDED_STM32_COMMON_HAL_ALARM_TOUCHALARM_H
|
||||
#pragma once
|
||||
|
||||
typedef struct {
|
||||
mp_obj_base_t base;
|
||||
const mcu_pin_obj_t *pin;
|
||||
} alarm_touch_touchalarm_obj_t;
|
||||
|
||||
#endif // MICROPY_INCLUDED_STM32_COMMON_HAL_ALARM_TOUCHALARM_H
|
||||
|
@ -33,10 +33,7 @@
|
||||
#include "common-hal/microcontroller/Pin.h"
|
||||
#include "shared-bindings/microcontroller/__init__.h"
|
||||
|
||||
#if CIRCUITPY_ALARM
|
||||
#include "common-hal/alarm/__init__.h"
|
||||
#endif
|
||||
#if CIRCUITPY_AUDIOPWMIO
|
||||
#ifdef CIRCUITPY_AUDIOPWMIO
|
||||
#include "common-hal/audiopwmio/PWMAudioOut.h"
|
||||
#endif
|
||||
#if CIRCUITPY_BUSIO
|
||||
@ -60,6 +57,9 @@
|
||||
#if CIRCUITPY_PULSEIO || CIRCUITPY_ALARM
|
||||
#include "peripherals/exti.h"
|
||||
#endif
|
||||
#if CIRCUITPY_ALARM
|
||||
#include "common-hal/alarm/__init__.h"
|
||||
#endif
|
||||
#if CIRCUITPY_RTC
|
||||
#include "shared-bindings/rtc/__init__.h"
|
||||
#endif
|
||||
@ -244,10 +244,6 @@ void SysTick_Handler(void) {
|
||||
void reset_port(void) {
|
||||
reset_all_pins();
|
||||
|
||||
#if CIRCUITPY_ALARM
|
||||
alarm_reset();
|
||||
#endif
|
||||
|
||||
#if CIRCUITPY_RTC
|
||||
rtc_reset();
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user