esp32: Make machine.soft_reset() work in main.py and reset_cause().
This commit fixes two issues on the esp32: - it enables machine.soft_reset() to be called in main.py; - it enables machine.reset_cause() to correctly identify a soft reset. The former is useful in that it enables soft resets in applications that are started at boot time. The support is patterned after the stm32 port.
This commit is contained in:
committed by
Damien George
parent
c10d431819
commit
d28dbcd6c7
@@ -59,6 +59,8 @@ typedef enum {
|
||||
MP_SOFT_RESET
|
||||
} reset_reason_t;
|
||||
|
||||
STATIC bool is_soft_reset = 0;
|
||||
|
||||
STATIC mp_obj_t machine_freq(size_t n_args, const mp_obj_t *args) {
|
||||
if (n_args == 0) {
|
||||
// get
|
||||
@@ -140,6 +142,9 @@ STATIC mp_obj_t machine_deepsleep(size_t n_args, const mp_obj_t *pos_args, mp_ma
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_deepsleep_obj, 0, machine_deepsleep);
|
||||
|
||||
STATIC mp_obj_t machine_reset_cause(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
if (is_soft_reset) {
|
||||
return MP_OBJ_NEW_SMALL_INT(MP_SOFT_RESET);
|
||||
}
|
||||
switch (esp_reset_reason()) {
|
||||
case ESP_RST_POWERON:
|
||||
case ESP_RST_BROWNOUT:
|
||||
@@ -171,6 +176,15 @@ STATIC mp_obj_t machine_reset_cause(size_t n_args, const mp_obj_t *pos_args, mp_
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_reset_cause_obj, 0, machine_reset_cause);
|
||||
|
||||
void machine_init(void) {
|
||||
is_soft_reset = 0;
|
||||
}
|
||||
|
||||
void machine_deinit(void) {
|
||||
// we are doing a soft-reset so change the reset_cause
|
||||
is_soft_reset = 1;
|
||||
}
|
||||
|
||||
STATIC mp_obj_t machine_wake_reason(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
return MP_OBJ_NEW_SMALL_INT(esp_sleep_get_wakeup_cause());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user