From ba100ae0691926676d4b025ed2d325921ab98d15 Mon Sep 17 00:00:00 2001 From: Phil Howard Date: Thu, 8 Dec 2022 12:35:57 +0000 Subject: [PATCH] Wakeup: Disable RTC & enable SR for Inky, always include shift function. Due to quirks with how QSTRs are passed, conditionally including a function is difficult. Instead, always include "get_shift_state" but throw a RuntimeError if its use is invalid (no shift register). --- micropython/modules/micropython-picow_enviro.cmake | 5 +++++ micropython/modules/micropython-picow_inky_frame.cmake | 8 +++++++- micropython/modules/wakeup/wakeup.c | 4 ---- micropython/modules/wakeup/wakeup.config.hpp | 2 +- micropython/modules/wakeup/wakeup.cpp | 5 +++-- micropython/modules/wakeup/wakeup.h | 4 +--- 6 files changed, 17 insertions(+), 11 deletions(-) diff --git a/micropython/modules/micropython-picow_enviro.cmake b/micropython/modules/micropython-picow_enviro.cmake index b3fcf252..99f127d7 100644 --- a/micropython/modules/micropython-picow_enviro.cmake +++ b/micropython/modules/micropython-picow_enviro.cmake @@ -45,6 +45,11 @@ include(pcf85063a/micropython) include(adcfft/micropython) include(wakeup/micropython) +# Configure wakeup for Enviro +target_compile_definitions(usermod_wakeup INTERFACE + -DWAKEUP_HAS_RTC=1 +) + # LEDs & Matrices include(plasma/micropython) diff --git a/micropython/modules/micropython-picow_inky_frame.cmake b/micropython/modules/micropython-picow_inky_frame.cmake index b3fcf252..1722406f 100644 --- a/micropython/modules/micropython-picow_inky_frame.cmake +++ b/micropython/modules/micropython-picow_inky_frame.cmake @@ -45,6 +45,11 @@ include(pcf85063a/micropython) include(adcfft/micropython) include(wakeup/micropython) +# Configure wakeup for Inky Frame +target_compile_definitions(usermod_wakeup INTERFACE + -DWAKEUP_HAS_SHIFT_REGISTER=1 +) + # LEDs & Matrices include(plasma/micropython) @@ -56,4 +61,5 @@ include(motor/micropython) # include(micropython-common) -include(modules_py/modules_py) \ No newline at end of file +include(modules_py/modules_py) + diff --git a/micropython/modules/wakeup/wakeup.c b/micropython/modules/wakeup/wakeup.c index 918c3220..93eb30d4 100644 --- a/micropython/modules/wakeup/wakeup.c +++ b/micropython/modules/wakeup/wakeup.c @@ -1,16 +1,12 @@ #include "wakeup.h" STATIC MP_DEFINE_CONST_FUN_OBJ_0(Wakeup_get_gpio_state_obj, Wakeup_get_gpio_state); -#if WAKEUP_HAS_SHIFT_REGISTER==1 STATIC MP_DEFINE_CONST_FUN_OBJ_0(Wakeup_get_shift_state_obj, Wakeup_get_shift_state); -#endif STATIC const mp_map_elem_t wakeup_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_wakeup) }, { MP_ROM_QSTR(MP_QSTR_get_gpio_state), MP_ROM_PTR(&Wakeup_get_gpio_state_obj) }, -#if WAKEUP_HAS_SHIFT_REGISTER==1 { MP_ROM_QSTR(MP_QSTR_get_shift_state), MP_ROM_PTR(&Wakeup_get_shift_state_obj) } -#endif }; STATIC MP_DEFINE_CONST_DICT(mp_module_wakeup_globals, wakeup_globals_table); diff --git a/micropython/modules/wakeup/wakeup.config.hpp b/micropython/modules/wakeup/wakeup.config.hpp index 056b11cb..b415e5e7 100644 --- a/micropython/modules/wakeup/wakeup.config.hpp +++ b/micropython/modules/wakeup/wakeup.config.hpp @@ -16,7 +16,7 @@ #endif #ifndef WAKEUP_HAS_RTC -#define WAKEUP_HAS_RTC (1) +#define WAKEUP_HAS_RTC (0) #endif #ifndef WAKEUP_HAS_SHIFT_REGISTER diff --git a/micropython/modules/wakeup/wakeup.cpp b/micropython/modules/wakeup/wakeup.cpp index 99653520..0b6801ea 100644 --- a/micropython/modules/wakeup/wakeup.cpp +++ b/micropython/modules/wakeup/wakeup.cpp @@ -62,10 +62,11 @@ mp_obj_t Wakeup_get_gpio_state() { return mp_obj_new_int(runtime_wakeup_gpio_state); } -#if WAKEUP_HAS_SHIFT_REGISTER==1 mp_obj_t Wakeup_get_shift_state() { + #if WAKEUP_HAS_SHIFT_REGISTER==1 return mp_obj_new_int(wakeup.shift_register_state); + #endif + mp_raise_msg(&mp_type_RuntimeError, "Wakeup_get_shift_state: board does not have a shift register."); } -#endif } \ No newline at end of file diff --git a/micropython/modules/wakeup/wakeup.h b/micropython/modules/wakeup/wakeup.h index 289f35f1..5babad57 100644 --- a/micropython/modules/wakeup/wakeup.h +++ b/micropython/modules/wakeup/wakeup.h @@ -2,6 +2,4 @@ #include "py/objstr.h" extern mp_obj_t Wakeup_get_gpio_state(); -#if WAKEUP_HAS_SHIFT_REGISTER==1 -extern mp_obj_t Wakeup_get_shift_state(); -#endif \ No newline at end of file +extern mp_obj_t Wakeup_get_shift_state(); \ No newline at end of file