blob: d755eb73cf20febb13db686e830a765901b7d45a [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 Glassbac91502020-07-02 21:12:18 -060011struct video_priv;
12
Simon Glass52c10c52016-01-14 18:10:37 -070013#define VID_FRAC_DIV 256
14
15#define VID_TO_PIXEL(x) ((x) / VID_FRAC_DIV)
16#define VID_TO_POS(x) ((x) * VID_FRAC_DIV)
17
Simon Glass84c7fb32016-01-18 19:52:17 -070018/**
19 * struct vidconsole_priv - uclass-private data about a console device
20 *
Simon Glass52c10c52016-01-14 18:10:37 -070021 * Drivers must set up @rows, @cols, @x_charsize, @y_charsize in their probe()
22 * method. Drivers may set up @xstart_frac if desired.
23 *
Heinrich Schuchardt9e933f12018-09-19 21:31:48 +020024 * @sdev: stdio device, acting as an output sink
25 * @xcur_frac: Current X position, in fractional units (VID_TO_POS(x))
26 * @ycur: Current Y position in pixels (0=top)
27 * @rows: Number of text rows
28 * @cols: Number of text columns
29 * @x_charsize: Character width in pixels
30 * @y_charsize: Character height in pixels
Simon Glass52c10c52016-01-14 18:10:37 -070031 * @tab_width_frac: Tab width in fractional units
Heinrich Schuchardt9e933f12018-09-19 21:31:48 +020032 * @xsize_frac: Width of the display in fractional units
Simon Glassa74451d2016-01-14 18:10:39 -070033 * @xstart_frac: Left margin for the text console in fractional units
Heinrich Schuchardt9e933f12018-09-19 21:31:48 +020034 * @last_ch: Last character written to the text console on this line
35 * @escape: TRUE if currently accumulating an ANSI escape sequence
36 * @escape_len: Length of accumulated escape sequence so far
37 * @col_saved: Saved X position, in fractional units (VID_TO_POS(x))
38 * @row_saved: Saved Y position in pixels (0=top)
39 * @escape_buf: Buffer to accumulate escape sequence
Simon Glass84c7fb32016-01-18 19:52:17 -070040 */
41struct vidconsole_priv {
42 struct stdio_dev sdev;
Simon Glass52c10c52016-01-14 18:10:37 -070043 int xcur_frac;
44 int ycur;
Simon Glass84c7fb32016-01-18 19:52:17 -070045 int rows;
46 int cols;
Simon Glass52c10c52016-01-14 18:10:37 -070047 int x_charsize;
48 int y_charsize;
49 int tab_width_frac;
50 int xsize_frac;
Simon Glassa74451d2016-01-14 18:10:39 -070051 int xstart_frac;
Simon Glassafee7432016-01-14 18:10:40 -070052 int last_ch;
Rob Clark06e7a0d2017-09-13 18:12:21 -040053 /*
54 * ANSI escape sequences are accumulated character by character,
55 * starting after the ESC char (0x1b) until the entire sequence
56 * is consumed at which point it is acted upon.
57 */
58 int escape;
59 int escape_len;
Heinrich Schuchardt9e933f12018-09-19 21:31:48 +020060 int row_saved;
61 int col_saved;
Rob Clark06e7a0d2017-09-13 18:12:21 -040062 char escape_buf[32];
Simon Glass84c7fb32016-01-18 19:52:17 -070063};
64
65/**
66 * struct vidconsole_ops - Video console operations
67 *
68 * These operations work on either an absolute console position (measured
69 * in pixels) or a text row number (measured in rows, where each row consists
70 * of an entire line of text - typically 16 pixels).
71 */
72struct vidconsole_ops {
73 /**
74 * putc_xy() - write a single character to a position
75 *
76 * @dev: Device to write to
Simon Glass52c10c52016-01-14 18:10:37 -070077 * @x_frac: Fractional pixel X position (0=left-most pixel) which
78 * is the X position multipled by VID_FRAC_DIV.
Simon Glass84c7fb32016-01-18 19:52:17 -070079 * @y: Pixel Y position (0=top-most pixel)
80 * @ch: Character to write
Simon Glass52c10c52016-01-14 18:10:37 -070081 * @return number of fractional pixels that the cursor should move,
82 * if all is OK, -EAGAIN if we ran out of space on this line, other -ve
83 * on error
Simon Glass84c7fb32016-01-18 19:52:17 -070084 */
Simon Glass52c10c52016-01-14 18:10:37 -070085 int (*putc_xy)(struct udevice *dev, uint x_frac, uint y, char ch);
Simon Glass84c7fb32016-01-18 19:52:17 -070086
87 /**
88 * move_rows() - Move text rows from one place to another
89 *
90 * @dev: Device to adjust
91 * @rowdst: Destination text row (0=top)
92 * @rowsrc: Source start text row
93 * @count: Number of text rows to move
94 * @return 0 if OK, -ve on error
95 */
96 int (*move_rows)(struct udevice *dev, uint rowdst, uint rowsrc,
97 uint count);
98
99 /**
100 * set_row() - Set the colour of a text row
101 *
102 * Every pixel contained within the text row is adjusted
103 *
104 * @dev: Device to adjust
105 * @row: Text row to adjust (0=top)
106 * @clr: Raw colour (pixel value) to write to each pixel
107 * @return 0 if OK, -ve on error
108 */
109 int (*set_row)(struct udevice *dev, uint row, int clr);
Simon Glassafee7432016-01-14 18:10:40 -0700110
111 /**
112 * entry_start() - Indicate that text entry is starting afresh
113 *
114 * Consoles which use proportional fonts need to track the position of
115 * each character output so that backspace will return to the correct
116 * place. This method signals to the console driver that a new entry
117 * line is being start (e.g. the user pressed return to start a new
118 * command). The driver can use this signal to empty its list of
119 * positions.
120 */
121 int (*entry_start)(struct udevice *dev);
Simon Glass33bd3b62016-01-14 18:10:41 -0700122
123 /**
124 * backspace() - Handle erasing the last character
125 *
126 * With proportional fonts the vidconsole uclass cannot itself erase
127 * the previous character. This optional method will be called when
128 * a backspace is needed. The driver should erase the previous
129 * character and update the cursor position (xcur_frac, ycur) to the
130 * start of the previous character.
131 *
132 * If not implement, default behaviour will work for fixed-width
133 * characters.
134 */
135 int (*backspace)(struct udevice *dev);
Simon Glass84c7fb32016-01-18 19:52:17 -0700136};
137
138/* Get a pointer to the driver operations for a video console device */
139#define vidconsole_get_ops(dev) ((struct vidconsole_ops *)(dev)->driver->ops)
140
141/**
142 * vidconsole_putc_xy() - write a single character to a position
143 *
144 * @dev: Device to write to
Simon Glass52c10c52016-01-14 18:10:37 -0700145 * @x_frac: Fractional pixel X position (0=left-most pixel) which
146 * is the X position multipled by VID_FRAC_DIV.
Simon Glass84c7fb32016-01-18 19:52:17 -0700147 * @y: Pixel Y position (0=top-most pixel)
148 * @ch: Character to write
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100149 * Return: number of fractional pixels that the cursor should move,
Simon Glass52c10c52016-01-14 18:10:37 -0700150 * if all is OK, -EAGAIN if we ran out of space on this line, other -ve
151 * on error
Simon Glass84c7fb32016-01-18 19:52:17 -0700152 */
153int vidconsole_putc_xy(struct udevice *dev, uint x, uint y, char ch);
154
155/**
156 * vidconsole_move_rows() - Move text rows from one place to another
157 *
158 * @dev: Device to adjust
159 * @rowdst: Destination text row (0=top)
160 * @rowsrc: Source start text row
161 * @count: Number of text rows to move
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100162 * Return: 0 if OK, -ve on error
Simon Glass84c7fb32016-01-18 19:52:17 -0700163 */
164int vidconsole_move_rows(struct udevice *dev, uint rowdst, uint rowsrc,
165 uint count);
166
167/**
168 * vidconsole_set_row() - Set the colour of a text row
169 *
170 * Every pixel contained within the text row is adjusted
171 *
172 * @dev: Device to adjust
173 * @row: Text row to adjust (0=top)
174 * @clr: Raw colour (pixel value) to write to each pixel
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100175 * Return: 0 if OK, -ve on error
Simon Glass84c7fb32016-01-18 19:52:17 -0700176 */
177int vidconsole_set_row(struct udevice *dev, uint row, int clr);
178
179/**
180 * vidconsole_put_char() - Output a character to the current console position
181 *
182 * Outputs a character to the console and advances the cursor. This function
183 * handles wrapping to new lines and scrolling the console. Special
184 * characters are handled also: \n, \r, \b and \t.
185 *
186 * The device always starts with the cursor at position 0,0 (top left). It
187 * can be adjusted manually using vidconsole_position_cursor().
188 *
189 * @dev: Device to adjust
190 * @ch: Character to write
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100191 * Return: 0 if OK, -ve on error
Simon Glass84c7fb32016-01-18 19:52:17 -0700192 */
193int vidconsole_put_char(struct udevice *dev, char ch);
194
195/**
Marek Vasuta89f9cb2019-05-17 20:22:31 +0200196 * vidconsole_put_string() - Output a string to the current console position
197 *
198 * Outputs a string to the console and advances the cursor. This function
199 * handles wrapping to new lines and scrolling the console. Special
200 * characters are handled also: \n, \r, \b and \t.
201 *
202 * The device always starts with the cursor at position 0,0 (top left). It
203 * can be adjusted manually using vidconsole_position_cursor().
204 *
205 * @dev: Device to adjust
206 * @str: String to write
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100207 * Return: 0 if OK, -ve on error
Marek Vasuta89f9cb2019-05-17 20:22:31 +0200208 */
209int vidconsole_put_string(struct udevice *dev, const char *str);
210
211/**
Simon Glass84c7fb32016-01-18 19:52:17 -0700212 * vidconsole_position_cursor() - Move the text cursor
213 *
214 * @dev: Device to adjust
215 * @col: New cursor text column
216 * @row: New cursor text row
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100217 * Return: 0 if OK, -ve on error
Simon Glass84c7fb32016-01-18 19:52:17 -0700218 */
219void vidconsole_position_cursor(struct udevice *dev, unsigned col,
220 unsigned row);
221
Simon Glassd622c5b2022-10-06 08:36:04 -0600222/**
223 * vidconsole_set_cursor_pos() - set cursor position
224 *
225 * The cursor is set to the new position and the start-of-line information is
226 * updated to the same position, so that a newline will return to @x
227 *
228 * @dev: video console device to update
229 * @x: x position from left in pixels
230 * @y: y position from top in pixels
231 */
232void vidconsole_set_cursor_pos(struct udevice *dev, int x, int y);
233
Simon Glass981f00b2022-10-06 08:36:14 -0600234/**
235 * vidconsole_list_fonts() - List the available fonts
236 *
237 * This shows a list on the console
238 */
239void vidconsole_list_fonts(void);
240
241/**
242 * vidconsole_select_font() - Select a font to use
243 *
244 * @dev: vidconsole device
245 * @name: Font name
246 * @size: Size of the font (norminal pixel height) or 0 for default
247 */
248int vidconsole_select_font(struct udevice *dev, const char *name, uint size);
249
Simon Glass9e972c32022-10-06 08:36:16 -0600250/**
251 * vidconsole_get_font() - get the current font name and size
252 *
253 * @dev: vidconsole device
254 * @sizep: Place to put the font size (nominal height in pixels)
255 * Returns: Current font name
256 */
257const char *vidconsole_get_font(struct udevice *dev, uint *sizep);
258
Simon Glass31a7e232020-07-02 21:12:23 -0600259#ifdef CONFIG_VIDEO_COPY
260/**
261 * vidconsole_sync_copy() - Sync back to the copy framebuffer
262 *
263 * This ensures that the copy framebuffer has the same data as the framebuffer
264 * for a particular region. It should be called after the framebuffer is updated
265 *
266 * @from and @to can be in either order. The region between them is synced.
267 *
268 * @dev: Vidconsole device being updated
269 * @from: Start/end address within the framebuffer (->fb)
270 * @to: Other address within the frame buffer
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100271 * Return: 0 if OK, -EFAULT if the start address is before the start of the
Simon Glass31a7e232020-07-02 21:12:23 -0600272 * frame buffer start
273 */
274int vidconsole_sync_copy(struct udevice *dev, void *from, void *to);
275
276/**
277 * vidconsole_memmove() - Perform a memmove() within the frame buffer
278 *
279 * This handles a memmove(), e.g. for scrolling. It also updates the copy
280 * framebuffer.
281 *
282 * @dev: Vidconsole device being updated
283 * @dst: Destination address within the framebuffer (->fb)
284 * @src: Source address within the framebuffer (->fb)
285 * @size: Number of bytes to transfer
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100286 * Return: 0 if OK, -EFAULT if the start address is before the start of the
Simon Glass31a7e232020-07-02 21:12:23 -0600287 * frame buffer start
288 */
289int vidconsole_memmove(struct udevice *dev, void *dst, const void *src,
290 int size);
291#else
292static inline int vidconsole_sync_copy(struct udevice *dev, void *from,
293 void *to)
294{
295 return 0;
296}
297
298static inline int vidconsole_memmove(struct udevice *dev, void *dst,
299 const void *src, int size)
300{
301 memmove(dst, src, size);
302
303 return 0;
304}
305
306#endif
307
Heinrich Schuchardt290e1d82018-02-08 21:47:11 +0100308#endif