1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-22 14:28:07 +00:00

unix: refactor T1 touch events to behave similarly to T2 touch events

This commit is contained in:
Pavol Rusnak 2018-10-02 17:24:03 +02:00
parent ff387ba716
commit 0ab0f9e418
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
6 changed files with 26 additions and 14 deletions

View File

@ -300,8 +300,8 @@ int ui_user_input(int zones)
{
for (;;) {
uint32_t evt = touch_click();
uint16_t x = touch_get_x(evt);
uint16_t y = touch_get_y(evt);
uint16_t x = touch_unpack_x(evt);
uint16_t y = touch_unpack_y(evt);
// clicked on Cancel button
if ((zones & INPUT_CANCEL) && x >= 9 && x < 9 + 108 && y > 184 && y < 184 + 50) {
return INPUT_CANCEL;

View File

@ -56,8 +56,6 @@ STATIC const mp_rom_map_elem_t mp_module_trezorio_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_TOUCH_START), MP_OBJ_NEW_SMALL_INT((TOUCH_START >> 24) & 0xFFU) },
{ MP_ROM_QSTR(MP_QSTR_TOUCH_MOVE), MP_OBJ_NEW_SMALL_INT((TOUCH_MOVE >> 24) & 0xFFU) },
{ MP_ROM_QSTR(MP_QSTR_TOUCH_END), MP_OBJ_NEW_SMALL_INT((TOUCH_END >> 24) & 0xFFU) },
{ MP_ROM_QSTR(MP_QSTR_TOUCH_CONFIRM), MP_OBJ_NEW_SMALL_INT((TOUCH_CONFIRM >> 24) & 0xFFU) },
{ MP_ROM_QSTR(MP_QSTR_TOUCH_CANCEL), MP_OBJ_NEW_SMALL_INT((TOUCH_CANCEL >> 24) & 0xFFU) },
};
STATIC MP_DEFINE_CONST_DICT(mp_module_trezorio_globals, mp_module_trezorio_globals_table);

View File

@ -46,7 +46,7 @@ static SDL_Renderer *RENDERER;
static SDL_Surface *BUFFER;
static SDL_Texture *TEXTURE, *BACKGROUND;
int sdl_display_res_x = DISPLAY_RESX, sdl_display_res_y = DISPLAY_RESX;
int sdl_display_res_x = DISPLAY_RESX, sdl_display_res_y = DISPLAY_RESY;
int sdl_touch_offset_x, sdl_touch_offset_y;
static struct {

View File

@ -212,8 +212,8 @@ static void test_touch(const char *args)
uint32_t evt = 0;
if (touch_click_timeout(&evt, timeout * 1000)) {
uint16_t x = touch_get_x(evt);
uint16_t y = touch_get_y(evt);
uint16_t x = touch_unpack_x(evt);
uint16_t y = touch_unpack_y(evt);
vcp_printf("OK %d %d", x, y);
} else {
vcp_printf("ERROR TIMEOUT");

View File

@ -25,8 +25,6 @@
#define TOUCH_START (1U << 24)
#define TOUCH_MOVE (1U << 25)
#define TOUCH_END (1U << 26)
#define TOUCH_CONFIRM (1U << 27)
#define TOUCH_CANCEL (1U << 28)
void touch_init(void);
void touch_power_on(void);
@ -34,8 +32,8 @@ void touch_power_off(void);
uint32_t touch_read(void);
uint32_t touch_click(void);
uint32_t touch_is_detected(void);
inline uint16_t touch_get_x(uint32_t evt) { return (evt >> 12) & 0xFFF; }
inline uint16_t touch_get_y(uint32_t evt) { return (evt >> 0) & 0xFFF; }
inline uint16_t touch_unpack_x(uint32_t evt) { return (evt >> 12) & 0xFFF; }
inline uint16_t touch_unpack_y(uint32_t evt) { return (evt >> 0) & 0xFFF; }
inline uint32_t touch_pack_xy(uint16_t x, uint16_t y) { return ((x & 0xFFF) << 12) | (y & 0xFFF); }
#endif

View File

@ -67,8 +67,24 @@ uint32_t touch_read(void)
}
break;
}
#endif
#if TREZOR_MODEL == 1
case SDL_KEYDOWN:
if (event.key.repeat) {
break;
}
switch (event.key.keysym.sym) {
case SDLK_LEFT:
return TOUCH_START | touch_pack_xy(0, sdl_display_res_y - 1);
case SDLK_RIGHT:
return TOUCH_START | touch_pack_xy(sdl_display_res_x - 1, sdl_display_res_y - 1);
}
break;
#endif
case SDL_KEYUP:
if (event.key.repeat) {
break;
}
switch (event.key.keysym.sym) {
case SDLK_ESCAPE:
__shutdown();
@ -77,10 +93,10 @@ uint32_t touch_read(void)
display_save("emu");
break;
#if TREZOR_MODEL == 1
case SDLK_RIGHT:
return TOUCH_CONFIRM;
case SDLK_LEFT:
return TOUCH_CANCEL;
return TOUCH_END | touch_pack_xy(0, sdl_display_res_y - 1);
case SDLK_RIGHT:
return TOUCH_END | touch_pack_xy(sdl_display_res_x - 1, sdl_display_res_y - 1);
#endif
}
break;