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

loader: move usb/flash init to mainloop, add simple demo

This commit is contained in:
Pavol Rusnak 2017-04-07 02:34:53 +02:00
parent 4ca7dd2345
commit 1851bffe26
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
3 changed files with 28 additions and 14 deletions

View File

@ -141,7 +141,26 @@ int usb_init_all(void) {
void mainloop(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) int main(void)
@ -152,18 +171,10 @@ int main(void)
__fatal_error("display_init failed"); __fatal_error("display_init failed");
} }
if (0 != flash_init()) {
__fatal_error("flash_init failed");
}
if (0 != touch_init()) { if (0 != touch_init()) {
__fatal_error("touch_init failed"); __fatal_error("touch_init failed");
} }
if (0 != usb_init_all()) {
__fatal_error("usb_init_all failed");
}
display_clear(); display_clear();
display_backlight(255); display_backlight(255);
@ -174,8 +185,6 @@ int main(void)
if (touch_read() != 0) { if (touch_read() != 0) {
mainloop(); mainloop();
} else { } else {
usb_stop();
usb_deinit();
check_and_jump(); check_and_jump();
} }

View File

@ -1,6 +1,7 @@
#include STM32_HAL_H #include STM32_HAL_H
#include <string.h> #include <string.h>
#include "touch.h"
I2C_HandleTypeDef i2c_handle = { I2C_HandleTypeDef i2c_handle = {
.Instance = I2C1, .Instance = I2C1,
@ -55,13 +56,13 @@ uint32_t touch_read(void) {
} }
uint32_t r = 0; uint32_t r = 0;
if (old_data[2] == 0 && data[2] == 1) { 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 } else
if (old_data[2] == 1 && data[2] == 1) { 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) { 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); memcpy(old_data, data, 16);
return r; return r;

View File

@ -1,6 +1,10 @@
#ifndef __TREZORHAL_TOUCH_H__ #ifndef __TREZORHAL_TOUCH_H__
#define __TREZORHAL_TOUCH_H__ #define __TREZORHAL_TOUCH_H__
#define TOUCH_START 0x00010000
#define TOUCH_MOVE 0x00020000
#define TOUCH_END 0x00040000
int touch_init(void); int touch_init(void);
uint32_t touch_read(void); uint32_t touch_read(void);