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