diff --git a/micropython/modules/badger2040/badger2040.c b/micropython/modules/badger2040/badger2040.c index 536811d0..2b42a96a 100644 --- a/micropython/modules/badger2040/badger2040.c +++ b/micropython/modules/badger2040/badger2040.c @@ -9,9 +9,6 @@ MP_DEFINE_CONST_FUN_OBJ_1(Badger2040_is_busy_obj, Badger2040_is_busy); 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); MP_DEFINE_CONST_FUN_OBJ_2(Badger2040_font_obj, Badger2040_font); @@ -38,6 +35,8 @@ MP_DEFINE_CONST_FUN_OBJ_3(Badger2040_command_obj, Badger2040_command); MP_DEFINE_CONST_FUN_OBJ_1(Badger2040_pressed_to_wake_obj, Badger2040_pressed_to_wake); MP_DEFINE_CONST_FUN_OBJ_0(Badger2040_clear_pressed_to_wake_obj, Badger2040_clear_pressed_to_wake); +MP_DEFINE_CONST_FUN_OBJ_1(Badger2040_halt_obj, Badger2040_halt); +MP_DEFINE_CONST_FUN_OBJ_0(Badger2040_woken_by_button_obj, Badger2040_woken_by_button); /***** Binding of Methods *****/ STATIC const mp_rom_map_elem_t Badger2040_locals_dict_table[] = { @@ -48,7 +47,6 @@ 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) }, @@ -95,6 +93,7 @@ STATIC const mp_rom_map_elem_t badger2040_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_pressed_to_wake), MP_ROM_PTR(&Badger2040_pressed_to_wake_obj) }, { MP_ROM_QSTR(MP_QSTR_clear_pressed_to_wake), MP_ROM_PTR(&Badger2040_clear_pressed_to_wake_obj) }, + { MP_ROM_QSTR(MP_QSTR_woken_by_button), MP_ROM_PTR(&Badger2040_woken_by_button_obj) }, { MP_ROM_QSTR(MP_QSTR_UPDATE_NORMAL), MP_ROM_INT(0) }, { MP_ROM_QSTR(MP_QSTR_UPDATE_MEDIUM), MP_ROM_INT(1) }, diff --git a/micropython/modules/badger2040/badger2040.cpp b/micropython/modules/badger2040/badger2040.cpp index 5b6d6f62..464655b0 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 get_current() { + return gpio_get_all() & (0x1f << pimoroni::Badger2040::DOWN); + } + bool any() const { return state > 0; } @@ -209,8 +213,7 @@ MICROPY_EVENT_POLL_HOOK return mp_const_none; } -mp_obj_t Badger2040_woken(mp_obj_t self_in) { - (void)self_in; +mp_obj_t Badger2040_woken_by_button() { return button_wake_state.any() ? mp_const_true : mp_const_false; } @@ -282,6 +285,11 @@ mp_obj_t Badger2040_pressed_to_wake2(mp_obj_t self_in, mp_obj_t button) { mp_obj_t Badger2040_clear_pressed_to_wake() { button_wake_state.clear(); + while(button_wake_state.get_current()) { +#ifdef MICROPY_EVENT_POLL_HOOK +MICROPY_EVENT_POLL_HOOK +#endif + } return mp_const_none; } diff --git a/micropython/modules/badger2040/badger2040.h b/micropython/modules/badger2040/badger2040.h index 0586b3e1..ae08294a 100644 --- a/micropython/modules/badger2040/badger2040.h +++ b/micropython/modules/badger2040/badger2040.h @@ -16,7 +16,6 @@ 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); @@ -45,3 +44,4 @@ extern mp_obj_t Badger2040_command(mp_obj_t self_in, mp_obj_t reg, mp_obj_t data extern mp_obj_t Badger2040_pressed_to_wake(mp_obj_t button); extern mp_obj_t Badger2040_clear_pressed_to_wake(); +extern mp_obj_t Badger2040_woken_by_button();