diff --git a/micropython/loader/main.c b/micropython/loader/main.c index 9d25b8922..3ba4d6679 100644 --- a/micropython/loader/main.c +++ b/micropython/loader/main.c @@ -141,7 +141,26 @@ int usb_init_all(void) { void mainloop(void) { - __fatal_error("touch detected - launch aborted"); + if (0 != flash_init()) { + __fatal_error("flash_init failed"); + } + + if (0 != usb_init_all()) { + __fatal_error("usb_init_all failed"); + } + + display_bar(0, 0, DISPLAY_RESX, DISPLAY_RESY, 0x001F); + display_refresh(); + + for(;;) { + uint32_t e = touch_read(); + if (e & TOUCH_START || e & TOUCH_MOVE) { + int x = (e >> 8) & 0xFF, y = e & 0xFF; + display_bar(x - 1, y - 1, 3, 3, 0xFFFF); + display_refresh(); + } + HAL_Delay(1); + } } int main(void) @@ -152,18 +171,10 @@ int main(void) __fatal_error("display_init failed"); } - if (0 != flash_init()) { - __fatal_error("flash_init failed"); - } - if (0 != touch_init()) { __fatal_error("touch_init failed"); } - if (0 != usb_init_all()) { - __fatal_error("usb_init_all failed"); - } - display_clear(); display_backlight(255); @@ -174,8 +185,6 @@ int main(void) if (touch_read() != 0) { mainloop(); } else { - usb_stop(); - usb_deinit(); check_and_jump(); } diff --git a/micropython/trezorhal/touch.c b/micropython/trezorhal/touch.c index 986e2f897..fd24208ab 100644 --- a/micropython/trezorhal/touch.c +++ b/micropython/trezorhal/touch.c @@ -1,6 +1,7 @@ #include STM32_HAL_H #include +#include "touch.h" I2C_HandleTypeDef i2c_handle = { .Instance = I2C1, @@ -55,13 +56,13 @@ uint32_t touch_read(void) { } uint32_t r = 0; if (old_data[2] == 0 && data[2] == 1) { - r = 0x00010000 + (data[4] << 8) + data[6]; // touch start + r = TOUCH_START | (data[4] << 8) | data[6]; // touch start } else if (old_data[2] == 1 && data[2] == 1) { - r = 0x00020000 + (data[4] << 8) + data[6]; // touch move + r = TOUCH_MOVE | (data[4] << 8) | data[6]; // touch move } if (old_data[2] == 1 && data[2] == 0) { - r = 0x00040000 + (data[4] << 8) + data[6]; // touch end + r = TOUCH_END | (data[4] << 8) | data[6]; // touch end } memcpy(old_data, data, 16); return r; diff --git a/micropython/trezorhal/touch.h b/micropython/trezorhal/touch.h index 2a31bf3a6..406efd781 100644 --- a/micropython/trezorhal/touch.h +++ b/micropython/trezorhal/touch.h @@ -1,6 +1,10 @@ #ifndef __TREZORHAL_TOUCH_H__ #define __TREZORHAL_TOUCH_H__ +#define TOUCH_START 0x00010000 +#define TOUCH_MOVE 0x00020000 +#define TOUCH_END 0x00040000 + int touch_init(void); uint32_t touch_read(void);