]>
Commit | Line | Data |
---|---|---|
83510766 SG |
1 | /* |
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 | ||
f2661786 SG |
10 | #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 | ||
83510766 SG |
15 | /** |
16 | * struct vidconsole_priv - uclass-private data about a console device | |
17 | * | |
f2661786 SG |
18 | * Drivers must set up @rows, @cols, @x_charsize, @y_charsize in their probe() |
19 | * method. Drivers may set up @xstart_frac if desired. | |
20 | * | |
83510766 | 21 | * @sdev: stdio device, acting as an output sink |
f2661786 SG |
22 | * @xcur_frac: Current X position, in fractional units (VID_TO_POS(x)) |
23 | * @curr_row: Current Y position in pixels (0=top) | |
83510766 SG |
24 | * @rows: Number of text rows |
25 | * @cols: Number of text columns | |
f2661786 SG |
26 | * @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 | |
c5b77d01 | 30 | * @xstart_frac: Left margin for the text console in fractional units |
58c733a7 | 31 | * @last_ch: Last character written to the text console on this line |
a085aa1f RC |
32 | * @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 | |
83510766 SG |
35 | */ |
36 | struct vidconsole_priv { | |
37 | struct stdio_dev sdev; | |
f2661786 SG |
38 | int xcur_frac; |
39 | int ycur; | |
83510766 SG |
40 | int rows; |
41 | int cols; | |
f2661786 SG |
42 | int x_charsize; |
43 | int y_charsize; | |
44 | int tab_width_frac; | |
45 | int xsize_frac; | |
c5b77d01 | 46 | int xstart_frac; |
58c733a7 | 47 | int last_ch; |
a085aa1f RC |
48 | /* |
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]; | |
83510766 SG |
56 | }; |
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 | */ | |
65 | struct vidconsole_ops { | |
66 | /** | |
67 | * putc_xy() - write a single character to a position | |
68 | * | |
69 | * @dev: Device to write to | |
f2661786 SG |
70 | * @x_frac: Fractional pixel X position (0=left-most pixel) which |
71 | * is the X position multipled by VID_FRAC_DIV. | |
83510766 SG |
72 | * @y: Pixel Y position (0=top-most pixel) |
73 | * @ch: Character to write | |
f2661786 SG |
74 | * @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 | |
83510766 | 77 | */ |
f2661786 | 78 | int (*putc_xy)(struct udevice *dev, uint x_frac, uint y, char ch); |
83510766 SG |
79 | |
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); | |
58c733a7 SG |
103 | |
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); | |
7b9f7e44 SG |
115 | |
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); | |
83510766 SG |
129 | }; |
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 | |
f2661786 SG |
138 | * @x_frac: Fractional pixel X position (0=left-most pixel) which |
139 | * is the X position multipled by VID_FRAC_DIV. | |
83510766 SG |
140 | * @y: Pixel Y position (0=top-most pixel) |
141 | * @ch: Character to write | |
f2661786 SG |
142 | * @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 | |
83510766 SG |
145 | */ |
146 | int 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 | */ | |
157 | int 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 | */ | |
170 | int 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 | */ | |
186 | int 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 | */ | |
196 | void vidconsole_position_cursor(struct udevice *dev, unsigned col, | |
197 | unsigned row); | |
198 | ||
199 | #endif |