From 2da4a15e7e947d2d304ec1ba392556c3e0393e13 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Fri, 6 Jan 2023 08:52:22 -0600 Subject: menu: Rename KEY_... to BKEY_... This enum values conflict with linux/input.h so rename them. Signed-off-by: Simon Glass --- common/menu.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'common/menu.c') diff --git a/common/menu.c b/common/menu.c index 8fe00965c0..a245c5a9c6 100644 --- a/common/menu.c +++ b/common/menu.c @@ -446,16 +446,16 @@ void bootmenu_autoboot_loop(struct bootmenu_data *menu, switch (c) { case '\e': *esc = 1; - *key = KEY_NONE; + *key = BKEY_NONE; break; case '\r': - *key = KEY_SELECT; + *key = BKEY_SELECT; break; case 0x3: /* ^C */ - *key = KEY_QUIT; + *key = BKEY_QUIT; break; default: - *key = KEY_NONE; + *key = BKEY_NONE; break; } @@ -471,7 +471,7 @@ void bootmenu_autoboot_loop(struct bootmenu_data *menu, printf(ANSI_CURSOR_POSITION ANSI_CLEAR_LINE, menu->count + 5, 1); if (menu->delay == 0) - *key = KEY_SELECT; + *key = BKEY_SELECT; } void bootmenu_loop(struct bootmenu_data *menu, @@ -503,17 +503,17 @@ void bootmenu_loop(struct bootmenu_data *menu, /* First char of ANSI escape sequence '\e' */ if (c == '\e') { *esc = 1; - *key = KEY_NONE; + *key = BKEY_NONE; } break; case 1: /* Second char of ANSI '[' */ if (c == '[') { *esc = 2; - *key = KEY_NONE; + *key = BKEY_NONE; } else { /* Alone ESC key was pressed */ - *key = KEY_QUIT; + *key = BKEY_QUIT; *esc = (c == '\e') ? 1 : 0; } break; @@ -522,7 +522,7 @@ void bootmenu_loop(struct bootmenu_data *menu, /* Third char of ANSI (number '1') - optional */ if (*esc == 2 && c == '1') { *esc = 3; - *key = KEY_NONE; + *key = BKEY_NONE; break; } @@ -530,31 +530,31 @@ void bootmenu_loop(struct bootmenu_data *menu, /* ANSI 'A' - key up was pressed */ if (c == 'A') - *key = KEY_UP; + *key = BKEY_UP; /* ANSI 'B' - key down was pressed */ else if (c == 'B') - *key = KEY_DOWN; + *key = BKEY_DOWN; /* other key was pressed */ else - *key = KEY_NONE; + *key = BKEY_NONE; break; } /* enter key was pressed */ if (c == '\r') - *key = KEY_SELECT; + *key = BKEY_SELECT; /* ^C was pressed */ if (c == 0x3) - *key = KEY_QUIT; + *key = BKEY_QUIT; if (c == '+') - *key = KEY_PLUS; + *key = BKEY_PLUS; if (c == '-') - *key = KEY_MINUS; + *key = BKEY_MINUS; if (c == ' ') - *key = KEY_SPACE; + *key = BKEY_SPACE; } -- cgit v1.2.3 From 5712976b26f7865f348aba51c9fa367c456e1795 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Fri, 6 Jan 2023 08:52:23 -0600 Subject: menu: Update bootmenu_autoboot_loop() to return the code Use the return value to save having to pass around a pointer. This also resolves any ambiguity about what *key contains when the function is called. Signed-off-by: Simon Glass --- cmd/bootmenu.c | 2 +- common/menu.c | 16 +++++++++------- include/menu.h | 7 +++---- 3 files changed, 13 insertions(+), 12 deletions(-) (limited to 'common/menu.c') diff --git a/cmd/bootmenu.c b/cmd/bootmenu.c index 1a14e8a190..086d04148a 100644 --- a/cmd/bootmenu.c +++ b/cmd/bootmenu.c @@ -93,7 +93,7 @@ static char *bootmenu_choice_entry(void *data) while (1) { if (menu->delay >= 0) { /* Autoboot was not stopped */ - bootmenu_autoboot_loop(menu, &key, &esc); + key = bootmenu_autoboot_loop(menu, &esc); } else { /* Some key was pressed, so autoboot was stopped */ bootmenu_loop(menu, &key, &esc); diff --git a/common/menu.c b/common/menu.c index a245c5a9c6..bafc8470d7 100644 --- a/common/menu.c +++ b/common/menu.c @@ -425,9 +425,9 @@ int menu_destroy(struct menu *m) return 1; } -void bootmenu_autoboot_loop(struct bootmenu_data *menu, - enum bootmenu_key *key, int *esc) +enum bootmenu_key bootmenu_autoboot_loop(struct bootmenu_data *menu, int *esc) { + enum bootmenu_key key = BKEY_NONE; int i, c; while (menu->delay > 0) { @@ -446,16 +446,16 @@ void bootmenu_autoboot_loop(struct bootmenu_data *menu, switch (c) { case '\e': *esc = 1; - *key = BKEY_NONE; + key = BKEY_NONE; break; case '\r': - *key = BKEY_SELECT; + key = BKEY_SELECT; break; case 0x3: /* ^C */ - *key = BKEY_QUIT; + key = BKEY_QUIT; break; default: - *key = BKEY_NONE; + key = BKEY_NONE; break; } @@ -471,7 +471,9 @@ void bootmenu_autoboot_loop(struct bootmenu_data *menu, printf(ANSI_CURSOR_POSITION ANSI_CLEAR_LINE, menu->count + 5, 1); if (menu->delay == 0) - *key = BKEY_SELECT; + key = BKEY_SELECT; + + return key; } void bootmenu_loop(struct bootmenu_data *menu, diff --git a/include/menu.h b/include/menu.h index 29b457921e..9f30a3c1ac 100644 --- a/include/menu.h +++ b/include/menu.h @@ -65,14 +65,13 @@ enum bootmenu_key { * indicating that the current option should be chosen. * * @menu: Menu being processed - * @key: Returns the code for the key the user pressed: + * @esc: Set to 1 if the escape key is pressed, otherwise not updated + * Returns: code for the key the user pressed: * enter: KEY_SELECT * Ctrl-C: KEY_QUIT * anything else: KEY_NONE - * @esc: Set to 1 if the escape key is pressed, otherwise not updated */ -void bootmenu_autoboot_loop(struct bootmenu_data *menu, - enum bootmenu_key *key, int *esc); +enum bootmenu_key bootmenu_autoboot_loop(struct bootmenu_data *menu, int *esc); /** * bootmenu_loop() - handle waiting for a keypress when autoboot is disabled -- cgit v1.2.3 From d0ca98dbd99c2534c9e96e4c226e52ab80f2248f Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Fri, 6 Jan 2023 08:52:24 -0600 Subject: menu: Update bootmenu_loop() to return the code Use the return value to save having to pass around a pointer. This also resolves any ambiguity about what *key contains when the function is called. Signed-off-by: Simon Glass --- cmd/bootmenu.c | 2 +- cmd/eficonfig.c | 4 ++-- common/menu.c | 30 ++++++++++++++++-------------- include/menu.h | 11 +++++------ 4 files changed, 24 insertions(+), 23 deletions(-) (limited to 'common/menu.c') diff --git a/cmd/bootmenu.c b/cmd/bootmenu.c index 086d04148a..43553dbcc9 100644 --- a/cmd/bootmenu.c +++ b/cmd/bootmenu.c @@ -96,7 +96,7 @@ static char *bootmenu_choice_entry(void *data) key = bootmenu_autoboot_loop(menu, &esc); } else { /* Some key was pressed, so autoboot was stopped */ - bootmenu_loop(menu, &key, &esc); + key = bootmenu_loop(menu, &esc); } switch (key) { diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c index 8f246bc271..96cb1a367f 100644 --- a/cmd/eficonfig.c +++ b/cmd/eficonfig.c @@ -191,7 +191,7 @@ static char *eficonfig_choice_entry(void *data) struct efimenu *efi_menu = data; while (1) { - bootmenu_loop((struct bootmenu_data *)efi_menu, &key, &esc); + key = bootmenu_loop((struct bootmenu_data *)efi_menu, &esc); switch (key) { case BKEY_UP: @@ -1868,7 +1868,7 @@ static efi_status_t eficonfig_choice_change_boot_order(struct efimenu *efi_menu) struct eficonfig_entry *entry, *tmp; while (1) { - bootmenu_loop(NULL, &key, &esc); + key = bootmenu_loop(NULL, &esc); switch (key) { case BKEY_PLUS: diff --git a/common/menu.c b/common/menu.c index bafc8470d7..6842f5409d 100644 --- a/common/menu.c +++ b/common/menu.c @@ -476,9 +476,9 @@ enum bootmenu_key bootmenu_autoboot_loop(struct bootmenu_data *menu, int *esc) return key; } -void bootmenu_loop(struct bootmenu_data *menu, - enum bootmenu_key *key, int *esc) +enum bootmenu_key bootmenu_loop(struct bootmenu_data *menu, int *esc) { + enum bootmenu_key key = BKEY_NONE; int c; if (*esc == 1) { @@ -505,17 +505,17 @@ void bootmenu_loop(struct bootmenu_data *menu, /* First char of ANSI escape sequence '\e' */ if (c == '\e') { *esc = 1; - *key = BKEY_NONE; + key = BKEY_NONE; } break; case 1: /* Second char of ANSI '[' */ if (c == '[') { *esc = 2; - *key = BKEY_NONE; + key = BKEY_NONE; } else { /* Alone ESC key was pressed */ - *key = BKEY_QUIT; + key = BKEY_QUIT; *esc = (c == '\e') ? 1 : 0; } break; @@ -524,7 +524,7 @@ void bootmenu_loop(struct bootmenu_data *menu, /* Third char of ANSI (number '1') - optional */ if (*esc == 2 && c == '1') { *esc = 3; - *key = BKEY_NONE; + key = BKEY_NONE; break; } @@ -532,31 +532,33 @@ void bootmenu_loop(struct bootmenu_data *menu, /* ANSI 'A' - key up was pressed */ if (c == 'A') - *key = BKEY_UP; + key = BKEY_UP; /* ANSI 'B' - key down was pressed */ else if (c == 'B') - *key = BKEY_DOWN; + key = BKEY_DOWN; /* other key was pressed */ else - *key = BKEY_NONE; + key = BKEY_NONE; break; } /* enter key was pressed */ if (c == '\r') - *key = BKEY_SELECT; + key = BKEY_SELECT; /* ^C was pressed */ if (c == 0x3) - *key = BKEY_QUIT; + key = BKEY_QUIT; if (c == '+') - *key = BKEY_PLUS; + key = BKEY_PLUS; if (c == '-') - *key = BKEY_MINUS; + key = BKEY_MINUS; if (c == ' ') - *key = BKEY_SPACE; + key = BKEY_SPACE; + + return key; } diff --git a/include/menu.h b/include/menu.h index 9f30a3c1ac..8b9b36214f 100644 --- a/include/menu.h +++ b/include/menu.h @@ -83,7 +83,10 @@ enum bootmenu_key bootmenu_autoboot_loop(struct bootmenu_data *menu, int *esc); * character is recognised * * @menu: Menu being processed - * @key: Returns the code for the key the user pressed: + * @esc: On input, a non-zero value indicates that an escape sequence has + * resulted in that many characters so far. On exit this is updated to the + * new number of characters + * Returns: code for the key the user pressed: * enter: BKEY_SELECT * Ctrl-C: BKEY_QUIT * Up arrow: BKEY_UP @@ -92,11 +95,7 @@ enum bootmenu_key bootmenu_autoboot_loop(struct bootmenu_data *menu, int *esc); * Plus: BKEY_PLUS * Minus: BKEY_MINUS * Space: BKEY_SPACE - * @esc: On input, a non-zero value indicates that an escape sequence has - * resulted in that many characters so far. On exit this is updated to the - * new number of characters */ -void bootmenu_loop(struct bootmenu_data *menu, - enum bootmenu_key *key, int *esc); +enum bootmenu_key bootmenu_loop(struct bootmenu_data *menu, int *esc); #endif /* __MENU_H__ */ -- cgit v1.2.3 From 86cc3c5215fc6e3c2cb77ee162c22ad91dbfaff5 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Fri, 6 Jan 2023 08:52:25 -0600 Subject: menu: Use a switch statement Convert the long line of if() statements to a switch() since this makes better use of the C language. Signed-off-by: Simon Glass --- common/menu.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'common/menu.c') diff --git a/common/menu.c b/common/menu.c index 6842f5409d..7db98942a6 100644 --- a/common/menu.c +++ b/common/menu.c @@ -543,22 +543,31 @@ enum bootmenu_key bootmenu_loop(struct bootmenu_data *menu, int *esc) break; } - /* enter key was pressed */ - if (c == '\r') + switch (c) { + case '\r': + /* enter key was pressed */ key = BKEY_SELECT; - - /* ^C was pressed */ - if (c == 0x3) + break; + case CTL_CH('c'): + /* ^C was pressed */ key = BKEY_QUIT; - - if (c == '+') + break; + case CTL_CH('p'): + key = BKEY_UP; + break; + case CTL_CH('n'): + key = BKEY_DOWN; + break; + case '+': key = BKEY_PLUS; - - if (c == '-') + break; + case '-': key = BKEY_MINUS; - - if (c == ' ') + break; + case ' ': key = BKEY_SPACE; + break; + } return key; } -- cgit v1.2.3 From 32bab0eae51b55898d1e2804e6614d9143840581 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Fri, 6 Jan 2023 08:52:26 -0600 Subject: menu: Make use of CLI character processing Avoid duplicating some of the escape-sequence processing here and use the CLI function instead. Signed-off-by: Simon Glass --- cmd/bootmenu.c | 9 ++++-- cmd/eficonfig.c | 12 ++++--- common/cli_getch.c | 12 ++++--- common/menu.c | 92 +++++++++++++++--------------------------------------- include/cli.h | 4 ++- include/menu.h | 7 +++-- 6 files changed, 56 insertions(+), 80 deletions(-) (limited to 'common/menu.c') diff --git a/cmd/bootmenu.c b/cmd/bootmenu.c index 43553dbcc9..3236ca5d79 100644 --- a/cmd/bootmenu.c +++ b/cmd/bootmenu.c @@ -4,6 +4,7 @@ */ #include +#include #include #include #include @@ -84,19 +85,21 @@ static void bootmenu_print_entry(void *data) static char *bootmenu_choice_entry(void *data) { + struct cli_ch_state s_cch, *cch = &s_cch; struct bootmenu_data *menu = data; struct bootmenu_entry *iter; enum bootmenu_key key = BKEY_NONE; - int esc = 0; int i; + cli_ch_init(cch); + while (1) { if (menu->delay >= 0) { /* Autoboot was not stopped */ - key = bootmenu_autoboot_loop(menu, &esc); + key = bootmenu_autoboot_loop(menu, cch); } else { /* Some key was pressed, so autoboot was stopped */ - key = bootmenu_loop(menu, &esc); + key = bootmenu_loop(menu, cch); } switch (key) { diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c index 96cb1a367f..d830e4af53 100644 --- a/cmd/eficonfig.c +++ b/cmd/eficonfig.c @@ -6,6 +6,7 @@ */ #include +#include #include #include #include @@ -184,14 +185,16 @@ static void eficonfig_display_statusline(struct menu *m) */ static char *eficonfig_choice_entry(void *data) { - int esc = 0; + struct cli_ch_state s_cch, *cch = &s_cch; struct list_head *pos, *n; struct eficonfig_entry *entry; enum bootmenu_key key = BKEY_NONE; struct efimenu *efi_menu = data; + cli_ch_init(cch); + while (1) { - key = bootmenu_loop((struct bootmenu_data *)efi_menu, &esc); + key = bootmenu_loop((struct bootmenu_data *)efi_menu, cch); switch (key) { case BKEY_UP: @@ -1862,13 +1865,14 @@ static void eficonfig_display_change_boot_order(struct efimenu *efi_menu) */ static efi_status_t eficonfig_choice_change_boot_order(struct efimenu *efi_menu) { - int esc = 0; + struct cli_ch_state s_cch, *cch = &s_cch; struct list_head *pos, *n; enum bootmenu_key key = BKEY_NONE; struct eficonfig_entry *entry, *tmp; + cli_ch_init(cch); while (1) { - key = bootmenu_loop(NULL, &esc); + key = bootmenu_loop(NULL, cch); switch (key) { case BKEY_PLUS: diff --git a/common/cli_getch.c b/common/cli_getch.c index 9eeea7fef2..87c23edcf4 100644 --- a/common/cli_getch.c +++ b/common/cli_getch.c @@ -140,10 +140,11 @@ int cli_ch_process(struct cli_ch_state *cch, int ichar) * sequence */ if (!ichar) { - if (cch->emit_upto) { + if (cch->emitting) { if (cch->emit_upto < cch->esc_len) return cch->esc_save[cch->emit_upto++]; cch->emit_upto = 0; + cch->emitting = false; } return 0; } else if (ichar == -ETIMEDOUT) { @@ -174,18 +175,21 @@ int cli_ch_process(struct cli_ch_state *cch, int ichar) case ESC_SAVE: /* save this character and return nothing */ cch->esc_save[cch->esc_len++] = ichar; - return 0; + ichar = 0; + break; case ESC_REJECT: /* * invalid escape sequence, start returning the * characters in it */ cch->esc_save[cch->esc_len++] = ichar; - return cch->esc_save[cch->emit_upto++]; + ichar = cch->esc_save[cch->emit_upto++]; + cch->emitting = true; + break; case ESC_CONVERTED: /* valid escape sequence, return the resulting char */ cch->esc_len = 0; - return ichar; + break; } } diff --git a/common/menu.c b/common/menu.c index 7db98942a6..45f36ae3ed 100644 --- a/common/menu.c +++ b/common/menu.c @@ -15,6 +15,8 @@ #include "menu.h" +#define ansi 0 + /* * Internally, each item in a menu is represented by a struct menu_item. * @@ -425,15 +427,19 @@ int menu_destroy(struct menu *m) return 1; } -enum bootmenu_key bootmenu_autoboot_loop(struct bootmenu_data *menu, int *esc) +enum bootmenu_key bootmenu_autoboot_loop(struct bootmenu_data *menu, + struct cli_ch_state *cch) { enum bootmenu_key key = BKEY_NONE; int i, c; while (menu->delay > 0) { - printf(ANSI_CURSOR_POSITION, menu->count + 5, 3); + if (ansi) + printf(ANSI_CURSOR_POSITION, menu->count + 5, 3); printf("Hit any key to stop autoboot: %d ", menu->delay); for (i = 0; i < 100; ++i) { + int ichar; + if (!tstc()) { schedule(); mdelay(10); @@ -443,12 +449,13 @@ enum bootmenu_key bootmenu_autoboot_loop(struct bootmenu_data *menu, int *esc) menu->delay = -1; c = getchar(); - switch (c) { - case '\e': - *esc = 1; + ichar = cli_ch_process(cch, c); + + switch (ichar) { + case '\0': key = BKEY_NONE; break; - case '\r': + case '\n': key = BKEY_SELECT; break; case 0x3: /* ^C */ @@ -458,7 +465,6 @@ enum bootmenu_key bootmenu_autoboot_loop(struct bootmenu_data *menu, int *esc) key = BKEY_NONE; break; } - break; } @@ -468,7 +474,8 @@ enum bootmenu_key bootmenu_autoboot_loop(struct bootmenu_data *menu, int *esc) --menu->delay; } - printf(ANSI_CURSOR_POSITION ANSI_CLEAR_LINE, menu->count + 5, 1); + if (ansi) + printf(ANSI_CURSOR_POSITION ANSI_CLEAR_LINE, menu->count + 5, 1); if (menu->delay == 0) key = BKEY_SELECT; @@ -476,79 +483,32 @@ enum bootmenu_key bootmenu_autoboot_loop(struct bootmenu_data *menu, int *esc) return key; } -enum bootmenu_key bootmenu_loop(struct bootmenu_data *menu, int *esc) +enum bootmenu_key bootmenu_loop(struct bootmenu_data *menu, + struct cli_ch_state *cch) { enum bootmenu_key key = BKEY_NONE; int c; - if (*esc == 1) { - if (tstc()) { - c = getchar(); - } else { + c = cli_ch_process(cch, 0); + if (!c) { + while (!c && !tstc()) { schedule(); mdelay(10); - if (tstc()) - c = getchar(); - else - c = '\e'; + c = cli_ch_process(cch, -ETIMEDOUT); } - } else { - while (!tstc()) { - schedule(); - mdelay(10); - } - c = getchar(); - } - - switch (*esc) { - case 0: - /* First char of ANSI escape sequence '\e' */ - if (c == '\e') { - *esc = 1; - key = BKEY_NONE; - } - break; - case 1: - /* Second char of ANSI '[' */ - if (c == '[') { - *esc = 2; - key = BKEY_NONE; - } else { - /* Alone ESC key was pressed */ - key = BKEY_QUIT; - *esc = (c == '\e') ? 1 : 0; - } - break; - case 2: - case 3: - /* Third char of ANSI (number '1') - optional */ - if (*esc == 2 && c == '1') { - *esc = 3; - key = BKEY_NONE; - break; + if (!c) { + c = getchar(); + c = cli_ch_process(cch, c); } - - *esc = 0; - - /* ANSI 'A' - key up was pressed */ - if (c == 'A') - key = BKEY_UP; - /* ANSI 'B' - key down was pressed */ - else if (c == 'B') - key = BKEY_DOWN; - /* other key was pressed */ - else - key = BKEY_NONE; - - break; } switch (c) { - case '\r': + case '\n': /* enter key was pressed */ key = BKEY_SELECT; break; case CTL_CH('c'): + case '\e': /* ^C was pressed */ key = BKEY_QUIT; break; diff --git a/include/cli.h b/include/cli.h index 863519e4b1..c777c90313 100644 --- a/include/cli.h +++ b/include/cli.h @@ -14,12 +14,14 @@ * * @esc_len: Number of escape characters read so far * @esc_save: Escape characters collected so far - * @emit_upto: Next character to emit from esc_save (0 if not emitting) + * @emit_upto: Next index to emit from esc_save + * @emitting: true if emitting from esc_save */ struct cli_ch_state { int esc_len; char esc_save[8]; int emit_upto; + bool emitting; }; /** diff --git a/include/menu.h b/include/menu.h index 8b9b36214f..3996075a33 100644 --- a/include/menu.h +++ b/include/menu.h @@ -6,6 +6,7 @@ #ifndef __MENU_H__ #define __MENU_H__ +struct cli_ch_state; struct menu; struct menu *menu_create(char *title, int timeout, int prompt, @@ -71,7 +72,8 @@ enum bootmenu_key { * Ctrl-C: KEY_QUIT * anything else: KEY_NONE */ -enum bootmenu_key bootmenu_autoboot_loop(struct bootmenu_data *menu, int *esc); +enum bootmenu_key bootmenu_autoboot_loop(struct bootmenu_data *menu, + struct cli_ch_state *cch); /** * bootmenu_loop() - handle waiting for a keypress when autoboot is disabled @@ -96,6 +98,7 @@ enum bootmenu_key bootmenu_autoboot_loop(struct bootmenu_data *menu, int *esc); * Minus: BKEY_MINUS * Space: BKEY_SPACE */ -enum bootmenu_key bootmenu_loop(struct bootmenu_data *menu, int *esc); +enum bootmenu_key bootmenu_loop(struct bootmenu_data *menu, + struct cli_ch_state *cch); #endif /* __MENU_H__ */ -- cgit v1.2.3 From 9e7ac0b0be5cb663e539716554d66f8f0890ca83 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Fri, 6 Jan 2023 08:52:35 -0600 Subject: 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 --- common/menu.c | 48 ++++++++++++++++++++++++++++++------------------ include/menu.h | 10 ++++++++++ 2 files changed, 40 insertions(+), 18 deletions(-) (limited to 'common/menu.c') 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; } diff --git a/include/menu.h b/include/menu.h index 3996075a33..1e88141d6b 100644 --- a/include/menu.h +++ b/include/menu.h @@ -53,6 +53,8 @@ enum bootmenu_key { BKEY_PLUS, BKEY_MINUS, BKEY_SPACE, + + BKEY_COUNT, }; /** @@ -101,4 +103,12 @@ enum bootmenu_key bootmenu_autoboot_loop(struct bootmenu_data *menu, enum bootmenu_key bootmenu_loop(struct bootmenu_data *menu, struct cli_ch_state *cch); +/** + * bootmenu_conv_key() - Convert a U-Boot keypress into a menu key + * + * @ichar: Keypress to convert (ASCII, including control characters) + * Returns: Menu key that corresponds to @ichar, or BKEY_NONE if none + */ +enum bootmenu_key bootmenu_conv_key(int ichar); + #endif /* __MENU_H__ */ -- cgit v1.2.3