diff --git a/micropython/extmod/modtrezormsg/modtrezormsg-stmhal.h b/micropython/extmod/modtrezormsg/modtrezormsg-stmhal.h index fc00ab8ee5..c86c9f2f48 100644 --- a/micropython/extmod/modtrezormsg/modtrezormsg-stmhal.h +++ b/micropython/extmod/modtrezormsg/modtrezormsg-stmhal.h @@ -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(); -} diff --git a/micropython/extmod/modtrezormsg/modtrezormsg-unix.h b/micropython/extmod/modtrezormsg/modtrezormsg-unix.h index 9cfe69911d..76ffade130 100644 --- a/micropython/extmod/modtrezormsg/modtrezormsg-unix.h +++ b/micropython/extmod/modtrezormsg/modtrezormsg-unix.h @@ -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(); -} diff --git a/micropython/extmod/modtrezormsg/modtrezormsg.c b/micropython/extmod/modtrezormsg/modtrezormsg.c index 4ec71a6fea..89952da990 100644 --- a/micropython/extmod/modtrezormsg/modtrezormsg.c +++ b/micropython/extmod/modtrezormsg/modtrezormsg.c @@ -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); diff --git a/micropython/extmod/modtrezorui/display-unix-sdl.h b/micropython/extmod/modtrezorui/display-unix-sdl.h index 4af7548504..bcd24b7afc 100644 --- a/micropython/extmod/modtrezorui/display-unix-sdl.h +++ b/micropython/extmod/modtrezorui/display-unix-sdl.h @@ -7,7 +7,6 @@ #include #include -#include #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); diff --git a/micropython/unix/Makefile b/micropython/unix/Makefile index bad9b02ee8..b3186f8b03 100644 --- a/micropython/unix/Makefile +++ b/micropython/unix/Makefile @@ -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 diff --git a/micropython/unix/options.h b/micropython/unix/options.h new file mode 100644 index 0000000000..0d5ce9550d --- /dev/null +++ b/micropython/unix/options.h @@ -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 diff --git a/micropython/unix/touch.c b/micropython/unix/touch.c new file mode 100644 index 0000000000..d29ec33eba --- /dev/null +++ b/micropython/unix/touch.c @@ -0,0 +1,52 @@ +/* + * Copyright (c) Pavol Rusnak, SatoshiLabs + * + * Licensed under TREZOR License + * see LICENSE file for details + */ + +#include + +#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; +}