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:
parent
dcb09012fb
commit
d1ed02fb98
@ -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;
|
const mp_uint_t mode = i & 0xFF00;
|
||||||
|
|
||||||
if (iface == TOUCH_IFACE) {
|
if (iface == TOUCH_IFACE) {
|
||||||
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));
|
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[0] = MP_OBJ_NEW_SMALL_INT((evt >> 24) & 0xFFU); // event type
|
||||||
tuple->items[1] = MP_OBJ_NEW_SMALL_INT((evt & 0xFF00) >> 8); // x position
|
tuple->items[1] = MP_OBJ_NEW_SMALL_INT((evt >> 12) & 0xFFFU); // x position
|
||||||
tuple->items[2] = MP_OBJ_NEW_SMALL_INT((evt & 0xFF)); // y position
|
tuple->items[2] = MP_OBJ_NEW_SMALL_INT(evt & 0xFFFU); // y position
|
||||||
ret->items[0] = MP_OBJ_NEW_SMALL_INT(i);
|
ret->items[0] = MP_OBJ_NEW_SMALL_INT(i);
|
||||||
ret->items[1] = MP_OBJ_FROM_PTR(tuple);
|
ret->items[1] = MP_OBJ_FROM_PTR(tuple);
|
||||||
return mp_const_true;
|
return mp_const_true;
|
||||||
|
@ -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_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_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), 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_START), MP_OBJ_NEW_SMALL_INT((TOUCH_START >> 24) & 0xFFU) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_TOUCH_MOVE), MP_OBJ_NEW_SMALL_INT((TOUCH_MOVE & 0xFF0000) >> 16) },
|
{ 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 & 0xFF0000) >> 16) },
|
{ 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_READ), MP_OBJ_NEW_SMALL_INT(POLL_READ) },
|
||||||
{ MP_ROM_QSTR(MP_QSTR_POLL_WRITE), MP_OBJ_NEW_SMALL_INT(POLL_WRITE) },
|
{ MP_ROM_QSTR(MP_QSTR_POLL_WRITE), MP_OBJ_NEW_SMALL_INT(POLL_WRITE) },
|
||||||
};
|
};
|
||||||
|
@ -61,13 +61,13 @@ uint32_t touch_read(void)
|
|||||||
|
|
||||||
if (data[0] == 0xff && data[1] == 0x00) {
|
if (data[0] == 0xff && data[1] == 0x00) {
|
||||||
if (data[2] == 0x01 && data[3] == 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
|
} else
|
||||||
if (data[2] == 0x01 && data[3] == 0x80) {
|
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
|
} else
|
||||||
if (data[2] == 0x00 && data[3] == 0x40) {
|
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];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,9 +10,9 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#define TOUCH_START 0x00010000
|
#define TOUCH_START (1U << 24)
|
||||||
#define TOUCH_MOVE 0x00020000
|
#define TOUCH_MOVE (2U << 24)
|
||||||
#define TOUCH_END 0x00040000
|
#define TOUCH_END (4U << 24)
|
||||||
|
|
||||||
void touch_init(void);
|
void touch_init(void);
|
||||||
uint32_t touch_read(void);
|
uint32_t touch_read(void);
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
|
#include "embed/trezorhal/touch.h"
|
||||||
|
|
||||||
uint32_t touch_read(void)
|
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;
|
if (x < 0 || y < 0 || x >= DISPLAY_RESX || y >= DISPLAY_RESY) break;
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
case SDL_MOUSEBUTTONDOWN:
|
case SDL_MOUSEBUTTONDOWN:
|
||||||
return (0x00 << 24) | (0x01 << 16) | (x << 8) | y; // touch_start
|
return TOUCH_START | (x << 12) | y;
|
||||||
break;
|
|
||||||
case SDL_MOUSEMOTION:
|
case SDL_MOUSEMOTION:
|
||||||
// remove other SDL_MOUSEMOTION events from queue
|
// remove other SDL_MOUSEMOTION events from queue
|
||||||
SDL_FlushEvent(SDL_MOUSEMOTION);
|
SDL_FlushEvent(SDL_MOUSEMOTION);
|
||||||
if (event.motion.state) {
|
if (event.motion.state) {
|
||||||
return (0x00 << 24) | (0x02 << 16) | (x << 8) | y; // touch_move
|
return TOUCH_MOVE | (x << 12) | y;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SDL_MOUSEBUTTONUP:
|
case SDL_MOUSEBUTTONUP:
|
||||||
return (0x00 << 24) | (0x04 << 16) | (x << 8) | y; // touch_end
|
return TOUCH_END | (x << 12) | y;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SDL_KEYUP:
|
case SDL_KEYUP:
|
||||||
|
Loading…
Reference in New Issue
Block a user