blob: 63af741778d286f4fd85e6332b35139a6d70d1ff [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Simon Glass83510762016-01-18 19:52:17 -07002/*
3 * Copyright (c) 2015 Google, Inc
Simon Glass83510762016-01-18 19:52:17 -07004 */
5
6#ifndef __video_console_h
7#define __video_console_h
8
Heinrich Schuchardt5c30fbb2018-02-08 21:47:11 +01009#include <video.h>
10
Simon Glassf2661782016-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 Schuchardt5c30fbb2018-02-08 21:47:11 +010016/*
Heinrich Schuchardt9ffa4d12018-02-08 21:47:12 +010017 * The 16 colors supported by the console
Heinrich Schuchardt5c30fbb2018-02-08 21:47:11 +010018 */
19enum color_idx {
20 VID_BLACK = 0,
21 VID_RED,
22 VID_GREEN,
Heinrich Schuchardt9ffa4d12018-02-08 21:47:12 +010023 VID_BROWN,
Heinrich Schuchardt5c30fbb2018-02-08 21:47:11 +010024 VID_BLUE,
25 VID_MAGENTA,
26 VID_CYAN,
Heinrich Schuchardt9ffa4d12018-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 Schuchardt5c30fbb2018-02-08 21:47:11 +010035 VID_WHITE,
36
37 VID_COLOR_COUNT
38};
39
Simon Glass83510762016-01-18 19:52:17 -070040/**
41 * struct vidconsole_priv - uclass-private data about a console device
42 *
Simon Glassf2661782016-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 *
Simon Glass83510762016-01-18 19:52:17 -070046 * @sdev: stdio device, acting as an output sink
Simon Glassf2661782016-01-14 18:10:37 -070047 * @xcur_frac: Current X position, in fractional units (VID_TO_POS(x))
48 * @curr_row: Current Y position in pixels (0=top)
Simon Glass83510762016-01-18 19:52:17 -070049 * @rows: Number of text rows
50 * @cols: Number of text columns
Simon Glassf2661782016-01-14 18:10:37 -070051 * @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
Simon Glassc5b77d02016-01-14 18:10:39 -070055 * @xstart_frac: Left margin for the text console in fractional units
Simon Glass58c733a2016-01-14 18:10:40 -070056 * @last_ch: Last character written to the text console on this line
Rob Clarka085aa12017-09-13 18:12:21 -040057 * @escape: TRUE if currently accumulating an ANSI escape sequence
58 * @escape_len: Length of accumulated escape sequence so far
59 * @escape_buf: Buffer to accumulate escape sequence
Simon Glass83510762016-01-18 19:52:17 -070060 */
61struct vidconsole_priv {
62 struct stdio_dev sdev;
Simon Glassf2661782016-01-14 18:10:37 -070063 int xcur_frac;
64 int ycur;
Simon Glass83510762016-01-18 19:52:17 -070065 int rows;
66 int cols;
Simon Glassf2661782016-01-14 18:10:37 -070067 int x_charsize;
68 int y_charsize;
69 int tab_width_frac;
70 int xsize_frac;
Simon Glassc5b77d02016-01-14 18:10:39 -070071 int xstart_frac;
Simon Glass58c733a2016-01-14 18:10:40 -070072 int last_ch;
Rob Clarka085aa12017-09-13 18:12:21 -040073 /*
74 * ANSI escape sequences are accumulated character by character,
75 * starting after the ESC char (0x1b) until the entire sequence
76 * is consumed at which point it is acted upon.
77 */
78 int escape;
79 int escape_len;
80 char escape_buf[32];
Simon Glass83510762016-01-18 19:52:17 -070081};
82
83/**
84 * struct vidconsole_ops - Video console operations
85 *
86 * These operations work on either an absolute console position (measured
87 * in pixels) or a text row number (measured in rows, where each row consists
88 * of an entire line of text - typically 16 pixels).
89 */
90struct vidconsole_ops {
91 /**
92 * putc_xy() - write a single character to a position
93 *
94 * @dev: Device to write to
Simon Glassf2661782016-01-14 18:10:37 -070095 * @x_frac: Fractional pixel X position (0=left-most pixel) which
96 * is the X position multipled by VID_FRAC_DIV.
Simon Glass83510762016-01-18 19:52:17 -070097 * @y: Pixel Y position (0=top-most pixel)
98 * @ch: Character to write
Simon Glassf2661782016-01-14 18:10:37 -070099 * @return number of fractional pixels that the cursor should move,
100 * if all is OK, -EAGAIN if we ran out of space on this line, other -ve
101 * on error
Simon Glass83510762016-01-18 19:52:17 -0700102 */
Simon Glassf2661782016-01-14 18:10:37 -0700103 int (*putc_xy)(struct udevice *dev, uint x_frac, uint y, char ch);
Simon Glass83510762016-01-18 19:52:17 -0700104
105 /**
106 * move_rows() - Move text rows from one place to another
107 *
108 * @dev: Device to adjust
109 * @rowdst: Destination text row (0=top)
110 * @rowsrc: Source start text row
111 * @count: Number of text rows to move
112 * @return 0 if OK, -ve on error
113 */
114 int (*move_rows)(struct udevice *dev, uint rowdst, uint rowsrc,
115 uint count);
116
117 /**
118 * set_row() - Set the colour of a text row
119 *
120 * Every pixel contained within the text row is adjusted
121 *
122 * @dev: Device to adjust
123 * @row: Text row to adjust (0=top)
124 * @clr: Raw colour (pixel value) to write to each pixel
125 * @return 0 if OK, -ve on error
126 */
127 int (*set_row)(struct udevice *dev, uint row, int clr);
Simon Glass58c733a2016-01-14 18:10:40 -0700128
129 /**
130 * entry_start() - Indicate that text entry is starting afresh
131 *
132 * Consoles which use proportional fonts need to track the position of
133 * each character output so that backspace will return to the correct
134 * place. This method signals to the console driver that a new entry
135 * line is being start (e.g. the user pressed return to start a new
136 * command). The driver can use this signal to empty its list of
137 * positions.
138 */
139 int (*entry_start)(struct udevice *dev);
Simon Glass7b9f7e42016-01-14 18:10:41 -0700140
141 /**
142 * backspace() - Handle erasing the last character
143 *
144 * With proportional fonts the vidconsole uclass cannot itself erase
145 * the previous character. This optional method will be called when
146 * a backspace is needed. The driver should erase the previous
147 * character and update the cursor position (xcur_frac, ycur) to the
148 * start of the previous character.
149 *
150 * If not implement, default behaviour will work for fixed-width
151 * characters.
152 */
153 int (*backspace)(struct udevice *dev);
Simon Glass83510762016-01-18 19:52:17 -0700154};
155
156/* Get a pointer to the driver operations for a video console device */
157#define vidconsole_get_ops(dev) ((struct vidconsole_ops *)(dev)->driver->ops)
158
159/**
160 * vidconsole_putc_xy() - write a single character to a position
161 *
162 * @dev: Device to write to
Simon Glassf2661782016-01-14 18:10:37 -0700163 * @x_frac: Fractional pixel X position (0=left-most pixel) which
164 * is the X position multipled by VID_FRAC_DIV.
Simon Glass83510762016-01-18 19:52:17 -0700165 * @y: Pixel Y position (0=top-most pixel)
166 * @ch: Character to write
Simon Glassf2661782016-01-14 18:10:37 -0700167 * @return number of fractional pixels that the cursor should move,
168 * if all is OK, -EAGAIN if we ran out of space on this line, other -ve
169 * on error
Simon Glass83510762016-01-18 19:52:17 -0700170 */
171int vidconsole_putc_xy(struct udevice *dev, uint x, uint y, char ch);
172
173/**
174 * vidconsole_move_rows() - Move text rows from one place to another
175 *
176 * @dev: Device to adjust
177 * @rowdst: Destination text row (0=top)
178 * @rowsrc: Source start text row
179 * @count: Number of text rows to move
180 * @return 0 if OK, -ve on error
181 */
182int vidconsole_move_rows(struct udevice *dev, uint rowdst, uint rowsrc,
183 uint count);
184
185/**
186 * vidconsole_set_row() - Set the colour of a text row
187 *
188 * Every pixel contained within the text row is adjusted
189 *
190 * @dev: Device to adjust
191 * @row: Text row to adjust (0=top)
192 * @clr: Raw colour (pixel value) to write to each pixel
193 * @return 0 if OK, -ve on error
194 */
195int vidconsole_set_row(struct udevice *dev, uint row, int clr);
196
197/**
198 * vidconsole_put_char() - Output a character to the current console position
199 *
200 * Outputs a character to the console and advances the cursor. This function
201 * handles wrapping to new lines and scrolling the console. Special
202 * characters are handled also: \n, \r, \b and \t.
203 *
204 * The device always starts with the cursor at position 0,0 (top left). It
205 * can be adjusted manually using vidconsole_position_cursor().
206 *
207 * @dev: Device to adjust
208 * @ch: Character to write
209 * @return 0 if OK, -ve on error
210 */
211int vidconsole_put_char(struct udevice *dev, char ch);
212
213/**
214 * vidconsole_position_cursor() - Move the text cursor
215 *
216 * @dev: Device to adjust
217 * @col: New cursor text column
218 * @row: New cursor text row
219 * @return 0 if OK, -ve on error
220 */
221void vidconsole_position_cursor(struct udevice *dev, unsigned col,
222 unsigned row);
223
Heinrich Schuchardt5c30fbb2018-02-08 21:47:11 +0100224#ifdef CONFIG_DM_VIDEO
225
226/**
227 * vid_console_color() - convert a color code to a pixel's internal
228 * representation
229 *
230 * The caller has to guarantee that the color index is less than
231 * VID_COLOR_COUNT.
232 *
233 * @priv private data of the console device
234 * @idx color index
235 * @return color value
236 */
237u32 vid_console_color(struct video_priv *priv, unsigned int idx);
238
239#endif
240
Simon Glass83510762016-01-18 19:52:17 -0700241#endif