From 0ec32a61468efcbdf8a8a2e6e10a0b4c0ea76c9c Mon Sep 17 00:00:00 2001 From: Saleem Rashid Date: Thu, 17 Nov 2016 19:10:57 +0000 Subject: [PATCH] timer: Replace screen timeout with SysTick This provides an incredibly accurate screen timeout and removes the superfluous screen timeout counter --- firmware/layout2.c | 4 ++++ firmware/trezor.c | 9 +-------- timer.c | 3 +++ timer.h | 5 +++++ 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/firmware/layout2.c b/firmware/layout2.c index e7d49262ab..91c409b6e6 100644 --- a/firmware/layout2.c +++ b/firmware/layout2.c @@ -28,6 +28,7 @@ #include "string.h" #include "util.h" #include "qr_encode.h" +#include "timer.h" void *layoutLast = layoutHome; @@ -81,6 +82,9 @@ void layoutHome(void) } } oledRefresh(); + + // Reset lock screen timeout + system_millis_lock = system_millis + SCREEN_TIMEOUT_MILLIS; } const char *str_amount(uint64_t amnt, const char *abbr, char *buf, int len) diff --git a/firmware/trezor.c b/firmware/trezor.c index a56e3d2e71..129fd61a4e 100644 --- a/firmware/trezor.c +++ b/firmware/trezor.c @@ -38,15 +38,12 @@ void __attribute__((noreturn)) __stack_chk_fail(void) for (;;) {} // loop forever } -static uint32_t saver_counter = 0; - void check_lock_screen(void) { buttonUpdate(); // wake from screensaver on any button if (layoutLast == layoutScreensaver && (button.NoUp || button.YesUp)) { - saver_counter = 0; layoutHome(); return; } @@ -82,15 +79,11 @@ void check_lock_screen(void) // if homescreen is shown for longer than 10 minutes, lock too if (layoutLast == layoutHome) { - saver_counter++; - if (saver_counter > 285000 * 60 * 10) { + if (system_millis >= system_millis_lock) { // lock the screen session_clear(true); layoutScreensaver(); - saver_counter = 0; } - } else { - saver_counter = 0; } } diff --git a/timer.c b/timer.c index 2be93e8937..e45ce740f0 100644 --- a/timer.c +++ b/timer.c @@ -26,6 +26,9 @@ /* 1 tick = 1 ms */ volatile uint32_t system_millis; +/* Screen timeout */ +uint32_t system_millis_lock; + /* * Initialise the Cortex-M3 SysTick timer */ diff --git a/timer.h b/timer.h index a69879c93d..53713cdfe5 100644 --- a/timer.h +++ b/timer.h @@ -23,6 +23,11 @@ /* 1 tick = 1 ms */ extern volatile uint32_t system_millis; +/* Screen timeout */ +extern uint32_t system_millis_lock; + +#define SCREEN_TIMEOUT_MILLIS (1000 * 60 * 10) /* 10 minutes */ + void timer_init(void); void sys_tick_handler(void);