1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-21 23:18:13 +00:00

remove ui.touch, add utils.select

This commit is contained in:
Pavol Rusnak 2016-04-28 22:58:15 +02:00
parent d7a937f553
commit 904127f263
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
6 changed files with 30 additions and 95 deletions

View File

@ -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,
};

View File

@ -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)

View File

@ -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);

View File

@ -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);

View File

@ -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)

2
vendor/micropython vendored

@ -1 +1 @@
Subproject commit 57b4be8a5c73dda20746d53a66a98c4b64498be4
Subproject commit da3fe60b7dc12ce393e9a63c9d6ac366b9c81045