diff --git a/micropython/board/PICO_W_ENVIRO/pico_sdk.patch b/micropython/board/PICO_W_ENVIRO/pico_sdk.off.patch similarity index 100% rename from micropython/board/PICO_W_ENVIRO/pico_sdk.patch rename to micropython/board/PICO_W_ENVIRO/pico_sdk.off.patch diff --git a/micropython/board/PICO_W_INKY/pico_sdk.patch b/micropython/board/PICO_W_INKY/pico_sdk.off.patch similarity index 100% rename from micropython/board/PICO_W_INKY/pico_sdk.patch rename to micropython/board/PICO_W_INKY/pico_sdk.off.patch diff --git a/micropython/modules/wakeup/wakeup.c b/micropython/modules/wakeup/wakeup.c index 69f2422c3..0b9d523e8 100644 --- a/micropython/modules/wakeup/wakeup.c +++ b/micropython/modules/wakeup/wakeup.c @@ -1,4 +1,25 @@ #include "wakeup.h" +#include "hardware/gpio.h" +#include "wakeup.config.hpp" +#include "pico/runtime_init.h" + + +uint32_t runtime_wakeup_gpio_state = 0; + +// Pins to toggle on wakeup +#ifndef PICO_WAKEUP_PIN_MASK +#define PICO_WAKEUP_PIN_MASK ((0b1 << 2) | (0b1 << 6)) +#endif + +// Direction +#ifndef PICO_WAKEUP_PIN_DIR +#define PICO_WAKEUP_PIN_DIR ((0b1 << 2) | (0b1 << 6)) +#endif + +// Value +#ifndef PICO_WAKEUP_PIN_VALUE +#define PICO_WAKEUP_PIN_VALUE ((0b1 << 2) | (0b1 << 6)) +#endif static MP_DEFINE_CONST_FUN_OBJ_0(Wakeup_get_gpio_state_obj, Wakeup_get_gpio_state); static MP_DEFINE_CONST_FUN_OBJ_0(Wakeup_reset_gpio_state_obj, Wakeup_reset_gpio_state); @@ -23,4 +44,17 @@ const mp_obj_module_t wakeup_user_cmodule = { MP_REGISTER_MODULE(MP_QSTR_wakeup, wakeup_user_cmodule, MODULE_WAKEUP_ENABLED); #else MP_REGISTER_MODULE(MP_QSTR_wakeup, wakeup_user_cmodule); -#endif \ No newline at end of file +#endif + +void runtime_init_latch(void) { + runtime_wakeup_gpio_state = gpio_get_all(); + + gpio_init_mask(PICO_WAKEUP_PIN_MASK); + gpio_set_dir_masked(PICO_WAKEUP_PIN_MASK, PICO_WAKEUP_PIN_DIR); + gpio_put_masked(PICO_WAKEUP_PIN_MASK, PICO_WAKEUP_PIN_VALUE); +}; + +// After runtime_init_early_resets, PICO_RUNTIME_INIT_EARLY_RESETS ? +PICO_RUNTIME_INIT_FUNC_HW(runtime_init_latch, "00101"); +// Too early? +// PICO_RUNTIME_INIT_FUNC_HW(runtime_init_latch, PICO_RUNTIME_INIT_EARLIEST);