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 | bac9150 | 2020-07-02 21:12:18 -0600 | [diff] [blame] | 11 | struct video_priv; |
| 12 | |
Simon Glass | 52c10c5 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 13 | #define VID_FRAC_DIV 256 |
| 14 | |
| 15 | #define VID_TO_PIXEL(x) ((x) / VID_FRAC_DIV) |
| 16 | #define VID_TO_POS(x) ((x) * VID_FRAC_DIV) |
| 17 | |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 18 | /** |
| 19 | * struct vidconsole_priv - uclass-private data about a console device |
| 20 | * |
Simon Glass | 52c10c5 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 21 | * Drivers must set up @rows, @cols, @x_charsize, @y_charsize in their probe() |
| 22 | * method. Drivers may set up @xstart_frac if desired. |
| 23 | * |
Heinrich Schuchardt | 9e933f1 | 2018-09-19 21:31:48 +0200 | [diff] [blame] | 24 | * @sdev: stdio device, acting as an output sink |
| 25 | * @xcur_frac: Current X position, in fractional units (VID_TO_POS(x)) |
| 26 | * @ycur: Current Y position in pixels (0=top) |
| 27 | * @rows: Number of text rows |
| 28 | * @cols: Number of text columns |
| 29 | * @x_charsize: Character width in pixels |
| 30 | * @y_charsize: Character height in pixels |
Simon Glass | 52c10c5 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 31 | * @tab_width_frac: Tab width in fractional units |
Heinrich Schuchardt | 9e933f1 | 2018-09-19 21:31:48 +0200 | [diff] [blame] | 32 | * @xsize_frac: Width of the display in fractional units |
Simon Glass | a74451d | 2016-01-14 18:10:39 -0700 | [diff] [blame] | 33 | * @xstart_frac: Left margin for the text console in fractional units |
Heinrich Schuchardt | 9e933f1 | 2018-09-19 21:31:48 +0200 | [diff] [blame] | 34 | * @last_ch: Last character written to the text console on this line |
| 35 | * @escape: TRUE if currently accumulating an ANSI escape sequence |
| 36 | * @escape_len: Length of accumulated escape sequence so far |
| 37 | * @col_saved: Saved X position, in fractional units (VID_TO_POS(x)) |
| 38 | * @row_saved: Saved Y position in pixels (0=top) |
| 39 | * @escape_buf: Buffer to accumulate escape sequence |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 40 | */ |
| 41 | struct vidconsole_priv { |
| 42 | struct stdio_dev sdev; |
Simon Glass | 52c10c5 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 43 | int xcur_frac; |
| 44 | int ycur; |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 45 | int rows; |
| 46 | int cols; |
Simon Glass | 52c10c5 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 47 | int x_charsize; |
| 48 | int y_charsize; |
| 49 | int tab_width_frac; |
| 50 | int xsize_frac; |
Simon Glass | a74451d | 2016-01-14 18:10:39 -0700 | [diff] [blame] | 51 | int xstart_frac; |
Simon Glass | afee743 | 2016-01-14 18:10:40 -0700 | [diff] [blame] | 52 | int last_ch; |
Rob Clark | 06e7a0d | 2017-09-13 18:12:21 -0400 | [diff] [blame] | 53 | /* |
| 54 | * ANSI escape sequences are accumulated character by character, |
| 55 | * starting after the ESC char (0x1b) until the entire sequence |
| 56 | * is consumed at which point it is acted upon. |
| 57 | */ |
| 58 | int escape; |
| 59 | int escape_len; |
Heinrich Schuchardt | 9e933f1 | 2018-09-19 21:31:48 +0200 | [diff] [blame] | 60 | int row_saved; |
| 61 | int col_saved; |
Rob Clark | 06e7a0d | 2017-09-13 18:12:21 -0400 | [diff] [blame] | 62 | char escape_buf[32]; |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | /** |
Simon Glass | 3b175ba | 2023-01-06 08:52:32 -0600 | [diff] [blame] | 66 | * struct vidfont_info - information about a font |
| 67 | * |
| 68 | * @name: Font name, e.g. nimbus_sans_l_regular |
| 69 | */ |
| 70 | struct vidfont_info { |
| 71 | const char *name; |
| 72 | }; |
| 73 | |
| 74 | /** |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 75 | * struct vidconsole_ops - Video console operations |
| 76 | * |
| 77 | * These operations work on either an absolute console position (measured |
| 78 | * in pixels) or a text row number (measured in rows, where each row consists |
| 79 | * of an entire line of text - typically 16 pixels). |
| 80 | */ |
| 81 | struct vidconsole_ops { |
| 82 | /** |
| 83 | * putc_xy() - write a single character to a position |
| 84 | * |
| 85 | * @dev: Device to write to |
Simon Glass | 52c10c5 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 86 | * @x_frac: Fractional pixel X position (0=left-most pixel) which |
| 87 | * is the X position multipled by VID_FRAC_DIV. |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 88 | * @y: Pixel Y position (0=top-most pixel) |
| 89 | * @ch: Character to write |
Simon Glass | 52c10c5 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 90 | * @return number of fractional pixels that the cursor should move, |
| 91 | * if all is OK, -EAGAIN if we ran out of space on this line, other -ve |
| 92 | * on error |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 93 | */ |
Simon Glass | 52c10c5 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 94 | int (*putc_xy)(struct udevice *dev, uint x_frac, uint y, char ch); |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 95 | |
| 96 | /** |
| 97 | * move_rows() - Move text rows from one place to another |
| 98 | * |
| 99 | * @dev: Device to adjust |
| 100 | * @rowdst: Destination text row (0=top) |
| 101 | * @rowsrc: Source start text row |
| 102 | * @count: Number of text rows to move |
| 103 | * @return 0 if OK, -ve on error |
| 104 | */ |
| 105 | int (*move_rows)(struct udevice *dev, uint rowdst, uint rowsrc, |
| 106 | uint count); |
| 107 | |
| 108 | /** |
| 109 | * set_row() - Set the colour of a text row |
| 110 | * |
| 111 | * Every pixel contained within the text row is adjusted |
| 112 | * |
| 113 | * @dev: Device to adjust |
| 114 | * @row: Text row to adjust (0=top) |
| 115 | * @clr: Raw colour (pixel value) to write to each pixel |
| 116 | * @return 0 if OK, -ve on error |
| 117 | */ |
| 118 | int (*set_row)(struct udevice *dev, uint row, int clr); |
Simon Glass | afee743 | 2016-01-14 18:10:40 -0700 | [diff] [blame] | 119 | |
| 120 | /** |
| 121 | * entry_start() - Indicate that text entry is starting afresh |
| 122 | * |
Simon Glass | 3b175ba | 2023-01-06 08:52:32 -0600 | [diff] [blame] | 123 | * @dev: Device to adjust |
| 124 | * Returns: 0 on success, -ve on error |
| 125 | * |
Simon Glass | afee743 | 2016-01-14 18:10:40 -0700 | [diff] [blame] | 126 | * Consoles which use proportional fonts need to track the position of |
| 127 | * each character output so that backspace will return to the correct |
| 128 | * place. This method signals to the console driver that a new entry |
| 129 | * line is being start (e.g. the user pressed return to start a new |
| 130 | * command). The driver can use this signal to empty its list of |
| 131 | * positions. |
| 132 | */ |
| 133 | int (*entry_start)(struct udevice *dev); |
Simon Glass | 33bd3b6 | 2016-01-14 18:10:41 -0700 | [diff] [blame] | 134 | |
| 135 | /** |
| 136 | * backspace() - Handle erasing the last character |
| 137 | * |
Simon Glass | 3b175ba | 2023-01-06 08:52:32 -0600 | [diff] [blame] | 138 | * @dev: Device to adjust |
| 139 | * Returns: 0 on success, -ve on error |
| 140 | * |
Simon Glass | 33bd3b6 | 2016-01-14 18:10:41 -0700 | [diff] [blame] | 141 | * With proportional fonts the vidconsole uclass cannot itself erase |
| 142 | * the previous character. This optional method will be called when |
| 143 | * a backspace is needed. The driver should erase the previous |
| 144 | * character and update the cursor position (xcur_frac, ycur) to the |
| 145 | * start of the previous character. |
| 146 | * |
| 147 | * If not implement, default behaviour will work for fixed-width |
| 148 | * characters. |
| 149 | */ |
| 150 | int (*backspace)(struct udevice *dev); |
Simon Glass | 3b175ba | 2023-01-06 08:52:32 -0600 | [diff] [blame] | 151 | |
| 152 | /** |
| 153 | * get_font() - Obtain information about a font (optional) |
| 154 | * |
| 155 | * @dev: Device to check |
| 156 | * @seq: Font number to query (0=first, 1=second, etc.) |
| 157 | * @info: Returns font information on success |
| 158 | * Returns: 0 on success, -ENOENT if no such font |
| 159 | */ |
| 160 | int (*get_font)(struct udevice *dev, int seq, |
| 161 | struct vidfont_info *info); |
| 162 | |
| 163 | /** |
| 164 | * select_font() - Select a particular font by name / size |
| 165 | * |
| 166 | * @dev: Device to adjust |
| 167 | * @name: Font name to use (NULL to use default) |
| 168 | * @size: Font size to use (0 to use default) |
| 169 | * Returns: 0 on success, -ENOENT if no such font |
| 170 | */ |
| 171 | int (*select_font)(struct udevice *dev, const char *name, uint size); |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 172 | }; |
| 173 | |
| 174 | /* Get a pointer to the driver operations for a video console device */ |
| 175 | #define vidconsole_get_ops(dev) ((struct vidconsole_ops *)(dev)->driver->ops) |
| 176 | |
| 177 | /** |
Simon Glass | 3b175ba | 2023-01-06 08:52:32 -0600 | [diff] [blame] | 178 | * vidconsole_get_font() - Obtain information about a font |
| 179 | * |
| 180 | * @dev: Device to check |
| 181 | * @seq: Font number to query (0=first, 1=second, etc.) |
| 182 | * @info: Returns font information on success |
| 183 | * Returns: 0 on success, -ENOENT if no such font, -ENOSYS if there is no such |
| 184 | * method |
| 185 | */ |
| 186 | int vidconsole_get_font(struct udevice *dev, int seq, |
| 187 | struct vidfont_info *info); |
| 188 | |
| 189 | /** |
| 190 | * vidconsole_select_font() - Select a particular font by name / size |
| 191 | * |
| 192 | * @dev: Device to adjust |
| 193 | * @name: Font name to use (NULL to use default) |
| 194 | * @size: Font size to use (0 to use default) |
| 195 | */ |
| 196 | int vidconsole_select_font(struct udevice *dev, const char *name, uint size); |
| 197 | |
| 198 | /** |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 199 | * vidconsole_putc_xy() - write a single character to a position |
| 200 | * |
| 201 | * @dev: Device to write to |
Simon Glass | 52c10c5 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 202 | * @x_frac: Fractional pixel X position (0=left-most pixel) which |
| 203 | * is the X position multipled by VID_FRAC_DIV. |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 204 | * @y: Pixel Y position (0=top-most pixel) |
| 205 | * @ch: Character to write |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 206 | * Return: number of fractional pixels that the cursor should move, |
Simon Glass | 52c10c5 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 207 | * if all is OK, -EAGAIN if we ran out of space on this line, other -ve |
| 208 | * on error |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 209 | */ |
| 210 | int vidconsole_putc_xy(struct udevice *dev, uint x, uint y, char ch); |
| 211 | |
| 212 | /** |
| 213 | * vidconsole_move_rows() - Move text rows from one place to another |
| 214 | * |
| 215 | * @dev: Device to adjust |
| 216 | * @rowdst: Destination text row (0=top) |
| 217 | * @rowsrc: Source start text row |
| 218 | * @count: Number of text rows to move |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 219 | * Return: 0 if OK, -ve on error |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 220 | */ |
| 221 | int vidconsole_move_rows(struct udevice *dev, uint rowdst, uint rowsrc, |
| 222 | uint count); |
| 223 | |
| 224 | /** |
| 225 | * vidconsole_set_row() - Set the colour of a text row |
| 226 | * |
| 227 | * Every pixel contained within the text row is adjusted |
| 228 | * |
| 229 | * @dev: Device to adjust |
| 230 | * @row: Text row to adjust (0=top) |
| 231 | * @clr: Raw colour (pixel value) to write to each pixel |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 232 | * Return: 0 if OK, -ve on error |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 233 | */ |
| 234 | int vidconsole_set_row(struct udevice *dev, uint row, int clr); |
| 235 | |
| 236 | /** |
| 237 | * vidconsole_put_char() - Output a character to the current console position |
| 238 | * |
| 239 | * Outputs a character to the console and advances the cursor. This function |
| 240 | * handles wrapping to new lines and scrolling the console. Special |
| 241 | * characters are handled also: \n, \r, \b and \t. |
| 242 | * |
| 243 | * The device always starts with the cursor at position 0,0 (top left). It |
| 244 | * can be adjusted manually using vidconsole_position_cursor(). |
| 245 | * |
| 246 | * @dev: Device to adjust |
| 247 | * @ch: Character to write |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 248 | * Return: 0 if OK, -ve on error |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 249 | */ |
| 250 | int vidconsole_put_char(struct udevice *dev, char ch); |
| 251 | |
| 252 | /** |
Marek Vasut | a89f9cb | 2019-05-17 20:22:31 +0200 | [diff] [blame] | 253 | * vidconsole_put_string() - Output a string to the current console position |
| 254 | * |
| 255 | * Outputs a string to the console and advances the cursor. This function |
| 256 | * handles wrapping to new lines and scrolling the console. Special |
| 257 | * characters are handled also: \n, \r, \b and \t. |
| 258 | * |
| 259 | * The device always starts with the cursor at position 0,0 (top left). It |
| 260 | * can be adjusted manually using vidconsole_position_cursor(). |
| 261 | * |
| 262 | * @dev: Device to adjust |
| 263 | * @str: String to write |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 264 | * Return: 0 if OK, -ve on error |
Marek Vasut | a89f9cb | 2019-05-17 20:22:31 +0200 | [diff] [blame] | 265 | */ |
| 266 | int vidconsole_put_string(struct udevice *dev, const char *str); |
| 267 | |
| 268 | /** |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 269 | * vidconsole_position_cursor() - Move the text cursor |
| 270 | * |
| 271 | * @dev: Device to adjust |
| 272 | * @col: New cursor text column |
| 273 | * @row: New cursor text row |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 274 | * Return: 0 if OK, -ve on error |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 275 | */ |
| 276 | void vidconsole_position_cursor(struct udevice *dev, unsigned col, |
| 277 | unsigned row); |
| 278 | |
Simon Glass | d622c5b | 2022-10-06 08:36:04 -0600 | [diff] [blame] | 279 | /** |
| 280 | * vidconsole_set_cursor_pos() - set cursor position |
| 281 | * |
| 282 | * The cursor is set to the new position and the start-of-line information is |
| 283 | * updated to the same position, so that a newline will return to @x |
| 284 | * |
| 285 | * @dev: video console device to update |
| 286 | * @x: x position from left in pixels |
| 287 | * @y: y position from top in pixels |
| 288 | */ |
| 289 | void vidconsole_set_cursor_pos(struct udevice *dev, int x, int y); |
| 290 | |
Simon Glass | 981f00b | 2022-10-06 08:36:14 -0600 | [diff] [blame] | 291 | /** |
| 292 | * vidconsole_list_fonts() - List the available fonts |
| 293 | * |
Simon Glass | 3b175ba | 2023-01-06 08:52:32 -0600 | [diff] [blame] | 294 | * @dev: vidconsole device to check |
Simon Glass | 981f00b | 2022-10-06 08:36:14 -0600 | [diff] [blame] | 295 | * |
Simon Glass | 3b175ba | 2023-01-06 08:52:32 -0600 | [diff] [blame] | 296 | * This shows a list of fonts known by this vidconsole. The list is displayed on |
| 297 | * the console (not necessarily @dev but probably) |
Simon Glass | 981f00b | 2022-10-06 08:36:14 -0600 | [diff] [blame] | 298 | */ |
Simon Glass | 3b175ba | 2023-01-06 08:52:32 -0600 | [diff] [blame] | 299 | void vidconsole_list_fonts(struct udevice *dev); |
Simon Glass | 981f00b | 2022-10-06 08:36:14 -0600 | [diff] [blame] | 300 | |
Simon Glass | 9e972c3 | 2022-10-06 08:36:16 -0600 | [diff] [blame] | 301 | /** |
Simon Glass | 3b175ba | 2023-01-06 08:52:32 -0600 | [diff] [blame] | 302 | * vidconsole_get_font_size() - get the current font name and size |
Simon Glass | 9e972c3 | 2022-10-06 08:36:16 -0600 | [diff] [blame] | 303 | * |
| 304 | * @dev: vidconsole device |
| 305 | * @sizep: Place to put the font size (nominal height in pixels) |
| 306 | * Returns: Current font name |
| 307 | */ |
Simon Glass | 3b175ba | 2023-01-06 08:52:32 -0600 | [diff] [blame] | 308 | const char *vidconsole_get_font_size(struct udevice *dev, uint *sizep); |
Simon Glass | 9e972c3 | 2022-10-06 08:36:16 -0600 | [diff] [blame] | 309 | |
Simon Glass | 31a7e23 | 2020-07-02 21:12:23 -0600 | [diff] [blame] | 310 | #ifdef CONFIG_VIDEO_COPY |
| 311 | /** |
| 312 | * vidconsole_sync_copy() - Sync back to the copy framebuffer |
| 313 | * |
| 314 | * This ensures that the copy framebuffer has the same data as the framebuffer |
| 315 | * for a particular region. It should be called after the framebuffer is updated |
| 316 | * |
| 317 | * @from and @to can be in either order. The region between them is synced. |
| 318 | * |
| 319 | * @dev: Vidconsole device being updated |
| 320 | * @from: Start/end address within the framebuffer (->fb) |
| 321 | * @to: Other address within the frame buffer |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 322 | * 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] | 323 | * frame buffer start |
| 324 | */ |
| 325 | int vidconsole_sync_copy(struct udevice *dev, void *from, void *to); |
| 326 | |
| 327 | /** |
| 328 | * vidconsole_memmove() - Perform a memmove() within the frame buffer |
| 329 | * |
| 330 | * This handles a memmove(), e.g. for scrolling. It also updates the copy |
| 331 | * framebuffer. |
| 332 | * |
| 333 | * @dev: Vidconsole device being updated |
| 334 | * @dst: Destination address within the framebuffer (->fb) |
| 335 | * @src: Source address within the framebuffer (->fb) |
| 336 | * @size: Number of bytes to transfer |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 337 | * 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] | 338 | * frame buffer start |
| 339 | */ |
| 340 | int vidconsole_memmove(struct udevice *dev, void *dst, const void *src, |
| 341 | int size); |
| 342 | #else |
Dzmitry Sankouski | aea2d2d | 2023-03-07 13:21:11 +0300 | [diff] [blame^] | 343 | |
| 344 | #include <string.h> |
| 345 | |
Simon Glass | 31a7e23 | 2020-07-02 21:12:23 -0600 | [diff] [blame] | 346 | static inline int vidconsole_sync_copy(struct udevice *dev, void *from, |
| 347 | void *to) |
| 348 | { |
| 349 | return 0; |
| 350 | } |
| 351 | |
| 352 | static inline int vidconsole_memmove(struct udevice *dev, void *dst, |
| 353 | const void *src, int size) |
| 354 | { |
| 355 | memmove(dst, src, size); |
| 356 | |
| 357 | return 0; |
| 358 | } |
| 359 | |
| 360 | #endif |
| 361 | |
Heinrich Schuchardt | 290e1d8 | 2018-02-08 21:47:11 +0100 | [diff] [blame] | 362 | #endif |