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 | |
Simon Glass | f266178 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 10 | #define VID_FRAC_DIV 256 |
| 11 | |
| 12 | #define VID_TO_PIXEL(x) ((x) / VID_FRAC_DIV) |
| 13 | #define VID_TO_POS(x) ((x) * VID_FRAC_DIV) |
| 14 | |
Simon Glass | 8351076 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 15 | /** |
| 16 | * struct vidconsole_priv - uclass-private data about a console device |
| 17 | * |
Simon Glass | f266178 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 18 | * Drivers must set up @rows, @cols, @x_charsize, @y_charsize in their probe() |
| 19 | * method. Drivers may set up @xstart_frac if desired. |
| 20 | * |
Simon Glass | 8351076 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 21 | * @sdev: stdio device, acting as an output sink |
Simon Glass | f266178 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 22 | * @xcur_frac: Current X position, in fractional units (VID_TO_POS(x)) |
| 23 | * @curr_row: Current Y position in pixels (0=top) |
Simon Glass | 8351076 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 24 | * @rows: Number of text rows |
| 25 | * @cols: Number of text columns |
Simon Glass | f266178 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 26 | * @x_charsize: Character width in pixels |
| 27 | * @y_charsize: Character height in pixels |
| 28 | * @tab_width_frac: Tab width in fractional units |
| 29 | * @xsize_frac: Width of the display in fractional units |
Simon Glass | c5b77d0 | 2016-01-14 18:10:39 -0700 | [diff] [blame] | 30 | * @xstart_frac: Left margin for the text console in fractional units |
Simon Glass | 58c733a | 2016-01-14 18:10:40 -0700 | [diff] [blame] | 31 | * @last_ch: Last character written to the text console on this line |
Simon Glass | 8351076 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 32 | */ |
| 33 | struct vidconsole_priv { |
| 34 | struct stdio_dev sdev; |
Simon Glass | f266178 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 35 | int xcur_frac; |
| 36 | int ycur; |
Simon Glass | 8351076 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 37 | int rows; |
| 38 | int cols; |
Simon Glass | f266178 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 39 | int x_charsize; |
| 40 | int y_charsize; |
| 41 | int tab_width_frac; |
| 42 | int xsize_frac; |
Simon Glass | c5b77d0 | 2016-01-14 18:10:39 -0700 | [diff] [blame] | 43 | int xstart_frac; |
Simon Glass | 58c733a | 2016-01-14 18:10:40 -0700 | [diff] [blame] | 44 | int last_ch; |
Simon Glass | 8351076 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 45 | }; |
| 46 | |
| 47 | /** |
| 48 | * struct vidconsole_ops - Video console operations |
| 49 | * |
| 50 | * These operations work on either an absolute console position (measured |
| 51 | * in pixels) or a text row number (measured in rows, where each row consists |
| 52 | * of an entire line of text - typically 16 pixels). |
| 53 | */ |
| 54 | struct vidconsole_ops { |
| 55 | /** |
| 56 | * putc_xy() - write a single character to a position |
| 57 | * |
| 58 | * @dev: Device to write to |
Simon Glass | f266178 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 59 | * @x_frac: Fractional pixel X position (0=left-most pixel) which |
| 60 | * is the X position multipled by VID_FRAC_DIV. |
Simon Glass | 8351076 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 61 | * @y: Pixel Y position (0=top-most pixel) |
| 62 | * @ch: Character to write |
Simon Glass | f266178 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 63 | * @return number of fractional pixels that the cursor should move, |
| 64 | * if all is OK, -EAGAIN if we ran out of space on this line, other -ve |
| 65 | * on error |
Simon Glass | 8351076 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 66 | */ |
Simon Glass | f266178 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 67 | 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] | 68 | |
| 69 | /** |
| 70 | * move_rows() - Move text rows from one place to another |
| 71 | * |
| 72 | * @dev: Device to adjust |
| 73 | * @rowdst: Destination text row (0=top) |
| 74 | * @rowsrc: Source start text row |
| 75 | * @count: Number of text rows to move |
| 76 | * @return 0 if OK, -ve on error |
| 77 | */ |
| 78 | int (*move_rows)(struct udevice *dev, uint rowdst, uint rowsrc, |
| 79 | uint count); |
| 80 | |
| 81 | /** |
| 82 | * set_row() - Set the colour of a text row |
| 83 | * |
| 84 | * Every pixel contained within the text row is adjusted |
| 85 | * |
| 86 | * @dev: Device to adjust |
| 87 | * @row: Text row to adjust (0=top) |
| 88 | * @clr: Raw colour (pixel value) to write to each pixel |
| 89 | * @return 0 if OK, -ve on error |
| 90 | */ |
| 91 | int (*set_row)(struct udevice *dev, uint row, int clr); |
Simon Glass | 58c733a | 2016-01-14 18:10:40 -0700 | [diff] [blame] | 92 | |
| 93 | /** |
| 94 | * entry_start() - Indicate that text entry is starting afresh |
| 95 | * |
| 96 | * Consoles which use proportional fonts need to track the position of |
| 97 | * each character output so that backspace will return to the correct |
| 98 | * place. This method signals to the console driver that a new entry |
| 99 | * line is being start (e.g. the user pressed return to start a new |
| 100 | * command). The driver can use this signal to empty its list of |
| 101 | * positions. |
| 102 | */ |
| 103 | int (*entry_start)(struct udevice *dev); |
Simon Glass | 7b9f7e4 | 2016-01-14 18:10:41 -0700 | [diff] [blame] | 104 | |
| 105 | /** |
| 106 | * backspace() - Handle erasing the last character |
| 107 | * |
| 108 | * With proportional fonts the vidconsole uclass cannot itself erase |
| 109 | * the previous character. This optional method will be called when |
| 110 | * a backspace is needed. The driver should erase the previous |
| 111 | * character and update the cursor position (xcur_frac, ycur) to the |
| 112 | * start of the previous character. |
| 113 | * |
| 114 | * If not implement, default behaviour will work for fixed-width |
| 115 | * characters. |
| 116 | */ |
| 117 | int (*backspace)(struct udevice *dev); |
Simon Glass | 8351076 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | /* Get a pointer to the driver operations for a video console device */ |
| 121 | #define vidconsole_get_ops(dev) ((struct vidconsole_ops *)(dev)->driver->ops) |
| 122 | |
| 123 | /** |
| 124 | * vidconsole_putc_xy() - write a single character to a position |
| 125 | * |
| 126 | * @dev: Device to write to |
Simon Glass | f266178 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 127 | * @x_frac: Fractional pixel X position (0=left-most pixel) which |
| 128 | * is the X position multipled by VID_FRAC_DIV. |
Simon Glass | 8351076 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 129 | * @y: Pixel Y position (0=top-most pixel) |
| 130 | * @ch: Character to write |
Simon Glass | f266178 | 2016-01-14 18:10:37 -0700 | [diff] [blame] | 131 | * @return number of fractional pixels that the cursor should move, |
| 132 | * if all is OK, -EAGAIN if we ran out of space on this line, other -ve |
| 133 | * on error |
Simon Glass | 8351076 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 134 | */ |
| 135 | int vidconsole_putc_xy(struct udevice *dev, uint x, uint y, char ch); |
| 136 | |
| 137 | /** |
| 138 | * vidconsole_move_rows() - Move text rows from one place to another |
| 139 | * |
| 140 | * @dev: Device to adjust |
| 141 | * @rowdst: Destination text row (0=top) |
| 142 | * @rowsrc: Source start text row |
| 143 | * @count: Number of text rows to move |
| 144 | * @return 0 if OK, -ve on error |
| 145 | */ |
| 146 | int vidconsole_move_rows(struct udevice *dev, uint rowdst, uint rowsrc, |
| 147 | uint count); |
| 148 | |
| 149 | /** |
| 150 | * vidconsole_set_row() - Set the colour of a text row |
| 151 | * |
| 152 | * Every pixel contained within the text row is adjusted |
| 153 | * |
| 154 | * @dev: Device to adjust |
| 155 | * @row: Text row to adjust (0=top) |
| 156 | * @clr: Raw colour (pixel value) to write to each pixel |
| 157 | * @return 0 if OK, -ve on error |
| 158 | */ |
| 159 | int vidconsole_set_row(struct udevice *dev, uint row, int clr); |
| 160 | |
| 161 | /** |
| 162 | * vidconsole_put_char() - Output a character to the current console position |
| 163 | * |
| 164 | * Outputs a character to the console and advances the cursor. This function |
| 165 | * handles wrapping to new lines and scrolling the console. Special |
| 166 | * characters are handled also: \n, \r, \b and \t. |
| 167 | * |
| 168 | * The device always starts with the cursor at position 0,0 (top left). It |
| 169 | * can be adjusted manually using vidconsole_position_cursor(). |
| 170 | * |
| 171 | * @dev: Device to adjust |
| 172 | * @ch: Character to write |
| 173 | * @return 0 if OK, -ve on error |
| 174 | */ |
| 175 | int vidconsole_put_char(struct udevice *dev, char ch); |
| 176 | |
| 177 | /** |
| 178 | * vidconsole_position_cursor() - Move the text cursor |
| 179 | * |
| 180 | * @dev: Device to adjust |
| 181 | * @col: New cursor text column |
| 182 | * @row: New cursor text row |
| 183 | * @return 0 if OK, -ve on error |
| 184 | */ |
| 185 | void vidconsole_position_cursor(struct udevice *dev, unsigned col, |
| 186 | unsigned row); |
| 187 | |
| 188 | #endif |