Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
| 2 | /* |
| 3 | * Copyright 2022 Google LLC |
| 4 | * Written by Simon Glass <sjg@chromium.org> |
| 5 | */ |
| 6 | |
Simon Glass | 8df4a4e | 2023-08-14 16:40:25 -0600 | [diff] [blame] | 7 | #ifndef __EXPO_H |
| 8 | #define __EXPO_H |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 9 | |
Simon Glass | a968f5f | 2023-10-01 19:13:31 -0600 | [diff] [blame] | 10 | #include <abuf.h> |
Simon Glass | c999e17 | 2023-06-01 10:22:53 -0600 | [diff] [blame] | 11 | #include <dm/ofnode_decl.h> |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 12 | #include <linux/list.h> |
| 13 | |
| 14 | struct udevice; |
| 15 | |
Simon Glass | a968f5f | 2023-10-01 19:13:31 -0600 | [diff] [blame] | 16 | #include <cli.h> |
| 17 | |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 18 | /** |
Simon Glass | 53a0a2f | 2024-10-14 16:31:57 -0600 | [diff] [blame] | 19 | * enum expo_id_t - standard expo IDs |
| 20 | * |
| 21 | * These are assumed to be in use at all times. Expos should use IDs starting |
| 22 | * from EXPOID_BASE_ID, |
| 23 | * |
| 24 | * @EXPOID_NONE: Not used, invalid ID 0 |
| 25 | * @EXPOID_SAVE: User has requested that the expo data be saved |
| 26 | * @EXPOID_DISCARD: User has requested that the expo data be discarded |
| 27 | * @EXPOID_BASE_ID: First ID which can be used for expo objects |
| 28 | */ |
| 29 | enum expo_id_t { |
| 30 | EXPOID_NONE, |
| 31 | |
| 32 | EXPOID_SAVE, |
| 33 | EXPOID_DISCARD, |
| 34 | |
| 35 | EXPOID_BASE_ID = 5, |
| 36 | }; |
| 37 | |
| 38 | /** |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 39 | * enum expoact_type - types of actions reported by the expo |
| 40 | * |
| 41 | * @EXPOACT_NONE: no action |
Simon Glass | f0e1e8c | 2023-06-01 10:22:59 -0600 | [diff] [blame] | 42 | * @EXPOACT_POINT_OBJ: object was highlighted (@id indicates which) |
Simon Glass | 719a3c6 | 2023-06-01 10:22:56 -0600 | [diff] [blame] | 43 | * @EXPOACT_POINT_ITEM: menu item was highlighted (@id indicates which) |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 44 | * @EXPOACT_SELECT: menu item was selected (@id indicates which) |
Simon Glass | f0e1e8c | 2023-06-01 10:22:59 -0600 | [diff] [blame] | 45 | * @EXPOACT_OPEN: menu was opened, so an item can be selected (@id indicates |
| 46 | * which menu object) |
| 47 | * @EXPOACT_CLOSE: menu was closed (@id indicates which menu object) |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 48 | * @EXPOACT_QUIT: request to exit the menu |
| 49 | */ |
| 50 | enum expoact_type { |
| 51 | EXPOACT_NONE, |
Simon Glass | f0e1e8c | 2023-06-01 10:22:59 -0600 | [diff] [blame] | 52 | EXPOACT_POINT_OBJ, |
Simon Glass | 719a3c6 | 2023-06-01 10:22:56 -0600 | [diff] [blame] | 53 | EXPOACT_POINT_ITEM, |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 54 | EXPOACT_SELECT, |
Simon Glass | f0e1e8c | 2023-06-01 10:22:59 -0600 | [diff] [blame] | 55 | EXPOACT_OPEN, |
| 56 | EXPOACT_CLOSE, |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 57 | EXPOACT_QUIT, |
| 58 | }; |
| 59 | |
| 60 | /** |
| 61 | * struct expo_action - an action report by the expo |
| 62 | * |
| 63 | * @type: Action type (EXPOACT_NONE if there is no action) |
Simon Glass | 719a3c6 | 2023-06-01 10:22:56 -0600 | [diff] [blame] | 64 | * @select: Used for EXPOACT_POINT_ITEM and EXPOACT_SELECT |
Heinrich Schuchardt | a99e8fe | 2024-09-18 23:58:03 +0200 | [diff] [blame] | 65 | * @select.id: ID number of the object affected. |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 66 | */ |
| 67 | struct expo_action { |
| 68 | enum expoact_type type; |
| 69 | union { |
| 70 | struct { |
| 71 | int id; |
| 72 | } select; |
| 73 | }; |
| 74 | }; |
| 75 | |
| 76 | /** |
Simon Glass | c999e17 | 2023-06-01 10:22:53 -0600 | [diff] [blame] | 77 | * struct expo_theme - theme for the expo |
| 78 | * |
| 79 | * @font_size: Default font size for all text |
| 80 | * @menu_inset: Inset width (on each side and top/bottom) for menu items |
| 81 | * @menuitem_gap_y: Gap between menu items in pixels |
Simon Glass | 377f18e | 2024-10-14 16:31:55 -0600 | [diff] [blame] | 82 | * @menu_title_margin_x: Gap between right side of menu title and left size of |
| 83 | * menu label |
Simon Glass | c999e17 | 2023-06-01 10:22:53 -0600 | [diff] [blame] | 84 | */ |
| 85 | struct expo_theme { |
| 86 | u32 font_size; |
| 87 | u32 menu_inset; |
| 88 | u32 menuitem_gap_y; |
Simon Glass | 377f18e | 2024-10-14 16:31:55 -0600 | [diff] [blame] | 89 | u32 menu_title_margin_x; |
Simon Glass | c999e17 | 2023-06-01 10:22:53 -0600 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | /** |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 93 | * struct expo - information about an expo |
| 94 | * |
| 95 | * A group of scenes which can be presented to the user, typically to obtain |
| 96 | * input or to make a selection. |
| 97 | * |
| 98 | * @name: Name of the expo (allocated) |
| 99 | * @display: Display to use (`UCLASS_VIDEO`), or NULL to use text mode |
Simon Glass | 67e2af1 | 2023-06-01 10:22:34 -0600 | [diff] [blame] | 100 | * @cons: Console to use (`UCLASS_VIDEO_CONSOLE`), or NULL to use text mode |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 101 | * @scene_id: Current scene ID (0 if none) |
| 102 | * @next_id: Next ID number to use, for automatic allocation |
| 103 | * @action: Action selected by user. At present only one is supported, with the |
| 104 | * type set to EXPOACT_NONE if there is no action |
| 105 | * @text_mode: true to use text mode for the menu (no vidconsole) |
Simon Glass | d353b75 | 2023-06-01 10:22:55 -0600 | [diff] [blame] | 106 | * @popup: true to use popup menus, instead of showing all items |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 107 | * @priv: Private data for the controller |
Simon Glass | 527d864 | 2025-05-02 08:46:20 -0600 | [diff] [blame] | 108 | * @done: Indicates that a cedit session is complete and the user has quit |
| 109 | * @save: Indicates that cedit data should be saved, rather than discarded |
Simon Glass | c999e17 | 2023-06-01 10:22:53 -0600 | [diff] [blame] | 110 | * @theme: Information about fonts styles, etc. |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 111 | * @scene_head: List of scenes |
| 112 | * @str_head: list of strings |
Simon Glass | 683d883 | 2025-05-02 08:46:15 -0600 | [diff] [blame] | 113 | * @cch: Keyboard context for input |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 114 | */ |
| 115 | struct expo { |
| 116 | char *name; |
| 117 | struct udevice *display; |
Simon Glass | 67e2af1 | 2023-06-01 10:22:34 -0600 | [diff] [blame] | 118 | struct udevice *cons; |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 119 | uint scene_id; |
| 120 | uint next_id; |
| 121 | struct expo_action action; |
| 122 | bool text_mode; |
Simon Glass | d353b75 | 2023-06-01 10:22:55 -0600 | [diff] [blame] | 123 | bool popup; |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 124 | void *priv; |
Simon Glass | 527d864 | 2025-05-02 08:46:20 -0600 | [diff] [blame] | 125 | bool done; |
| 126 | bool save; |
Simon Glass | c999e17 | 2023-06-01 10:22:53 -0600 | [diff] [blame] | 127 | struct expo_theme theme; |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 128 | struct list_head scene_head; |
| 129 | struct list_head str_head; |
Simon Glass | 683d883 | 2025-05-02 08:46:15 -0600 | [diff] [blame] | 130 | struct cli_ch_state cch; |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 131 | }; |
| 132 | |
| 133 | /** |
| 134 | * struct expo_string - a string that can be used in an expo |
| 135 | * |
| 136 | * @id: ID number of the string |
| 137 | * @str: String |
| 138 | * @sibling: Node to link this object to its siblings |
| 139 | */ |
| 140 | struct expo_string { |
| 141 | uint id; |
| 142 | const char *str; |
| 143 | struct list_head sibling; |
| 144 | }; |
| 145 | |
| 146 | /** |
| 147 | * struct scene - information about a scene in an expo |
| 148 | * |
| 149 | * A collection of text/image/menu items in an expo |
| 150 | * |
| 151 | * @expo: Expo this scene is part of |
| 152 | * @name: Name of the scene (allocated) |
| 153 | * @id: ID number of the scene |
Simon Glass | ea274b6 | 2023-06-01 10:22:27 -0600 | [diff] [blame] | 154 | * @title_id: String ID of title of the scene (allocated) |
Simon Glass | d353b75 | 2023-06-01 10:22:55 -0600 | [diff] [blame] | 155 | * @highlight_id: ID of highlighted object, if any |
Simon Glass | a968f5f | 2023-10-01 19:13:31 -0600 | [diff] [blame] | 156 | * @cls: cread state to use for input |
| 157 | * @buf: Buffer for input |
| 158 | * @entry_save: Buffer to hold vidconsole text-entry information |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 159 | * @sibling: Node to link this scene to its siblings |
| 160 | * @obj_head: List of objects in the scene |
| 161 | */ |
| 162 | struct scene { |
| 163 | struct expo *expo; |
| 164 | char *name; |
| 165 | uint id; |
Simon Glass | ea274b6 | 2023-06-01 10:22:27 -0600 | [diff] [blame] | 166 | uint title_id; |
Simon Glass | d353b75 | 2023-06-01 10:22:55 -0600 | [diff] [blame] | 167 | uint highlight_id; |
Simon Glass | a968f5f | 2023-10-01 19:13:31 -0600 | [diff] [blame] | 168 | struct cli_line_state cls; |
| 169 | struct abuf buf; |
| 170 | struct abuf entry_save; |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 171 | struct list_head sibling; |
| 172 | struct list_head obj_head; |
| 173 | }; |
| 174 | |
| 175 | /** |
| 176 | * enum scene_obj_t - type of a scene object |
| 177 | * |
| 178 | * @SCENEOBJT_NONE: Used to indicate that the type does not matter |
| 179 | * @SCENEOBJT_IMAGE: Image data to render |
| 180 | * @SCENEOBJT_TEXT: Text line to render |
| 181 | * @SCENEOBJT_MENU: Menu containing items the user can select |
Simon Glass | 6116e76 | 2023-10-01 19:13:32 -0600 | [diff] [blame] | 182 | * @SCENEOBJT_TEXTLINE: Line of text the user can edit |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 183 | */ |
| 184 | enum scene_obj_t { |
| 185 | SCENEOBJT_NONE = 0, |
| 186 | SCENEOBJT_IMAGE, |
| 187 | SCENEOBJT_TEXT, |
Simon Glass | 193bfea | 2023-10-01 19:13:27 -0600 | [diff] [blame] | 188 | |
| 189 | /* types from here on can be highlighted */ |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 190 | SCENEOBJT_MENU, |
Simon Glass | 6116e76 | 2023-10-01 19:13:32 -0600 | [diff] [blame] | 191 | SCENEOBJT_TEXTLINE, |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 192 | }; |
| 193 | |
| 194 | /** |
Simon Glass | 854ca69 | 2025-05-02 08:46:30 -0600 | [diff] [blame^] | 195 | * struct scene_obj_bbox - Dimensions of an object |
Simon Glass | 7b04395 | 2023-06-01 10:22:49 -0600 | [diff] [blame] | 196 | * |
| 197 | * @x: x position, in pixels from left side |
| 198 | * @y: y position, in pixels from top |
| 199 | * @w: width, in pixels |
| 200 | * @h: height, in pixels |
| 201 | */ |
Simon Glass | 854ca69 | 2025-05-02 08:46:30 -0600 | [diff] [blame^] | 202 | struct scene_obj_bbox { |
Simon Glass | 7b04395 | 2023-06-01 10:22:49 -0600 | [diff] [blame] | 203 | int x; |
| 204 | int y; |
| 205 | int w; |
| 206 | int h; |
| 207 | }; |
| 208 | |
| 209 | /** |
Simon Glass | 6081b0f | 2023-06-01 10:22:50 -0600 | [diff] [blame] | 210 | * enum scene_obj_flags_t - flags for objects |
| 211 | * |
| 212 | * @SCENEOF_HIDE: object should be hidden |
Simon Glass | d353b75 | 2023-06-01 10:22:55 -0600 | [diff] [blame] | 213 | * @SCENEOF_POINT: object should be highlighted |
| 214 | * @SCENEOF_OPEN: object should be opened (e.g. menu is opened so that an option |
| 215 | * can be selected) |
Simon Glass | 6081b0f | 2023-06-01 10:22:50 -0600 | [diff] [blame] | 216 | */ |
| 217 | enum scene_obj_flags_t { |
| 218 | SCENEOF_HIDE = 1 << 0, |
Simon Glass | d353b75 | 2023-06-01 10:22:55 -0600 | [diff] [blame] | 219 | SCENEOF_POINT = 1 << 1, |
| 220 | SCENEOF_OPEN = 1 << 2, |
Simon Glass | 6081b0f | 2023-06-01 10:22:50 -0600 | [diff] [blame] | 221 | }; |
| 222 | |
Simon Glass | a968f5f | 2023-10-01 19:13:31 -0600 | [diff] [blame] | 223 | enum { |
| 224 | /* Maximum number of characters allowed in an line editor */ |
| 225 | EXPO_MAX_CHARS = 250, |
| 226 | }; |
| 227 | |
Simon Glass | 6081b0f | 2023-06-01 10:22:50 -0600 | [diff] [blame] | 228 | /** |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 229 | * struct scene_obj - information about an object in a scene |
| 230 | * |
| 231 | * @scene: Scene that this object relates to |
| 232 | * @name: Name of the object (allocated) |
| 233 | * @id: ID number of the object |
| 234 | * @type: Type of this object |
Simon Glass | 854ca69 | 2025-05-02 08:46:30 -0600 | [diff] [blame^] | 235 | * @bbox: Dimensions for this object |
Simon Glass | 6081b0f | 2023-06-01 10:22:50 -0600 | [diff] [blame] | 236 | * @flags: Flags for this object |
Simon Glass | 2b91ca6 | 2023-08-14 16:40:37 -0600 | [diff] [blame] | 237 | * @bit_length: Number of bits used for this object in CMOS RAM |
| 238 | * @start_bit: Start bit to use for this object in CMOS RAM |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 239 | * @sibling: Node to link this object to its siblings |
| 240 | */ |
| 241 | struct scene_obj { |
| 242 | struct scene *scene; |
| 243 | char *name; |
| 244 | uint id; |
| 245 | enum scene_obj_t type; |
Simon Glass | 854ca69 | 2025-05-02 08:46:30 -0600 | [diff] [blame^] | 246 | struct scene_obj_bbox bbox; |
Simon Glass | 2b91ca6 | 2023-08-14 16:40:37 -0600 | [diff] [blame] | 247 | u8 flags; |
| 248 | u8 bit_length; |
| 249 | u16 start_bit; |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 250 | struct list_head sibling; |
| 251 | }; |
| 252 | |
Simon Glass | 193bfea | 2023-10-01 19:13:27 -0600 | [diff] [blame] | 253 | /* object can be highlighted when moving around expo */ |
| 254 | static inline bool scene_obj_can_highlight(const struct scene_obj *obj) |
| 255 | { |
| 256 | return obj->type >= SCENEOBJT_MENU; |
| 257 | } |
| 258 | |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 259 | /** |
| 260 | * struct scene_obj_img - information about an image object in a scene |
| 261 | * |
| 262 | * This is a rectangular image which is blitted onto the display |
| 263 | * |
| 264 | * @obj: Basic object information |
| 265 | * @data: Image data in BMP format |
| 266 | */ |
| 267 | struct scene_obj_img { |
| 268 | struct scene_obj obj; |
| 269 | char *data; |
| 270 | }; |
| 271 | |
| 272 | /** |
| 273 | * struct scene_obj_txt - information about a text object in a scene |
| 274 | * |
| 275 | * This is a single-line text object |
| 276 | * |
| 277 | * @obj: Basic object information |
| 278 | * @str_id: ID of the text string to display |
| 279 | * @font_name: Name of font (allocated by caller) |
| 280 | * @font_size: Nominal size of font in pixels |
| 281 | */ |
| 282 | struct scene_obj_txt { |
| 283 | struct scene_obj obj; |
| 284 | uint str_id; |
| 285 | const char *font_name; |
| 286 | uint font_size; |
| 287 | }; |
| 288 | |
| 289 | /** |
| 290 | * struct scene_obj_menu - information about a menu object in a scene |
| 291 | * |
| 292 | * A menu has a number of items which can be selected by the user |
| 293 | * |
| 294 | * It also has: |
| 295 | * |
| 296 | * - a text/image object (@pointer_id) which points to the current item |
| 297 | * (@cur_item_id) |
| 298 | * |
| 299 | * - a preview object which shows an image related to the current item |
| 300 | * |
| 301 | * @obj: Basic object information |
| 302 | * @title_id: ID of the title text, or 0 if none |
| 303 | * @cur_item_id: ID of the current menu item, or 0 if none |
| 304 | * @pointer_id: ID of the object pointing to the current selection |
| 305 | * @item_head: List of items in the menu |
| 306 | */ |
| 307 | struct scene_obj_menu { |
| 308 | struct scene_obj obj; |
| 309 | uint title_id; |
| 310 | uint cur_item_id; |
| 311 | uint pointer_id; |
| 312 | struct list_head item_head; |
| 313 | }; |
| 314 | |
| 315 | /** |
| 316 | * enum scene_menuitem_flags_t - flags for menu items |
| 317 | * |
| 318 | * @SCENEMIF_GAP_BEFORE: Add a gap before this item |
| 319 | */ |
| 320 | enum scene_menuitem_flags_t { |
| 321 | SCENEMIF_GAP_BEFORE = 1 << 0, |
| 322 | }; |
| 323 | |
| 324 | /** |
| 325 | * struct scene_menitem - a menu item in a menu |
| 326 | * |
| 327 | * A menu item has: |
| 328 | * |
| 329 | * - text object holding the name (short) and description (can be longer) |
| 330 | * - a text object holding the keypress |
| 331 | * |
| 332 | * @name: Name of the item (this is allocated by this call) |
| 333 | * @id: ID number of the object |
| 334 | * @key_id: ID of text object to use as the keypress to show |
| 335 | * @label_id: ID of text object to use as the label text |
| 336 | * @desc_id: ID of text object to use as the description text |
| 337 | * @preview_id: ID of the preview object, or 0 if none |
| 338 | * @flags: Flags for this item |
Simon Glass | 100389f | 2024-10-14 16:31:58 -0600 | [diff] [blame] | 339 | * @value: Value for this item, or INT_MAX to use sequence |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 340 | * @sibling: Node to link this item to its siblings |
| 341 | */ |
| 342 | struct scene_menitem { |
| 343 | char *name; |
| 344 | uint id; |
| 345 | uint key_id; |
| 346 | uint label_id; |
| 347 | uint desc_id; |
| 348 | uint preview_id; |
| 349 | uint flags; |
Simon Glass | 100389f | 2024-10-14 16:31:58 -0600 | [diff] [blame] | 350 | int value; |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 351 | struct list_head sibling; |
| 352 | }; |
| 353 | |
| 354 | /** |
Simon Glass | 6116e76 | 2023-10-01 19:13:32 -0600 | [diff] [blame] | 355 | * struct scene_obj_textline - information about a textline in a scene |
| 356 | * |
| 357 | * A textline has a prompt and a line of editable text |
| 358 | * |
| 359 | * @obj: Basic object information |
| 360 | * @label_id: ID of the label text, or 0 if none |
| 361 | * @edit_id: ID of the editable text |
| 362 | * @max_chars: Maximum number of characters allowed |
| 363 | * @buf: Text buffer containing current text |
| 364 | * @pos: Cursor position |
| 365 | */ |
| 366 | struct scene_obj_textline { |
| 367 | struct scene_obj obj; |
| 368 | uint label_id; |
| 369 | uint edit_id; |
| 370 | uint max_chars; |
| 371 | struct abuf buf; |
| 372 | uint pos; |
| 373 | }; |
| 374 | |
| 375 | /** |
Simon Glass | 377f18e | 2024-10-14 16:31:55 -0600 | [diff] [blame] | 376 | * struct expo_arrange_info - Information used when arranging a scene |
| 377 | * |
| 378 | * @label_width: Maximum width of labels in scene |
| 379 | */ |
| 380 | struct expo_arrange_info { |
| 381 | int label_width; |
| 382 | }; |
| 383 | |
| 384 | /** |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 385 | * expo_new() - create a new expo |
| 386 | * |
| 387 | * Allocates a new expo |
| 388 | * |
| 389 | * @name: Name of expo (this is allocated by this call) |
| 390 | * @priv: Private data for the controller |
| 391 | * @expp: Returns a pointer to the new expo on success |
| 392 | * Returns: 0 if OK, -ENOMEM if out of memory |
| 393 | */ |
| 394 | int expo_new(const char *name, void *priv, struct expo **expp); |
| 395 | |
| 396 | /** |
| 397 | * expo_destroy() - Destroy an expo and free all its memory |
| 398 | * |
| 399 | * @exp: Expo to destroy |
| 400 | */ |
| 401 | void expo_destroy(struct expo *exp); |
| 402 | |
| 403 | /** |
Simon Glass | 6e9e415 | 2023-06-01 10:22:47 -0600 | [diff] [blame] | 404 | * expo_set_dynamic_start() - Set the start of the 'dynamic' IDs |
| 405 | * |
| 406 | * It is common for a set of 'static' IDs to be used to refer to objects in the |
| 407 | * expo. These typically use an enum so that they are defined in sequential |
| 408 | * order. |
| 409 | * |
| 410 | * Dynamic IDs (for objects not in the enum) are intended to be used for |
| 411 | * objects to which the code does not need to refer. These are ideally located |
| 412 | * above the static IDs. |
| 413 | * |
| 414 | * Use this function to set the start of the dynamic range, making sure that the |
| 415 | * value is higher than all the statically allocated IDs. |
| 416 | * |
| 417 | * @exp: Expo to update |
| 418 | * @dyn_start: Start ID that expo should use for dynamic allocation |
| 419 | */ |
| 420 | void expo_set_dynamic_start(struct expo *exp, uint dyn_start); |
| 421 | |
| 422 | /** |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 423 | * expo_str() - add a new string to an expo |
| 424 | * |
| 425 | * @exp: Expo to update |
| 426 | * @name: Name to use (this is allocated by this call) |
| 427 | * @id: ID to use for the new object (0 to allocate one) |
| 428 | * @str: Pointer to text to display (allocated by caller) |
| 429 | * Returns: ID number for the object (typically @id), or -ve on error |
| 430 | */ |
| 431 | int expo_str(struct expo *exp, const char *name, uint id, const char *str); |
| 432 | |
| 433 | /** |
| 434 | * expo_get_str() - Get a string by ID |
| 435 | * |
| 436 | * @exp: Expo to use |
| 437 | * @id: String ID to look up |
| 438 | * @returns string, or NULL if not found |
| 439 | */ |
| 440 | const char *expo_get_str(struct expo *exp, uint id); |
| 441 | |
| 442 | /** |
| 443 | * expo_set_display() - set the display to use for a expo |
| 444 | * |
| 445 | * @exp: Expo to update |
| 446 | * @dev: Display to use (`UCLASS_VIDEO`), NULL to use text mode |
| 447 | * Returns: 0 (always) |
| 448 | */ |
| 449 | int expo_set_display(struct expo *exp, struct udevice *dev); |
| 450 | |
| 451 | /** |
Simon Glass | 7a96005 | 2023-06-01 10:22:52 -0600 | [diff] [blame] | 452 | * expo_calc_dims() - Calculate the dimensions of the objects |
| 453 | * |
| 454 | * Updates the width and height of all objects based on their contents |
| 455 | * |
| 456 | * @exp: Expo to update |
| 457 | * Returns 0 if OK, -ENOTSUPP if there is no graphical console |
| 458 | */ |
| 459 | int expo_calc_dims(struct expo *exp); |
| 460 | |
| 461 | /** |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 462 | * expo_set_scene_id() - Set the current scene ID |
| 463 | * |
| 464 | * @exp: Expo to update |
| 465 | * @scene_id: New scene ID to use (0 to select no scene) |
| 466 | * Returns: 0 if OK, -ENOENT if there is no scene with that ID |
| 467 | */ |
| 468 | int expo_set_scene_id(struct expo *exp, uint scene_id); |
| 469 | |
| 470 | /** |
Simon Glass | c892511 | 2023-06-01 10:23:02 -0600 | [diff] [blame] | 471 | * expo_first_scene_id() - Get the ID of the first scene |
| 472 | * |
| 473 | * @exp: Expo to check |
| 474 | * Returns: Scene ID of first scene, or -ENOENT if there are no scenes |
| 475 | */ |
| 476 | int expo_first_scene_id(struct expo *exp); |
| 477 | |
| 478 | /** |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 479 | * expo_render() - render the expo on the display / console |
| 480 | * |
| 481 | * @exp: Expo to render |
| 482 | * |
| 483 | * Returns: 0 if OK, -ECHILD if there is no current scene, -ENOENT if the |
| 484 | * current scene is not found, other error if something else goes wrong |
| 485 | */ |
| 486 | int expo_render(struct expo *exp); |
| 487 | |
| 488 | /** |
Simon Glass | b2c4034 | 2023-06-01 10:22:37 -0600 | [diff] [blame] | 489 | * expo_set_text_mode() - Controls whether the expo renders in text mode |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 490 | * |
| 491 | * @exp: Expo to update |
| 492 | * @text_mode: true to use text mode, false to use the console |
| 493 | */ |
Simon Glass | b2c4034 | 2023-06-01 10:22:37 -0600 | [diff] [blame] | 494 | void expo_set_text_mode(struct expo *exp, bool text_mode); |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 495 | |
| 496 | /** |
| 497 | * scene_new() - create a new scene in a expo |
| 498 | * |
| 499 | * The scene is given the ID @id which must be unique across all scenes, objects |
| 500 | * and items. The expo's @next_id is updated to at least @id + 1 |
| 501 | * |
| 502 | * @exp: Expo to update |
| 503 | * @name: Name to use (this is allocated by this call) |
| 504 | * @id: ID to use for the new scene (0 to allocate one) |
| 505 | * @scnp: Returns a pointer to the new scene on success |
| 506 | * Returns: ID number for the scene (typically @id), or -ve on error |
| 507 | */ |
| 508 | int scene_new(struct expo *exp, const char *name, uint id, struct scene **scnp); |
| 509 | |
| 510 | /** |
| 511 | * expo_lookup_scene_id() - Look up a scene by ID |
| 512 | * |
| 513 | * @exp: Expo to check |
| 514 | * @scene_id: Scene ID to look up |
| 515 | * @returns pointer to scene if found, else NULL |
| 516 | */ |
| 517 | struct scene *expo_lookup_scene_id(struct expo *exp, uint scene_id); |
| 518 | |
| 519 | /** |
Simon Glass | 01922ec | 2023-06-01 10:22:57 -0600 | [diff] [blame] | 520 | * scene_highlight_first() - Highlight the first item in a scene |
| 521 | * |
| 522 | * This highlights the first item, so that the user can see that it is pointed |
| 523 | * to |
| 524 | * |
| 525 | * @scn: Scene to update |
| 526 | */ |
| 527 | void scene_highlight_first(struct scene *scn); |
| 528 | |
| 529 | /** |
| 530 | * scene_set_highlight_id() - Set the object which is highlighted |
| 531 | * |
| 532 | * Sets a new object to highlight in the scene |
| 533 | * |
| 534 | * @scn: Scene to update |
| 535 | * @id: ID of object to highlight |
| 536 | */ |
| 537 | void scene_set_highlight_id(struct scene *scn, uint id); |
| 538 | |
| 539 | /** |
| 540 | * scene_set_open() - Set whether an item is open or not |
| 541 | * |
| 542 | * @scn: Scene to update |
| 543 | * @id: ID of object to update |
| 544 | * @open: true to open the object, false to close it |
| 545 | * Returns: 0 if OK, -ENOENT if @id is invalid |
| 546 | */ |
| 547 | int scene_set_open(struct scene *scn, uint id, bool open); |
| 548 | |
| 549 | /** |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 550 | * scene_obj_count() - Count the number of objects in a scene |
| 551 | * |
| 552 | * @scn: Scene to check |
| 553 | * Returns: number of objects in the scene, 0 if none |
| 554 | */ |
| 555 | int scene_obj_count(struct scene *scn); |
| 556 | |
| 557 | /** |
| 558 | * scene_img() - add a new image to a scene |
| 559 | * |
| 560 | * @scn: Scene to update |
| 561 | * @name: Name to use (this is allocated by this call) |
| 562 | * @id: ID to use for the new object (0 to allocate one) |
| 563 | * @data: Pointer to image data |
| 564 | * @imgp: If non-NULL, returns the new object |
| 565 | * Returns: ID number for the object (typically @id), or -ve on error |
| 566 | */ |
| 567 | int scene_img(struct scene *scn, const char *name, uint id, char *data, |
| 568 | struct scene_obj_img **imgp); |
| 569 | |
| 570 | /** |
| 571 | * scene_txt() - add a new text object to a scene |
| 572 | * |
| 573 | * @scn: Scene to update |
| 574 | * @name: Name to use (this is allocated by this call) |
| 575 | * @id: ID to use for the new object (0 to allocate one) |
| 576 | * @str_id: ID of the string to use |
| 577 | * @txtp: If non-NULL, returns the new object |
| 578 | * Returns: ID number for the object (typically @id), or -ve on error |
| 579 | */ |
| 580 | int scene_txt(struct scene *scn, const char *name, uint id, uint str_id, |
| 581 | struct scene_obj_txt **txtp); |
| 582 | |
| 583 | /** |
Simon Glass | db6a051 | 2023-10-01 19:13:23 -0600 | [diff] [blame] | 584 | * scene_txt_str() - add a new string to expo and text object to a scene |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 585 | * |
| 586 | * @scn: Scene to update |
| 587 | * @name: Name to use (this is allocated by this call) |
| 588 | * @id: ID to use for the new object (0 to allocate one) |
| 589 | * @str_id: ID of the string to use |
| 590 | * @str: Pointer to text to display (allocated by caller) |
| 591 | * @txtp: If non-NULL, returns the new object |
| 592 | * Returns: ID number for the object (typically @id), or -ve on error |
| 593 | */ |
| 594 | int scene_txt_str(struct scene *scn, const char *name, uint id, uint str_id, |
| 595 | const char *str, struct scene_obj_txt **txtp); |
| 596 | |
| 597 | /** |
| 598 | * scene_menu() - create a menu |
| 599 | * |
| 600 | * @scn: Scene to update |
| 601 | * @name: Name to use (this is allocated by this call) |
| 602 | * @id: ID to use for the new object (0 to allocate one) |
| 603 | * @menup: If non-NULL, returns the new object |
| 604 | * Returns: ID number for the object (typically @id), or -ve on error |
| 605 | */ |
| 606 | int scene_menu(struct scene *scn, const char *name, uint id, |
| 607 | struct scene_obj_menu **menup); |
| 608 | |
| 609 | /** |
Simon Glass | 6116e76 | 2023-10-01 19:13:32 -0600 | [diff] [blame] | 610 | * scene_textline() - create a textline |
| 611 | * |
| 612 | * @scn: Scene to update |
| 613 | * @name: Name to use (this is allocated by this call) |
| 614 | * @id: ID to use for the new object (0 to allocate one) |
| 615 | * @max_chars: Maximum length of the textline in characters |
| 616 | * @tlinep: If non-NULL, returns the new object |
| 617 | * Returns: ID number for the object (typically @id), or -ve on error |
| 618 | */ |
| 619 | int scene_textline(struct scene *scn, const char *name, uint id, uint max_chars, |
| 620 | struct scene_obj_textline **tlinep); |
| 621 | |
| 622 | /** |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 623 | * scene_txt_set_font() - Set the font for an object |
| 624 | * |
| 625 | * @scn: Scene to update |
| 626 | * @id: ID of object to update |
| 627 | * @font_name: Font name to use (allocated by caller) |
| 628 | * @font_size: Font size to use (nominal height in pixels) |
| 629 | */ |
| 630 | int scene_txt_set_font(struct scene *scn, uint id, const char *font_name, |
| 631 | uint font_size); |
| 632 | |
| 633 | /** |
| 634 | * scene_obj_set_pos() - Set the postion of an object |
| 635 | * |
| 636 | * @scn: Scene to update |
| 637 | * @id: ID of object to update |
| 638 | * @x: x position, in pixels from left side |
| 639 | * @y: y position, in pixels from top |
| 640 | * Returns: 0 if OK, -ENOENT if @id is invalid |
| 641 | */ |
| 642 | int scene_obj_set_pos(struct scene *scn, uint id, int x, int y); |
| 643 | |
| 644 | /** |
Simon Glass | 7a96005 | 2023-06-01 10:22:52 -0600 | [diff] [blame] | 645 | * scene_obj_set_size() - Set the size of an object |
| 646 | * |
| 647 | * @scn: Scene to update |
| 648 | * @id: ID of object to update |
| 649 | * @w: width in pixels |
| 650 | * @h: height in pixels |
| 651 | * Returns: 0 if OK, -ENOENT if @id is invalid |
| 652 | */ |
| 653 | int scene_obj_set_size(struct scene *scn, uint id, int w, int h); |
| 654 | |
| 655 | /** |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 656 | * scene_obj_set_hide() - Set whether an object is hidden |
| 657 | * |
| 658 | * The update happens when the expo is next rendered. |
| 659 | * |
| 660 | * @scn: Scene to update |
| 661 | * @id: ID of object to update |
| 662 | * @hide: true to hide the object, false to show it |
| 663 | * Returns: 0 if OK, -ENOENT if @id is invalid |
| 664 | */ |
| 665 | int scene_obj_set_hide(struct scene *scn, uint id, bool hide); |
| 666 | |
| 667 | /** |
| 668 | * scene_menu_set_title() - Set the title of a menu |
| 669 | * |
| 670 | * @scn: Scene to update |
| 671 | * @id: ID of menu object to update |
| 672 | * @title_id: ID of text object to use as the title |
| 673 | * Returns: 0 if OK, -ENOENT if @id is invalid, -EINVAL if @title_id is invalid |
| 674 | */ |
| 675 | int scene_menu_set_title(struct scene *scn, uint id, uint title_id); |
| 676 | |
| 677 | /** |
| 678 | * scene_menu_set_pointer() - Set the item pointer for a menu |
| 679 | * |
| 680 | * This is a visual indicator of the current item, typically a ">" character |
| 681 | * which sits next to the current item and moves when the user presses the |
| 682 | * up/down arrow keys |
| 683 | * |
| 684 | * @scn: Scene to update |
| 685 | * @id: ID of menu object to update |
| 686 | * @cur_item_id: ID of text or image object to use as a pointer to the current |
| 687 | * item |
| 688 | * Returns: 0 if OK, -ENOENT if @id is invalid, -EINVAL if @cur_item_id is invalid |
| 689 | */ |
| 690 | int scene_menu_set_pointer(struct scene *scn, uint id, uint cur_item_id); |
| 691 | |
| 692 | /** |
Simon Glass | be04b96 | 2025-05-02 08:46:24 -0600 | [diff] [blame] | 693 | * scene_menu_select_item() - move the pointer/highlight to an item |
| 694 | * |
| 695 | * @scn: Scene to update |
| 696 | * @id: ID of menu object to update |
| 697 | * @sel_id: ID of the menuitem to select |
| 698 | * Return 0 on success, -ENOENT if there was no such item |
| 699 | */ |
| 700 | int scene_menu_select_item(struct scene *scn, uint id, uint sel_id); |
| 701 | |
| 702 | /** |
| 703 | * scene_menu_get_cur_item() - get the currently pointed-to item |
| 704 | * |
| 705 | * @scn: Scene to update |
| 706 | * @id: ID of menu object to update |
| 707 | * Return ID of the current item the menu is pointing to, -ENOENT if @id is not |
| 708 | * valid, 0 if no item is pointed to |
| 709 | */ |
| 710 | int scene_menu_get_cur_item(struct scene *scn, uint id); |
| 711 | |
| 712 | /** |
Simon Glass | d8adbe9 | 2023-01-06 08:52:36 -0600 | [diff] [blame] | 713 | * scene_obj_get_hw() - Get width and height of an object in a scene |
| 714 | * |
| 715 | * @scn: Scene to check |
| 716 | * @id: ID of menu object to check |
| 717 | * @widthp: If non-NULL, returns width of object in pixels |
| 718 | * Returns: Height of object in pixels |
| 719 | */ |
| 720 | int scene_obj_get_hw(struct scene *scn, uint id, int *widthp); |
| 721 | |
| 722 | /** |
| 723 | * scene_menuitem() - Add an item to a menu |
| 724 | * |
| 725 | * @scn: Scene to update |
| 726 | * @menu_id: ID of menu object to update |
| 727 | * @name: Name to use (this is allocated by this call) |
| 728 | * @id: ID to use for the new object (0 to allocate one) |
| 729 | * @key_id: ID of text object to use as the keypress to show |
| 730 | * @label_id: ID of text object to use as the label text |
| 731 | * @desc_id: ID of text object to use as the description text |
| 732 | * @preview_id: ID of object to use as the preview (text or image) |
| 733 | * @flags: Flags for this item (enum scene_menuitem_flags_t) |
| 734 | * @itemp: If non-NULL, returns the new object |
| 735 | * Returns: ID number for the item (typically @id), or -ve on error |
| 736 | */ |
| 737 | int scene_menuitem(struct scene *scn, uint menu_id, const char *name, uint id, |
| 738 | uint key_id, uint label_id, uint desc_id, uint preview_id, |
| 739 | uint flags, struct scene_menitem **itemp); |
| 740 | |
| 741 | /** |
| 742 | * scene_arrange() - Arrange the scene to deal with object sizes |
| 743 | * |
| 744 | * Updates any menus in the scene so that their objects are in the right place. |
| 745 | * |
| 746 | * @scn: Scene to arrange |
| 747 | * Returns: 0 if OK, -ve on error |
| 748 | */ |
| 749 | int scene_arrange(struct scene *scn); |
| 750 | |
| 751 | /** |
| 752 | * expo_send_key() - set a keypress to the expo |
| 753 | * |
| 754 | * @exp: Expo to receive the key |
| 755 | * @key: Key to send (ASCII or enum bootmenu_key) |
| 756 | * Returns: 0 if OK, -ECHILD if there is no current scene |
| 757 | */ |
| 758 | int expo_send_key(struct expo *exp, int key); |
| 759 | |
| 760 | /** |
| 761 | * expo_action_get() - read user input from the expo |
| 762 | * |
| 763 | * @exp: Expo to check |
| 764 | * @act: Returns action |
| 765 | * Returns: 0 if OK, -EAGAIN if there was no action to return |
| 766 | */ |
| 767 | int expo_action_get(struct expo *exp, struct expo_action *act); |
| 768 | |
Simon Glass | c999e17 | 2023-06-01 10:22:53 -0600 | [diff] [blame] | 769 | /** |
| 770 | * expo_apply_theme() - Apply a theme to an expo |
| 771 | * |
| 772 | * @exp: Expo to update |
| 773 | * @node: Node containing the theme |
| 774 | */ |
| 775 | int expo_apply_theme(struct expo *exp, ofnode node); |
| 776 | |
Simon Glass | 6130072 | 2023-06-01 10:23:01 -0600 | [diff] [blame] | 777 | /** |
| 778 | * expo_build() - Build an expo from an FDT description |
| 779 | * |
| 780 | * Build a complete expo from a description in the provided devicetree. |
| 781 | * |
Massimo Pegorer | c8c7002 | 2023-09-09 12:32:28 +0200 | [diff] [blame] | 782 | * See doc/develop/expo.rst for a description of the format |
Simon Glass | 6130072 | 2023-06-01 10:23:01 -0600 | [diff] [blame] | 783 | * |
| 784 | * @root: Root node for expo description |
| 785 | * @expp: Returns the new expo |
| 786 | * Returns: 0 if OK, -ENOMEM if out of memory, -EINVAL if there is a format |
| 787 | * error, -ENOENT if there is a references to a non-existent string |
| 788 | */ |
| 789 | int expo_build(ofnode root, struct expo **expp); |
| 790 | |
Simon Glass | 3434420 | 2024-10-14 16:32:11 -0600 | [diff] [blame] | 791 | /** |
| 792 | * cb_expo_build() - Build an expo for coreboot CMOS RAM |
| 793 | * |
| 794 | * @expp: Returns the expo created |
| 795 | * Return: 0 if OK, -ve on error |
| 796 | */ |
| 797 | int cb_expo_build(struct expo **expp); |
| 798 | |
Simon Glass | 137b442 | 2025-05-02 08:46:16 -0600 | [diff] [blame] | 799 | /** |
| 800 | * expo_poll() - render an expo and see if the user takes an action |
| 801 | * |
| 802 | * Thsi calls expo_render() and then checks for a keypress. If there is one, it |
| 803 | * is processed and the resulting action returned, if any |
| 804 | * |
| 805 | * @exp: Expo to poll |
| 806 | * @act: Returns action on success |
| 807 | * Return: 0 if an action was obtained, -EAGAIN if not, other error if something |
| 808 | * went wrong |
| 809 | */ |
| 810 | int expo_poll(struct expo *exp, struct expo_action *act); |
| 811 | |
Simon Glass | 8df4a4e | 2023-08-14 16:40:25 -0600 | [diff] [blame] | 812 | #endif /*__EXPO_H */ |