blob: 3e1e00c23f930ef311f89b12e4e821f22e6ec483 [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 Glass2d7c2682020-07-02 21:12:18 -060011struct video_priv;
12
Simon Glassf2661782016-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 Glass83510762016-01-18 19:52:17 -070018/**
19 * struct vidconsole_priv - uclass-private data about a console device
20 *
Simon Glassf2661782016-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 Schuchardt662f3812018-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 Glassf2661782016-01-14 18:10:37 -070031 * @tab_width_frac: Tab width in fractional units
Heinrich Schuchardt662f3812018-09-19 21:31:48 +020032 * @xsize_frac: Width of the display in fractional units
Simon Glassc5b77d02016-01-14 18:10:39 -070033 * @xstart_frac: Left margin for the text console in fractional units
Heinrich Schuchardt662f3812018-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 Glass83510762016-01-18 19:52:17 -070040 */
41struct vidconsole_priv {
42 struct stdio_dev sdev;
Simon Glassf2661782016-01-14 18:10:37 -070043 int xcur_frac;
44 int ycur;
Simon Glass83510762016-01-18 19:52:17 -070045 int rows;
46 int cols;
Simon Glassf2661782016-01-14 18:10:37 -070047 int x_charsize;
48 int y_charsize;
49 int tab_width_frac;
50 int xsize_frac;
Simon Glassc5b77d02016-01-14 18:10:39 -070051 int xstart_frac;
Simon Glass58c733a2016-01-14 18:10:40 -070052 int last_ch;
Rob Clarka085aa12017-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 Schuchardt662f3812018-09-19 21:31:48 +020060 int row_saved;
61 int col_saved;
Rob Clarka085aa12017-09-13 18:12:21 -040062 char escape_buf[32];
Simon Glass83510762016-01-18 19:52:17 -070063};
64
65/**
Simon Glass0e38bd82023-01-06 08:52:32 -060066 * struct vidfont_info - information about a font
67 *
68 * @name: Font name, e.g. nimbus_sans_l_regular
69 */
70struct vidfont_info {
71 const char *name;
72};
73
74/**
Simon Glass83510762016-01-18 19:52:17 -070075 * struct vidconsole_ops - Video console operations
76 *
77 * These operations work on either an absolute console position (measured
78 * in pixels) or a text row number (measured in rows, where each row consists
79 * of an entire line of text - typically 16 pixels).
80 */
81struct vidconsole_ops {
82 /**
83 * putc_xy() - write a single character to a position
84 *
85 * @dev: Device to write to
Simon Glassf2661782016-01-14 18:10:37 -070086 * @x_frac: Fractional pixel X position (0=left-most pixel) which
87 * is the X position multipled by VID_FRAC_DIV.
Simon Glass83510762016-01-18 19:52:17 -070088 * @y: Pixel Y position (0=top-most pixel)
89 * @ch: Character to write
Simon Glassf2661782016-01-14 18:10:37 -070090 * @return number of fractional pixels that the cursor should move,
91 * if all is OK, -EAGAIN if we ran out of space on this line, other -ve
92 * on error
Simon Glass83510762016-01-18 19:52:17 -070093 */
Simon Glassf2661782016-01-14 18:10:37 -070094 int (*putc_xy)(struct udevice *dev, uint x_frac, uint y, char ch);
Simon Glass83510762016-01-18 19:52:17 -070095
96 /**
97 * move_rows() - Move text rows from one place to another
98 *
99 * @dev: Device to adjust
100 * @rowdst: Destination text row (0=top)
101 * @rowsrc: Source start text row
102 * @count: Number of text rows to move
103 * @return 0 if OK, -ve on error
104 */
105 int (*move_rows)(struct udevice *dev, uint rowdst, uint rowsrc,
106 uint count);
107
108 /**
109 * set_row() - Set the colour of a text row
110 *
111 * Every pixel contained within the text row is adjusted
112 *
113 * @dev: Device to adjust
114 * @row: Text row to adjust (0=top)
115 * @clr: Raw colour (pixel value) to write to each pixel
116 * @return 0 if OK, -ve on error
117 */
118 int (*set_row)(struct udevice *dev, uint row, int clr);
Simon Glass58c733a2016-01-14 18:10:40 -0700119
120 /**
121 * entry_start() - Indicate that text entry is starting afresh
122 *
Simon Glass0e38bd82023-01-06 08:52:32 -0600123 * @dev: Device to adjust
124 * Returns: 0 on success, -ve on error
125 *
Simon Glass58c733a2016-01-14 18:10:40 -0700126 * Consoles which use proportional fonts need to track the position of
127 * each character output so that backspace will return to the correct
128 * place. This method signals to the console driver that a new entry
129 * line is being start (e.g. the user pressed return to start a new
130 * command). The driver can use this signal to empty its list of
131 * positions.
132 */
133 int (*entry_start)(struct udevice *dev);
Simon Glass7b9f7e42016-01-14 18:10:41 -0700134
135 /**
136 * backspace() - Handle erasing the last character
137 *
Simon Glass0e38bd82023-01-06 08:52:32 -0600138 * @dev: Device to adjust
139 * Returns: 0 on success, -ve on error
140 *
Simon Glass7b9f7e42016-01-14 18:10:41 -0700141 * With proportional fonts the vidconsole uclass cannot itself erase
142 * the previous character. This optional method will be called when
143 * a backspace is needed. The driver should erase the previous
144 * character and update the cursor position (xcur_frac, ycur) to the
145 * start of the previous character.
146 *
147 * If not implement, default behaviour will work for fixed-width
148 * characters.
149 */
150 int (*backspace)(struct udevice *dev);
Simon Glass0e38bd82023-01-06 08:52:32 -0600151
152 /**
153 * get_font() - Obtain information about a font (optional)
154 *
155 * @dev: Device to check
156 * @seq: Font number to query (0=first, 1=second, etc.)
157 * @info: Returns font information on success
158 * Returns: 0 on success, -ENOENT if no such font
159 */
160 int (*get_font)(struct udevice *dev, int seq,
161 struct vidfont_info *info);
162
163 /**
164 * select_font() - Select a particular font by name / size
165 *
166 * @dev: Device to adjust
167 * @name: Font name to use (NULL to use default)
168 * @size: Font size to use (0 to use default)
169 * Returns: 0 on success, -ENOENT if no such font
170 */
171 int (*select_font)(struct udevice *dev, const char *name, uint size);
Simon Glass83510762016-01-18 19:52:17 -0700172};
173
174/* Get a pointer to the driver operations for a video console device */
175#define vidconsole_get_ops(dev) ((struct vidconsole_ops *)(dev)->driver->ops)
176
177/**
Simon Glass0e38bd82023-01-06 08:52:32 -0600178 * vidconsole_get_font() - Obtain information about a font
179 *
180 * @dev: Device to check
181 * @seq: Font number to query (0=first, 1=second, etc.)
182 * @info: Returns font information on success
183 * Returns: 0 on success, -ENOENT if no such font, -ENOSYS if there is no such
184 * method
185 */
186int vidconsole_get_font(struct udevice *dev, int seq,
187 struct vidfont_info *info);
188
189/**
190 * vidconsole_select_font() - Select a particular font by name / size
191 *
192 * @dev: Device to adjust
193 * @name: Font name to use (NULL to use default)
194 * @size: Font size to use (0 to use default)
195 */
196int vidconsole_select_font(struct udevice *dev, const char *name, uint size);
197
198/**
Simon Glass83510762016-01-18 19:52:17 -0700199 * vidconsole_putc_xy() - write a single character to a position
200 *
201 * @dev: Device to write to
Simon Glassf2661782016-01-14 18:10:37 -0700202 * @x_frac: Fractional pixel X position (0=left-most pixel) which
203 * is the X position multipled by VID_FRAC_DIV.
Simon Glass83510762016-01-18 19:52:17 -0700204 * @y: Pixel Y position (0=top-most pixel)
205 * @ch: Character to write
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100206 * Return: number of fractional pixels that the cursor should move,
Simon Glassf2661782016-01-14 18:10:37 -0700207 * if all is OK, -EAGAIN if we ran out of space on this line, other -ve
208 * on error
Simon Glass83510762016-01-18 19:52:17 -0700209 */
210int vidconsole_putc_xy(struct udevice *dev, uint x, uint y, char ch);
211
212/**
213 * vidconsole_move_rows() - Move text rows from one place to another
214 *
215 * @dev: Device to adjust
216 * @rowdst: Destination text row (0=top)
217 * @rowsrc: Source start text row
218 * @count: Number of text rows to move
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100219 * Return: 0 if OK, -ve on error
Simon Glass83510762016-01-18 19:52:17 -0700220 */
221int vidconsole_move_rows(struct udevice *dev, uint rowdst, uint rowsrc,
222 uint count);
223
224/**
225 * vidconsole_set_row() - Set the colour of a text row
226 *
227 * Every pixel contained within the text row is adjusted
228 *
229 * @dev: Device to adjust
230 * @row: Text row to adjust (0=top)
231 * @clr: Raw colour (pixel value) to write to each pixel
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100232 * Return: 0 if OK, -ve on error
Simon Glass83510762016-01-18 19:52:17 -0700233 */
234int vidconsole_set_row(struct udevice *dev, uint row, int clr);
235
236/**
237 * vidconsole_put_char() - Output a character to the current console position
238 *
239 * Outputs a character to the console and advances the cursor. This function
240 * handles wrapping to new lines and scrolling the console. Special
241 * characters are handled also: \n, \r, \b and \t.
242 *
243 * The device always starts with the cursor at position 0,0 (top left). It
244 * can be adjusted manually using vidconsole_position_cursor().
245 *
246 * @dev: Device to adjust
247 * @ch: Character to write
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100248 * Return: 0 if OK, -ve on error
Simon Glass83510762016-01-18 19:52:17 -0700249 */
250int vidconsole_put_char(struct udevice *dev, char ch);
251
252/**
Marek Vasute63168a2019-05-17 20:22:31 +0200253 * vidconsole_put_string() - Output a string to the current console position
254 *
255 * Outputs a string to the console and advances the cursor. This function
256 * handles wrapping to new lines and scrolling the console. Special
257 * characters are handled also: \n, \r, \b and \t.
258 *
259 * The device always starts with the cursor at position 0,0 (top left). It
260 * can be adjusted manually using vidconsole_position_cursor().
261 *
262 * @dev: Device to adjust
263 * @str: String to write
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100264 * Return: 0 if OK, -ve on error
Marek Vasute63168a2019-05-17 20:22:31 +0200265 */
266int vidconsole_put_string(struct udevice *dev, const char *str);
267
268/**
Simon Glass83510762016-01-18 19:52:17 -0700269 * vidconsole_position_cursor() - Move the text cursor
270 *
271 * @dev: Device to adjust
272 * @col: New cursor text column
273 * @row: New cursor text row
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100274 * Return: 0 if OK, -ve on error
Simon Glass83510762016-01-18 19:52:17 -0700275 */
276void vidconsole_position_cursor(struct udevice *dev, unsigned col,
277 unsigned row);
278
Simon Glass6b6dc0d2022-10-06 08:36:04 -0600279/**
280 * vidconsole_set_cursor_pos() - set cursor position
281 *
282 * The cursor is set to the new position and the start-of-line information is
283 * updated to the same position, so that a newline will return to @x
284 *
285 * @dev: video console device to update
286 * @x: x position from left in pixels
287 * @y: y position from top in pixels
288 */
289void vidconsole_set_cursor_pos(struct udevice *dev, int x, int y);
290
Simon Glass57a847c2022-10-06 08:36:14 -0600291/**
292 * vidconsole_list_fonts() - List the available fonts
293 *
Simon Glass0e38bd82023-01-06 08:52:32 -0600294 * @dev: vidconsole device to check
Simon Glass57a847c2022-10-06 08:36:14 -0600295 *
Simon Glass0e38bd82023-01-06 08:52:32 -0600296 * This shows a list of fonts known by this vidconsole. The list is displayed on
297 * the console (not necessarily @dev but probably)
Simon Glass57a847c2022-10-06 08:36:14 -0600298 */
Simon Glass0e38bd82023-01-06 08:52:32 -0600299void vidconsole_list_fonts(struct udevice *dev);
Simon Glass57a847c2022-10-06 08:36:14 -0600300
Simon Glass430e1672022-10-06 08:36:16 -0600301/**
Simon Glass0e38bd82023-01-06 08:52:32 -0600302 * vidconsole_get_font_size() - get the current font name and size
Simon Glass430e1672022-10-06 08:36:16 -0600303 *
304 * @dev: vidconsole device
305 * @sizep: Place to put the font size (nominal height in pixels)
306 * Returns: Current font name
307 */
Simon Glass0e38bd82023-01-06 08:52:32 -0600308const char *vidconsole_get_font_size(struct udevice *dev, uint *sizep);
Simon Glass430e1672022-10-06 08:36:16 -0600309
Simon Glass8c0b5d22020-07-02 21:12:23 -0600310#ifdef CONFIG_VIDEO_COPY
311/**
312 * vidconsole_sync_copy() - Sync back to the copy framebuffer
313 *
314 * This ensures that the copy framebuffer has the same data as the framebuffer
315 * for a particular region. It should be called after the framebuffer is updated
316 *
317 * @from and @to can be in either order. The region between them is synced.
318 *
319 * @dev: Vidconsole device being updated
320 * @from: Start/end address within the framebuffer (->fb)
321 * @to: Other address within the frame buffer
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100322 * Return: 0 if OK, -EFAULT if the start address is before the start of the
Simon Glass8c0b5d22020-07-02 21:12:23 -0600323 * frame buffer start
324 */
325int vidconsole_sync_copy(struct udevice *dev, void *from, void *to);
326
327/**
328 * vidconsole_memmove() - Perform a memmove() within the frame buffer
329 *
330 * This handles a memmove(), e.g. for scrolling. It also updates the copy
331 * framebuffer.
332 *
333 * @dev: Vidconsole device being updated
334 * @dst: Destination address within the framebuffer (->fb)
335 * @src: Source address within the framebuffer (->fb)
336 * @size: Number of bytes to transfer
Heinrich Schuchardt185f8122022-01-19 18:05:50 +0100337 * Return: 0 if OK, -EFAULT if the start address is before the start of the
Simon Glass8c0b5d22020-07-02 21:12:23 -0600338 * frame buffer start
339 */
340int vidconsole_memmove(struct udevice *dev, void *dst, const void *src,
341 int size);
342#else
Dzmitry Sankouski31547252023-03-07 13:21:11 +0300343
344#include <string.h>
345
Simon Glass8c0b5d22020-07-02 21:12:23 -0600346static inline int vidconsole_sync_copy(struct udevice *dev, void *from,
347 void *to)
348{
349 return 0;
350}
351
352static inline int vidconsole_memmove(struct udevice *dev, void *dst,
353 const void *src, int size)
354{
355 memmove(dst, src, size);
356
357 return 0;
358}
359
360#endif
361
Heinrich Schuchardt5c30fbb2018-02-08 21:47:11 +0100362#endif