From 218b9984bb256a4567cd54418c32154466966ab4 Mon Sep 17 00:00:00 2001 From: Jochen Hoenicke Date: Wed, 29 Apr 2015 19:10:48 +0200 Subject: [PATCH] New usbDelay that delays and handles USB requests Added usbDelay that polls usb port (for system requests) while delaying. This is called instead of delay in the button and pin delay functions. Experimental evaluation gave that the cycle count should be roughly divided by 28.5. --- firmware/protect.c | 4 ++-- firmware/usb.c | 7 +++++++ firmware/usb.h | 1 + 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/firmware/protect.c b/firmware/protect.c index b79dae8..1cac5ed 100644 --- a/firmware/protect.c +++ b/firmware/protect.c @@ -57,7 +57,7 @@ bool protectButton(ButtonRequestType type, bool confirm_only) // button acked - check buttons if (acked) { - delay(100000); + usbDelay(3500); buttonUpdate(); if (button.YesUp) { result = true; @@ -165,7 +165,7 @@ bool protectPin(bool use_cached) } layoutDialog(DIALOG_ICON_INFO, NULL, NULL, NULL, "Wrong PIN entered", NULL, "Please wait", secstr, "to continue ...", NULL); // wait one second - delay(24000000); + usbDelay(840000); } } const char *pin; diff --git a/firmware/usb.c b/firmware/usb.c index 43c7bd9..03baabd 100644 --- a/firmware/usb.c +++ b/firmware/usb.c @@ -332,3 +332,10 @@ void usbTiny(char set) { tiny = set; } + +void usbDelay(int cycles) +{ + while (cycles--) { + usbd_poll(usbd_dev); + } +} diff --git a/firmware/usb.h b/firmware/usb.h index eec42e3..d1dc250 100644 --- a/firmware/usb.h +++ b/firmware/usb.h @@ -24,5 +24,6 @@ void usbInit(void); void usbPoll(void); void usbReconnect(void); void usbTiny(char set); +void usbDelay(int cycles); #endif