]> git.ipfire.org Git - people/ms/u-boot.git/blob - board/MAI/menu/menu.h
* Code cleanup:
[people/ms/u-boot.git] / board / MAI / menu / menu.h
1 #ifndef MENU_H
2 #define MENU_H
3
4 /* A single menu */
5 typedef void (*menu_finish_callback)(struct menu_s *menu);
6
7 typedef struct menu_s
8 {
9 char *name; /* Menu name */
10 int num_options; /* Number of options in this menu */
11 int flags; /* Various flags - see below */
12 int option_align; /* Aligns options to a field width of this much characters if != 0 */
13
14 struct menu_option_s **options; /* Pointer to this menu's options */
15 menu_finish_callback callback; /* Called when the menu closes */
16 } menu_t;
17
18 /*
19 * type: Type of the option (see below)
20 * name: Name to display for this option
21 * help: Optional help string
22 * id : optional id number
23 * sys : pointer for system-specific data, init to NULL and don't touch
24 */
25
26 #define OPTION_PREAMBLE \
27 int type; \
28 char *name; \
29 char *help; \
30 int id; \
31 void *sys; \
32
33
34 /*
35 * Menu option types.
36 * There are a number of different layouts for menu options depending
37 * on their types. Currently there are the following possibilities:
38 *
39 * Submenu:
40 * This entry links to a new menu.
41 *
42 * Boolean:
43 * A simple on/off toggle entry. Booleans can be either yes/no, 0/1 or on/off.
44 * Optionally, this entry can enable/disable a set of other options. An example would
45 * be to enable/disable on-board USB, and if enabled give access to further options like
46 * irq settings, base address etc.
47 *
48 * Text:
49 * A single line/limited number of characters text entry box. Text can be restricted
50 * to a certain charset (digits/hex digits/all/custom). Result is also available as an
51 * int if numeric.
52 *
53 * Selection:
54 * One-of-many type of selection entry. User may choose on of a set of strings, which
55 * maps to a specific value for the variable.
56 *
57 * Routine:
58 * Selecting this calls an entry-specific routine. This can be used for saving contents etc.
59 *
60 * Custom:
61 * Display and behaviour of this entry is defined by a set of callbacks.
62 */
63
64 #define MENU_SUBMENU_TYPE 0
65 typedef struct menu_submenu_s
66 {
67 OPTION_PREAMBLE
68
69 menu_t * submenu; /* Pointer to the submenu */
70 } menu_submenu_t;
71
72 #define MENU_BOOLEAN_TYPE 1
73 typedef struct menu_boolean_s
74 {
75 OPTION_PREAMBLE
76
77 char *variable; /* Name of the variable to getenv()/setenv() */
78 int subtype; /* Subtype (on/off, 0/1, yes/no, enable/disable), see below */
79 int mutex; /* Bit mask of options to enable/disable. Bit 0 is the option
80 immediately following this one, bit 1 is the next one etc.
81 bit 7 = 0 means to disable when this option is off,
82 bit 7 = 1 means to disable when this option is on.
83 An option is disabled when the type field's upper bit is set */
84 } menu_boolean_t;
85
86 /* BOOLEAN Menu flags */
87 #define MENU_BOOLEAN_ONOFF 0x01
88 #define MENU_BOOLEAN_01 0x02
89 #define MENU_BOOLEAN_YESNO 0x03
90 #define MENU_BOOLEAN_ENDIS 0x04
91 #define MENU_BOOLEAN_TYPE_MASK 0x07
92
93
94 #define MENU_TEXT_TYPE 2
95 typedef struct menu_text_s
96 {
97 OPTION_PREAMBLE
98
99 char *variable; /* Name of the variable to getenv()/setenv() */
100 int maxchars; /* Max number of characters */
101 char *charset; /* Optional charset to use */
102 int flags; /* Flags - see below */
103 } menu_text_t;
104
105 /* TEXT entry menu flags */
106 #define MENU_TEXT_NUMERIC 0x01
107 #define MENU_TEXT_HEXADECIMAL 0x02
108 #define MENU_TEXT_FREE 0x03
109 #define MENU_TEXT_TYPE_MASK 0x07
110
111
112 #define MENU_SELECTION_TYPE 3
113 typedef struct menu_select_option_s
114 {
115 char *map_from; /* Map this variable contents ... */
116 char *map_to; /* ... to this menu text and vice versa */
117 } menu_select_option_t;
118
119 typedef struct menu_select_s
120 {
121 OPTION_PREAMBLE
122
123 int num_options; /* Number of mappings */
124 menu_select_option_t **options;
125 /* Option list array */
126 } menu_select_t;
127
128
129 #define MENU_ROUTINE_TYPE 4
130 typedef void (*menu_routine_callback)(struct menu_routine_s *);
131
132 typedef struct menu_routine_s
133 {
134 OPTION_PREAMBLE
135 menu_routine_callback callback;
136 /* routine to be called */
137 void *user_data; /* User data, don't care for system */
138 } menu_routine_t;
139
140
141 #define MENU_CUSTOM_TYPE 5
142 typedef void (*menu_custom_draw)(struct menu_custom_s *);
143 typedef void (*menu_custom_key)(struct menu_custom_s *, int);
144
145 typedef struct menu_custom_s
146 {
147 OPTION_PREAMBLE
148 menu_custom_draw drawfunc;
149 menu_custom_key keyfunc;
150 void *user_data;
151 } menu_custom_t;
152
153 /*
154 * The menu option superstructure
155 */
156 typedef struct menu_option_s
157 {
158 union
159 {
160 menu_submenu_t m_sub_menu;
161 menu_boolean_t m_boolean;
162 menu_text_t m_text;
163 menu_select_t m_select;
164 menu_routine_t m_routine;
165 };
166 } menu_option_t;
167
168 /* Init the menu system. Returns <0 on error */
169 int menu_init(menu_t *root);
170
171 /* Execute a single menu. Returns <0 on error */
172 int menu_do(menu_t *menu);
173
174 #endif