summaryrefslogtreecommitdiff
path: root/board/MAI/menu/menu.h
blob: 23d89a70685ae58ad3bb4af1945ed49bb73c6fae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#ifndef MENU_H
#define MENU_H

/* A single menu */
typedef void (*menu_finish_callback)(struct menu_s *menu);

typedef struct menu_s {
	char *name;		/* Menu name */
	int num_options;	/* Number of options in this menu */
	int flags;		/* Various flags - see below */
	int option_align;	/* Aligns options to a field width of this much characters if != 0 */

	struct menu_option_s **options;	/* Pointer to this menu's options */
	menu_finish_callback callback;	/* Called when the menu closes */
} menu_t;

/*
 * type: Type of the option (see below)
 * name: Name to display for this option
 * help: Optional help string
 * id  : optional id number
 * sys : pointer for system-specific data, init to NULL and don't touch
 */

#define OPTION_PREAMBLE		\
	int type;		\
	char *name;		\
	char *help;		\
	int id;			\
	void *sys;

/*
 * Menu option types.
 * There are a number of different layouts for menu options depending
 * on their types. Currently there are the following possibilities:
 *
 * Submenu:
 *   This entry links to a new menu.
 *
 * Boolean:
 *   A simple on/off toggle entry. Booleans can be either yes/no, 0/1 or on/off.
 *   Optionally, this entry can enable/disable a set of other options. An example would
 *   be to enable/disable on-board USB, and if enabled give access to further options like
 *   irq settings, base address etc.
 *
 * Text:
 *   A single line/limited number of characters text entry box. Text can be restricted
 *   to a certain charset (digits/hex digits/all/custom). Result is also available as an
 *   int if numeric.
 *
 * Selection:
 *   One-of-many type of selection entry. User may choose on of a set of strings, which
 *   maps to a specific value for the variable.
 *
 * Routine:
 *   Selecting this calls an entry-specific routine. This can be used for saving contents etc.
 *
 * Custom:
 *   Display and behaviour of this entry is defined by a set of callbacks.
 */

#define MENU_SUBMENU_TYPE 0
typedef struct menu_submenu_s
{
    OPTION_PREAMBLE

    menu_t *   submenu;            /* Pointer to the submenu */
} menu_submenu_t;

#define MENU_BOOLEAN_TYPE 1
typedef struct menu_boolean_s
{
    OPTION_PREAMBLE

    char *variable;                /* Name of the variable to getenv()/setenv() */
    int subtype;                   /* Subtype (on/off, 0/1, yes/no, enable/disable), see below */
    int mutex;                     /* Bit mask of options to enable/disable. Bit 0 is the option
				      immediately following this one, bit 1 is the next one etc.
				      bit 7 = 0 means to disable when this option is off,
				      bit 7 = 1 means to disable when this option is on.
				      An option is disabled when the type field's upper bit is set */
} menu_boolean_t;

/* BOOLEAN Menu flags */
#define MENU_BOOLEAN_ONOFF         0x01
#define MENU_BOOLEAN_01            0x02
#define MENU_BOOLEAN_YESNO         0x03
#define MENU_BOOLEAN_ENDIS         0x04
#define MENU_BOOLEAN_TYPE_MASK     0x07


#define MENU_TEXT_TYPE 2
typedef struct menu_text_s
{
    OPTION_PREAMBLE

    char *variable;                /* Name of the variable to getenv()/setenv() */
    int maxchars;                  /* Max number of characters */
    char *charset;                 /* Optional charset to use */
    int flags;                     /* Flags - see below */
} menu_text_t;

/* TEXT entry menu flags */
#define MENU_TEXT_NUMERIC         0x01
#define MENU_TEXT_HEXADECIMAL     0x02
#define MENU_TEXT_FREE            0x03
#define MENU_TEXT_TYPE_MASK       0x07


#define MENU_SELECTION_TYPE 3
typedef struct menu_select_option_s {
	char *map_from;		/* Map this variable contents ... */
	char *map_to;		/* ... to this menu text and vice versa */
} menu_select_option_t;

typedef struct menu_select_s {
	OPTION_PREAMBLE int num_options;	/* Number of mappings */
	menu_select_option_t **options;
	/* Option list array */
} menu_select_t;


#define MENU_ROUTINE_TYPE 4
typedef void (*menu_routine_callback) (struct menu_routine_s *);

typedef struct menu_routine_s {
	OPTION_PREAMBLE menu_routine_callback callback;
	/* routine to be called */
	void *user_data;	/* User data, don't care for system */
} menu_routine_t;


#define MENU_CUSTOM_TYPE 5
typedef void (*menu_custom_draw) (struct menu_custom_s *);
typedef void (*menu_custom_key) (struct menu_custom_s *, int);

typedef struct menu_custom_s {
	OPTION_PREAMBLE menu_custom_draw drawfunc;
	menu_custom_key keyfunc;
	void *user_data;
} menu_custom_t;

/*
 * The menu option superstructure
 */
typedef struct menu_option_s {
	union {
		menu_submenu_t m_sub_menu;
		menu_boolean_t m_boolean;
		menu_text_t m_text;
		menu_select_t m_select;
		menu_routine_t m_routine;
	};
} menu_option_t;

/* Init the menu system. Returns <0 on error */
int menu_init(menu_t *root);

/* Execute a single menu. Returns <0 on error */
int menu_do(menu_t *menu);

#endif