1
1
#include "wakeup.h"
2
+ #include "hardware/gpio.h"
3
+ #include "wakeup.config.hpp"
4
+ #include "pico/runtime_init.h"
5
+
6
+
7
+ uint32_t runtime_wakeup_gpio_state = 0 ;
8
+
9
+ // Pins to toggle on wakeup
10
+ #ifndef PICO_WAKEUP_PIN_MASK
11
+ #define PICO_WAKEUP_PIN_MASK ((0b1 << 2) | (0b1 << 6))
12
+ #endif
13
+
14
+ // Direction
15
+ #ifndef PICO_WAKEUP_PIN_DIR
16
+ #define PICO_WAKEUP_PIN_DIR ((0b1 << 2) | (0b1 << 6))
17
+ #endif
18
+
19
+ // Value
20
+ #ifndef PICO_WAKEUP_PIN_VALUE
21
+ #define PICO_WAKEUP_PIN_VALUE ((0b1 << 2) | (0b1 << 6))
22
+ #endif
2
23
3
24
static MP_DEFINE_CONST_FUN_OBJ_0 (Wakeup_get_gpio_state_obj , Wakeup_get_gpio_state ) ;
4
25
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 = {
23
44
MP_REGISTER_MODULE (MP_QSTR_wakeup , wakeup_user_cmodule , MODULE_WAKEUP_ENABLED );
24
45
#else
25
46
MP_REGISTER_MODULE (MP_QSTR_wakeup , wakeup_user_cmodule );
26
- #endif
47
+ #endif
48
+
49
+ void runtime_init_latch (void ) {
50
+ runtime_wakeup_gpio_state = gpio_get_all ();
51
+
52
+ gpio_init_mask (PICO_WAKEUP_PIN_MASK );
53
+ gpio_set_dir_masked (PICO_WAKEUP_PIN_MASK , PICO_WAKEUP_PIN_DIR );
54
+ gpio_put_masked (PICO_WAKEUP_PIN_MASK , PICO_WAKEUP_PIN_VALUE );
55
+ };
56
+
57
+ // After runtime_init_early_resets, PICO_RUNTIME_INIT_EARLY_RESETS ?
58
+ PICO_RUNTIME_INIT_FUNC_HW (runtime_init_latch , "00101" );
59
+ // Too early?
60
+ // PICO_RUNTIME_INIT_FUNC_HW(runtime_init_latch, PICO_RUNTIME_INIT_EARLIEST);
0 commit comments