diff options
author | Simon Glass <sjg@chromium.org> | 2023-01-06 08:52:35 -0600 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2023-01-16 18:26:50 -0500 |
commit | 9e7ac0b0be5cb663e539716554d66f8f0890ca83 (patch) | |
tree | 74f0cbd7b08352973af302a10820dab740e76a25 /common/menu.c | |
parent | 24d8e1b37b90760a6c9867f37210aa4b1f2e8f63 (diff) |
menu: Factor out menu-keypress decoding
Move this code into a separate function so that it can be used in the new
VBE menu.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'common/menu.c')
-rw-r--r-- | common/menu.c | 48 |
1 files changed, 30 insertions, 18 deletions
diff --git a/common/menu.c b/common/menu.c index 45f36ae3ed..cdcdbb2a18 100644 --- a/common/menu.c +++ b/common/menu.c @@ -483,26 +483,11 @@ enum bootmenu_key bootmenu_autoboot_loop(struct bootmenu_data *menu, return key; } -enum bootmenu_key bootmenu_loop(struct bootmenu_data *menu, - struct cli_ch_state *cch) +enum bootmenu_key bootmenu_conv_key(int ichar) { - enum bootmenu_key key = BKEY_NONE; - int c; - - c = cli_ch_process(cch, 0); - if (!c) { - while (!c && !tstc()) { - schedule(); - mdelay(10); - c = cli_ch_process(cch, -ETIMEDOUT); - } - if (!c) { - c = getchar(); - c = cli_ch_process(cch, c); - } - } + enum bootmenu_key key; - switch (c) { + switch (ichar) { case '\n': /* enter key was pressed */ key = BKEY_SELECT; @@ -527,7 +512,34 @@ enum bootmenu_key bootmenu_loop(struct bootmenu_data *menu, case ' ': key = BKEY_SPACE; break; + default: + key = BKEY_NONE; + break; + } + + return key; +} + +enum bootmenu_key bootmenu_loop(struct bootmenu_data *menu, + struct cli_ch_state *cch) +{ + enum bootmenu_key key; + int c; + + c = cli_ch_process(cch, 0); + if (!c) { + while (!c && !tstc()) { + schedule(); + mdelay(10); + c = cli_ch_process(cch, -ETIMEDOUT); + } + if (!c) { + c = getchar(); + c = cli_ch_process(cch, c); + } } + key = bootmenu_conv_key(c); + return key; } |