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 | |
Heinrich Schuchardt | 290e1d8 | 2018-02-08 21:47:11 +0100 | [diff] [blame] | 18 | /* |
Heinrich Schuchardt | 2a436db | 2018-02-08 21:47:12 +0100 | [diff] [blame] | 19 | * The 16 colors supported by the console |
Heinrich Schuchardt | 290e1d8 | 2018-02-08 21:47:11 +0100 | [diff] [blame] | 20 | */ |
| 21 | enum color_idx { |
| 22 | VID_BLACK = 0, |
| 23 | VID_RED, |
| 24 | VID_GREEN, |
Heinrich Schuchardt | 2a436db | 2018-02-08 21:47:12 +0100 | [diff] [blame] | 25 | VID_BROWN, |
Heinrich Schuchardt | 290e1d8 | 2018-02-08 21:47:11 +0100 | [diff] [blame] | 26 | VID_BLUE, |
| 27 | VID_MAGENTA, |
| 28 | VID_CYAN, |
Heinrich Schuchardt | 2a436db | 2018-02-08 21:47:12 +0100 | [diff] [blame] | 29 | VID_LIGHT_GRAY, |
| 30 | VID_GRAY, |
| 31 | VID_LIGHT_RED, |
| 32 | VID_LIGTH_GREEN, |
| 33 | VID_YELLOW, |
| 34 | VID_LIGHT_BLUE, |
| 35 | VID_LIGHT_MAGENTA, |
| 36 | VID_LIGHT_CYAN, |
Heinrich Schuchardt | 290e1d8 | 2018-02-08 21:47:11 +0100 | [diff] [blame] | 37 | VID_WHITE, |
| 38 | |
| 39 | VID_COLOR_COUNT |
| 40 | }; |
| 41 | |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 42 | /** |
| 43 | * struct vidconsole_priv - uclass-private data about a console device |
| 44 | * |
Simon Glass | 52c10c5 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 45 | * Drivers must set up @rows, @cols, @x_charsize, @y_charsize in their probe() |
| 46 | * method. Drivers may set up @xstart_frac if desired. |
| 47 | * |
Heinrich Schuchardt | 9e933f1 | 2018-09-19 21:31:48 +0200 | [diff] [blame] | 48 | * @sdev: stdio device, acting as an output sink |
| 49 | * @xcur_frac: Current X position, in fractional units (VID_TO_POS(x)) |
| 50 | * @ycur: Current Y position in pixels (0=top) |
| 51 | * @rows: Number of text rows |
| 52 | * @cols: Number of text columns |
| 53 | * @x_charsize: Character width in pixels |
| 54 | * @y_charsize: Character height in pixels |
Simon Glass | 52c10c5 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 55 | * @tab_width_frac: Tab width in fractional units |
Heinrich Schuchardt | 9e933f1 | 2018-09-19 21:31:48 +0200 | [diff] [blame] | 56 | * @xsize_frac: Width of the display in fractional units |
Simon Glass | a74451d | 2016-01-14 18:10:39 -0700 | [diff] [blame] | 57 | * @xstart_frac: Left margin for the text console in fractional units |
Heinrich Schuchardt | 9e933f1 | 2018-09-19 21:31:48 +0200 | [diff] [blame] | 58 | * @last_ch: Last character written to the text console on this line |
| 59 | * @escape: TRUE if currently accumulating an ANSI escape sequence |
| 60 | * @escape_len: Length of accumulated escape sequence so far |
| 61 | * @col_saved: Saved X position, in fractional units (VID_TO_POS(x)) |
| 62 | * @row_saved: Saved Y position in pixels (0=top) |
| 63 | * @escape_buf: Buffer to accumulate escape sequence |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 64 | */ |
| 65 | struct vidconsole_priv { |
| 66 | struct stdio_dev sdev; |
Simon Glass | 52c10c5 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 67 | int xcur_frac; |
| 68 | int ycur; |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 69 | int rows; |
| 70 | int cols; |
Simon Glass | 52c10c5 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 71 | int x_charsize; |
| 72 | int y_charsize; |
| 73 | int tab_width_frac; |
| 74 | int xsize_frac; |
Simon Glass | a74451d | 2016-01-14 18:10:39 -0700 | [diff] [blame] | 75 | int xstart_frac; |
Simon Glass | afee743 | 2016-01-14 18:10:40 -0700 | [diff] [blame] | 76 | int last_ch; |
Rob Clark | 06e7a0d | 2017-09-13 18:12:21 -0400 | [diff] [blame] | 77 | /* |
| 78 | * ANSI escape sequences are accumulated character by character, |
| 79 | * starting after the ESC char (0x1b) until the entire sequence |
| 80 | * is consumed at which point it is acted upon. |
| 81 | */ |
| 82 | int escape; |
| 83 | int escape_len; |
Heinrich Schuchardt | 9e933f1 | 2018-09-19 21:31:48 +0200 | [diff] [blame] | 84 | int row_saved; |
| 85 | int col_saved; |
Rob Clark | 06e7a0d | 2017-09-13 18:12:21 -0400 | [diff] [blame] | 86 | char escape_buf[32]; |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | /** |
| 90 | * struct vidconsole_ops - Video console operations |
| 91 | * |
| 92 | * These operations work on either an absolute console position (measured |
| 93 | * in pixels) or a text row number (measured in rows, where each row consists |
| 94 | * of an entire line of text - typically 16 pixels). |
| 95 | */ |
| 96 | struct vidconsole_ops { |
| 97 | /** |
| 98 | * putc_xy() - write a single character to a position |
| 99 | * |
| 100 | * @dev: Device to write to |
Simon Glass | 52c10c5 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 101 | * @x_frac: Fractional pixel X position (0=left-most pixel) which |
| 102 | * is the X position multipled by VID_FRAC_DIV. |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 103 | * @y: Pixel Y position (0=top-most pixel) |
| 104 | * @ch: Character to write |
Simon Glass | 52c10c5 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 105 | * @return number of fractional pixels that the cursor should move, |
| 106 | * if all is OK, -EAGAIN if we ran out of space on this line, other -ve |
| 107 | * on error |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 108 | */ |
Simon Glass | 52c10c5 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 109 | 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] | 110 | |
| 111 | /** |
| 112 | * move_rows() - Move text rows from one place to another |
| 113 | * |
| 114 | * @dev: Device to adjust |
| 115 | * @rowdst: Destination text row (0=top) |
| 116 | * @rowsrc: Source start text row |
| 117 | * @count: Number of text rows to move |
| 118 | * @return 0 if OK, -ve on error |
| 119 | */ |
| 120 | int (*move_rows)(struct udevice *dev, uint rowdst, uint rowsrc, |
| 121 | uint count); |
| 122 | |
| 123 | /** |
| 124 | * set_row() - Set the colour of a text row |
| 125 | * |
| 126 | * Every pixel contained within the text row is adjusted |
| 127 | * |
| 128 | * @dev: Device to adjust |
| 129 | * @row: Text row to adjust (0=top) |
| 130 | * @clr: Raw colour (pixel value) to write to each pixel |
| 131 | * @return 0 if OK, -ve on error |
| 132 | */ |
| 133 | int (*set_row)(struct udevice *dev, uint row, int clr); |
Simon Glass | afee743 | 2016-01-14 18:10:40 -0700 | [diff] [blame] | 134 | |
| 135 | /** |
| 136 | * entry_start() - Indicate that text entry is starting afresh |
| 137 | * |
| 138 | * Consoles which use proportional fonts need to track the position of |
| 139 | * each character output so that backspace will return to the correct |
| 140 | * place. This method signals to the console driver that a new entry |
| 141 | * line is being start (e.g. the user pressed return to start a new |
| 142 | * command). The driver can use this signal to empty its list of |
| 143 | * positions. |
| 144 | */ |
| 145 | int (*entry_start)(struct udevice *dev); |
Simon Glass | 33bd3b6 | 2016-01-14 18:10:41 -0700 | [diff] [blame] | 146 | |
| 147 | /** |
| 148 | * backspace() - Handle erasing the last character |
| 149 | * |
| 150 | * With proportional fonts the vidconsole uclass cannot itself erase |
| 151 | * the previous character. This optional method will be called when |
| 152 | * a backspace is needed. The driver should erase the previous |
| 153 | * character and update the cursor position (xcur_frac, ycur) to the |
| 154 | * start of the previous character. |
| 155 | * |
| 156 | * If not implement, default behaviour will work for fixed-width |
| 157 | * characters. |
| 158 | */ |
| 159 | int (*backspace)(struct udevice *dev); |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 160 | }; |
| 161 | |
| 162 | /* Get a pointer to the driver operations for a video console device */ |
| 163 | #define vidconsole_get_ops(dev) ((struct vidconsole_ops *)(dev)->driver->ops) |
| 164 | |
| 165 | /** |
| 166 | * vidconsole_putc_xy() - write a single character to a position |
| 167 | * |
| 168 | * @dev: Device to write to |
Simon Glass | 52c10c5 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 169 | * @x_frac: Fractional pixel X position (0=left-most pixel) which |
| 170 | * is the X position multipled by VID_FRAC_DIV. |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 171 | * @y: Pixel Y position (0=top-most pixel) |
| 172 | * @ch: Character to write |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 173 | * Return: number of fractional pixels that the cursor should move, |
Simon Glass | 52c10c5 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 174 | * if all is OK, -EAGAIN if we ran out of space on this line, other -ve |
| 175 | * on error |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 176 | */ |
| 177 | int vidconsole_putc_xy(struct udevice *dev, uint x, uint y, char ch); |
| 178 | |
| 179 | /** |
| 180 | * vidconsole_move_rows() - Move text rows from one place to another |
| 181 | * |
| 182 | * @dev: Device to adjust |
| 183 | * @rowdst: Destination text row (0=top) |
| 184 | * @rowsrc: Source start text row |
| 185 | * @count: Number of text rows to move |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 186 | * Return: 0 if OK, -ve on error |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 187 | */ |
| 188 | int vidconsole_move_rows(struct udevice *dev, uint rowdst, uint rowsrc, |
| 189 | uint count); |
| 190 | |
| 191 | /** |
| 192 | * vidconsole_set_row() - Set the colour of a text row |
| 193 | * |
| 194 | * Every pixel contained within the text row is adjusted |
| 195 | * |
| 196 | * @dev: Device to adjust |
| 197 | * @row: Text row to adjust (0=top) |
| 198 | * @clr: Raw colour (pixel value) to write to each pixel |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 199 | * Return: 0 if OK, -ve on error |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 200 | */ |
| 201 | int vidconsole_set_row(struct udevice *dev, uint row, int clr); |
| 202 | |
| 203 | /** |
| 204 | * vidconsole_put_char() - Output a character to the current console position |
| 205 | * |
| 206 | * Outputs a character to the console and advances the cursor. This function |
| 207 | * handles wrapping to new lines and scrolling the console. Special |
| 208 | * characters are handled also: \n, \r, \b and \t. |
| 209 | * |
| 210 | * The device always starts with the cursor at position 0,0 (top left). It |
| 211 | * can be adjusted manually using vidconsole_position_cursor(). |
| 212 | * |
| 213 | * @dev: Device to adjust |
| 214 | * @ch: Character to write |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 215 | * Return: 0 if OK, -ve on error |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 216 | */ |
| 217 | int vidconsole_put_char(struct udevice *dev, char ch); |
| 218 | |
| 219 | /** |
Marek Vasut | a89f9cb | 2019-05-17 20:22:31 +0200 | [diff] [blame] | 220 | * vidconsole_put_string() - Output a string to the current console position |
| 221 | * |
| 222 | * Outputs a string to the console and advances the cursor. This function |
| 223 | * handles wrapping to new lines and scrolling the console. Special |
| 224 | * characters are handled also: \n, \r, \b and \t. |
| 225 | * |
| 226 | * The device always starts with the cursor at position 0,0 (top left). It |
| 227 | * can be adjusted manually using vidconsole_position_cursor(). |
| 228 | * |
| 229 | * @dev: Device to adjust |
| 230 | * @str: String to write |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 231 | * Return: 0 if OK, -ve on error |
Marek Vasut | a89f9cb | 2019-05-17 20:22:31 +0200 | [diff] [blame] | 232 | */ |
| 233 | int vidconsole_put_string(struct udevice *dev, const char *str); |
| 234 | |
| 235 | /** |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 236 | * vidconsole_position_cursor() - Move the text cursor |
| 237 | * |
| 238 | * @dev: Device to adjust |
| 239 | * @col: New cursor text column |
| 240 | * @row: New cursor text row |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 241 | * Return: 0 if OK, -ve on error |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 242 | */ |
| 243 | void vidconsole_position_cursor(struct udevice *dev, unsigned col, |
| 244 | unsigned row); |
| 245 | |
Heinrich Schuchardt | 290e1d8 | 2018-02-08 21:47:11 +0100 | [diff] [blame] | 246 | /** |
| 247 | * vid_console_color() - convert a color code to a pixel's internal |
| 248 | * representation |
| 249 | * |
| 250 | * The caller has to guarantee that the color index is less than |
| 251 | * VID_COLOR_COUNT. |
| 252 | * |
| 253 | * @priv private data of the console device |
| 254 | * @idx color index |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 255 | * Return: color value |
Heinrich Schuchardt | 290e1d8 | 2018-02-08 21:47:11 +0100 | [diff] [blame] | 256 | */ |
| 257 | u32 vid_console_color(struct video_priv *priv, unsigned int idx); |
| 258 | |
Simon Glass | 31a7e23 | 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 | 47b4c02 | 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 | 31a7e23 | 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 | 47b4c02 | 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 | 31a7e23 | 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 | 290e1d8 | 2018-02-08 21:47:11 +0100 | [diff] [blame] | 308 | #endif |