Skip to content

Commit 9a705c8

Browse files
committed
Wakeup: Port wakeup runtime functionality to SDK 2.0.0.
1 parent 1dcc67c commit 9a705c8

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

micropython/modules/wakeup/wakeup.c

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,25 @@
11
#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
223

324
static MP_DEFINE_CONST_FUN_OBJ_0(Wakeup_get_gpio_state_obj, Wakeup_get_gpio_state);
425
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 = {
2344
MP_REGISTER_MODULE(MP_QSTR_wakeup, wakeup_user_cmodule, MODULE_WAKEUP_ENABLED);
2445
#else
2546
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

Comments
 (0)