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

pull/25/head
Pavol Rusnak 7 years ago
parent 4ca7dd2345
commit 1851bffe26
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

@ -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();
}

@ -1,6 +1,7 @@
#include STM32_HAL_H
#include <string.h>
#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;

@ -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);

Loading…
Cancel
Save