From ee6c7eb46f3835a027e8e7278418683ff7a32031 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Fri, 6 Jan 2023 08:52:21 -0600 Subject: bootmenu: Add a few comments The behaviour of these two functions is completely undocumented. Add some notes so the poor, suffering dev can figure out what is going on. Signed-off-by: Simon Glass --- include/menu.h | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'include/menu.h') diff --git a/include/menu.h b/include/menu.h index 702aacb170c..0b4d9734149 100644 --- a/include/menu.h +++ b/include/menu.h @@ -42,6 +42,7 @@ struct bootmenu_data { struct bootmenu_entry *first; /* first menu entry */ }; +/** enum bootmenu_key - keys that can be returned by the bootmenu */ enum bootmenu_key { KEY_NONE = 0, KEY_UP, @@ -53,8 +54,49 @@ enum bootmenu_key { KEY_SPACE, }; +/** + * bootmenu_autoboot_loop() - handle autobooting if no key is pressed + * + * This shows a prompt to allow the user to press a key to interrupt auto boot + * of the first menu option. + * + * It then waits for the required time (menu->delay in seconds) for a key to be + * pressed. If nothing is pressed in that time, @key returns KEY_SELECT + * indicating that the current option should be chosen. + * + * @menu: Menu being processed + * @key: Returns the 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); + +/** + * bootmenu_loop() - handle waiting for a keypress when autoboot is disabled + * + * This is used when the menu delay is negative, indicating that the delay has + * elapsed, or there was no delay to begin with. + * + * It reads a character and processes it, returning a menu-key code if a + * character is recognised + * + * @menu: Menu being processed + * @key: Returns the code for the key the user pressed: + * enter: KEY_SELECT + * Ctrl-C: KEY_QUIT + * Up arrow: KEY_UP + * Down arrow: KEY_DOWN + * Escape (by itself): KEY_QUIT + * Plus: KEY_PLUS + * Minus: KEY_MINUS + * Space: KEY_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); -- cgit v1.2.3 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 --- include/menu.h | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'include/menu.h') diff --git a/include/menu.h b/include/menu.h index 0b4d9734149..29b457921e9 100644 --- a/include/menu.h +++ b/include/menu.h @@ -44,14 +44,14 @@ struct bootmenu_data { /** enum bootmenu_key - keys that can be returned by the bootmenu */ enum bootmenu_key { - KEY_NONE = 0, - KEY_UP, - KEY_DOWN, - KEY_SELECT, - KEY_QUIT, - KEY_PLUS, - KEY_MINUS, - KEY_SPACE, + BKEY_NONE = 0, + BKEY_UP, + BKEY_DOWN, + BKEY_SELECT, + BKEY_QUIT, + BKEY_PLUS, + BKEY_MINUS, + BKEY_SPACE, }; /** @@ -85,14 +85,14 @@ void bootmenu_autoboot_loop(struct bootmenu_data *menu, * * @menu: Menu being processed * @key: Returns the code for the key the user pressed: - * enter: KEY_SELECT - * Ctrl-C: KEY_QUIT - * Up arrow: KEY_UP - * Down arrow: KEY_DOWN - * Escape (by itself): KEY_QUIT - * Plus: KEY_PLUS - * Minus: KEY_MINUS - * Space: KEY_SPACE + * enter: BKEY_SELECT + * Ctrl-C: BKEY_QUIT + * Up arrow: BKEY_UP + * Down arrow: BKEY_DOWN + * Escape (by itself): BKEY_QUIT + * 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 -- 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 --- include/menu.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'include/menu.h') diff --git a/include/menu.h b/include/menu.h index 29b457921e9..9f30a3c1acd 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 --- include/menu.h | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'include/menu.h') diff --git a/include/menu.h b/include/menu.h index 9f30a3c1acd..8b9b36214f7 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 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 --- include/menu.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'include/menu.h') diff --git a/include/menu.h b/include/menu.h index 8b9b36214f7..3996075a337 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 --- include/menu.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'include/menu.h') diff --git a/include/menu.h b/include/menu.h index 3996075a337..1e88141d6bf 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