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