blob: 0936ceaaf1c7b502241ecb7501c3a41dcb9fd6ce [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Simon Glass84c7fb32016-01-18 19:52:17 -07002/*
3 * Copyright (c) 2015 Google, Inc
Simon Glass84c7fb32016-01-18 19:52:17 -07004 */
5
6#ifndef __video_console_h
7#define __video_console_h
8
Heinrich Schuchardt290e1d82018-02-08 21:47:11 +01009#include <video.h>
10
Simon Glass52c10c52016-01-14 18:10:37 -070011#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 Schuchardt290e1d82018-02-08 21:47:11 +010016/*
Heinrich Schuchardt2a436db2018-02-08 21:47:12 +010017 * The 16 colors supported by the console
Heinrich Schuchardt290e1d82018-02-08 21:47:11 +010018 */
19enum color_idx {
20 VID_BLACK = 0,
21 VID_RED,
22 VID_GREEN,
Heinrich Schuchardt2a436db2018-02-08 21:47:12 +010023 VID_BROWN,
Heinrich Schuchardt290e1d82018-02-08 21:47:11 +010024 VID_BLUE,
25 VID_MAGENTA,
26 VID_CYAN,
Heinrich Schuchardt2a436db2018-02-08 21:47:12 +010027 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 Schuchardt290e1d82018-02-08 21:47:11 +010035 VID_WHITE,
36
37 VID_COLOR_COUNT
38};
39
Simon Glass84c7fb32016-01-18 19:52:17 -070040/**
41 * struct vidconsole_priv - uclass-private data about a console device
42 *
Simon Glass52c10c52016-01-14 18:10:37 -070043 * 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 Schuchardt9e933f12018-09-19 21:31:48 +020046 * @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 Glass52c10c52016-01-14 18:10:37 -070053 * @tab_width_frac: Tab width in fractional units
Heinrich Schuchardt9e933f12018-09-19 21:31:48 +020054 * @xsize_frac: Width of the display in fractional units
Simon Glassa74451d2016-01-14 18:10:39 -070055 * @xstart_frac: Left margin for the text console in fractional units
Heinrich Schuchardt9e933f12018-09-19 21:31:48 +020056 * @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 Glass84c7fb32016-01-18 19:52:17 -070062 */
63struct vidconsole_priv {
64 struct stdio_dev sdev;
Simon Glass52c10c52016-01-14 18:10:37 -070065 int xcur_frac;
66 int ycur;
Simon Glass84c7fb32016-01-18 19:52:17 -070067 int rows;
68 int cols;
Simon Glass52c10c52016-01-14 18:10:37 -070069 int x_charsize;
70 int y_charsize;
71 int tab_width_frac;
72 int xsize_frac;
Simon Glassa74451d2016-01-14 18:10:39 -070073 int xstart_frac;
Simon Glassafee7432016-01-14 18:10:40 -070074 int last_ch;
Rob Clark06e7a0d2017-09-13 18:12:21 -040075 /*
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 Schuchardt9e933f12018-09-19 21:31:48 +020082 int row_saved;
83 int col_saved;
Rob Clark06e7a0d2017-09-13 18:12:21 -040084 char escape_buf[32];
Simon Glass84c7fb32016-01-18 19:52:17 -070085};
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 */
94struct vidconsole_ops {
95 /**
96 * putc_xy() - write a single character to a position
97 *
98 * @dev: Device to write to
Simon Glass52c10c52016-01-14 18:10:37 -070099 * @x_frac: Fractional pixel X position (0=left-most pixel) which
100 * is the X position multipled by VID_FRAC_DIV.
Simon Glass84c7fb32016-01-18 19:52:17 -0700101 * @y: Pixel Y position (0=top-most pixel)
102 * @ch: Character to write
Simon Glass52c10c52016-01-14 18:10:37 -0700103 * @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 Glass84c7fb32016-01-18 19:52:17 -0700106 */
Simon Glass52c10c52016-01-14 18:10:37 -0700107 int (*putc_xy)(struct udevice *dev, uint x_frac, uint y, char ch);
Simon Glass84c7fb32016-01-18 19:52:17 -0700108
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 Glassafee7432016-01-14 18:10:40 -0700132
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 Glass33bd3b62016-01-14 18:10:41 -0700144
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 Glass84c7fb32016-01-18 19:52:17 -0700158};
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 Glass52c10c52016-01-14 18:10:37 -0700167 * @x_frac: Fractional pixel X position (0=left-most pixel) which
168 * is the X position multipled by VID_FRAC_DIV.
Simon Glass84c7fb32016-01-18 19:52:17 -0700169 * @y: Pixel Y position (0=top-most pixel)
170 * @ch: Character to write
Simon Glass52c10c52016-01-14 18:10:37 -0700171 * @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 Glass84c7fb32016-01-18 19:52:17 -0700174 */
175int 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 */
186int 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 */
199int 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 */
215int vidconsole_put_char(struct udevice *dev, char ch);
216
217/**
Marek Vasuta89f9cb2019-05-17 20:22:31 +0200218 * vidconsole_put_string() - Output a string to the current console position
219 *
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.
223 *
224 * The device always starts with the cursor at position 0,0 (top left). It
225 * can be adjusted manually using vidconsole_position_cursor().
226 *
227 * @dev: Device to adjust
228 * @str: String to write
229 * @return 0 if OK, -ve on error
230 */
231int vidconsole_put_string(struct udevice *dev, const char *str);
232
233/**
Simon Glass84c7fb32016-01-18 19:52:17 -0700234 * vidconsole_position_cursor() - Move the text cursor
235 *
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
240 */
241void vidconsole_position_cursor(struct udevice *dev, unsigned col,
242 unsigned row);
243
Heinrich Schuchardt290e1d82018-02-08 21:47:11 +0100244#ifdef CONFIG_DM_VIDEO
245
246/**
247 * vid_console_color() - convert a color code to a pixel's internal
248 * representation
249 *
250 * The caller has to guarantee that the color index is less than
251 * VID_COLOR_COUNT.
252 *
253 * @priv private data of the console device
254 * @idx color index
255 * @return color value
256 */
257u32 vid_console_color(struct video_priv *priv, unsigned int idx);
258
259#endif
260
Simon Glass84c7fb32016-01-18 19:52:17 -0700261#endif