Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2015 Google, Inc |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #ifndef __video_console_h |
| 7 | #define __video_console_h |
| 8 | |
Simon Glass | 95bcad4 | 2025-04-02 06:29:36 +1300 | [diff] [blame^] | 9 | #include <alist.h> |
Heinrich Schuchardt | 290e1d8 | 2018-02-08 21:47:11 +0100 | [diff] [blame] | 10 | #include <video.h> |
| 11 | |
Simon Glass | 34b5c25 | 2023-10-01 19:13:19 -0600 | [diff] [blame] | 12 | struct abuf; |
Simon Glass | bac9150 | 2020-07-02 21:12:18 -0600 | [diff] [blame] | 13 | struct video_priv; |
| 14 | |
Simon Glass | 52c10c5 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 15 | #define VID_FRAC_DIV 256 |
| 16 | |
| 17 | #define VID_TO_PIXEL(x) ((x) / VID_FRAC_DIV) |
| 18 | #define VID_TO_POS(x) ((x) * VID_FRAC_DIV) |
| 19 | |
Simon Glass | 377f79aa | 2023-10-01 19:13:21 -0600 | [diff] [blame] | 20 | enum { |
| 21 | /* cursor width in pixels */ |
| 22 | VIDCONSOLE_CURSOR_WIDTH = 2, |
| 23 | }; |
| 24 | |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 25 | /** |
| 26 | * struct vidconsole_priv - uclass-private data about a console device |
| 27 | * |
Simon Glass | 52c10c5 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 28 | * Drivers must set up @rows, @cols, @x_charsize, @y_charsize in their probe() |
| 29 | * method. Drivers may set up @xstart_frac if desired. |
| 30 | * |
Simon Glass | aea571d | 2024-10-14 16:31:54 -0600 | [diff] [blame] | 31 | * Note that these values relate to the rotated console, so that an 80x25 |
| 32 | * console which is rotated 90 degrees will have rows=80 and cols=25 |
| 33 | * |
| 34 | * The xcur_frac and ycur values refer to the unrotated coordinates, that is |
| 35 | * xcur_frac always advances with each character, even if its limit might be |
| 36 | * vid_priv->ysize instead of vid_priv->xsize if the console is rotated 90 or |
| 37 | * 270 degrees. |
| 38 | * |
Heinrich Schuchardt | 9e933f1 | 2018-09-19 21:31:48 +0200 | [diff] [blame] | 39 | * @sdev: stdio device, acting as an output sink |
| 40 | * @xcur_frac: Current X position, in fractional units (VID_TO_POS(x)) |
| 41 | * @ycur: Current Y position in pixels (0=top) |
| 42 | * @rows: Number of text rows |
| 43 | * @cols: Number of text columns |
| 44 | * @x_charsize: Character width in pixels |
| 45 | * @y_charsize: Character height in pixels |
Simon Glass | 52c10c5 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 46 | * @tab_width_frac: Tab width in fractional units |
Heinrich Schuchardt | 9e933f1 | 2018-09-19 21:31:48 +0200 | [diff] [blame] | 47 | * @xsize_frac: Width of the display in fractional units |
Simon Glass | a74451d | 2016-01-14 18:10:39 -0700 | [diff] [blame] | 48 | * @xstart_frac: Left margin for the text console in fractional units |
Heinrich Schuchardt | 9e933f1 | 2018-09-19 21:31:48 +0200 | [diff] [blame] | 49 | * @last_ch: Last character written to the text console on this line |
| 50 | * @escape: TRUE if currently accumulating an ANSI escape sequence |
| 51 | * @escape_len: Length of accumulated escape sequence so far |
| 52 | * @col_saved: Saved X position, in fractional units (VID_TO_POS(x)) |
| 53 | * @row_saved: Saved Y position in pixels (0=top) |
| 54 | * @escape_buf: Buffer to accumulate escape sequence |
Janne Grunau | 5548c36 | 2024-03-16 22:50:19 +0100 | [diff] [blame] | 55 | * @utf8_buf: Buffer to accumulate UTF-8 byte sequence |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 56 | */ |
| 57 | struct vidconsole_priv { |
| 58 | struct stdio_dev sdev; |
Simon Glass | 52c10c5 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 59 | int xcur_frac; |
| 60 | int ycur; |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 61 | int rows; |
| 62 | int cols; |
Simon Glass | 52c10c5 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 63 | int x_charsize; |
| 64 | int y_charsize; |
| 65 | int tab_width_frac; |
| 66 | int xsize_frac; |
Simon Glass | a74451d | 2016-01-14 18:10:39 -0700 | [diff] [blame] | 67 | int xstart_frac; |
Simon Glass | afee743 | 2016-01-14 18:10:40 -0700 | [diff] [blame] | 68 | int last_ch; |
Rob Clark | 06e7a0d | 2017-09-13 18:12:21 -0400 | [diff] [blame] | 69 | /* |
| 70 | * ANSI escape sequences are accumulated character by character, |
| 71 | * starting after the ESC char (0x1b) until the entire sequence |
| 72 | * is consumed at which point it is acted upon. |
| 73 | */ |
| 74 | int escape; |
| 75 | int escape_len; |
Heinrich Schuchardt | 9e933f1 | 2018-09-19 21:31:48 +0200 | [diff] [blame] | 76 | int row_saved; |
| 77 | int col_saved; |
Rob Clark | 06e7a0d | 2017-09-13 18:12:21 -0400 | [diff] [blame] | 78 | char escape_buf[32]; |
Janne Grunau | 5548c36 | 2024-03-16 22:50:19 +0100 | [diff] [blame] | 79 | char utf8_buf[5]; |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | /** |
Simon Glass | 3b175ba | 2023-01-06 08:52:32 -0600 | [diff] [blame] | 83 | * struct vidfont_info - information about a font |
| 84 | * |
| 85 | * @name: Font name, e.g. nimbus_sans_l_regular |
| 86 | */ |
| 87 | struct vidfont_info { |
| 88 | const char *name; |
| 89 | }; |
| 90 | |
| 91 | /** |
Simon Glass | a73a8b8 | 2023-06-01 10:22:45 -0600 | [diff] [blame] | 92 | * struct vidconsole_colour - Holds colour information |
| 93 | * |
| 94 | * @colour_fg: Foreground colour (pixel value) |
| 95 | * @colour_bg: Background colour (pixel value) |
| 96 | */ |
| 97 | struct vidconsole_colour { |
| 98 | u32 colour_fg; |
| 99 | u32 colour_bg; |
| 100 | }; |
| 101 | |
| 102 | /** |
Simon Glass | 5caf125 | 2023-06-01 10:22:46 -0600 | [diff] [blame] | 103 | * struct vidconsole_bbox - Bounding box of text |
| 104 | * |
| 105 | * This describes the bounding box of something, measured in pixels. The x0/y0 |
| 106 | * pair is inclusive; the x1/y2 pair is exclusive, meaning that it is one pixel |
| 107 | * beyond the extent of the object |
| 108 | * |
| 109 | * @valid: Values are valid (bounding box is known) |
| 110 | * @x0: left x position, in pixels from left side |
| 111 | * @y0: top y position, in pixels from top |
| 112 | * @x1: right x position + 1 |
| 113 | * @y1: botton y position + 1 |
| 114 | */ |
| 115 | struct vidconsole_bbox { |
| 116 | bool valid; |
| 117 | int x0; |
| 118 | int y0; |
| 119 | int x1; |
| 120 | int y1; |
| 121 | }; |
| 122 | |
| 123 | /** |
Simon Glass | 95bcad4 | 2025-04-02 06:29:36 +1300 | [diff] [blame^] | 124 | * vidconsole_mline - Holds information about a line of measured text |
| 125 | * |
| 126 | * @bbox: Bounding box of the line, assuming it starts at 0,0 |
| 127 | * @start: String index of the first character in the line |
| 128 | * @len: Number of characters in the line |
| 129 | */ |
| 130 | struct vidconsole_mline { |
| 131 | struct vidconsole_bbox bbox; |
| 132 | int start; |
| 133 | int len; |
| 134 | }; |
| 135 | |
| 136 | /** |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 137 | * struct vidconsole_ops - Video console operations |
| 138 | * |
| 139 | * These operations work on either an absolute console position (measured |
| 140 | * in pixels) or a text row number (measured in rows, where each row consists |
| 141 | * of an entire line of text - typically 16 pixels). |
| 142 | */ |
| 143 | struct vidconsole_ops { |
| 144 | /** |
| 145 | * putc_xy() - write a single character to a position |
| 146 | * |
| 147 | * @dev: Device to write to |
Simon Glass | 52c10c5 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 148 | * @x_frac: Fractional pixel X position (0=left-most pixel) which |
| 149 | * is the X position multipled by VID_FRAC_DIV. |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 150 | * @y: Pixel Y position (0=top-most pixel) |
Janne Grunau | 5548c36 | 2024-03-16 22:50:19 +0100 | [diff] [blame] | 151 | * @cp: UTF-32 code point to write |
Simon Glass | 52c10c5 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 152 | * @return number of fractional pixels that the cursor should move, |
| 153 | * if all is OK, -EAGAIN if we ran out of space on this line, other -ve |
| 154 | * on error |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 155 | */ |
Janne Grunau | 5548c36 | 2024-03-16 22:50:19 +0100 | [diff] [blame] | 156 | int (*putc_xy)(struct udevice *dev, uint x_frac, uint y, int cp); |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 157 | |
| 158 | /** |
| 159 | * move_rows() - Move text rows from one place to another |
| 160 | * |
| 161 | * @dev: Device to adjust |
| 162 | * @rowdst: Destination text row (0=top) |
| 163 | * @rowsrc: Source start text row |
| 164 | * @count: Number of text rows to move |
| 165 | * @return 0 if OK, -ve on error |
| 166 | */ |
| 167 | int (*move_rows)(struct udevice *dev, uint rowdst, uint rowsrc, |
| 168 | uint count); |
| 169 | |
| 170 | /** |
| 171 | * set_row() - Set the colour of a text row |
| 172 | * |
| 173 | * Every pixel contained within the text row is adjusted |
| 174 | * |
| 175 | * @dev: Device to adjust |
| 176 | * @row: Text row to adjust (0=top) |
| 177 | * @clr: Raw colour (pixel value) to write to each pixel |
| 178 | * @return 0 if OK, -ve on error |
| 179 | */ |
| 180 | int (*set_row)(struct udevice *dev, uint row, int clr); |
Simon Glass | afee743 | 2016-01-14 18:10:40 -0700 | [diff] [blame] | 181 | |
| 182 | /** |
| 183 | * entry_start() - Indicate that text entry is starting afresh |
| 184 | * |
Simon Glass | 3b175ba | 2023-01-06 08:52:32 -0600 | [diff] [blame] | 185 | * @dev: Device to adjust |
| 186 | * Returns: 0 on success, -ve on error |
| 187 | * |
Simon Glass | afee743 | 2016-01-14 18:10:40 -0700 | [diff] [blame] | 188 | * Consoles which use proportional fonts need to track the position of |
| 189 | * each character output so that backspace will return to the correct |
| 190 | * place. This method signals to the console driver that a new entry |
| 191 | * line is being start (e.g. the user pressed return to start a new |
| 192 | * command). The driver can use this signal to empty its list of |
| 193 | * positions. |
| 194 | */ |
| 195 | int (*entry_start)(struct udevice *dev); |
Simon Glass | 33bd3b6 | 2016-01-14 18:10:41 -0700 | [diff] [blame] | 196 | |
| 197 | /** |
| 198 | * backspace() - Handle erasing the last character |
| 199 | * |
Simon Glass | 3b175ba | 2023-01-06 08:52:32 -0600 | [diff] [blame] | 200 | * @dev: Device to adjust |
| 201 | * Returns: 0 on success, -ve on error |
| 202 | * |
Simon Glass | 33bd3b6 | 2016-01-14 18:10:41 -0700 | [diff] [blame] | 203 | * With proportional fonts the vidconsole uclass cannot itself erase |
| 204 | * the previous character. This optional method will be called when |
| 205 | * a backspace is needed. The driver should erase the previous |
| 206 | * character and update the cursor position (xcur_frac, ycur) to the |
| 207 | * start of the previous character. |
| 208 | * |
| 209 | * If not implement, default behaviour will work for fixed-width |
| 210 | * characters. |
| 211 | */ |
| 212 | int (*backspace)(struct udevice *dev); |
Simon Glass | 3b175ba | 2023-01-06 08:52:32 -0600 | [diff] [blame] | 213 | |
| 214 | /** |
| 215 | * get_font() - Obtain information about a font (optional) |
| 216 | * |
| 217 | * @dev: Device to check |
| 218 | * @seq: Font number to query (0=first, 1=second, etc.) |
| 219 | * @info: Returns font information on success |
| 220 | * Returns: 0 on success, -ENOENT if no such font |
| 221 | */ |
| 222 | int (*get_font)(struct udevice *dev, int seq, |
| 223 | struct vidfont_info *info); |
| 224 | |
| 225 | /** |
Dzmitry Sankouski | 86c6a53 | 2023-03-07 13:21:15 +0300 | [diff] [blame] | 226 | * get_font_size() - get the current font name and size |
| 227 | * |
| 228 | * @dev: vidconsole device |
| 229 | * @sizep: Place to put the font size (nominal height in pixels) |
| 230 | * Returns: Current font name |
| 231 | */ |
| 232 | const char *(*get_font_size)(struct udevice *dev, uint *sizep); |
| 233 | |
| 234 | /** |
Simon Glass | 3b175ba | 2023-01-06 08:52:32 -0600 | [diff] [blame] | 235 | * select_font() - Select a particular font by name / size |
| 236 | * |
| 237 | * @dev: Device to adjust |
| 238 | * @name: Font name to use (NULL to use default) |
| 239 | * @size: Font size to use (0 to use default) |
| 240 | * Returns: 0 on success, -ENOENT if no such font |
| 241 | */ |
| 242 | int (*select_font)(struct udevice *dev, const char *name, uint size); |
Simon Glass | 5caf125 | 2023-06-01 10:22:46 -0600 | [diff] [blame] | 243 | |
| 244 | /** |
Simon Glass | 95bcad4 | 2025-04-02 06:29:36 +1300 | [diff] [blame^] | 245 | * measure() - Measure the bounding box of some text |
Simon Glass | 5caf125 | 2023-06-01 10:22:46 -0600 | [diff] [blame] | 246 | * |
Simon Glass | 95bcad4 | 2025-04-02 06:29:36 +1300 | [diff] [blame^] | 247 | * @dev: Console device to use |
Simon Glass | 5caf125 | 2023-06-01 10:22:46 -0600 | [diff] [blame] | 248 | * @name: Font name to use (NULL to use default) |
| 249 | * @size: Font size to use (0 to use default) |
| 250 | * @text: Text to measure |
| 251 | * @bbox: Returns bounding box of text, assuming it is positioned |
| 252 | * at 0,0 |
Simon Glass | 95bcad4 | 2025-04-02 06:29:36 +1300 | [diff] [blame^] | 253 | * @lines: If non-NULL, this must be an alist of |
| 254 | * struct vidconsole_mline inited by caller. A separate |
| 255 | * record is added for each line of text |
| 256 | * |
Simon Glass | 5caf125 | 2023-06-01 10:22:46 -0600 | [diff] [blame] | 257 | * Returns: 0 on success, -ENOENT if no such font |
| 258 | */ |
| 259 | int (*measure)(struct udevice *dev, const char *name, uint size, |
Simon Glass | 95bcad4 | 2025-04-02 06:29:36 +1300 | [diff] [blame^] | 260 | const char *text, struct vidconsole_bbox *bbox, |
| 261 | struct alist *lines); |
Simon Glass | 8b82e59 | 2023-10-01 19:13:18 -0600 | [diff] [blame] | 262 | |
| 263 | /** |
| 264 | * nominal() - Measure the expected width of a line of text |
| 265 | * |
| 266 | * Uses an average font width and nominal height |
| 267 | * |
| 268 | * @dev: Console device to use |
| 269 | * @name: Font name, NULL for default |
| 270 | * @size: Font size, ignored if @name is NULL |
| 271 | * @num_chars: Number of characters to use |
| 272 | * @bbox: Returns nounding box of @num_chars characters |
| 273 | * Returns: 0 if OK, -ve on error |
| 274 | */ |
| 275 | int (*nominal)(struct udevice *dev, const char *name, uint size, |
| 276 | uint num_chars, struct vidconsole_bbox *bbox); |
Simon Glass | 34b5c25 | 2023-10-01 19:13:19 -0600 | [diff] [blame] | 277 | |
| 278 | /** |
| 279 | * entry_save() - Save any text-entry information for later use |
| 280 | * |
| 281 | * Saves text-entry context such as a list of positions for each |
| 282 | * character in the string. |
| 283 | * |
| 284 | * @dev: Console device to use |
| 285 | * @buf: Buffer to hold saved data |
| 286 | * Return: 0 if OK, -ENOMEM if out of memory |
| 287 | */ |
| 288 | int (*entry_save)(struct udevice *dev, struct abuf *buf); |
| 289 | |
| 290 | /** |
| 291 | * entry_restore() - Restore text-entry information for current use |
| 292 | * |
| 293 | * Restores text-entry context such as a list of positions for each |
| 294 | * character in the string. |
| 295 | * |
| 296 | * @dev: Console device to use |
| 297 | * @buf: Buffer containing data to restore |
| 298 | * Return: 0 if OK, -ve on error |
| 299 | */ |
| 300 | int (*entry_restore)(struct udevice *dev, struct abuf *buf); |
Simon Glass | 377f79aa | 2023-10-01 19:13:21 -0600 | [diff] [blame] | 301 | |
| 302 | /** |
| 303 | * set_cursor_visible() - Show or hide the cursor |
| 304 | * |
| 305 | * Shows or hides a cursor at the current position |
| 306 | * |
| 307 | * @dev: Console device to use |
| 308 | * @visible: true to show the cursor, false to hide it |
| 309 | * @x: X position in pixels |
| 310 | * @y: Y position in pixels |
| 311 | * @index: Character position (0 = at start) |
| 312 | * Return: 0 if OK, -ve on error |
| 313 | */ |
| 314 | int (*set_cursor_visible)(struct udevice *dev, bool visible, |
| 315 | uint x, uint y, uint index); |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 316 | }; |
| 317 | |
| 318 | /* Get a pointer to the driver operations for a video console device */ |
| 319 | #define vidconsole_get_ops(dev) ((struct vidconsole_ops *)(dev)->driver->ops) |
| 320 | |
| 321 | /** |
Simon Glass | 3b175ba | 2023-01-06 08:52:32 -0600 | [diff] [blame] | 322 | * vidconsole_get_font() - Obtain information about a font |
| 323 | * |
| 324 | * @dev: Device to check |
| 325 | * @seq: Font number to query (0=first, 1=second, etc.) |
| 326 | * @info: Returns font information on success |
| 327 | * Returns: 0 on success, -ENOENT if no such font, -ENOSYS if there is no such |
| 328 | * method |
| 329 | */ |
| 330 | int vidconsole_get_font(struct udevice *dev, int seq, |
| 331 | struct vidfont_info *info); |
| 332 | |
| 333 | /** |
| 334 | * vidconsole_select_font() - Select a particular font by name / size |
| 335 | * |
| 336 | * @dev: Device to adjust |
| 337 | * @name: Font name to use (NULL to use default) |
| 338 | * @size: Font size to use (0 to use default) |
| 339 | */ |
| 340 | int vidconsole_select_font(struct udevice *dev, const char *name, uint size); |
| 341 | |
Simon Glass | 95bcad4 | 2025-04-02 06:29:36 +1300 | [diff] [blame^] | 342 | /** |
| 343 | * vidconsole_measure() - Measure the bounding box of some text |
| 344 | * |
| 345 | * @dev: Device to adjust |
| 346 | * @name: Font name to use (NULL to use default) |
| 347 | * @size: Font size to use (0 to use default) |
| 348 | * @text: Text to measure |
| 349 | * @bbox: Returns bounding box of text, assuming it is positioned |
| 350 | * at 0,0 |
| 351 | * @lines: If non-NULL, this must be an alist of |
| 352 | * struct vidconsole_mline inited by caller. The list is emptied |
| 353 | * and then a separate record is added for each line of text |
Simon Glass | 5caf125 | 2023-06-01 10:22:46 -0600 | [diff] [blame] | 354 | * |
Simon Glass | 95bcad4 | 2025-04-02 06:29:36 +1300 | [diff] [blame^] | 355 | * Returns: 0 on success, -ENOENT if no such font |
Simon Glass | 5caf125 | 2023-06-01 10:22:46 -0600 | [diff] [blame] | 356 | */ |
| 357 | int vidconsole_measure(struct udevice *dev, const char *name, uint size, |
Simon Glass | 95bcad4 | 2025-04-02 06:29:36 +1300 | [diff] [blame^] | 358 | const char *text, struct vidconsole_bbox *bbox, |
| 359 | struct alist *lines); |
Simon Glass | 3b175ba | 2023-01-06 08:52:32 -0600 | [diff] [blame] | 360 | /** |
Simon Glass | 8b82e59 | 2023-10-01 19:13:18 -0600 | [diff] [blame] | 361 | * vidconsole_nominal() - Measure the expected width of a line of text |
| 362 | * |
| 363 | * Uses an average font width and nominal height |
| 364 | * |
| 365 | * @dev: Console device to use |
| 366 | * @name: Font name, NULL for default |
| 367 | * @size: Font size, ignored if @name is NULL |
| 368 | * @num_chars: Number of characters to use |
| 369 | * @bbox: Returns nounding box of @num_chars characters |
| 370 | * Returns: 0 if OK, -ve on error |
| 371 | */ |
| 372 | int vidconsole_nominal(struct udevice *dev, const char *name, uint size, |
| 373 | uint num_chars, struct vidconsole_bbox *bbox); |
| 374 | |
| 375 | /** |
Simon Glass | 34b5c25 | 2023-10-01 19:13:19 -0600 | [diff] [blame] | 376 | * vidconsole_entry_save() - Save any text-entry information for later use |
| 377 | * |
| 378 | * Saves text-entry context such as a list of positions for each |
| 379 | * character in the string. |
| 380 | * |
| 381 | * @dev: Console device to use |
| 382 | * @buf: Buffer to hold saved data |
| 383 | * Return: 0 if OK, -ENOMEM if out of memory |
| 384 | */ |
| 385 | int vidconsole_entry_save(struct udevice *dev, struct abuf *buf); |
| 386 | |
| 387 | /** |
| 388 | * entry_restore() - Restore text-entry information for current use |
| 389 | * |
| 390 | * Restores text-entry context such as a list of positions for each |
| 391 | * character in the string. |
| 392 | * |
| 393 | * @dev: Console device to use |
| 394 | * @buf: Buffer containing data to restore |
| 395 | * Return: 0 if OK, -ve on error |
| 396 | */ |
| 397 | int vidconsole_entry_restore(struct udevice *dev, struct abuf *buf); |
| 398 | |
| 399 | /** |
Simon Glass | 377f79aa | 2023-10-01 19:13:21 -0600 | [diff] [blame] | 400 | * vidconsole_set_cursor_visible() - Show or hide the cursor |
| 401 | * |
| 402 | * Shows or hides a cursor at the current position |
| 403 | * |
| 404 | * @dev: Console device to use |
| 405 | * @visible: true to show the cursor, false to hide it |
| 406 | * @x: X position in pixels |
| 407 | * @y: Y position in pixels |
| 408 | * @index: Character position (0 = at start) |
| 409 | * Return: 0 if OK, -ve on error |
| 410 | */ |
| 411 | int vidconsole_set_cursor_visible(struct udevice *dev, bool visible, |
| 412 | uint x, uint y, uint index); |
| 413 | |
| 414 | /** |
Simon Glass | a73a8b8 | 2023-06-01 10:22:45 -0600 | [diff] [blame] | 415 | * vidconsole_push_colour() - Temporarily change the font colour |
| 416 | * |
| 417 | * @dev: Device to adjust |
| 418 | * @fg: Foreground colour to select |
| 419 | * @bg: Background colour to select |
| 420 | * @old: Place to store the current colour, so it can be restored |
| 421 | */ |
| 422 | void vidconsole_push_colour(struct udevice *dev, enum colour_idx fg, |
| 423 | enum colour_idx bg, struct vidconsole_colour *old); |
| 424 | |
| 425 | /** |
| 426 | * vidconsole_pop_colour() - Restore the original colour |
| 427 | * |
| 428 | * @dev: Device to adjust |
| 429 | * @old: Old colour to be restored |
| 430 | */ |
| 431 | void vidconsole_pop_colour(struct udevice *dev, struct vidconsole_colour *old); |
| 432 | |
| 433 | /** |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 434 | * vidconsole_putc_xy() - write a single character to a position |
| 435 | * |
| 436 | * @dev: Device to write to |
Simon Glass | 52c10c5 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 437 | * @x_frac: Fractional pixel X position (0=left-most pixel) which |
| 438 | * is the X position multipled by VID_FRAC_DIV. |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 439 | * @y: Pixel Y position (0=top-most pixel) |
Janne Grunau | 5548c36 | 2024-03-16 22:50:19 +0100 | [diff] [blame] | 440 | * @cp: UTF-32 code point to write |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 441 | * Return: number of fractional pixels that the cursor should move, |
Simon Glass | 52c10c5 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 442 | * if all is OK, -EAGAIN if we ran out of space on this line, other -ve |
| 443 | * on error |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 444 | */ |
Janne Grunau | 5548c36 | 2024-03-16 22:50:19 +0100 | [diff] [blame] | 445 | int vidconsole_putc_xy(struct udevice *dev, uint x, uint y, int cp); |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 446 | |
| 447 | /** |
| 448 | * vidconsole_move_rows() - Move text rows from one place to another |
| 449 | * |
| 450 | * @dev: Device to adjust |
| 451 | * @rowdst: Destination text row (0=top) |
| 452 | * @rowsrc: Source start text row |
| 453 | * @count: Number of text rows to move |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 454 | * Return: 0 if OK, -ve on error |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 455 | */ |
| 456 | int vidconsole_move_rows(struct udevice *dev, uint rowdst, uint rowsrc, |
| 457 | uint count); |
| 458 | |
| 459 | /** |
| 460 | * vidconsole_set_row() - Set the colour of a text row |
| 461 | * |
| 462 | * Every pixel contained within the text row is adjusted |
| 463 | * |
| 464 | * @dev: Device to adjust |
| 465 | * @row: Text row to adjust (0=top) |
| 466 | * @clr: Raw colour (pixel value) to write to each pixel |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 467 | * Return: 0 if OK, -ve on error |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 468 | */ |
| 469 | int vidconsole_set_row(struct udevice *dev, uint row, int clr); |
| 470 | |
| 471 | /** |
Simon Glass | 4446c4b | 2023-10-01 19:13:20 -0600 | [diff] [blame] | 472 | * vidconsole_entry_start() - Set the start position of a vidconsole line |
| 473 | * |
| 474 | * Marks the current cursor position as the start of a line |
| 475 | * |
| 476 | * @dev: Device to adjust |
| 477 | */ |
| 478 | int vidconsole_entry_start(struct udevice *dev); |
| 479 | |
| 480 | /** |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 481 | * vidconsole_put_char() - Output a character to the current console position |
| 482 | * |
| 483 | * Outputs a character to the console and advances the cursor. This function |
| 484 | * handles wrapping to new lines and scrolling the console. Special |
| 485 | * characters are handled also: \n, \r, \b and \t. |
| 486 | * |
| 487 | * The device always starts with the cursor at position 0,0 (top left). It |
| 488 | * can be adjusted manually using vidconsole_position_cursor(). |
| 489 | * |
| 490 | * @dev: Device to adjust |
| 491 | * @ch: Character to write |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 492 | * Return: 0 if OK, -ve on error |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 493 | */ |
| 494 | int vidconsole_put_char(struct udevice *dev, char ch); |
| 495 | |
| 496 | /** |
Marek Vasut | a89f9cb | 2019-05-17 20:22:31 +0200 | [diff] [blame] | 497 | * vidconsole_put_string() - Output a string to the current console position |
| 498 | * |
| 499 | * Outputs a string to the console and advances the cursor. This function |
| 500 | * handles wrapping to new lines and scrolling the console. Special |
| 501 | * characters are handled also: \n, \r, \b and \t. |
| 502 | * |
| 503 | * The device always starts with the cursor at position 0,0 (top left). It |
| 504 | * can be adjusted manually using vidconsole_position_cursor(). |
| 505 | * |
| 506 | * @dev: Device to adjust |
| 507 | * @str: String to write |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 508 | * Return: 0 if OK, -ve on error |
Marek Vasut | a89f9cb | 2019-05-17 20:22:31 +0200 | [diff] [blame] | 509 | */ |
| 510 | int vidconsole_put_string(struct udevice *dev, const char *str); |
| 511 | |
| 512 | /** |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 513 | * vidconsole_position_cursor() - Move the text cursor |
| 514 | * |
| 515 | * @dev: Device to adjust |
| 516 | * @col: New cursor text column |
| 517 | * @row: New cursor text row |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 518 | * Return: 0 if OK, -ve on error |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 519 | */ |
| 520 | void vidconsole_position_cursor(struct udevice *dev, unsigned col, |
| 521 | unsigned row); |
| 522 | |
Simon Glass | d622c5b | 2022-10-06 08:36:04 -0600 | [diff] [blame] | 523 | /** |
Simon Glass | 90679c6 | 2023-03-10 12:47:21 -0800 | [diff] [blame] | 524 | * vidconsole_clear_and_reset() - Clear the console and reset the cursor |
| 525 | * |
| 526 | * The cursor is placed at the start of the console |
| 527 | * |
| 528 | * @dev: vidconsole device to adjust |
| 529 | */ |
| 530 | int vidconsole_clear_and_reset(struct udevice *dev); |
| 531 | |
| 532 | /** |
Simon Glass | d622c5b | 2022-10-06 08:36:04 -0600 | [diff] [blame] | 533 | * vidconsole_set_cursor_pos() - set cursor position |
| 534 | * |
| 535 | * The cursor is set to the new position and the start-of-line information is |
| 536 | * updated to the same position, so that a newline will return to @x |
| 537 | * |
| 538 | * @dev: video console device to update |
| 539 | * @x: x position from left in pixels |
| 540 | * @y: y position from top in pixels |
| 541 | */ |
| 542 | void vidconsole_set_cursor_pos(struct udevice *dev, int x, int y); |
| 543 | |
Simon Glass | 981f00b | 2022-10-06 08:36:14 -0600 | [diff] [blame] | 544 | /** |
| 545 | * vidconsole_list_fonts() - List the available fonts |
| 546 | * |
Simon Glass | 3b175ba | 2023-01-06 08:52:32 -0600 | [diff] [blame] | 547 | * @dev: vidconsole device to check |
Simon Glass | 981f00b | 2022-10-06 08:36:14 -0600 | [diff] [blame] | 548 | * |
Simon Glass | 3b175ba | 2023-01-06 08:52:32 -0600 | [diff] [blame] | 549 | * This shows a list of fonts known by this vidconsole. The list is displayed on |
| 550 | * the console (not necessarily @dev but probably) |
Simon Glass | 981f00b | 2022-10-06 08:36:14 -0600 | [diff] [blame] | 551 | */ |
Simon Glass | 3b175ba | 2023-01-06 08:52:32 -0600 | [diff] [blame] | 552 | void vidconsole_list_fonts(struct udevice *dev); |
Simon Glass | 981f00b | 2022-10-06 08:36:14 -0600 | [diff] [blame] | 553 | |
Simon Glass | 9e972c3 | 2022-10-06 08:36:16 -0600 | [diff] [blame] | 554 | /** |
Simon Glass | 3b175ba | 2023-01-06 08:52:32 -0600 | [diff] [blame] | 555 | * vidconsole_get_font_size() - get the current font name and size |
Simon Glass | 9e972c3 | 2022-10-06 08:36:16 -0600 | [diff] [blame] | 556 | * |
| 557 | * @dev: vidconsole device |
| 558 | * @sizep: Place to put the font size (nominal height in pixels) |
Dzmitry Sankouski | 86c6a53 | 2023-03-07 13:21:15 +0300 | [diff] [blame] | 559 | * @name: pointer to font name, a placeholder for result |
| 560 | * Return: 0 if OK, -ENOSYS if not implemented in driver |
Simon Glass | 9e972c3 | 2022-10-06 08:36:16 -0600 | [diff] [blame] | 561 | */ |
Dzmitry Sankouski | 86c6a53 | 2023-03-07 13:21:15 +0300 | [diff] [blame] | 562 | int vidconsole_get_font_size(struct udevice *dev, const char **name, uint *sizep); |
Simon Glass | 9e972c3 | 2022-10-06 08:36:16 -0600 | [diff] [blame] | 563 | |
Heinrich Schuchardt | 290e1d8 | 2018-02-08 21:47:11 +0100 | [diff] [blame] | 564 | #endif |