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