1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-18 20:38:10 +00:00

modtrezormsg: untagle touch

This commit is contained in:
Pavol Rusnak 2017-03-16 19:14:12 +01:00
parent 6c982a64d1
commit 4a7540f5b9
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
7 changed files with 71 additions and 60 deletions

View File

@ -5,8 +5,6 @@
* see LICENSE file for details
*/
#include "touch.h"
extern struct _USBD_HandleTypeDef hUSBDDevice;
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);
@ -29,8 +27,3 @@ ssize_t msg_send(uint8_t iface, const uint8_t *buf, size_t len)
}
return len;
}
uint32_t msg_poll_touch(void)
{
return touch_read();
}

View File

@ -67,10 +67,3 @@ ssize_t msg_send(uint8_t iface, const uint8_t *buf, size_t len)
}
return r;
}
extern uint32_t trezorui_poll_event(void);
uint32_t msg_poll_touch(void)
{
return trezorui_poll_event();
}

View File

@ -99,6 +99,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_TrezorMsg_Msg_send_obj, mod_TrezorMsg_Msg_s
#define TICK_RESOLUTION 1000
#define TOUCH_IFACE 0
extern uint32_t touch_read(void); // defined in HAL
/// def trezor.msg.select(timeout_us: int) -> tuple:
/// '''
@ -112,7 +113,7 @@ STATIC mp_obj_t mod_TrezorMsg_Msg_select(mp_obj_t self, mp_obj_t timeout_us) {
timeout = 0;
}
for(;;) {
uint32_t e = msg_poll_touch();
uint32_t e = touch_read();
if (e) {
mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(mp_obj_new_tuple(4, NULL));
tuple->items[0] = MP_OBJ_NEW_SMALL_INT(TOUCH_IFACE);

View File

@ -7,7 +7,6 @@
#include <stdlib.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#define DISPLAY_BORDER 16
@ -33,49 +32,6 @@ void DATA(uint8_t x) {
}
}
// this should match values used in msg_poll_ui_event() in modtrezormsg/modtrezormsg-stmhal.h
uint32_t trezorui_poll_event(void)
{
SDL_Event event;
int x, y;
SDL_PumpEvents();
if (SDL_PollEvent(&event) > 0) {
switch (event.type) {
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEMOTION:
case SDL_MOUSEBUTTONUP:
x = event.button.x - DISPLAY_BORDER;
y = event.button.y - DISPLAY_BORDER;
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;
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
}
break;
case SDL_MOUSEBUTTONUP:
return (0x00 << 24) | (0x04 << 16) | (x << 8) | y; // touch_end
break;
}
break;
case SDL_KEYUP:
if (event.key.keysym.sym == SDLK_ESCAPE) {
exit(3);
}
break;
case SDL_QUIT:
exit(3);
break;
}
}
return 0;
}
void display_init(void)
{
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
@ -86,7 +42,7 @@ void display_init(void)
printf("SDL_CreateWindow Error: %s\n", SDL_GetError());
SDL_Quit();
}
RENDERER = SDL_CreateRenderer(win, -1, SDL_RENDERER_SOFTWARE);
RENDERER = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED);
if (!RENDERER) {
printf("SDL_CreateRenderer Error: %s\n", SDL_GetError());
SDL_DestroyWindow(win);

View File

@ -69,6 +69,7 @@ endif
# OBJ micropython/extmod/modtrezormsg
ifeq ($(MICROPY_PY_TREZORMSG),1)
SRC_MOD += $(EXTMOD_DIR)/../unix/touch.c
SRC_MOD += $(EXTMOD_DIR)/modtrezormsg/modtrezormsg.c
endif

View File

@ -0,0 +1,15 @@
/*
* Copyright (c) Pavol Rusnak, SatoshiLabs
*
* Licensed under TREZOR License
* see LICENSE file for details
*/
#ifndef __OPTIONS_H__
#define __OPTIONS_H__
#define DISPLAY_RESX 240
#define DISPLAY_RESY 240
#define DISPLAY_BORDER 16
#endif

52
micropython/unix/touch.c Normal file
View File

@ -0,0 +1,52 @@
/*
* Copyright (c) Pavol Rusnak, SatoshiLabs
*
* Licensed under TREZOR License
* see LICENSE file for details
*/
#include <SDL2/SDL.h>
#include "options.h"
uint32_t touch_read(void)
{
SDL_Event event;
int x, y;
SDL_PumpEvents();
if (SDL_PollEvent(&event) > 0) {
switch (event.type) {
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEMOTION:
case SDL_MOUSEBUTTONUP:
x = event.button.x - DISPLAY_BORDER;
y = event.button.y - DISPLAY_BORDER;
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;
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
}
break;
case SDL_MOUSEBUTTONUP:
return (0x00 << 24) | (0x04 << 16) | (x << 8) | y; // touch_end
break;
}
break;
case SDL_KEYUP:
if (event.key.keysym.sym == SDLK_ESCAPE) {
exit(3);
}
break;
case SDL_QUIT:
exit(3);
break;
}
}
return 0;
}