2 * Copyright (c) 2015 Google, Inc
4 * SPDX-License-Identifier: GPL-2.0+
7 #ifndef __video_console_h
8 #define __video_console_h
10 #define VID_FRAC_DIV 256
12 #define VID_TO_PIXEL(x) ((x) / VID_FRAC_DIV)
13 #define VID_TO_POS(x) ((x) * VID_FRAC_DIV)
16 * struct vidconsole_priv - uclass-private data about a console device
18 * Drivers must set up @rows, @cols, @x_charsize, @y_charsize in their probe()
19 * method. Drivers may set up @xstart_frac if desired.
21 * @sdev: stdio device, acting as an output sink
22 * @xcur_frac: Current X position, in fractional units (VID_TO_POS(x))
23 * @curr_row: Current Y position in pixels (0=top)
24 * @rows: Number of text rows
25 * @cols: Number of text columns
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
30 * @xstart_frac: Left margin for the text console in fractional units
31 * @last_ch: Last character written to the text console on this line
32 * @escape: TRUE if currently accumulating an ANSI escape sequence
33 * @escape_len: Length of accumulated escape sequence so far
34 * @escape_buf: Buffer to accumulate escape sequence
36 struct vidconsole_priv {
37 struct stdio_dev sdev;
49 * ANSI escape sequences are accumulated character by character,
50 * starting after the ESC char (0x1b) until the entire sequence
51 * is consumed at which point it is acted upon.
59 * struct vidconsole_ops - Video console operations
61 * These operations work on either an absolute console position (measured
62 * in pixels) or a text row number (measured in rows, where each row consists
63 * of an entire line of text - typically 16 pixels).
65 struct vidconsole_ops {
67 * putc_xy() - write a single character to a position
69 * @dev: Device to write to
70 * @x_frac: Fractional pixel X position (0=left-most pixel) which
71 * is the X position multipled by VID_FRAC_DIV.
72 * @y: Pixel Y position (0=top-most pixel)
73 * @ch: Character to write
74 * @return number of fractional pixels that the cursor should move,
75 * if all is OK, -EAGAIN if we ran out of space on this line, other -ve
78 int (*putc_xy)(struct udevice *dev, uint x_frac, uint y, char ch);
81 * move_rows() - Move text rows from one place to another
83 * @dev: Device to adjust
84 * @rowdst: Destination text row (0=top)
85 * @rowsrc: Source start text row
86 * @count: Number of text rows to move
87 * @return 0 if OK, -ve on error
89 int (*move_rows)(struct udevice *dev, uint rowdst, uint rowsrc,
93 * set_row() - Set the colour of a text row
95 * Every pixel contained within the text row is adjusted
97 * @dev: Device to adjust
98 * @row: Text row to adjust (0=top)
99 * @clr: Raw colour (pixel value) to write to each pixel
100 * @return 0 if OK, -ve on error
102 int (*set_row)(struct udevice *dev, uint row, int clr);
105 * entry_start() - Indicate that text entry is starting afresh
107 * Consoles which use proportional fonts need to track the position of
108 * each character output so that backspace will return to the correct
109 * place. This method signals to the console driver that a new entry
110 * line is being start (e.g. the user pressed return to start a new
111 * command). The driver can use this signal to empty its list of
114 int (*entry_start)(struct udevice *dev);
117 * backspace() - Handle erasing the last character
119 * With proportional fonts the vidconsole uclass cannot itself erase
120 * the previous character. This optional method will be called when
121 * a backspace is needed. The driver should erase the previous
122 * character and update the cursor position (xcur_frac, ycur) to the
123 * start of the previous character.
125 * If not implement, default behaviour will work for fixed-width
128 int (*backspace)(struct udevice *dev);
131 /* Get a pointer to the driver operations for a video console device */
132 #define vidconsole_get_ops(dev) ((struct vidconsole_ops *)(dev)->driver->ops)
135 * vidconsole_putc_xy() - write a single character to a position
137 * @dev: Device to write to
138 * @x_frac: Fractional pixel X position (0=left-most pixel) which
139 * is the X position multipled by VID_FRAC_DIV.
140 * @y: Pixel Y position (0=top-most pixel)
141 * @ch: Character to write
142 * @return number of fractional pixels that the cursor should move,
143 * if all is OK, -EAGAIN if we ran out of space on this line, other -ve
146 int vidconsole_putc_xy(struct udevice *dev, uint x, uint y, char ch);
149 * vidconsole_move_rows() - Move text rows from one place to another
151 * @dev: Device to adjust
152 * @rowdst: Destination text row (0=top)
153 * @rowsrc: Source start text row
154 * @count: Number of text rows to move
155 * @return 0 if OK, -ve on error
157 int vidconsole_move_rows(struct udevice *dev, uint rowdst, uint rowsrc,
161 * vidconsole_set_row() - Set the colour of a text row
163 * Every pixel contained within the text row is adjusted
165 * @dev: Device to adjust
166 * @row: Text row to adjust (0=top)
167 * @clr: Raw colour (pixel value) to write to each pixel
168 * @return 0 if OK, -ve on error
170 int vidconsole_set_row(struct udevice *dev, uint row, int clr);
173 * vidconsole_put_char() - Output a character to the current console position
175 * Outputs a character to the console and advances the cursor. This function
176 * handles wrapping to new lines and scrolling the console. Special
177 * characters are handled also: \n, \r, \b and \t.
179 * The device always starts with the cursor at position 0,0 (top left). It
180 * can be adjusted manually using vidconsole_position_cursor().
182 * @dev: Device to adjust
183 * @ch: Character to write
184 * @return 0 if OK, -ve on error
186 int vidconsole_put_char(struct udevice *dev, char ch);
189 * vidconsole_position_cursor() - Move the text cursor
191 * @dev: Device to adjust
192 * @col: New cursor text column
193 * @row: New cursor text row
194 * @return 0 if OK, -ve on error
196 void vidconsole_position_cursor(struct udevice *dev, unsigned col,