]> git.sur5r.net Git - u-boot/blob - include/video_console.h
656a47295f62e630887edc3e01a80bcbbb40235d
[u-boot] / include / video_console.h
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
10 #include <video.h>
11
12 #define VID_FRAC_DIV    256
13
14 #define VID_TO_PIXEL(x) ((x) / VID_FRAC_DIV)
15 #define VID_TO_POS(x)   ((x) * VID_FRAC_DIV)
16
17 /*
18  * The 8 colors supported by the console
19  */
20 enum color_idx {
21         VID_BLACK = 0,
22         VID_RED,
23         VID_GREEN,
24         VID_YELLOW,
25         VID_BLUE,
26         VID_MAGENTA,
27         VID_CYAN,
28         VID_WHITE,
29
30         VID_COLOR_COUNT
31 };
32
33 /**
34  * struct vidconsole_priv - uclass-private data about a console device
35  *
36  * Drivers must set up @rows, @cols, @x_charsize, @y_charsize in their probe()
37  * method. Drivers may set up @xstart_frac if desired.
38  *
39  * @sdev:       stdio device, acting as an output sink
40  * @xcur_frac:  Current X position, in fractional units (VID_TO_POS(x))
41  * @curr_row:   Current Y position in pixels (0=top)
42  * @rows:       Number of text rows
43  * @cols:       Number of text columns
44  * @x_charsize: Character width in pixels
45  * @y_charsize: Character height in pixels
46  * @tab_width_frac:     Tab width in fractional units
47  * @xsize_frac: Width of the display in fractional units
48  * @xstart_frac:        Left margin for the text console in fractional units
49  * @last_ch:    Last character written to the text console on this line
50  * @escape:     TRUE if currently accumulating an ANSI escape sequence
51  * @escape_len: Length of accumulated escape sequence so far
52  * @escape_buf: Buffer to accumulate escape sequence
53  */
54 struct vidconsole_priv {
55         struct stdio_dev sdev;
56         int xcur_frac;
57         int ycur;
58         int rows;
59         int cols;
60         int x_charsize;
61         int y_charsize;
62         int tab_width_frac;
63         int xsize_frac;
64         int xstart_frac;
65         int last_ch;
66         /*
67          * ANSI escape sequences are accumulated character by character,
68          * starting after the ESC char (0x1b) until the entire sequence
69          * is consumed at which point it is acted upon.
70          */
71         int escape;
72         int escape_len;
73         char escape_buf[32];
74 };
75
76 /**
77  * struct vidconsole_ops - Video console operations
78  *
79  * These operations work on either an absolute console position (measured
80  * in pixels) or a text row number (measured in rows, where each row consists
81  * of an entire line of text - typically 16 pixels).
82  */
83 struct vidconsole_ops {
84         /**
85          * putc_xy() - write a single character to a position
86          *
87          * @dev:        Device to write to
88          * @x_frac:     Fractional pixel X position (0=left-most pixel) which
89          *              is the X position multipled by VID_FRAC_DIV.
90          * @y:          Pixel Y position (0=top-most pixel)
91          * @ch:         Character to write
92          * @return number of fractional pixels that the cursor should move,
93          * if all is OK, -EAGAIN if we ran out of space on this line, other -ve
94          * on error
95          */
96         int (*putc_xy)(struct udevice *dev, uint x_frac, uint y, char ch);
97
98         /**
99          * move_rows() - Move text rows from one place to another
100          *
101          * @dev:        Device to adjust
102          * @rowdst:     Destination text row (0=top)
103          * @rowsrc:     Source start text row
104          * @count:      Number of text rows to move
105          * @return 0 if OK, -ve on error
106          */
107         int (*move_rows)(struct udevice *dev, uint rowdst, uint rowsrc,
108                           uint count);
109
110         /**
111          * set_row() - Set the colour of a text row
112          *
113          * Every pixel contained within the text row is adjusted
114          *
115          * @dev:        Device to adjust
116          * @row:        Text row to adjust (0=top)
117          * @clr:        Raw colour (pixel value) to write to each pixel
118          * @return 0 if OK, -ve on error
119          */
120         int (*set_row)(struct udevice *dev, uint row, int clr);
121
122         /**
123          * entry_start() - Indicate that text entry is starting afresh
124          *
125          * Consoles which use proportional fonts need to track the position of
126          * each character output so that backspace will return to the correct
127          * place. This method signals to the console driver that a new entry
128          * line is being start (e.g. the user pressed return to start a new
129          * command). The driver can use this signal to empty its list of
130          * positions.
131          */
132         int (*entry_start)(struct udevice *dev);
133
134         /**
135          * backspace() - Handle erasing the last character
136          *
137          * With proportional fonts the vidconsole uclass cannot itself erase
138          * the previous character. This optional method will be called when
139          * a backspace is needed. The driver should erase the previous
140          * character and update the cursor position (xcur_frac, ycur) to the
141          * start of the previous character.
142          *
143          * If not implement, default behaviour will work for fixed-width
144          * characters.
145          */
146         int (*backspace)(struct udevice *dev);
147 };
148
149 /* Get a pointer to the driver operations for a video console device */
150 #define vidconsole_get_ops(dev)  ((struct vidconsole_ops *)(dev)->driver->ops)
151
152 /**
153  * vidconsole_putc_xy() - write a single character to a position
154  *
155  * @dev:        Device to write to
156  * @x_frac:     Fractional pixel X position (0=left-most pixel) which
157  *              is the X position multipled by VID_FRAC_DIV.
158  * @y:          Pixel Y position (0=top-most pixel)
159  * @ch:         Character to write
160  * @return number of fractional pixels that the cursor should move,
161  * if all is OK, -EAGAIN if we ran out of space on this line, other -ve
162  * on error
163  */
164 int vidconsole_putc_xy(struct udevice *dev, uint x, uint y, char ch);
165
166 /**
167  * vidconsole_move_rows() - Move text rows from one place to another
168  *
169  * @dev:        Device to adjust
170  * @rowdst:     Destination text row (0=top)
171  * @rowsrc:     Source start text row
172  * @count:      Number of text rows to move
173  * @return 0 if OK, -ve on error
174  */
175 int vidconsole_move_rows(struct udevice *dev, uint rowdst, uint rowsrc,
176                          uint count);
177
178 /**
179  * vidconsole_set_row() - Set the colour of a text row
180  *
181  * Every pixel contained within the text row is adjusted
182  *
183  * @dev:        Device to adjust
184  * @row:        Text row to adjust (0=top)
185  * @clr:        Raw colour (pixel value) to write to each pixel
186  * @return 0 if OK, -ve on error
187  */
188 int vidconsole_set_row(struct udevice *dev, uint row, int clr);
189
190 /**
191  * vidconsole_put_char() - Output a character to the current console position
192  *
193  * Outputs a character to the console and advances the cursor. This function
194  * handles wrapping to new lines and scrolling the console. Special
195  * characters are handled also: \n, \r, \b and \t.
196  *
197  * The device always starts with the cursor at position 0,0 (top left). It
198  * can be adjusted manually using vidconsole_position_cursor().
199  *
200  * @dev:        Device to adjust
201  * @ch:         Character to write
202  * @return 0 if OK, -ve on error
203  */
204 int vidconsole_put_char(struct udevice *dev, char ch);
205
206 /**
207  * vidconsole_position_cursor() - Move the text cursor
208  *
209  * @dev:        Device to adjust
210  * @col:        New cursor text column
211  * @row:        New cursor text row
212  * @return 0 if OK, -ve on error
213  */
214 void vidconsole_position_cursor(struct udevice *dev, unsigned col,
215                                 unsigned row);
216
217 #ifdef CONFIG_DM_VIDEO
218
219 /**
220  * vid_console_color() - convert a color code to a pixel's internal
221  * representation
222  *
223  * The caller has to guarantee that the color index is less than
224  * VID_COLOR_COUNT.
225  *
226  * @priv        private data of the console device
227  * @idx         color index
228  * @return      color value
229  */
230 u32 vid_console_color(struct video_priv *priv, unsigned int idx);
231
232 #endif
233
234 #endif