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