1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 23:48:12 +00:00

touch: use full 12-bit X and Y values

This commit is contained in:
mcudev 2017-10-26 10:23:04 -04:00 committed by Pavol Rusnak
parent dcb09012fb
commit d1ed02fb98
5 changed files with 17 additions and 18 deletions

View File

@ -53,12 +53,12 @@ STATIC mp_obj_t mod_trezorio_poll(mp_obj_t ifaces, mp_obj_t list_ref, mp_obj_t t
const mp_uint_t mode = i & 0xFF00;
if (iface == TOUCH_IFACE) {
uint32_t evt = touch_read();
const uint32_t evt = touch_read();
if (evt) {
mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(mp_obj_new_tuple(3, NULL));
tuple->items[0] = MP_OBJ_NEW_SMALL_INT((evt & 0xFF0000) >> 16); // event type
tuple->items[1] = MP_OBJ_NEW_SMALL_INT((evt & 0xFF00) >> 8); // x position
tuple->items[2] = MP_OBJ_NEW_SMALL_INT((evt & 0xFF)); // y position
tuple->items[0] = MP_OBJ_NEW_SMALL_INT((evt >> 24) & 0xFFU); // event type
tuple->items[1] = MP_OBJ_NEW_SMALL_INT((evt >> 12) & 0xFFFU); // x position
tuple->items[2] = MP_OBJ_NEW_SMALL_INT(evt & 0xFFFU); // y position
ret->items[0] = MP_OBJ_NEW_SMALL_INT(i);
ret->items[1] = MP_OBJ_FROM_PTR(tuple);
return mp_const_true;

View File

@ -30,9 +30,9 @@ STATIC const mp_rom_map_elem_t mp_module_trezorio_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_VCP), MP_ROM_PTR(&mod_trezorio_VCP_type) },
{ MP_ROM_QSTR(MP_QSTR_poll), MP_ROM_PTR(&mod_trezorio_poll_obj) },
{ MP_ROM_QSTR(MP_QSTR_TOUCH), MP_OBJ_NEW_SMALL_INT(TOUCH_IFACE) },
{ MP_ROM_QSTR(MP_QSTR_TOUCH_START), MP_OBJ_NEW_SMALL_INT((TOUCH_START & 0xFF0000) >> 16) },
{ MP_ROM_QSTR(MP_QSTR_TOUCH_MOVE), MP_OBJ_NEW_SMALL_INT((TOUCH_MOVE & 0xFF0000) >> 16) },
{ MP_ROM_QSTR(MP_QSTR_TOUCH_END), MP_OBJ_NEW_SMALL_INT((TOUCH_END & 0xFF0000) >> 16) },
{ 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_POLL_READ), MP_OBJ_NEW_SMALL_INT(POLL_READ) },
{ MP_ROM_QSTR(MP_QSTR_POLL_WRITE), MP_OBJ_NEW_SMALL_INT(POLL_WRITE) },
};

View File

@ -61,13 +61,13 @@ uint32_t touch_read(void)
if (data[0] == 0xff && data[1] == 0x00) {
if (data[2] == 0x01 && data[3] == 0x00) {
return TOUCH_START | (data[4] << 8) | data[6]; // touch start
return TOUCH_START | ((data[3] & 0xF) << 20) | (data[4] << 12) | ((data[5] & 0xF) << 8) | data[6];
} else
if (data[2] == 0x01 && data[3] == 0x80) {
return TOUCH_MOVE | (data[4] << 8) | data[6]; // touch move
return TOUCH_MOVE | ((data[3] & 0xF) << 20) | (data[4] << 12) | ((data[5] & 0xF) << 8) | data[6];
} else
if (data[2] == 0x00 && data[3] == 0x40) {
return TOUCH_END | (data[4] << 8) | data[6]; // touch end
return TOUCH_END | ((data[3] & 0xF) << 20) | (data[4] << 12) | ((data[5] & 0xF) << 8) | data[6];
}
}

View File

@ -10,9 +10,9 @@
#include <stdint.h>
#define TOUCH_START 0x00010000
#define TOUCH_MOVE 0x00020000
#define TOUCH_END 0x00040000
#define TOUCH_START (1U << 24)
#define TOUCH_MOVE (2U << 24)
#define TOUCH_END (4U << 24)
void touch_init(void);
uint32_t touch_read(void);

View File

@ -11,6 +11,7 @@
#endif
#include "options.h"
#include "embed/trezorhal/touch.h"
uint32_t touch_read(void)
{
@ -28,18 +29,16 @@ uint32_t touch_read(void)
if (x < 0 || y < 0 || x >= DISPLAY_RESX || y >= DISPLAY_RESY) break;
switch (event.type) {
case SDL_MOUSEBUTTONDOWN:
return (0x00 << 24) | (0x01 << 16) | (x << 8) | y; // touch_start
break;
return TOUCH_START | (x << 12) | y;
case SDL_MOUSEMOTION:
// remove other SDL_MOUSEMOTION events from queue
SDL_FlushEvent(SDL_MOUSEMOTION);
if (event.motion.state) {
return (0x00 << 24) | (0x02 << 16) | (x << 8) | y; // touch_move
return TOUCH_MOVE | (x << 12) | y;
}
break;
case SDL_MOUSEBUTTONUP:
return (0x00 << 24) | (0x04 << 16) | (x << 8) | y; // touch_end
break;
return TOUCH_END | (x << 12) | y;
}
break;
case SDL_KEYUP: