diff --git a/extmod/modtrezorui/modtrezorui-touch.h b/extmod/modtrezorui/modtrezorui-touch.h deleted file mode 100644 index ce265290..00000000 --- a/extmod/modtrezorui/modtrezorui-touch.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) Pavol Rusnak, SatoshiLabs - * - * Licensed under Microsoft Reference Source License (Ms-RSL) - * see LICENSE.md file for details - */ - -// touch callbacks - -mp_obj_t touch_start_callback = mp_const_none; -mp_obj_t touch_move_callback = mp_const_none; -mp_obj_t touch_end_callback = mp_const_none; - -void touch_start(mp_int_t x, mp_int_t y) { - if (touch_start_callback != mp_const_none) { - mp_call_function_2(touch_start_callback, MP_OBJ_NEW_SMALL_INT(x), MP_OBJ_NEW_SMALL_INT(y)); - } -} - -void touch_move(mp_int_t x, mp_int_t y) { - if (touch_move_callback != mp_const_none) { - mp_call_function_2(touch_move_callback, MP_OBJ_NEW_SMALL_INT(x), MP_OBJ_NEW_SMALL_INT(y)); - } -} - -void touch_end(mp_int_t x, mp_int_t y) { - if (touch_end_callback != mp_const_none) { - mp_call_function_2(touch_end_callback, MP_OBJ_NEW_SMALL_INT(x), MP_OBJ_NEW_SMALL_INT(y)); - } -} - -// class Touch(object): -typedef struct _mp_obj_Touch_t { - mp_obj_base_t base; -} mp_obj_Touch_t; - -// def Touch.__init__(self) -STATIC mp_obj_t mod_TrezorUi_Touch_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { - mp_arg_check_num(n_args, n_kw, 0, 0, false); - mp_obj_Touch_t *o = m_new_obj(mp_obj_Touch_t); - o->base.type = type; - return MP_OBJ_FROM_PTR(o); -} - -// def Touch.start(self, callback) -> None -STATIC mp_obj_t mod_TrezorUi_Touch_start(mp_obj_t self, mp_obj_t callback) { - touch_start_callback = callback; - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorUi_Touch_start_obj, mod_TrezorUi_Touch_start); - -// def Touch.move(self, callback) -> None -STATIC mp_obj_t mod_TrezorUi_Touch_move(mp_obj_t self, mp_obj_t callback) { - touch_move_callback = callback; - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorUi_Touch_move_obj, mod_TrezorUi_Touch_move); - -// def Touch.end(self, callback) -> None -STATIC mp_obj_t mod_TrezorUi_Touch_end(mp_obj_t self, mp_obj_t callback) { - touch_end_callback = callback; - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorUi_Touch_end_obj, mod_TrezorUi_Touch_end); - -// Touch stuff - -STATIC const mp_rom_map_elem_t mod_TrezorUi_Touch_locals_dict_table[] = { - { MP_ROM_QSTR(MP_QSTR_start), MP_ROM_PTR(&mod_TrezorUi_Touch_start_obj) }, - { MP_ROM_QSTR(MP_QSTR_move), MP_ROM_PTR(&mod_TrezorUi_Touch_move_obj) }, - { MP_ROM_QSTR(MP_QSTR_end), MP_ROM_PTR(&mod_TrezorUi_Touch_end_obj) }, -}; -STATIC MP_DEFINE_CONST_DICT(mod_TrezorUi_Touch_locals_dict, mod_TrezorUi_Touch_locals_dict_table); - -STATIC const mp_obj_type_t mod_TrezorUi_Touch_type = { - { &mp_type_type }, - .name = MP_QSTR_Touch, - .make_new = mod_TrezorUi_Touch_make_new, - .locals_dict = (void*)&mod_TrezorUi_Touch_locals_dict, -}; diff --git a/extmod/modtrezorui/modtrezorui-unix.h b/extmod/modtrezorui/modtrezorui-unix.h index 53d15e37..b0d2b0ae 100644 --- a/extmod/modtrezorui/modtrezorui-unix.h +++ b/extmod/modtrezorui/modtrezorui-unix.h @@ -34,33 +34,29 @@ static void DATAfunc(uint8_t x) { } } -void touch_start(mp_int_t x, mp_int_t y); -void touch_move(mp_int_t x, mp_int_t y); -void touch_end(mp_int_t x, mp_int_t y); - -void upy_idle_func(void) +uint32_t trezorui_poll_sdl_event(uint32_t timeout_us) { SDL_Event event; int x, y; - while (SDL_PollEvent(&event) > 0) { + if (SDL_WaitEventTimeout(&event, timeout_us / 1000) > 0) { switch (event.type) { case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEMOTION: case SDL_MOUSEBUTTONUP: x = event.button.x - DISPLAY_BORDER; y = event.button.y - DISPLAY_BORDER; - if (x < 0 || y < 0 || x >= RESX || y >= RESY) continue; + if (x < 0 || y < 0 || x >= RESX || y >= RESY) break; switch (event.type) { case SDL_MOUSEBUTTONDOWN: - touch_start(x, y); + return (0x00 << 24) | (0x01 << 16) | (x << 8) | y; // touch_start break; case SDL_MOUSEMOTION: if (event.motion.state) { - touch_move(x, y); + return (0x00 << 24) | (0x02 << 16) | (x << 8) | y; // touch_move } break; case SDL_MOUSEBUTTONUP: - touch_end(x, y); + return (0x00 << 24) | (0x03 << 16) | (x << 8) | y; // touch_end break; } break; @@ -69,7 +65,7 @@ void upy_idle_func(void) break; } } - return; + return 0; } static void display_init(void) diff --git a/extmod/modtrezorui/modtrezorui.c b/extmod/modtrezorui/modtrezorui.c index 67bb0adf..76064da4 100644 --- a/extmod/modtrezorui/modtrezorui.c +++ b/extmod/modtrezorui/modtrezorui.c @@ -28,14 +28,11 @@ #include "modtrezorui-display.h" -#include "modtrezorui-touch.h" - // module stuff STATIC const mp_rom_map_elem_t mp_module_TrezorUi_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_TrezorUi) }, { MP_ROM_QSTR(MP_QSTR_Display), MP_ROM_PTR(&mod_TrezorUi_Display_type) }, - { MP_ROM_QSTR(MP_QSTR_Touch), MP_ROM_PTR(&mod_TrezorUi_Touch_type) }, }; STATIC MP_DEFINE_CONST_DICT(mp_module_TrezorUi_globals, mp_module_TrezorUi_globals_table); diff --git a/extmod/modtrezorutils/modtrezorutils.c b/extmod/modtrezorutils/modtrezorutils.c index 938240a7..b3025a6f 100644 --- a/extmod/modtrezorutils/modtrezorutils.c +++ b/extmod/modtrezorutils/modtrezorutils.c @@ -42,10 +42,29 @@ STATIC mp_obj_t mod_TrezorUtils_Utils_memaccess(mp_obj_t self, mp_obj_t address, } STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorUtils_Utils_memaccess_obj, mod_TrezorUtils_Utils_memaccess); +// from modtrezorui +uint32_t trezorui_poll_sdl_event(uint32_t timeout_us); + +// def Utils.select(self, timeout_us: int) -> None/tuple +STATIC mp_obj_t mod_TrezorUtils_Utils_select(mp_obj_t self, mp_obj_t timeout_us) { + uint32_t to = mp_obj_get_int(timeout_us); + uint32_t e = trezorui_poll_sdl_event(to); + if (e) { + mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(mp_obj_new_tuple(3, NULL)); + tuple->items[0] = MP_OBJ_NEW_SMALL_INT((e & 0xFF0000) >> 16); + tuple->items[1] = MP_OBJ_NEW_SMALL_INT((e & 0xFF00) >> 8); + tuple->items[2] = MP_OBJ_NEW_SMALL_INT((e & 0xFF)); + return MP_OBJ_FROM_PTR(tuple); + } + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_TrezorUtils_Utils_select_obj, mod_TrezorUtils_Utils_select); + // Utils stuff STATIC const mp_rom_map_elem_t mod_TrezorUtils_Utils_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_memaccess), MP_ROM_PTR(&mod_TrezorUtils_Utils_memaccess_obj) }, + { MP_ROM_QSTR(MP_QSTR_select), MP_ROM_PTR(&mod_TrezorUtils_Utils_select_obj) }, }; STATIC MP_DEFINE_CONST_DICT(mod_TrezorUtils_Utils_locals_dict, mod_TrezorUtils_Utils_locals_dict_table); diff --git a/src/trezor/utils.py b/src/trezor/utils.py index 1775ae17..bfc2da7a 100644 --- a/src/trezor/utils.py +++ b/src/trezor/utils.py @@ -8,6 +8,9 @@ type_gen = type((lambda: (yield))()) def memaccess(address, length): return _utils.memaccess(address, length) +def select(timeout_us): + return _utils.select(timeout_us) + def unimport_func(func): def inner(*args, **kwargs): mods = set(sys.modules) diff --git a/vendor/micropython b/vendor/micropython index 57b4be8a..da3fe60b 160000 --- a/vendor/micropython +++ b/vendor/micropython @@ -1 +1 @@ -Subproject commit 57b4be8a5c73dda20746d53a66a98c4b64498be4 +Subproject commit da3fe60b7dc12ce393e9a63c9d6ac366b9c81045