1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-20 05:18:08 +00:00

fix(core): prevent overloading app with touch events

[no changelog]
This commit is contained in:
tychovrahe 2024-05-22 22:19:14 +02:00 committed by TychoVrahe
parent 1be6208a02
commit b178c10e8b
4 changed files with 46 additions and 31 deletions

View File

@ -31,6 +31,7 @@
#define POLL_WRITE (0x0100) #define POLL_WRITE (0x0100)
extern bool usb_connected_previously; extern bool usb_connected_previously;
extern uint32_t last_touch_sample_time;
/// package: trezorio.__init__ /// package: trezorio.__init__
@ -84,38 +85,46 @@ STATIC mp_obj_t mod_trezorio_poll(mp_obj_t ifaces, mp_obj_t list_ref,
} }
#if defined USE_TOUCH #if defined USE_TOUCH
else if (iface == TOUCH_IFACE) { else if (iface == TOUCH_IFACE) {
const uint32_t evt = touch_read(); const uint32_t evt = touch_read();
if (evt) { if (evt) {
mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(mp_obj_new_tuple(3, NULL)); // ignore TOUCH_MOVE events if they are too frequent
const uint32_t etype = (evt >> 24) & 0xFFU; // event type if ((evt & TOUCH_MOVE) == 0 ||
const uint32_t ex = (evt >> 12) & 0xFFFU; // x position (hal_ticks_ms() - last_touch_sample_time > 10)) {
const uint32_t ey = evt & 0xFFFU; // y position last_touch_sample_time = hal_ticks_ms();
uint32_t exr; // rotated x position
uint32_t eyr; // rotated y position mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(mp_obj_new_tuple(3, NULL));
switch (display_orientation(-1)) { const uint32_t etype = (evt >> 24) & 0xFFU; // event type
case 90: const uint32_t ex = (evt >> 12) & 0xFFFU; // x position
exr = ey; const uint32_t ey = evt & 0xFFFU; // y position
eyr = DISPLAY_RESX - ex; uint32_t exr; // rotated x position
break; uint32_t eyr; // rotated y position
case 180: switch (display_orientation(-1)) {
exr = DISPLAY_RESX - ex; case 90:
eyr = DISPLAY_RESY - ey; exr = ey;
break; eyr = DISPLAY_RESX - ex;
case 270: break;
exr = DISPLAY_RESY - ey; case 180:
eyr = ex; exr = DISPLAY_RESX - ex;
break; eyr = DISPLAY_RESY - ey;
default: break;
exr = ex; case 270:
eyr = ey; exr = DISPLAY_RESY - ey;
break; eyr = ex;
break;
default:
exr = ex;
eyr = ey;
break;
}
tuple->items[0] = MP_OBJ_NEW_SMALL_INT(etype);
tuple->items[1] = MP_OBJ_NEW_SMALL_INT(exr);
tuple->items[2] = MP_OBJ_NEW_SMALL_INT(eyr);
ret->items[0] = MP_OBJ_NEW_SMALL_INT(i);
ret->items[1] = MP_OBJ_FROM_PTR(tuple);
return mp_const_true;
} }
tuple->items[0] = MP_OBJ_NEW_SMALL_INT(etype);
tuple->items[1] = MP_OBJ_NEW_SMALL_INT(exr);
tuple->items[2] = MP_OBJ_NEW_SMALL_INT(eyr);
ret->items[0] = MP_OBJ_NEW_SMALL_INT(i);
ret->items[1] = MP_OBJ_FROM_PTR(tuple);
return mp_const_true;
} }
} else if (iface == USB_DATA_IFACE) { } else if (iface == USB_DATA_IFACE) {
bool usb_connected = usb_configured() == sectrue ? true : false; bool usb_connected = usb_configured() == sectrue ? true : false;

View File

@ -35,6 +35,8 @@
// Whether USB data pins were connected on last check (USB configured) // Whether USB data pins were connected on last check (USB configured)
bool usb_connected_previously = true; bool usb_connected_previously = true;
uint32_t last_touch_sample_time = 0;
#define CHECK_PARAM_RANGE(value, minimum, maximum) \ #define CHECK_PARAM_RANGE(value, minimum, maximum) \
if (value < minimum || value > maximum) { \ if (value < minimum || value > maximum) { \
mp_raise_ValueError(#value " is out of range"); \ mp_raise_ValueError(#value " is out of range"); \

View File

@ -266,7 +266,12 @@ uint32_t touch_read(void) {
touching = 1; touching = 1;
return TOUCH_START | xy; return TOUCH_START | xy;
} else if ((number_of_touch_points == 1) && (event_flag == EVENT_CONTACT)) { } else if ((number_of_touch_points == 1) && (event_flag == EVENT_CONTACT)) {
return TOUCH_MOVE | xy; if (touching) {
return TOUCH_MOVE | xy;
} else {
touching = 1;
return TOUCH_START | xy;
}
} else if ((number_of_touch_points == 0) && (event_flag == EVENT_LIFT_UP)) { } else if ((number_of_touch_points == 0) && (event_flag == EVENT_LIFT_UP)) {
touching = 0; touching = 0;
return TOUCH_END | xy; return TOUCH_END | xy;

View File

@ -211,7 +211,6 @@ uint32_t touch_read(void) {
if (ev_type != 0) { if (ev_type != 0) {
_touch_x = ev_x; _touch_x = ev_x;
_touch_y = ev_y; _touch_y = ev_y;
break;
} }
} }
return ev_type | touch_pack_xy(ev_x, ev_y); return ev_type | touch_pack_xy(ev_x, ev_y);