mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-27 01:48:17 +00:00
trezorhal: unix: refactor touch get/pack functionality
This commit is contained in:
parent
2f567ee822
commit
8ef2098763
@ -194,8 +194,8 @@ static void test_touch(const char *args)
|
|||||||
|
|
||||||
uint32_t evt = 0;
|
uint32_t evt = 0;
|
||||||
if (touch_click_timeout(&evt, timeout * 1000)) {
|
if (touch_click_timeout(&evt, timeout * 1000)) {
|
||||||
uint32_t x = (evt >> 12) & 0xFFF;
|
uint16_t x = touch_get_x(evt);
|
||||||
uint32_t y = (evt >> 0) & 0xFFF;
|
uint16_t y = touch_get_y(evt);
|
||||||
vcp_printf("OK %d %d", x, y);
|
vcp_printf("OK %d %d", x, y);
|
||||||
} else {
|
} else {
|
||||||
vcp_printf("ERROR TIMEOUT");
|
vcp_printf("ERROR TIMEOUT");
|
||||||
|
@ -13,6 +13,18 @@
|
|||||||
#include "secbool.h"
|
#include "secbool.h"
|
||||||
#include "touch.h"
|
#include "touch.h"
|
||||||
|
|
||||||
|
#define TOUCH_ADDRESS (0x38U << 1) // the HAL requires the 7-bit address to be shifted by one bit
|
||||||
|
#define TOUCH_PACKET_SIZE 7U
|
||||||
|
#define EVENT_PRESS_DOWN 0x00U
|
||||||
|
#define EVENT_CONTACT 0x80U
|
||||||
|
#define EVENT_LIFT_UP 0x40U
|
||||||
|
#define EVENT_NO_EVENT 0xC0U
|
||||||
|
#define GESTURE_NO_GESTURE 0x00U
|
||||||
|
#define X_POS_MSB (touch_data[3] & 0x0FU)
|
||||||
|
#define X_POS_LSB (touch_data[4])
|
||||||
|
#define Y_POS_MSB (touch_data[5] & 0x0FU)
|
||||||
|
#define Y_POS_LSB (touch_data[6])
|
||||||
|
|
||||||
static I2C_HandleTypeDef i2c_handle;
|
static I2C_HandleTypeDef i2c_handle;
|
||||||
|
|
||||||
void touch_init(void)
|
void touch_init(void)
|
||||||
@ -91,14 +103,14 @@ uint32_t touch_read(void)
|
|||||||
|
|
||||||
const uint32_t number_of_touch_points = touch_data[2] & 0x0F; // valid values are 0, 1, 2 (invalid 0xF before first touch) (tested with FT6206)
|
const uint32_t number_of_touch_points = touch_data[2] & 0x0F; // valid values are 0, 1, 2 (invalid 0xF before first touch) (tested with FT6206)
|
||||||
const uint32_t event_flag = touch_data[3] & 0xC0;
|
const uint32_t event_flag = touch_data[3] & 0xC0;
|
||||||
|
|
||||||
if (touch_data[1] == GESTURE_NO_GESTURE) {
|
if (touch_data[1] == GESTURE_NO_GESTURE) {
|
||||||
|
uint32_t xy = touch_pack_xy((X_POS_MSB << 8) | X_POS_LSB, (Y_POS_MSB << 8) | Y_POS_LSB);
|
||||||
if ((number_of_touch_points == 1) && (event_flag == EVENT_PRESS_DOWN)) {
|
if ((number_of_touch_points == 1) && (event_flag == EVENT_PRESS_DOWN)) {
|
||||||
return TOUCH_START | X_Y_POS;
|
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 | X_Y_POS;
|
return TOUCH_MOVE | 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)) {
|
||||||
return TOUCH_END | X_Y_POS;
|
return TOUCH_END | xy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,21 +14,11 @@
|
|||||||
#define TOUCH_MOVE (2U << 24)
|
#define TOUCH_MOVE (2U << 24)
|
||||||
#define TOUCH_END (4U << 24)
|
#define TOUCH_END (4U << 24)
|
||||||
|
|
||||||
#define TOUCH_ADDRESS (0x38U << 1) // the HAL requires the 7-bit address to be shifted by one bit
|
|
||||||
#define TOUCH_PACKET_SIZE 7U
|
|
||||||
#define EVENT_PRESS_DOWN 0x00U
|
|
||||||
#define EVENT_CONTACT 0x80U
|
|
||||||
#define EVENT_LIFT_UP 0x40U
|
|
||||||
#define EVENT_NO_EVENT 0xC0U
|
|
||||||
#define GESTURE_NO_GESTURE 0x00U
|
|
||||||
#define X_POS_MSB (touch_data[3] & 0xFU)
|
|
||||||
#define X_POS_LSB (touch_data[4])
|
|
||||||
#define Y_POS_MSB (touch_data[5] & 0xFU)
|
|
||||||
#define Y_POS_LSB (touch_data[6])
|
|
||||||
#define X_Y_POS ((X_POS_MSB << 20) | (X_POS_LSB << 12) | (Y_POS_MSB << 8) | (Y_POS_LSB))
|
|
||||||
|
|
||||||
void touch_init(void);
|
void touch_init(void);
|
||||||
uint32_t touch_read(void);
|
uint32_t touch_read(void);
|
||||||
uint32_t touch_click(void);
|
uint32_t touch_click(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 uint32_t touch_pack_xy(uint16_t x, uint16_t y) { return ((x & 0xFFF) << 12) | (y & 0xFFF); }
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -31,16 +31,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 TOUCH_START | (x << 12) | y;
|
return TOUCH_START | touch_pack_xy(x, y);
|
||||||
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 TOUCH_MOVE | (x << 12) | y;
|
return TOUCH_MOVE | touch_pack_xy(x, y);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SDL_MOUSEBUTTONUP:
|
case SDL_MOUSEBUTTONUP:
|
||||||
return TOUCH_END | (x << 12) | y;
|
return TOUCH_END | touch_pack_xy(x, y);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SDL_KEYUP:
|
case SDL_KEYUP:
|
||||||
|
Loading…
Reference in New Issue
Block a user