blob: 9dce234bd928cf24372532c0923f868f44b1a326 [file] [log] [blame]
Simon Glass83510762016-01-18 19:52:17 -07001/*
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 Glassf2661782016-01-14 18:10:37 -070010#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 Glass83510762016-01-18 19:52:17 -070015/**
16 * struct vidconsole_priv - uclass-private data about a console device
17 *
Simon Glassf2661782016-01-14 18:10:37 -070018 * 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 Glass83510762016-01-18 19:52:17 -070021 * @sdev: stdio device, acting as an output sink
Simon Glassf2661782016-01-14 18:10:37 -070022 * @xcur_frac: Current X position, in fractional units (VID_TO_POS(x))
23 * @curr_row: Current Y position in pixels (0=top)
Simon Glass83510762016-01-18 19:52:17 -070024 * @rows: Number of text rows
25 * @cols: Number of text columns
Simon Glassf2661782016-01-14 18:10:37 -070026 * @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 Glassc5b77d02016-01-14 18:10:39 -070030 * @xstart_frac: Left margin for the text console in fractional units
Simon Glass58c733a2016-01-14 18:10:40 -070031 * @last_ch: Last character written to the text console on this line
Rob Clarka085aa12017-09-13 18:12:21 -040032 * @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
Simon Glass83510762016-01-18 19:52:17 -070035 */
36struct vidconsole_priv {
37 struct stdio_dev sdev;
Simon Glassf2661782016-01-14 18:10:37 -070038 int xcur_frac;
39 int ycur;
Simon Glass83510762016-01-18 19:52:17 -070040 int rows;
41 int cols;
Simon Glassf2661782016-01-14 18:10:37 -070042 int x_charsize;
43 int y_charsize;
44 int tab_width_frac;
45 int xsize_frac;
Simon Glassc5b77d02016-01-14 18:10:39 -070046 int xstart_frac;
Simon Glass58c733a2016-01-14 18:10:40 -070047 int last_ch;
Rob Clarka085aa12017-09-13 18:12:21 -040048 /*
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.
52 */
53 int escape;
54 int escape_len;
55 char escape_buf[32];
Simon Glass83510762016-01-18 19:52:17 -070056};
57
58/**
59 * struct vidconsole_ops - Video console operations
60 *
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).
64 */
65struct vidconsole_ops {
66 /**
67 * putc_xy() - write a single character to a position
68 *
69 * @dev: Device to write to
Simon Glassf2661782016-01-14 18:10:37 -070070 * @x_frac: Fractional pixel X position (0=left-most pixel) which
71 * is the X position multipled by VID_FRAC_DIV.
Simon Glass83510762016-01-18 19:52:17 -070072 * @y: Pixel Y position (0=top-most pixel)
73 * @ch: Character to write
Simon Glassf2661782016-01-14 18:10:37 -070074 * @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
76 * on error
Simon Glass83510762016-01-18 19:52:17 -070077 */
Simon Glassf2661782016-01-14 18:10:37 -070078 int (*putc_xy)(struct udevice *dev, uint x_frac, uint y, char ch);
Simon Glass83510762016-01-18 19:52:17 -070079
80 /**
81 * move_rows() - Move text rows from one place to another
82 *
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
88 */
89 int (*move_rows)(struct udevice *dev, uint rowdst, uint rowsrc,
90 uint count);
91
92 /**
93 * set_row() - Set the colour of a text row
94 *
95 * Every pixel contained within the text row is adjusted
96 *
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
101 */
102 int (*set_row)(struct udevice *dev, uint row, int clr);
Simon Glass58c733a2016-01-14 18:10:40 -0700103
104 /**
105 * entry_start() - Indicate that text entry is starting afresh
106 *
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
112 * positions.
113 */
114 int (*entry_start)(struct udevice *dev);
Simon Glass7b9f7e42016-01-14 18:10:41 -0700115
116 /**
117 * backspace() - Handle erasing the last character
118 *
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.
124 *
125 * If not implement, default behaviour will work for fixed-width
126 * characters.
127 */
128 int (*backspace)(struct udevice *dev);
Simon Glass83510762016-01-18 19:52:17 -0700129};
130
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)
133
134/**
135 * vidconsole_putc_xy() - write a single character to a position
136 *
137 * @dev: Device to write to
Simon Glassf2661782016-01-14 18:10:37 -0700138 * @x_frac: Fractional pixel X position (0=left-most pixel) which
139 * is the X position multipled by VID_FRAC_DIV.
Simon Glass83510762016-01-18 19:52:17 -0700140 * @y: Pixel Y position (0=top-most pixel)
141 * @ch: Character to write
Simon Glassf2661782016-01-14 18:10:37 -0700142 * @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
144 * on error
Simon Glass83510762016-01-18 19:52:17 -0700145 */
146int vidconsole_putc_xy(struct udevice *dev, uint x, uint y, char ch);
147
148/**
149 * vidconsole_move_rows() - Move text rows from one place to another
150 *
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
156 */
157int vidconsole_move_rows(struct udevice *dev, uint rowdst, uint rowsrc,
158 uint count);
159
160/**
161 * vidconsole_set_row() - Set the colour of a text row
162 *
163 * Every pixel contained within the text row is adjusted
164 *
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
169 */
170int vidconsole_set_row(struct udevice *dev, uint row, int clr);
171
172/**
173 * vidconsole_put_char() - Output a character to the current console position
174 *
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.
178 *
179 * The device always starts with the cursor at position 0,0 (top left). It
180 * can be adjusted manually using vidconsole_position_cursor().
181 *
182 * @dev: Device to adjust
183 * @ch: Character to write
184 * @return 0 if OK, -ve on error
185 */
186int vidconsole_put_char(struct udevice *dev, char ch);
187
188/**
189 * vidconsole_position_cursor() - Move the text cursor
190 *
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
195 */
196void vidconsole_position_cursor(struct udevice *dev, unsigned col,
197 unsigned row);
198
199#endif