From: Simon Glass <sjg@chromium.org> The current algorithm spends 10ms or more looking for keyboard input. Since we expect the frame rate to be 50 or more, it should be OK to only check once. Handle the timeout by recording the timestamp of the last key and timing out the CLI entry after 10ms. This allows an 'Escape' key to work, rather than it just waiting forever for a terminal sequence that starts with escape. Signed-off-by: Simon Glass <sjg@chromium.org> --- (no changes since v1) boot/expo.c | 16 ++++++++-------- include/expo.h | 2 ++ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/boot/expo.c b/boot/expo.c index ebe31059e87..5704dd9fecc 100644 --- a/boot/expo.c +++ b/boot/expo.c @@ -16,6 +16,7 @@ #include <mapmem.h> #include <menu.h> #include <mouse.h> +#include <time.h> #include <video.h> #include <watchdog.h> #include <linux/delay.h> @@ -45,6 +46,7 @@ int expo_new(const char *name, void *priv, struct expo **expp) INIT_LIST_HEAD(&exp->str_head); exp->next_id = EXPOID_BASE_ID; cli_ch_init(&exp->cch); + exp->last_key_ms = get_timer(0); *expp = exp; @@ -488,21 +490,19 @@ static int poll_keys(struct expo *exp) ichar = cli_ch_process(&exp->cch, 0); if (!ichar) { - int i; - - for (i = 0; i < 10 && !ichar && !tstc(); i++) { - schedule(); - mdelay(2); - ichar = cli_ch_process(&exp->cch, -ETIMEDOUT); - } - while (!ichar && tstc()) { + /* Check once for available input */ + if (tstc()) { ichar = getchar(); ichar = cli_ch_process(&exp->cch, ichar); } + + if (!ichar && get_timer(exp->last_key_ms) >= 10) + ichar = cli_ch_process(&exp->cch, -ETIMEDOUT); } key = 0; if (ichar) { + exp->last_key_ms = get_timer(0); key = bootmenu_conv_key(ichar); if (key == BKEY_NONE || key >= BKEY_FIRST_EXTRA) key = ichar; diff --git a/include/expo.h b/include/expo.h index e9e71f4fe36..b51d946f367 100644 --- a/include/expo.h +++ b/include/expo.h @@ -146,6 +146,7 @@ struct expo_theme { * @scene_head: List of scenes * @str_head: list of strings * @cch: Keyboard context for input + * @last_key_ms: timestamp of the last key received */ struct expo { char *name; @@ -173,6 +174,7 @@ struct expo { struct list_head scene_head; struct list_head str_head; struct cli_ch_state cch; + ulong last_key_ms; }; /** -- 2.43.0