Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Jason Hobbs | 0685d82 | 2011-08-23 11:06:49 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2010-2011 Calxeda, Inc. |
Jason Hobbs | 0685d82 | 2011-08-23 11:06:49 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #ifndef __MENU_H__ |
| 7 | #define __MENU_H__ |
| 8 | |
Simon Glass | 9d8d387 | 2023-01-06 08:52:26 -0600 | [diff] [blame] | 9 | struct cli_ch_state; |
Jason Hobbs | 0685d82 | 2011-08-23 11:06:49 +0000 | [diff] [blame] | 10 | struct menu; |
| 11 | |
Jason Hobbs | 65febe6 | 2011-08-23 11:06:50 +0000 | [diff] [blame] | 12 | struct menu *menu_create(char *title, int timeout, int prompt, |
Thirupathaiah Annapureddy | d6b9f6b | 2020-03-18 11:38:42 -0700 | [diff] [blame] | 13 | void (*display_statusline)(struct menu *), |
Pali Rohár | d0d8d3b | 2013-03-23 14:50:40 +0000 | [diff] [blame] | 14 | void (*item_data_print)(void *), |
| 15 | char *(*item_choice)(void *), |
developer | c2a1e9e | 2024-10-29 17:47:16 +0800 | [diff] [blame] | 16 | bool (*need_reprint)(void *), |
Pali Rohár | d0d8d3b | 2013-03-23 14:50:40 +0000 | [diff] [blame] | 17 | void *item_choice_data); |
Jason Hobbs | 0685d82 | 2011-08-23 11:06:49 +0000 | [diff] [blame] | 18 | int menu_default_set(struct menu *m, char *item_key); |
| 19 | int menu_get_choice(struct menu *m, void **choice); |
| 20 | int menu_item_add(struct menu *m, char *item_key, void *item_data); |
| 21 | int menu_destroy(struct menu *m); |
Anatolij Gustschin | fb6068a | 2013-03-23 14:52:04 +0000 | [diff] [blame] | 22 | int menu_default_choice(struct menu *m, void **choice); |
Jason Hobbs | 0685d82 | 2011-08-23 11:06:49 +0000 | [diff] [blame] | 23 | |
Simon Glass | ab81008 | 2019-07-20 20:51:26 -0600 | [diff] [blame] | 24 | /** |
| 25 | * menu_show() Show a boot menu |
| 26 | * |
| 27 | * This shows a menu and lets the user select an option. The menu is defined by |
| 28 | * environment variables (see README.bootmenu). |
| 29 | * |
| 30 | * This function doesn't normally return, but if the users requests the command |
| 31 | * problem, it will. |
| 32 | * |
| 33 | * @bootdelay: Delay to wait before running the default menu option (0 to run |
| 34 | * the entry immediately) |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 35 | * Return: If it returns, it always returns -1 to indicate that the boot should |
Simon Glass | ab81008 | 2019-07-20 20:51:26 -0600 | [diff] [blame] | 36 | * be aborted and the command prompt should be provided |
| 37 | */ |
Heiko Schocher | b4c1df8 | 2012-01-16 21:13:35 +0000 | [diff] [blame] | 38 | int menu_show(int bootdelay); |
Simon Glass | ab81008 | 2019-07-20 20:51:26 -0600 | [diff] [blame] | 39 | |
Masahisa Kojima | 0e1b996 | 2022-04-28 17:09:45 +0900 | [diff] [blame] | 40 | struct bootmenu_data { |
| 41 | int delay; /* delay for autoboot */ |
| 42 | int active; /* active menu entry */ |
developer | c1c0d2c | 2024-10-29 17:47:22 +0800 | [diff] [blame] | 43 | int last_active; /* last active menu entry */ |
Masahisa Kojima | 0e1b996 | 2022-04-28 17:09:45 +0900 | [diff] [blame] | 44 | int count; /* total count of menu entries */ |
| 45 | struct bootmenu_entry *first; /* first menu entry */ |
| 46 | }; |
| 47 | |
Simon Glass | 415d87b | 2023-01-06 08:52:21 -0600 | [diff] [blame] | 48 | /** enum bootmenu_key - keys that can be returned by the bootmenu */ |
Masahisa Kojima | 0e1b996 | 2022-04-28 17:09:45 +0900 | [diff] [blame] | 49 | enum bootmenu_key { |
Simon Glass | 05ecdf8 | 2023-01-06 08:52:22 -0600 | [diff] [blame] | 50 | BKEY_NONE = 0, |
| 51 | BKEY_UP, |
| 52 | BKEY_DOWN, |
| 53 | BKEY_SELECT, |
| 54 | BKEY_QUIT, |
Simon Glass | eb8af2c | 2023-10-01 19:13:36 -0600 | [diff] [blame] | 55 | BKEY_SAVE, |
| 56 | |
| 57 | /* 'extra' keys, which are used by menus but not cedit */ |
Simon Glass | 05ecdf8 | 2023-01-06 08:52:22 -0600 | [diff] [blame] | 58 | BKEY_PLUS, |
| 59 | BKEY_MINUS, |
| 60 | BKEY_SPACE, |
Simon Glass | 1b56fe1 | 2023-01-06 08:52:35 -0600 | [diff] [blame] | 61 | |
| 62 | BKEY_COUNT, |
Simon Glass | eb8af2c | 2023-10-01 19:13:36 -0600 | [diff] [blame] | 63 | |
| 64 | /* Keys from here on are not used by cedit */ |
| 65 | BKEY_FIRST_EXTRA = BKEY_PLUS, |
Masahisa Kojima | 0e1b996 | 2022-04-28 17:09:45 +0900 | [diff] [blame] | 66 | }; |
| 67 | |
Simon Glass | 415d87b | 2023-01-06 08:52:21 -0600 | [diff] [blame] | 68 | /** |
| 69 | * bootmenu_autoboot_loop() - handle autobooting if no key is pressed |
| 70 | * |
| 71 | * This shows a prompt to allow the user to press a key to interrupt auto boot |
| 72 | * of the first menu option. |
| 73 | * |
| 74 | * It then waits for the required time (menu->delay in seconds) for a key to be |
| 75 | * pressed. If nothing is pressed in that time, @key returns KEY_SELECT |
| 76 | * indicating that the current option should be chosen. |
| 77 | * |
| 78 | * @menu: Menu being processed |
Simon Glass | 81544c4 | 2023-01-06 08:52:23 -0600 | [diff] [blame] | 79 | * @esc: Set to 1 if the escape key is pressed, otherwise not updated |
| 80 | * Returns: code for the key the user pressed: |
Simon Glass | 415d87b | 2023-01-06 08:52:21 -0600 | [diff] [blame] | 81 | * enter: KEY_SELECT |
| 82 | * Ctrl-C: KEY_QUIT |
| 83 | * anything else: KEY_NONE |
Simon Glass | 415d87b | 2023-01-06 08:52:21 -0600 | [diff] [blame] | 84 | */ |
Simon Glass | 9d8d387 | 2023-01-06 08:52:26 -0600 | [diff] [blame] | 85 | enum bootmenu_key bootmenu_autoboot_loop(struct bootmenu_data *menu, |
| 86 | struct cli_ch_state *cch); |
Simon Glass | 415d87b | 2023-01-06 08:52:21 -0600 | [diff] [blame] | 87 | |
| 88 | /** |
| 89 | * bootmenu_loop() - handle waiting for a keypress when autoboot is disabled |
| 90 | * |
| 91 | * This is used when the menu delay is negative, indicating that the delay has |
| 92 | * elapsed, or there was no delay to begin with. |
| 93 | * |
| 94 | * It reads a character and processes it, returning a menu-key code if a |
| 95 | * character is recognised |
| 96 | * |
| 97 | * @menu: Menu being processed |
Simon Glass | f1d3c8e | 2023-01-06 08:52:24 -0600 | [diff] [blame] | 98 | * @esc: On input, a non-zero value indicates that an escape sequence has |
| 99 | * resulted in that many characters so far. On exit this is updated to the |
| 100 | * new number of characters |
| 101 | * Returns: code for the key the user pressed: |
Simon Glass | 05ecdf8 | 2023-01-06 08:52:22 -0600 | [diff] [blame] | 102 | * enter: BKEY_SELECT |
| 103 | * Ctrl-C: BKEY_QUIT |
| 104 | * Up arrow: BKEY_UP |
| 105 | * Down arrow: BKEY_DOWN |
| 106 | * Escape (by itself): BKEY_QUIT |
| 107 | * Plus: BKEY_PLUS |
| 108 | * Minus: BKEY_MINUS |
| 109 | * Space: BKEY_SPACE |
Simon Glass | 415d87b | 2023-01-06 08:52:21 -0600 | [diff] [blame] | 110 | */ |
Simon Glass | 9d8d387 | 2023-01-06 08:52:26 -0600 | [diff] [blame] | 111 | enum bootmenu_key bootmenu_loop(struct bootmenu_data *menu, |
| 112 | struct cli_ch_state *cch); |
Masahisa Kojima | 0e1b996 | 2022-04-28 17:09:45 +0900 | [diff] [blame] | 113 | |
Simon Glass | 1b56fe1 | 2023-01-06 08:52:35 -0600 | [diff] [blame] | 114 | /** |
| 115 | * bootmenu_conv_key() - Convert a U-Boot keypress into a menu key |
| 116 | * |
| 117 | * @ichar: Keypress to convert (ASCII, including control characters) |
| 118 | * Returns: Menu key that corresponds to @ichar, or BKEY_NONE if none |
| 119 | */ |
| 120 | enum bootmenu_key bootmenu_conv_key(int ichar); |
| 121 | |
Jason Hobbs | 0685d82 | 2011-08-23 11:06:49 +0000 | [diff] [blame] | 122 | #endif /* __MENU_H__ */ |