mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-19 21:08:07 +00:00
fix(core): prevent overloading app with touch events
[no changelog]
This commit is contained in:
parent
1be6208a02
commit
b178c10e8b
@ -31,6 +31,7 @@
|
||||
#define POLL_WRITE (0x0100)
|
||||
|
||||
extern bool usb_connected_previously;
|
||||
extern uint32_t last_touch_sample_time;
|
||||
|
||||
/// 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
|
||||
else if (iface == TOUCH_IFACE) {
|
||||
|
||||
const uint32_t evt = touch_read();
|
||||
|
||||
if (evt) {
|
||||
mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(mp_obj_new_tuple(3, NULL));
|
||||
const uint32_t etype = (evt >> 24) & 0xFFU; // event type
|
||||
const uint32_t ex = (evt >> 12) & 0xFFFU; // x position
|
||||
const uint32_t ey = evt & 0xFFFU; // y position
|
||||
uint32_t exr; // rotated x position
|
||||
uint32_t eyr; // rotated y position
|
||||
switch (display_orientation(-1)) {
|
||||
case 90:
|
||||
exr = ey;
|
||||
eyr = DISPLAY_RESX - ex;
|
||||
break;
|
||||
case 180:
|
||||
exr = DISPLAY_RESX - ex;
|
||||
eyr = DISPLAY_RESY - ey;
|
||||
break;
|
||||
case 270:
|
||||
exr = DISPLAY_RESY - ey;
|
||||
eyr = ex;
|
||||
break;
|
||||
default:
|
||||
exr = ex;
|
||||
eyr = ey;
|
||||
break;
|
||||
// ignore TOUCH_MOVE events if they are too frequent
|
||||
if ((evt & TOUCH_MOVE) == 0 ||
|
||||
(hal_ticks_ms() - last_touch_sample_time > 10)) {
|
||||
last_touch_sample_time = hal_ticks_ms();
|
||||
|
||||
mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(mp_obj_new_tuple(3, NULL));
|
||||
const uint32_t etype = (evt >> 24) & 0xFFU; // event type
|
||||
const uint32_t ex = (evt >> 12) & 0xFFFU; // x position
|
||||
const uint32_t ey = evt & 0xFFFU; // y position
|
||||
uint32_t exr; // rotated x position
|
||||
uint32_t eyr; // rotated y position
|
||||
switch (display_orientation(-1)) {
|
||||
case 90:
|
||||
exr = ey;
|
||||
eyr = DISPLAY_RESX - ex;
|
||||
break;
|
||||
case 180:
|
||||
exr = DISPLAY_RESX - ex;
|
||||
eyr = DISPLAY_RESY - ey;
|
||||
break;
|
||||
case 270:
|
||||
exr = DISPLAY_RESY - ey;
|
||||
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) {
|
||||
bool usb_connected = usb_configured() == sectrue ? true : false;
|
||||
|
@ -35,6 +35,8 @@
|
||||
// Whether USB data pins were connected on last check (USB configured)
|
||||
bool usb_connected_previously = true;
|
||||
|
||||
uint32_t last_touch_sample_time = 0;
|
||||
|
||||
#define CHECK_PARAM_RANGE(value, minimum, maximum) \
|
||||
if (value < minimum || value > maximum) { \
|
||||
mp_raise_ValueError(#value " is out of range"); \
|
||||
|
@ -266,7 +266,12 @@ uint32_t touch_read(void) {
|
||||
touching = 1;
|
||||
return TOUCH_START | xy;
|
||||
} 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)) {
|
||||
touching = 0;
|
||||
return TOUCH_END | xy;
|
||||
|
@ -211,7 +211,6 @@ uint32_t touch_read(void) {
|
||||
if (ev_type != 0) {
|
||||
_touch_x = ev_x;
|
||||
_touch_y = ev_y;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ev_type | touch_pack_xy(ev_x, ev_y);
|
||||
|
Loading…
Reference in New Issue
Block a user