Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Simon Glass | 8351076 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2015 Google, Inc |
Simon Glass | 8351076 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #ifndef __video_console_h |
| 7 | #define __video_console_h |
| 8 | |
Heinrich Schuchardt | 5c30fbb | 2018-02-08 21:47:11 +0100 | [diff] [blame] | 9 | #include <video.h> |
| 10 | |
Simon Glass | 2d7c268 | 2020-07-02 21:12:18 -0600 | [diff] [blame] | 11 | struct video_priv; |
| 12 | |
Simon Glass | f266178 | 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 | 8351076 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 18 | /** |
| 19 | * struct vidconsole_priv - uclass-private data about a console device |
| 20 | * |
Simon Glass | f266178 | 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 | 662f381 | 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 | f266178 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 31 | * @tab_width_frac: Tab width in fractional units |
Heinrich Schuchardt | 662f381 | 2018-09-19 21:31:48 +0200 | [diff] [blame] | 32 | * @xsize_frac: Width of the display in fractional units |
Simon Glass | c5b77d0 | 2016-01-14 18:10:39 -0700 | [diff] [blame] | 33 | * @xstart_frac: Left margin for the text console in fractional units |
Heinrich Schuchardt | 662f381 | 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 | 8351076 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 40 | */ |
| 41 | struct vidconsole_priv { |
| 42 | struct stdio_dev sdev; |
Simon Glass | f266178 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 43 | int xcur_frac; |
| 44 | int ycur; |
Simon Glass | 8351076 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 45 | int rows; |
| 46 | int cols; |
Simon Glass | f266178 | 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 | c5b77d0 | 2016-01-14 18:10:39 -0700 | [diff] [blame] | 51 | int xstart_frac; |
Simon Glass | 58c733a | 2016-01-14 18:10:40 -0700 | [diff] [blame] | 52 | int last_ch; |
Rob Clark | a085aa1 | 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 | 662f381 | 2018-09-19 21:31:48 +0200 | [diff] [blame] | 60 | int row_saved; |
| 61 | int col_saved; |
Rob Clark | a085aa1 | 2017-09-13 18:12:21 -0400 | [diff] [blame] | 62 | char escape_buf[32]; |
Simon Glass | 8351076 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | /** |
| 66 | * struct vidconsole_ops - Video console operations |
| 67 | * |
| 68 | * These operations work on either an absolute console position (measured |
| 69 | * in pixels) or a text row number (measured in rows, where each row consists |
| 70 | * of an entire line of text - typically 16 pixels). |
| 71 | */ |
| 72 | struct vidconsole_ops { |
| 73 | /** |
| 74 | * putc_xy() - write a single character to a position |
| 75 | * |
| 76 | * @dev: Device to write to |
Simon Glass | f266178 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 77 | * @x_frac: Fractional pixel X position (0=left-most pixel) which |
| 78 | * is the X position multipled by VID_FRAC_DIV. |
Simon Glass | 8351076 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 79 | * @y: Pixel Y position (0=top-most pixel) |
| 80 | * @ch: Character to write |
Simon Glass | f266178 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 81 | * @return number of fractional pixels that the cursor should move, |
| 82 | * if all is OK, -EAGAIN if we ran out of space on this line, other -ve |
| 83 | * on error |
Simon Glass | 8351076 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 84 | */ |
Simon Glass | f266178 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 85 | int (*putc_xy)(struct udevice *dev, uint x_frac, uint y, char ch); |
Simon Glass | 8351076 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 86 | |
| 87 | /** |
| 88 | * move_rows() - Move text rows from one place to another |
| 89 | * |
| 90 | * @dev: Device to adjust |
| 91 | * @rowdst: Destination text row (0=top) |
| 92 | * @rowsrc: Source start text row |
| 93 | * @count: Number of text rows to move |
| 94 | * @return 0 if OK, -ve on error |
| 95 | */ |
| 96 | int (*move_rows)(struct udevice *dev, uint rowdst, uint rowsrc, |
| 97 | uint count); |
| 98 | |
| 99 | /** |
| 100 | * set_row() - Set the colour of a text row |
| 101 | * |
| 102 | * Every pixel contained within the text row is adjusted |
| 103 | * |
| 104 | * @dev: Device to adjust |
| 105 | * @row: Text row to adjust (0=top) |
| 106 | * @clr: Raw colour (pixel value) to write to each pixel |
| 107 | * @return 0 if OK, -ve on error |
| 108 | */ |
| 109 | int (*set_row)(struct udevice *dev, uint row, int clr); |
Simon Glass | 58c733a | 2016-01-14 18:10:40 -0700 | [diff] [blame] | 110 | |
| 111 | /** |
| 112 | * entry_start() - Indicate that text entry is starting afresh |
| 113 | * |
| 114 | * Consoles which use proportional fonts need to track the position of |
| 115 | * each character output so that backspace will return to the correct |
| 116 | * place. This method signals to the console driver that a new entry |
| 117 | * line is being start (e.g. the user pressed return to start a new |
| 118 | * command). The driver can use this signal to empty its list of |
| 119 | * positions. |
| 120 | */ |
| 121 | int (*entry_start)(struct udevice *dev); |
Simon Glass | 7b9f7e4 | 2016-01-14 18:10:41 -0700 | [diff] [blame] | 122 | |
| 123 | /** |
| 124 | * backspace() - Handle erasing the last character |
| 125 | * |
| 126 | * With proportional fonts the vidconsole uclass cannot itself erase |
| 127 | * the previous character. This optional method will be called when |
| 128 | * a backspace is needed. The driver should erase the previous |
| 129 | * character and update the cursor position (xcur_frac, ycur) to the |
| 130 | * start of the previous character. |
| 131 | * |
| 132 | * If not implement, default behaviour will work for fixed-width |
| 133 | * characters. |
| 134 | */ |
| 135 | int (*backspace)(struct udevice *dev); |
Simon Glass | 8351076 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 136 | }; |
| 137 | |
| 138 | /* Get a pointer to the driver operations for a video console device */ |
| 139 | #define vidconsole_get_ops(dev) ((struct vidconsole_ops *)(dev)->driver->ops) |
| 140 | |
| 141 | /** |
| 142 | * vidconsole_putc_xy() - write a single character to a position |
| 143 | * |
| 144 | * @dev: Device to write to |
Simon Glass | f266178 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 145 | * @x_frac: Fractional pixel X position (0=left-most pixel) which |
| 146 | * is the X position multipled by VID_FRAC_DIV. |
Simon Glass | 8351076 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 147 | * @y: Pixel Y position (0=top-most pixel) |
| 148 | * @ch: Character to write |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 149 | * Return: number of fractional pixels that the cursor should move, |
Simon Glass | f266178 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 150 | * if all is OK, -EAGAIN if we ran out of space on this line, other -ve |
| 151 | * on error |
Simon Glass | 8351076 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 152 | */ |
| 153 | int vidconsole_putc_xy(struct udevice *dev, uint x, uint y, char ch); |
| 154 | |
| 155 | /** |
| 156 | * vidconsole_move_rows() - Move text rows from one place to another |
| 157 | * |
| 158 | * @dev: Device to adjust |
| 159 | * @rowdst: Destination text row (0=top) |
| 160 | * @rowsrc: Source start text row |
| 161 | * @count: Number of text rows to move |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 162 | * Return: 0 if OK, -ve on error |
Simon Glass | 8351076 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 163 | */ |
| 164 | int vidconsole_move_rows(struct udevice *dev, uint rowdst, uint rowsrc, |
| 165 | uint count); |
| 166 | |
| 167 | /** |
| 168 | * vidconsole_set_row() - Set the colour of a text row |
| 169 | * |
| 170 | * Every pixel contained within the text row is adjusted |
| 171 | * |
| 172 | * @dev: Device to adjust |
| 173 | * @row: Text row to adjust (0=top) |
| 174 | * @clr: Raw colour (pixel value) to write to each pixel |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 175 | * Return: 0 if OK, -ve on error |
Simon Glass | 8351076 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 176 | */ |
| 177 | int vidconsole_set_row(struct udevice *dev, uint row, int clr); |
| 178 | |
| 179 | /** |
| 180 | * vidconsole_put_char() - Output a character to the current console position |
| 181 | * |
| 182 | * Outputs a character to the console and advances the cursor. This function |
| 183 | * handles wrapping to new lines and scrolling the console. Special |
| 184 | * characters are handled also: \n, \r, \b and \t. |
| 185 | * |
| 186 | * The device always starts with the cursor at position 0,0 (top left). It |
| 187 | * can be adjusted manually using vidconsole_position_cursor(). |
| 188 | * |
| 189 | * @dev: Device to adjust |
| 190 | * @ch: Character to write |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 191 | * Return: 0 if OK, -ve on error |
Simon Glass | 8351076 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 192 | */ |
| 193 | int vidconsole_put_char(struct udevice *dev, char ch); |
| 194 | |
| 195 | /** |
Marek Vasut | e63168a | 2019-05-17 20:22:31 +0200 | [diff] [blame] | 196 | * vidconsole_put_string() - Output a string to the current console position |
| 197 | * |
| 198 | * Outputs a string to the console and advances the cursor. This function |
| 199 | * handles wrapping to new lines and scrolling the console. Special |
| 200 | * characters are handled also: \n, \r, \b and \t. |
| 201 | * |
| 202 | * The device always starts with the cursor at position 0,0 (top left). It |
| 203 | * can be adjusted manually using vidconsole_position_cursor(). |
| 204 | * |
| 205 | * @dev: Device to adjust |
| 206 | * @str: String to write |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 207 | * Return: 0 if OK, -ve on error |
Marek Vasut | e63168a | 2019-05-17 20:22:31 +0200 | [diff] [blame] | 208 | */ |
| 209 | int vidconsole_put_string(struct udevice *dev, const char *str); |
| 210 | |
| 211 | /** |
Simon Glass | 8351076 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 212 | * vidconsole_position_cursor() - Move the text cursor |
| 213 | * |
| 214 | * @dev: Device to adjust |
| 215 | * @col: New cursor text column |
| 216 | * @row: New cursor text row |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 217 | * Return: 0 if OK, -ve on error |
Simon Glass | 8351076 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 218 | */ |
| 219 | void vidconsole_position_cursor(struct udevice *dev, unsigned col, |
| 220 | unsigned row); |
| 221 | |
Simon Glass | 6b6dc0d | 2022-10-06 08:36:04 -0600 | [diff] [blame] | 222 | /** |
| 223 | * vidconsole_set_cursor_pos() - set cursor position |
| 224 | * |
| 225 | * The cursor is set to the new position and the start-of-line information is |
| 226 | * updated to the same position, so that a newline will return to @x |
| 227 | * |
| 228 | * @dev: video console device to update |
| 229 | * @x: x position from left in pixels |
| 230 | * @y: y position from top in pixels |
| 231 | */ |
| 232 | void vidconsole_set_cursor_pos(struct udevice *dev, int x, int y); |
| 233 | |
Simon Glass | 57a847c | 2022-10-06 08:36:14 -0600 | [diff] [blame] | 234 | /** |
| 235 | * vidconsole_list_fonts() - List the available fonts |
| 236 | * |
| 237 | * This shows a list on the console |
| 238 | */ |
| 239 | void vidconsole_list_fonts(void); |
| 240 | |
| 241 | /** |
| 242 | * vidconsole_select_font() - Select a font to use |
| 243 | * |
| 244 | * @dev: vidconsole device |
| 245 | * @name: Font name |
| 246 | * @size: Size of the font (norminal pixel height) or 0 for default |
| 247 | */ |
| 248 | int vidconsole_select_font(struct udevice *dev, const char *name, uint size); |
| 249 | |
Simon Glass | 430e167 | 2022-10-06 08:36:16 -0600 | [diff] [blame] | 250 | /** |
| 251 | * vidconsole_get_font() - get the current font name and size |
| 252 | * |
| 253 | * @dev: vidconsole device |
| 254 | * @sizep: Place to put the font size (nominal height in pixels) |
| 255 | * Returns: Current font name |
| 256 | */ |
| 257 | const char *vidconsole_get_font(struct udevice *dev, uint *sizep); |
| 258 | |
Simon Glass | 8c0b5d2 | 2020-07-02 21:12:23 -0600 | [diff] [blame] | 259 | #ifdef CONFIG_VIDEO_COPY |
| 260 | /** |
| 261 | * vidconsole_sync_copy() - Sync back to the copy framebuffer |
| 262 | * |
| 263 | * This ensures that the copy framebuffer has the same data as the framebuffer |
| 264 | * for a particular region. It should be called after the framebuffer is updated |
| 265 | * |
| 266 | * @from and @to can be in either order. The region between them is synced. |
| 267 | * |
| 268 | * @dev: Vidconsole device being updated |
| 269 | * @from: Start/end address within the framebuffer (->fb) |
| 270 | * @to: Other address within the frame buffer |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 271 | * Return: 0 if OK, -EFAULT if the start address is before the start of the |
Simon Glass | 8c0b5d2 | 2020-07-02 21:12:23 -0600 | [diff] [blame] | 272 | * frame buffer start |
| 273 | */ |
| 274 | int vidconsole_sync_copy(struct udevice *dev, void *from, void *to); |
| 275 | |
| 276 | /** |
| 277 | * vidconsole_memmove() - Perform a memmove() within the frame buffer |
| 278 | * |
| 279 | * This handles a memmove(), e.g. for scrolling. It also updates the copy |
| 280 | * framebuffer. |
| 281 | * |
| 282 | * @dev: Vidconsole device being updated |
| 283 | * @dst: Destination address within the framebuffer (->fb) |
| 284 | * @src: Source address within the framebuffer (->fb) |
| 285 | * @size: Number of bytes to transfer |
Heinrich Schuchardt | 185f812 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 286 | * Return: 0 if OK, -EFAULT if the start address is before the start of the |
Simon Glass | 8c0b5d2 | 2020-07-02 21:12:23 -0600 | [diff] [blame] | 287 | * frame buffer start |
| 288 | */ |
| 289 | int vidconsole_memmove(struct udevice *dev, void *dst, const void *src, |
| 290 | int size); |
| 291 | #else |
| 292 | static inline int vidconsole_sync_copy(struct udevice *dev, void *from, |
| 293 | void *to) |
| 294 | { |
| 295 | return 0; |
| 296 | } |
| 297 | |
| 298 | static inline int vidconsole_memmove(struct udevice *dev, void *dst, |
| 299 | const void *src, int size) |
| 300 | { |
| 301 | memmove(dst, src, size); |
| 302 | |
| 303 | return 0; |
| 304 | } |
| 305 | |
| 306 | #endif |
| 307 | |
Heinrich Schuchardt | 5c30fbb | 2018-02-08 21:47:11 +0100 | [diff] [blame] | 308 | #endif |