From a7f2014309b8f745a2fdcb3ca00f313d7c42b4c1 Mon Sep 17 00:00:00 2001 From: Mike Bell Date: Thu, 24 Mar 2022 21:21:20 +0000 Subject: [PATCH] Add woken method --- micropython/modules/badger2040/badger2040.c | 2 ++ micropython/modules/badger2040/badger2040.cpp | 9 +++++++++ micropython/modules/badger2040/badger2040.h | 1 + 3 files changed, 12 insertions(+) diff --git a/micropython/modules/badger2040/badger2040.c b/micropython/modules/badger2040/badger2040.c index 18d63b41..536811d0 100644 --- a/micropython/modules/badger2040/badger2040.c +++ b/micropython/modules/badger2040/badger2040.c @@ -10,6 +10,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(Badger2040_update_obj, Badger2040_update); MP_DEFINE_CONST_FUN_OBJ_KW(Badger2040_partial_update_obj, 4, Badger2040_partial_update); MP_DEFINE_CONST_FUN_OBJ_1(Badger2040_halt_obj, Badger2040_halt); +MP_DEFINE_CONST_FUN_OBJ_1(Badger2040_woken_obj, Badger2040_woken); MP_DEFINE_CONST_FUN_OBJ_2(Badger2040_invert_obj, Badger2040_invert); MP_DEFINE_CONST_FUN_OBJ_2(Badger2040_led_obj, Badger2040_led); @@ -47,6 +48,7 @@ STATIC const mp_rom_map_elem_t Badger2040_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_partial_update), MP_ROM_PTR(&Badger2040_partial_update_obj) }, { MP_ROM_QSTR(MP_QSTR_halt), MP_ROM_PTR(&Badger2040_halt_obj) }, + { MP_ROM_QSTR(MP_QSTR_woken), MP_ROM_PTR(&Badger2040_woken_obj) }, { MP_ROM_QSTR(MP_QSTR_invert), MP_ROM_PTR(&Badger2040_invert_obj) }, { MP_ROM_QSTR(MP_QSTR_led), MP_ROM_PTR(&Badger2040_led_obj) }, diff --git a/micropython/modules/badger2040/badger2040.cpp b/micropython/modules/badger2040/badger2040.cpp index 1736daaa..c3c0c6c2 100644 --- a/micropython/modules/badger2040/badger2040.cpp +++ b/micropython/modules/badger2040/badger2040.cpp @@ -14,6 +14,10 @@ namespace { gpio_put(pimoroni::Badger2040::ENABLE_3V3, 1); } + bool any() const { + return state > 0; + } + bool get(uint32_t pin) const { return state & (0b1 << pin); } @@ -199,6 +203,11 @@ MICROPY_EVENT_POLL_HOOK return mp_const_none; } +mp_obj_t Badger2040_woken(mp_obj_t self_in) { + (void)self_in; + return button_wake_state.any() ? mp_const_true : mp_const_false; +} + mp_obj_t Badger2040_halt(mp_obj_t self_in) { _Badger2040_obj_t *self = MP_OBJ_TO_PTR2(self_in, _Badger2040_obj_t); diff --git a/micropython/modules/badger2040/badger2040.h b/micropython/modules/badger2040/badger2040.h index ea486550..0586b3e1 100644 --- a/micropython/modules/badger2040/badger2040.h +++ b/micropython/modules/badger2040/badger2040.h @@ -16,6 +16,7 @@ extern mp_obj_t Badger2040_update(mp_obj_t self_in); extern mp_obj_t Badger2040_partial_update(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args); extern mp_obj_t Badger2040_halt(mp_obj_t self_in); +extern mp_obj_t Badger2040_woken(mp_obj_t self_in); extern mp_obj_t Badger2040_invert(mp_obj_t self_in, mp_obj_t invert); extern mp_obj_t Badger2040_led(mp_obj_t self_in, mp_obj_t brightness);