mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-19 14:08:11 +00:00
generate proper events from touchscreen
This commit is contained in:
parent
0d3facf99e
commit
e480871db3
@ -1,8 +1,10 @@
|
||||
extern struct _USBD_HandleTypeDef hUSBDDevice;
|
||||
extern int switch_get(void);
|
||||
extern uint8_t USBD_HID_SendReport(struct _USBD_HandleTypeDef *pdev, uint8_t *report, uint16_t len);
|
||||
extern int USBD_HID_Rx(uint8_t *buf, uint32_t len, uint32_t timeout);
|
||||
|
||||
extern I2C_HandleTypeDef I2CHandle1;
|
||||
extern HAL_StatusTypeDef HAL_I2C_Master_Receive(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout);
|
||||
|
||||
void msg_init(void)
|
||||
{
|
||||
}
|
||||
@ -23,18 +25,23 @@ ssize_t msg_send(uint8_t iface, const uint8_t *buf, size_t len)
|
||||
// this should match values used in trezorui_poll_sdl_event() in modtrezorui/display-unix.h
|
||||
uint32_t msg_poll_ui_event(void)
|
||||
{
|
||||
static int lp = 0;
|
||||
static uint8_t data[16], old_data[16];
|
||||
if (HAL_OK != HAL_I2C_Master_Receive(&I2CHandle1, 56 << 1, data, 16, 1)) {
|
||||
return 0; // read failure
|
||||
}
|
||||
if (0 == memcmp(data, old_data, 16)) {
|
||||
return 0; // no new event
|
||||
}
|
||||
uint32_t r = 0;
|
||||
int p = switch_get();
|
||||
if (lp == 0 && p == 1) {
|
||||
r = 0x00010000; // touch start
|
||||
if (old_data[2] == 0 && data[2] == 1) {
|
||||
r = 0x00010000 + (data[4] << 8) + data[6]; // touch start
|
||||
} else
|
||||
if (lp == 1 && p == 1) {
|
||||
r = 0x00020000; // touch move
|
||||
if (old_data[2] == 1 && data[2] == 1) {
|
||||
r = 0x00020000 + (data[4] << 8) + data[6]; // touch move
|
||||
}
|
||||
if (lp == 1 && p == 0) {
|
||||
r = 0x00040000; // touch end
|
||||
if (old_data[2] == 1 && data[2] == 0) {
|
||||
r = 0x00040000 + (data[4] << 8) + data[6]; // touch end
|
||||
}
|
||||
lp = p;
|
||||
memcpy(old_data, data, 16);
|
||||
return r;
|
||||
}
|
||||
|
@ -4,3 +4,4 @@ if sys.platform in ['trezor', 'pyboard']: # stmhal
|
||||
import pyb
|
||||
# hid=(subclass, protocol, max_packet_len, polling_interval, report_desc)
|
||||
pyb.usb_mode('VCP+HID', vid=0x1209, pid=0x53C1, hid=(0, 0, 64, 1, b'\x06\x00\xff\x09\x01\xa1\x01\x09\x20\x15\x00\x26\xff\x00\x75\x08\x95\x40\x81\x02\x09\x21\x15\x00\x26\xff\x00\x75\x08\x95\x40\x91\x02\xc0'))
|
||||
pyb.I2C(1, pyb.I2C.MASTER)
|
||||
|
Loading…
Reference in New Issue
Block a user