Clean up API
This commit is contained in:
parent
91e530d36c
commit
17585e1e07
7
main.c
7
main.c
@ -163,7 +163,7 @@ STATIC void start_mp(supervisor_allocation* heap) {
|
||||
// Record which alarm woke us up, if any. An object may be created so the heap must be functional.
|
||||
shared_alarm_save_wake_alarm();
|
||||
// Reset alarm module only after we retrieved the wakeup alarm.
|
||||
common_hal_alarm_reset();
|
||||
alarm_reset();
|
||||
#endif
|
||||
|
||||
#if CIRCUITPY_NETWORK
|
||||
@ -293,9 +293,13 @@ STATIC bool run_code_py(safe_mode_t safe_mode) {
|
||||
stack_resize();
|
||||
filesystem_flush();
|
||||
supervisor_allocation* heap = allocate_remaining_memory();
|
||||
|
||||
// Prepare the VM state. Includes an alarm check/reset for sleep.
|
||||
start_mp(heap);
|
||||
|
||||
// This is where the user's python code is actually executed:
|
||||
found_main = maybe_run_list(supported_filenames, &result);
|
||||
// If that didn't work, double check the extensions
|
||||
#if CIRCUITPY_FULL_BUILD
|
||||
if (!found_main){
|
||||
found_main = maybe_run_list(double_extension_filenames, &result);
|
||||
@ -305,6 +309,7 @@ STATIC bool run_code_py(safe_mode_t safe_mode) {
|
||||
}
|
||||
#endif
|
||||
|
||||
// Finished executing python code. Cleanup includes a board reset.
|
||||
cleanup_after_vm(heap);
|
||||
|
||||
if (result.return_code & PYEXEC_FORCED_EXIT) {
|
||||
|
@ -54,7 +54,7 @@ const alarm_sleep_memory_obj_t alarm_sleep_memory_obj = {
|
||||
},
|
||||
};
|
||||
|
||||
void common_hal_alarm_reset(void) {
|
||||
void alarm_reset(void) {
|
||||
alarm_sleep_memory_reset();
|
||||
alarm_pin_pinalarm_reset();
|
||||
alarm_time_timealarm_reset();
|
||||
@ -144,7 +144,7 @@ mp_obj_t common_hal_alarm_light_sleep_until_alarms(size_t n_alarms, const mp_obj
|
||||
}
|
||||
|
||||
mp_obj_t wake_alarm = _get_wake_alarm(n_alarms, alarms);
|
||||
alarm_pin_pinalarm_reset_alarms(n_alarms, alarms);
|
||||
alarm_reset();
|
||||
return wake_alarm;
|
||||
}
|
||||
|
||||
|
@ -31,6 +31,6 @@
|
||||
|
||||
const alarm_sleep_memory_obj_t alarm_sleep_memory_obj;
|
||||
|
||||
extern void common_hal_alarm_reset(void);
|
||||
extern void alarm_reset(void);
|
||||
|
||||
#endif // MICROPY_INCLUDED_ESP32S2_COMMON_HAL_ALARM__INIT__H
|
||||
|
@ -38,7 +38,7 @@
|
||||
#include "components/soc/src/esp32s2/include/hal/gpio_ll.h"
|
||||
#include "components/xtensa/include/esp_debug_helpers.h"
|
||||
|
||||
void common_hal_alarm_pin_pinalarm_construct(alarm_pin_pinalarm_obj_t *self, mcu_pin_obj_t *pin, bool value, bool edge, bool pull) {
|
||||
void common_hal_alarm_pin_pinalarm_construct(alarm_pin_pinalarm_obj_t *self, const mcu_pin_obj_t *pin, bool value, bool edge, bool pull) {
|
||||
if (edge) {
|
||||
mp_raise_ValueError(translate("Cannot wake on pin edge. Only level."));
|
||||
}
|
||||
@ -51,7 +51,7 @@ void common_hal_alarm_pin_pinalarm_construct(alarm_pin_pinalarm_obj_t *self, mcu
|
||||
self->pull = pull;
|
||||
}
|
||||
|
||||
mcu_pin_obj_t *common_hal_alarm_pin_pinalarm_get_pin(alarm_pin_pinalarm_obj_t *self) {
|
||||
const mcu_pin_obj_t *common_hal_alarm_pin_pinalarm_get_pin(alarm_pin_pinalarm_obj_t *self) {
|
||||
return self->pin;
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
typedef struct {
|
||||
mp_obj_base_t base;
|
||||
mcu_pin_obj_t *pin;
|
||||
const mcu_pin_obj_t *pin;
|
||||
bool value;
|
||||
bool pull;
|
||||
} alarm_pin_pinalarm_obj_t;
|
||||
|
@ -45,7 +45,7 @@
|
||||
|
||||
#define STM_ALARM_FLAG RTC->BKP0R
|
||||
|
||||
void common_hal_alarm_reset(void) {
|
||||
void alarm_reset(void) {
|
||||
// Reset the alarm flag
|
||||
STM_ALARM_FLAG = 0x00;
|
||||
// alarm_sleep_memory_reset();
|
||||
@ -131,7 +131,7 @@ mp_obj_t common_hal_alarm_light_sleep_until_alarms(size_t n_alarms, const mp_obj
|
||||
}
|
||||
|
||||
mp_obj_t wake_alarm = _get_wake_alarm(n_alarms, alarms);
|
||||
common_hal_alarm_reset();
|
||||
alarm_reset();
|
||||
return wake_alarm;
|
||||
}
|
||||
|
||||
|
@ -31,6 +31,6 @@
|
||||
|
||||
const alarm_sleep_memory_obj_t alarm_sleep_memory_obj;
|
||||
|
||||
extern void common_hal_alarm_reset(void);
|
||||
extern void alarm_reset(void);
|
||||
|
||||
#endif // MICROPY_INCLUDED_STM32_COMMON_HAL_ALARM__INIT__H
|
||||
|
@ -43,7 +43,7 @@ STATIC void pin_alarm_callback(uint8_t num) {
|
||||
HAL_GPIO_EXTI_IRQHandler(pin_mask(num));
|
||||
}
|
||||
|
||||
void common_hal_alarm_pin_pinalarm_construct(alarm_pin_pinalarm_obj_t *self, mcu_pin_obj_t *pin, bool value, bool edge, bool pull) {
|
||||
void common_hal_alarm_pin_pinalarm_construct(alarm_pin_pinalarm_obj_t *self, const mcu_pin_obj_t *pin, bool value, bool edge, bool pull) {
|
||||
if (!edge) {
|
||||
mp_raise_NotImplementedError(translate("Only edge detection is available on this hardware"));
|
||||
}
|
||||
@ -70,7 +70,7 @@ void common_hal_alarm_pin_pinalarm_construct(alarm_pin_pinalarm_obj_t *self, mcu
|
||||
self->pull = pull;
|
||||
}
|
||||
|
||||
mcu_pin_obj_t *common_hal_alarm_pin_pinalarm_get_pin(alarm_pin_pinalarm_obj_t *self) {
|
||||
const mcu_pin_obj_t *common_hal_alarm_pin_pinalarm_get_pin(alarm_pin_pinalarm_obj_t *self) {
|
||||
return self->pin;
|
||||
}
|
||||
|
||||
@ -112,6 +112,7 @@ void alarm_pin_pinalarm_reset(void) {
|
||||
HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1);
|
||||
alarm_pin_triggered = 0;
|
||||
woke_up = false;
|
||||
deep_wkup_enabled = false;
|
||||
}
|
||||
|
||||
// Deep sleep alarms don't actually make use of EXTI, but we pretend they're the same.
|
||||
@ -135,17 +136,6 @@ void alarm_pin_pinalarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_ob
|
||||
}
|
||||
}
|
||||
|
||||
void alarm_pin_pinalarm_reset_alarms(bool deep_sleep, size_t n_alarms, const mp_obj_t *alarms) {
|
||||
alarm_pin_triggered = 0;
|
||||
deep_wkup_enabled = false;
|
||||
for (size_t i = 0; i < n_alarms; i++) {
|
||||
if (MP_OBJ_IS_TYPE(alarms[i], &alarm_pin_pinalarm_type)) {
|
||||
alarm_pin_pinalarm_obj_t *alarm = MP_OBJ_TO_PTR(alarms[i]);
|
||||
stm_peripherals_exti_disable(alarm->pin->number);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If we don't have WKUP enabled, ensure it's disabled
|
||||
// TODO; is this really required?
|
||||
void alarm_pin_pinalarm_prepare_for_deep_sleep(void) {
|
||||
|
@ -29,14 +29,13 @@
|
||||
|
||||
typedef struct {
|
||||
mp_obj_base_t base;
|
||||
mcu_pin_obj_t *pin;
|
||||
const mcu_pin_obj_t *pin;
|
||||
bool value;
|
||||
bool pull;
|
||||
} alarm_pin_pinalarm_obj_t;
|
||||
|
||||
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_reset_alarms(bool deep_sleep, size_t n_alarms, const mp_obj_t *alarms);
|
||||
void alarm_pin_pinalarm_prepare_for_deep_sleep(void);
|
||||
mp_obj_t alarm_pin_pinalarm_get_wakeup_alarm(size_t n_alarms, const mp_obj_t *alarms);
|
||||
bool alarm_pin_pinalarm_woke_us_up(void);
|
||||
|
@ -73,7 +73,7 @@ STATIC mp_obj_t alarm_pin_pinalarm_make_new(const mp_obj_type_t *type, mp_uint_t
|
||||
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
|
||||
mp_arg_parse_all(0, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
|
||||
|
||||
mcu_pin_obj_t *pin = validate_obj_is_free_pin(args[ARG_pin].u_obj);
|
||||
const mcu_pin_obj_t *pin = validate_obj_is_free_pin(args[ARG_pin].u_obj);
|
||||
|
||||
common_hal_alarm_pin_pinalarm_construct(self,
|
||||
pin,
|
||||
@ -89,7 +89,7 @@ STATIC mp_obj_t alarm_pin_pinalarm_make_new(const mp_obj_type_t *type, mp_uint_t
|
||||
//|
|
||||
STATIC mp_obj_t alarm_pin_pinalarm_obj_get_pin(mp_obj_t self_in) {
|
||||
alarm_pin_pinalarm_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
mcu_pin_obj_t *pin = common_hal_alarm_pin_pinalarm_get_pin(self);
|
||||
const mcu_pin_obj_t *pin = common_hal_alarm_pin_pinalarm_get_pin(self);
|
||||
if (pin == NULL) {
|
||||
return mp_const_none;
|
||||
}
|
||||
|
@ -34,8 +34,8 @@
|
||||
|
||||
extern const mp_obj_type_t alarm_pin_pinalarm_type;
|
||||
|
||||
void common_hal_alarm_pin_pinalarm_construct(alarm_pin_pinalarm_obj_t *self, mcu_pin_obj_t *pin, bool value, bool edge, bool pull);
|
||||
extern mcu_pin_obj_t *common_hal_alarm_pin_pinalarm_get_pin(alarm_pin_pinalarm_obj_t *self);
|
||||
void common_hal_alarm_pin_pinalarm_construct(alarm_pin_pinalarm_obj_t *self, const mcu_pin_obj_t *pin, bool value, bool edge, bool pull);
|
||||
extern const mcu_pin_obj_t *common_hal_alarm_pin_pinalarm_get_pin(alarm_pin_pinalarm_obj_t *self);
|
||||
extern bool common_hal_alarm_pin_pinalarm_get_value(alarm_pin_pinalarm_obj_t *self);
|
||||
extern bool common_hal_alarm_pin_pinalarm_get_edge(alarm_pin_pinalarm_obj_t *self);
|
||||
extern bool common_hal_alarm_pin_pinalarm_get_pull(alarm_pin_pinalarm_obj_t *self);
|
||||
|
Loading…
Reference in New Issue
Block a user