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