blob: 6571c39b1430f4a16ac78439163ab2bd55bc1b56 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Jason Hobbsb69bf522011-08-23 11:06:49 +00002/*
3 * Copyright 2010-2011 Calxeda, Inc.
Jason Hobbsb69bf522011-08-23 11:06:49 +00004 */
5
6#ifndef __MENU_H__
7#define __MENU_H__
8
Simon Glass32bab0e2023-01-06 08:52:26 -06009struct cli_ch_state;
Jason Hobbsb69bf522011-08-23 11:06:49 +000010struct menu;
11
Jason Hobbsb41bc5a2011-08-23 11:06:50 +000012struct menu *menu_create(char *title, int timeout, int prompt,
Thirupathaiah Annapureddy5168d7a2020-03-18 11:38:42 -070013 void (*display_statusline)(struct menu *),
Pali Rohárfc9d64f2013-03-23 14:50:40 +000014 void (*item_data_print)(void *),
15 char *(*item_choice)(void *),
16 void *item_choice_data);
Jason Hobbsb69bf522011-08-23 11:06:49 +000017int menu_default_set(struct menu *m, char *item_key);
18int menu_get_choice(struct menu *m, void **choice);
19int menu_item_add(struct menu *m, char *item_key, void *item_data);
20int menu_destroy(struct menu *m);
Anatolij Gustschin6a3439f2013-03-23 14:52:04 +000021int menu_default_choice(struct menu *m, void **choice);
Jason Hobbsb69bf522011-08-23 11:06:49 +000022
Simon Glass14b9df12019-07-20 20:51:26 -060023/**
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)
Heinrich Schuchardt185f8122022-01-19 18:05:50 +010034 * Return: If it returns, it always returns -1 to indicate that the boot should
Simon Glass14b9df12019-07-20 20:51:26 -060035 * be aborted and the command prompt should be provided
36 */
Heiko Schocher317d6c52012-01-16 21:13:35 +000037int menu_show(int bootdelay);
Simon Glass14b9df12019-07-20 20:51:26 -060038
Masahisa Kojima3ae6cf52022-04-28 17:09:45 +090039struct 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
Simon Glassee6c7eb2023-01-06 08:52:21 -060046/** enum bootmenu_key - keys that can be returned by the bootmenu */
Masahisa Kojima3ae6cf52022-04-28 17:09:45 +090047enum bootmenu_key {
Simon Glass2da4a152023-01-06 08:52:22 -060048 BKEY_NONE = 0,
49 BKEY_UP,
50 BKEY_DOWN,
51 BKEY_SELECT,
52 BKEY_QUIT,
Simon Glass8579cb02023-10-01 19:13:36 -060053 BKEY_SAVE,
54
55 /* 'extra' keys, which are used by menus but not cedit */
Simon Glass2da4a152023-01-06 08:52:22 -060056 BKEY_PLUS,
57 BKEY_MINUS,
58 BKEY_SPACE,
Simon Glass9e7ac0b2023-01-06 08:52:35 -060059
60 BKEY_COUNT,
Simon Glass8579cb02023-10-01 19:13:36 -060061
62 /* Keys from here on are not used by cedit */
63 BKEY_FIRST_EXTRA = BKEY_PLUS,
Masahisa Kojima3ae6cf52022-04-28 17:09:45 +090064};
65
Simon Glassee6c7eb2023-01-06 08:52:21 -060066/**
67 * bootmenu_autoboot_loop() - handle autobooting if no key is pressed
68 *
69 * This shows a prompt to allow the user to press a key to interrupt auto boot
70 * of the first menu option.
71 *
72 * It then waits for the required time (menu->delay in seconds) for a key to be
73 * pressed. If nothing is pressed in that time, @key returns KEY_SELECT
74 * indicating that the current option should be chosen.
75 *
76 * @menu: Menu being processed
Simon Glass57129762023-01-06 08:52:23 -060077 * @esc: Set to 1 if the escape key is pressed, otherwise not updated
78 * Returns: code for the key the user pressed:
Simon Glassee6c7eb2023-01-06 08:52:21 -060079 * enter: KEY_SELECT
80 * Ctrl-C: KEY_QUIT
81 * anything else: KEY_NONE
Simon Glassee6c7eb2023-01-06 08:52:21 -060082 */
Simon Glass32bab0e2023-01-06 08:52:26 -060083enum bootmenu_key bootmenu_autoboot_loop(struct bootmenu_data *menu,
84 struct cli_ch_state *cch);
Simon Glassee6c7eb2023-01-06 08:52:21 -060085
86/**
87 * bootmenu_loop() - handle waiting for a keypress when autoboot is disabled
88 *
89 * This is used when the menu delay is negative, indicating that the delay has
90 * elapsed, or there was no delay to begin with.
91 *
92 * It reads a character and processes it, returning a menu-key code if a
93 * character is recognised
94 *
95 * @menu: Menu being processed
Simon Glassd0ca98d2023-01-06 08:52:24 -060096 * @esc: On input, a non-zero value indicates that an escape sequence has
97 * resulted in that many characters so far. On exit this is updated to the
98 * new number of characters
99 * Returns: code for the key the user pressed:
Simon Glass2da4a152023-01-06 08:52:22 -0600100 * enter: BKEY_SELECT
101 * Ctrl-C: BKEY_QUIT
102 * Up arrow: BKEY_UP
103 * Down arrow: BKEY_DOWN
104 * Escape (by itself): BKEY_QUIT
105 * Plus: BKEY_PLUS
106 * Minus: BKEY_MINUS
107 * Space: BKEY_SPACE
Simon Glassee6c7eb2023-01-06 08:52:21 -0600108 */
Simon Glass32bab0e2023-01-06 08:52:26 -0600109enum bootmenu_key bootmenu_loop(struct bootmenu_data *menu,
110 struct cli_ch_state *cch);
Masahisa Kojima3ae6cf52022-04-28 17:09:45 +0900111
Simon Glass9e7ac0b2023-01-06 08:52:35 -0600112/**
113 * bootmenu_conv_key() - Convert a U-Boot keypress into a menu key
114 *
115 * @ichar: Keypress to convert (ASCII, including control characters)
116 * Returns: Menu key that corresponds to @ichar, or BKEY_NONE if none
117 */
118enum bootmenu_key bootmenu_conv_key(int ichar);
119
Jason Hobbsb69bf522011-08-23 11:06:49 +0000120#endif /* __MENU_H__ */