1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Copyright (c) 2015 Google, Inc
6 #ifndef __video_console_h
7 #define __video_console_h
11 #define VID_FRAC_DIV 256
13 #define VID_TO_PIXEL(x) ((x) / VID_FRAC_DIV)
14 #define VID_TO_POS(x) ((x) * VID_FRAC_DIV)
17 * The 16 colors supported by the console
41 * struct vidconsole_priv - uclass-private data about a console device
43 * Drivers must set up @rows, @cols, @x_charsize, @y_charsize in their probe()
44 * method. Drivers may set up @xstart_frac if desired.
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
53 * @tab_width_frac: Tab width in fractional units
54 * @xsize_frac: Width of the display in fractional units
55 * @xstart_frac: Left margin for the text console in fractional units
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
63 struct vidconsole_priv {
64 struct stdio_dev sdev;
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.
88 * struct vidconsole_ops - Video console operations
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).
94 struct vidconsole_ops {
96 * putc_xy() - write a single character to a position
98 * @dev: Device to write to
99 * @x_frac: Fractional pixel X position (0=left-most pixel) which
100 * is the X position multipled by VID_FRAC_DIV.
101 * @y: Pixel Y position (0=top-most pixel)
102 * @ch: Character to write
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
107 int (*putc_xy)(struct udevice *dev, uint x_frac, uint y, char ch);
110 * move_rows() - Move text rows from one place to another
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
118 int (*move_rows)(struct udevice *dev, uint rowdst, uint rowsrc,
122 * set_row() - Set the colour of a text row
124 * Every pixel contained within the text row is adjusted
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
131 int (*set_row)(struct udevice *dev, uint row, int clr);
134 * entry_start() - Indicate that text entry is starting afresh
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
143 int (*entry_start)(struct udevice *dev);
146 * backspace() - Handle erasing the last character
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.
154 * If not implement, default behaviour will work for fixed-width
157 int (*backspace)(struct udevice *dev);
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)
164 * vidconsole_putc_xy() - write a single character to a position
166 * @dev: Device to write to
167 * @x_frac: Fractional pixel X position (0=left-most pixel) which
168 * is the X position multipled by VID_FRAC_DIV.
169 * @y: Pixel Y position (0=top-most pixel)
170 * @ch: Character to write
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
175 int vidconsole_putc_xy(struct udevice *dev, uint x, uint y, char ch);
178 * vidconsole_move_rows() - Move text rows from one place to another
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
186 int vidconsole_move_rows(struct udevice *dev, uint rowdst, uint rowsrc,
190 * vidconsole_set_row() - Set the colour of a text row
192 * Every pixel contained within the text row is adjusted
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
199 int vidconsole_set_row(struct udevice *dev, uint row, int clr);
202 * vidconsole_put_char() - Output a character to the current console position
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.
208 * The device always starts with the cursor at position 0,0 (top left). It
209 * can be adjusted manually using vidconsole_position_cursor().
211 * @dev: Device to adjust
212 * @ch: Character to write
213 * @return 0 if OK, -ve on error
215 int vidconsole_put_char(struct udevice *dev, char ch);
218 * vidconsole_put_string() - Output a string to the current console position
220 * Outputs a string to the console and advances the cursor. This function
221 * handles wrapping to new lines and scrolling the console. Special
222 * characters are handled also: \n, \r, \b and \t.
224 * The device always starts with the cursor at position 0,0 (top left). It
225 * can be adjusted manually using vidconsole_position_cursor().
227 * @dev: Device to adjust
228 * @str: String to write
229 * @return 0 if OK, -ve on error
231 int vidconsole_put_string(struct udevice *dev, const char *str);
234 * vidconsole_position_cursor() - Move the text cursor
236 * @dev: Device to adjust
237 * @col: New cursor text column
238 * @row: New cursor text row
239 * @return 0 if OK, -ve on error
241 void vidconsole_position_cursor(struct udevice *dev, unsigned col,
244 #ifdef CONFIG_DM_VIDEO
247 * vid_console_color() - convert a color code to a pixel's internal
250 * The caller has to guarantee that the color index is less than
253 * @priv private data of the console device
255 * @return color value
257 u32 vid_console_color(struct video_priv *priv, unsigned int idx);