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