Merge tag 'xilinx-for-v2023.04-rc1' of https://source.denx.de/u-boot/custodians/u...
[platform/kernel/u-boot.git] / include / menu.h
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * Copyright 2010-2011 Calxeda, Inc.
4  */
5
6 #ifndef __MENU_H__
7 #define __MENU_H__
8
9 struct cli_ch_state;
10 struct menu;
11
12 struct menu *menu_create(char *title, int timeout, int prompt,
13                                 void (*display_statusline)(struct menu *),
14                                 void (*item_data_print)(void *),
15                                 char *(*item_choice)(void *),
16                                 void *item_choice_data);
17 int menu_default_set(struct menu *m, char *item_key);
18 int menu_get_choice(struct menu *m, void **choice);
19 int menu_item_add(struct menu *m, char *item_key, void *item_data);
20 int menu_destroy(struct menu *m);
21 int menu_default_choice(struct menu *m, void **choice);
22
23 /**
24  * menu_show() Show a boot menu
25  *
26  * This shows a menu and lets the user select an option. The menu is defined by
27  * environment variables (see README.bootmenu).
28  *
29  * This function doesn't normally return, but if the users requests the command
30  * problem, it will.
31  *
32  * @bootdelay: Delay to wait before running the default menu option (0 to run
33  *              the entry immediately)
34  * Return: If it returns, it always returns -1 to indicate that the boot should
35  *      be aborted and the command prompt should be provided
36  */
37 int menu_show(int bootdelay);
38
39 struct bootmenu_data {
40         int delay;                      /* delay for autoboot */
41         int active;                     /* active menu entry */
42         int count;                      /* total count of menu entries */
43         struct bootmenu_entry *first;   /* first menu entry */
44 };
45
46 /** enum bootmenu_key - keys that can be returned by the bootmenu */
47 enum bootmenu_key {
48         BKEY_NONE = 0,
49         BKEY_UP,
50         BKEY_DOWN,
51         BKEY_SELECT,
52         BKEY_QUIT,
53         BKEY_PLUS,
54         BKEY_MINUS,
55         BKEY_SPACE,
56
57         BKEY_COUNT,
58 };
59
60 /**
61  * bootmenu_autoboot_loop() - handle autobooting if no key is pressed
62  *
63  * This shows a prompt to allow the user to press a key to interrupt auto boot
64  * of the first menu option.
65  *
66  * It then waits for the required time (menu->delay in seconds) for a key to be
67  * pressed. If nothing is pressed in that time, @key returns KEY_SELECT
68  * indicating that the current option should be chosen.
69  *
70  * @menu: Menu being processed
71  * @esc: Set to 1 if the escape key is pressed, otherwise not updated
72  * Returns: code for the key the user pressed:
73  *      enter: KEY_SELECT
74  *      Ctrl-C: KEY_QUIT
75  *      anything else: KEY_NONE
76  */
77 enum bootmenu_key bootmenu_autoboot_loop(struct bootmenu_data *menu,
78                                          struct cli_ch_state *cch);
79
80 /**
81  * bootmenu_loop() - handle waiting for a keypress when autoboot is disabled
82  *
83  * This is used when the menu delay is negative, indicating that the delay has
84  * elapsed, or there was no delay to begin with.
85  *
86  * It reads a character and processes it, returning a menu-key code if a
87  * character is recognised
88  *
89  * @menu: Menu being processed
90  * @esc: On input, a non-zero value indicates that an escape sequence has
91  *      resulted in that many characters so far. On exit this is updated to the
92  *      new number of characters
93  * Returns: code for the key the user pressed:
94  *      enter: BKEY_SELECT
95  *      Ctrl-C: BKEY_QUIT
96  *      Up arrow: BKEY_UP
97  *      Down arrow: BKEY_DOWN
98  *      Escape (by itself): BKEY_QUIT
99  *      Plus: BKEY_PLUS
100  *      Minus: BKEY_MINUS
101  *      Space: BKEY_SPACE
102  */
103 enum bootmenu_key bootmenu_loop(struct bootmenu_data *menu,
104                                 struct cli_ch_state *cch);
105
106 /**
107  * bootmenu_conv_key() - Convert a U-Boot keypress into a menu key
108  *
109  * @ichar: Keypress to convert (ASCII, including control characters)
110  * Returns: Menu key that corresponds to @ichar, or BKEY_NONE if none
111  */
112 enum bootmenu_key bootmenu_conv_key(int ichar);
113
114 #endif /* __MENU_H__ */