summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2018-12-26 22:44:09 +1100
committerDamien George <damien.p.george@gmail.com>2019-01-27 11:13:32 +1100
commit285d265eee834c763749f54a6d806e284be1160c (patch)
tree6ae38f5e5ed36a7061f760b0a419c9c04391a69a
parentb16146d18907b921eefec527f7a700413309dd12 (diff)
stm32: Implement machine.lightsleep().
-rw-r--r--ports/stm32/modmachine.c19
-rw-r--r--ports/stm32/modmachine.h4
-rw-r--r--ports/stm32/modpyb.c2
-rw-r--r--ports/stm32/rtc.h2
4 files changed, 19 insertions, 8 deletions
diff --git a/ports/stm32/modmachine.c b/ports/stm32/modmachine.c
index 06c07812c..e14753bfe 100644
--- a/ports/stm32/modmachine.c
+++ b/ports/stm32/modmachine.c
@@ -329,17 +329,25 @@ STATIC mp_obj_t machine_freq(size_t n_args, const mp_obj_t *args) {
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_freq_obj, 0, 4, machine_freq);
-STATIC mp_obj_t machine_sleep(void) {
+STATIC mp_obj_t machine_lightsleep(size_t n_args, const mp_obj_t *args) {
+ if (n_args != 0) {
+ mp_obj_t args2[2] = {MP_OBJ_NULL, args[0]};
+ pyb_rtc_wakeup(2, args2);
+ }
powerctrl_enter_stop_mode();
return mp_const_none;
}
-MP_DEFINE_CONST_FUN_OBJ_0(machine_sleep_obj, machine_sleep);
+MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_lightsleep_obj, 0, 1, machine_lightsleep);
-STATIC mp_obj_t machine_deepsleep(void) {
+STATIC mp_obj_t machine_deepsleep(size_t n_args, const mp_obj_t *args) {
+ if (n_args != 0) {
+ mp_obj_t args2[2] = {MP_OBJ_NULL, args[0]};
+ pyb_rtc_wakeup(2, args2);
+ }
powerctrl_enter_standby_mode();
return mp_const_none;
}
-MP_DEFINE_CONST_FUN_OBJ_0(machine_deepsleep_obj, machine_deepsleep);
+MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_deepsleep_obj, 0, 1, machine_deepsleep);
STATIC mp_obj_t machine_reset_cause(void) {
return MP_OBJ_NEW_SMALL_INT(reset_cause);
@@ -358,7 +366,8 @@ STATIC const mp_rom_map_elem_t machine_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_rng), MP_ROM_PTR(&pyb_rng_get_obj) },
#endif
{ MP_ROM_QSTR(MP_QSTR_idle), MP_ROM_PTR(&pyb_wfi_obj) },
- { MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&machine_sleep_obj) },
+ { MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&machine_lightsleep_obj) },
+ { MP_ROM_QSTR(MP_QSTR_lightsleep), MP_ROM_PTR(&machine_lightsleep_obj) },
{ MP_ROM_QSTR(MP_QSTR_deepsleep), MP_ROM_PTR(&machine_deepsleep_obj) },
{ MP_ROM_QSTR(MP_QSTR_reset_cause), MP_ROM_PTR(&machine_reset_cause_obj) },
#if 0
diff --git a/ports/stm32/modmachine.h b/ports/stm32/modmachine.h
index 88fe23692..f105bbeec 100644
--- a/ports/stm32/modmachine.h
+++ b/ports/stm32/modmachine.h
@@ -36,7 +36,7 @@ MP_DECLARE_CONST_FUN_OBJ_0(machine_unique_id_obj);
MP_DECLARE_CONST_FUN_OBJ_0(machine_reset_obj);
MP_DECLARE_CONST_FUN_OBJ_0(machine_bootloader_obj);
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_freq_obj);
-MP_DECLARE_CONST_FUN_OBJ_0(machine_sleep_obj);
-MP_DECLARE_CONST_FUN_OBJ_0(machine_deepsleep_obj);
+MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_lightsleep_obj);
+MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_deepsleep_obj);
#endif // MICROPY_INCLUDED_STM32_MODMACHINE_H
diff --git a/ports/stm32/modpyb.c b/ports/stm32/modpyb.c
index 0e8313d10..60b287fb1 100644
--- a/ports/stm32/modpyb.c
+++ b/ports/stm32/modpyb.c
@@ -134,7 +134,7 @@ STATIC const mp_rom_map_elem_t pyb_module_globals_table[] = {
#endif
#if MICROPY_PY_PYB_LEGACY
- { MP_ROM_QSTR(MP_QSTR_stop), MP_ROM_PTR(&machine_sleep_obj) },
+ { MP_ROM_QSTR(MP_QSTR_stop), MP_ROM_PTR(&machine_lightsleep_obj) },
{ MP_ROM_QSTR(MP_QSTR_standby), MP_ROM_PTR(&machine_deepsleep_obj) },
#endif
{ MP_ROM_QSTR(MP_QSTR_main), MP_ROM_PTR(&pyb_main_obj) },
diff --git a/ports/stm32/rtc.h b/ports/stm32/rtc.h
index 307f8885e..d3840c1b7 100644
--- a/ports/stm32/rtc.h
+++ b/ports/stm32/rtc.h
@@ -32,4 +32,6 @@ extern const mp_obj_type_t pyb_rtc_type;
void rtc_init_start(bool force_init);
void rtc_init_finalise(void);
+mp_obj_t pyb_rtc_wakeup(size_t n_args, const mp_obj_t *args);
+
#endif // MICROPY_INCLUDED_STM32_RTC_H