xref: /OK3568_Linux_fs/u-boot/include/video_console.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Copyright (c) 2015 Google, Inc
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * SPDX-License-Identifier:	GPL-2.0+
5*4882a593Smuzhiyun  */
6*4882a593Smuzhiyun 
7*4882a593Smuzhiyun #ifndef __video_console_h
8*4882a593Smuzhiyun #define __video_console_h
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun #define VID_FRAC_DIV	256
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun #define VID_TO_PIXEL(x)	((x) / VID_FRAC_DIV)
13*4882a593Smuzhiyun #define VID_TO_POS(x)	((x) * VID_FRAC_DIV)
14*4882a593Smuzhiyun 
15*4882a593Smuzhiyun /**
16*4882a593Smuzhiyun  * struct vidconsole_priv - uclass-private data about a console device
17*4882a593Smuzhiyun  *
18*4882a593Smuzhiyun  * Drivers must set up @rows, @cols, @x_charsize, @y_charsize in their probe()
19*4882a593Smuzhiyun  * method. Drivers may set up @xstart_frac if desired.
20*4882a593Smuzhiyun  *
21*4882a593Smuzhiyun  * @sdev:	stdio device, acting as an output sink
22*4882a593Smuzhiyun  * @xcur_frac:	Current X position, in fractional units (VID_TO_POS(x))
23*4882a593Smuzhiyun  * @curr_row:	Current Y position in pixels (0=top)
24*4882a593Smuzhiyun  * @rows:	Number of text rows
25*4882a593Smuzhiyun  * @cols:	Number of text columns
26*4882a593Smuzhiyun  * @x_charsize:	Character width in pixels
27*4882a593Smuzhiyun  * @y_charsize:	Character height in pixels
28*4882a593Smuzhiyun  * @tab_width_frac:	Tab width in fractional units
29*4882a593Smuzhiyun  * @xsize_frac:	Width of the display in fractional units
30*4882a593Smuzhiyun  * @xstart_frac:	Left margin for the text console in fractional units
31*4882a593Smuzhiyun  * @last_ch:	Last character written to the text console on this line
32*4882a593Smuzhiyun  */
33*4882a593Smuzhiyun struct vidconsole_priv {
34*4882a593Smuzhiyun 	struct stdio_dev sdev;
35*4882a593Smuzhiyun 	int xcur_frac;
36*4882a593Smuzhiyun 	int ycur;
37*4882a593Smuzhiyun 	int rows;
38*4882a593Smuzhiyun 	int cols;
39*4882a593Smuzhiyun 	int x_charsize;
40*4882a593Smuzhiyun 	int y_charsize;
41*4882a593Smuzhiyun 	int tab_width_frac;
42*4882a593Smuzhiyun 	int xsize_frac;
43*4882a593Smuzhiyun 	int xstart_frac;
44*4882a593Smuzhiyun 	int last_ch;
45*4882a593Smuzhiyun };
46*4882a593Smuzhiyun 
47*4882a593Smuzhiyun /**
48*4882a593Smuzhiyun  * struct vidconsole_ops - Video console operations
49*4882a593Smuzhiyun  *
50*4882a593Smuzhiyun  * These operations work on either an absolute console position (measured
51*4882a593Smuzhiyun  * in pixels) or a text row number (measured in rows, where each row consists
52*4882a593Smuzhiyun  * of an entire line of text - typically 16 pixels).
53*4882a593Smuzhiyun  */
54*4882a593Smuzhiyun struct vidconsole_ops {
55*4882a593Smuzhiyun 	/**
56*4882a593Smuzhiyun 	 * putc_xy() - write a single character to a position
57*4882a593Smuzhiyun 	 *
58*4882a593Smuzhiyun 	 * @dev:	Device to write to
59*4882a593Smuzhiyun 	 * @x_frac:	Fractional pixel X position (0=left-most pixel) which
60*4882a593Smuzhiyun 	 *		is the X position multipled by VID_FRAC_DIV.
61*4882a593Smuzhiyun 	 * @y:		Pixel Y position (0=top-most pixel)
62*4882a593Smuzhiyun 	 * @ch:		Character to write
63*4882a593Smuzhiyun 	 * @return number of fractional pixels that the cursor should move,
64*4882a593Smuzhiyun 	 * if all is OK, -EAGAIN if we ran out of space on this line, other -ve
65*4882a593Smuzhiyun 	 * on error
66*4882a593Smuzhiyun 	 */
67*4882a593Smuzhiyun 	int (*putc_xy)(struct udevice *dev, uint x_frac, uint y, char ch);
68*4882a593Smuzhiyun 
69*4882a593Smuzhiyun 	/**
70*4882a593Smuzhiyun 	 * move_rows() - Move text rows from one place to another
71*4882a593Smuzhiyun 	 *
72*4882a593Smuzhiyun 	 * @dev:	Device to adjust
73*4882a593Smuzhiyun 	 * @rowdst:	Destination text row (0=top)
74*4882a593Smuzhiyun 	 * @rowsrc:	Source start text row
75*4882a593Smuzhiyun 	 * @count:	Number of text rows to move
76*4882a593Smuzhiyun 	 * @return 0 if OK, -ve on error
77*4882a593Smuzhiyun 	 */
78*4882a593Smuzhiyun 	int (*move_rows)(struct udevice *dev, uint rowdst, uint rowsrc,
79*4882a593Smuzhiyun 			  uint count);
80*4882a593Smuzhiyun 
81*4882a593Smuzhiyun 	/**
82*4882a593Smuzhiyun 	 * set_row() - Set the colour of a text row
83*4882a593Smuzhiyun 	 *
84*4882a593Smuzhiyun 	 * Every pixel contained within the text row is adjusted
85*4882a593Smuzhiyun 	 *
86*4882a593Smuzhiyun 	 * @dev:	Device to adjust
87*4882a593Smuzhiyun 	 * @row:	Text row to adjust (0=top)
88*4882a593Smuzhiyun 	 * @clr:	Raw colour (pixel value) to write to each pixel
89*4882a593Smuzhiyun 	 * @return 0 if OK, -ve on error
90*4882a593Smuzhiyun 	 */
91*4882a593Smuzhiyun 	int (*set_row)(struct udevice *dev, uint row, int clr);
92*4882a593Smuzhiyun 
93*4882a593Smuzhiyun 	/**
94*4882a593Smuzhiyun 	 * entry_start() - Indicate that text entry is starting afresh
95*4882a593Smuzhiyun 	 *
96*4882a593Smuzhiyun 	 * Consoles which use proportional fonts need to track the position of
97*4882a593Smuzhiyun 	 * each character output so that backspace will return to the correct
98*4882a593Smuzhiyun 	 * place. This method signals to the console driver that a new entry
99*4882a593Smuzhiyun 	 * line is being start (e.g. the user pressed return to start a new
100*4882a593Smuzhiyun 	 * command). The driver can use this signal to empty its list of
101*4882a593Smuzhiyun 	 * positions.
102*4882a593Smuzhiyun 	 */
103*4882a593Smuzhiyun 	int (*entry_start)(struct udevice *dev);
104*4882a593Smuzhiyun 
105*4882a593Smuzhiyun 	/**
106*4882a593Smuzhiyun 	 * backspace() - Handle erasing the last character
107*4882a593Smuzhiyun 	 *
108*4882a593Smuzhiyun 	 * With proportional fonts the vidconsole uclass cannot itself erase
109*4882a593Smuzhiyun 	 * the previous character. This optional method will be called when
110*4882a593Smuzhiyun 	 * a backspace is needed. The driver should erase the previous
111*4882a593Smuzhiyun 	 * character and update the cursor position (xcur_frac, ycur) to the
112*4882a593Smuzhiyun 	 * start of the previous character.
113*4882a593Smuzhiyun 	 *
114*4882a593Smuzhiyun 	 * If not implement, default behaviour will work for fixed-width
115*4882a593Smuzhiyun 	 * characters.
116*4882a593Smuzhiyun 	 */
117*4882a593Smuzhiyun 	int (*backspace)(struct udevice *dev);
118*4882a593Smuzhiyun };
119*4882a593Smuzhiyun 
120*4882a593Smuzhiyun /* Get a pointer to the driver operations for a video console device */
121*4882a593Smuzhiyun #define vidconsole_get_ops(dev)  ((struct vidconsole_ops *)(dev)->driver->ops)
122*4882a593Smuzhiyun 
123*4882a593Smuzhiyun /**
124*4882a593Smuzhiyun  * vidconsole_putc_xy() - write a single character to a position
125*4882a593Smuzhiyun  *
126*4882a593Smuzhiyun  * @dev:	Device to write to
127*4882a593Smuzhiyun  * @x_frac:	Fractional pixel X position (0=left-most pixel) which
128*4882a593Smuzhiyun  *		is the X position multipled by VID_FRAC_DIV.
129*4882a593Smuzhiyun  * @y:		Pixel Y position (0=top-most pixel)
130*4882a593Smuzhiyun  * @ch:		Character to write
131*4882a593Smuzhiyun  * @return number of fractional pixels that the cursor should move,
132*4882a593Smuzhiyun  * if all is OK, -EAGAIN if we ran out of space on this line, other -ve
133*4882a593Smuzhiyun  * on error
134*4882a593Smuzhiyun  */
135*4882a593Smuzhiyun int vidconsole_putc_xy(struct udevice *dev, uint x, uint y, char ch);
136*4882a593Smuzhiyun 
137*4882a593Smuzhiyun /**
138*4882a593Smuzhiyun  * vidconsole_move_rows() - Move text rows from one place to another
139*4882a593Smuzhiyun  *
140*4882a593Smuzhiyun  * @dev:	Device to adjust
141*4882a593Smuzhiyun  * @rowdst:	Destination text row (0=top)
142*4882a593Smuzhiyun  * @rowsrc:	Source start text row
143*4882a593Smuzhiyun  * @count:	Number of text rows to move
144*4882a593Smuzhiyun  * @return 0 if OK, -ve on error
145*4882a593Smuzhiyun  */
146*4882a593Smuzhiyun int vidconsole_move_rows(struct udevice *dev, uint rowdst, uint rowsrc,
147*4882a593Smuzhiyun 			 uint count);
148*4882a593Smuzhiyun 
149*4882a593Smuzhiyun /**
150*4882a593Smuzhiyun  * vidconsole_set_row() - Set the colour of a text row
151*4882a593Smuzhiyun  *
152*4882a593Smuzhiyun  * Every pixel contained within the text row is adjusted
153*4882a593Smuzhiyun  *
154*4882a593Smuzhiyun  * @dev:	Device to adjust
155*4882a593Smuzhiyun  * @row:	Text row to adjust (0=top)
156*4882a593Smuzhiyun  * @clr:	Raw colour (pixel value) to write to each pixel
157*4882a593Smuzhiyun  * @return 0 if OK, -ve on error
158*4882a593Smuzhiyun  */
159*4882a593Smuzhiyun int vidconsole_set_row(struct udevice *dev, uint row, int clr);
160*4882a593Smuzhiyun 
161*4882a593Smuzhiyun /**
162*4882a593Smuzhiyun  * vidconsole_put_char() - Output a character to the current console position
163*4882a593Smuzhiyun  *
164*4882a593Smuzhiyun  * Outputs a character to the console and advances the cursor. This function
165*4882a593Smuzhiyun  * handles wrapping to new lines and scrolling the console. Special
166*4882a593Smuzhiyun  * characters are handled also: \n, \r, \b and \t.
167*4882a593Smuzhiyun  *
168*4882a593Smuzhiyun  * The device always starts with the cursor at position 0,0 (top left). It
169*4882a593Smuzhiyun  * can be adjusted manually using vidconsole_position_cursor().
170*4882a593Smuzhiyun  *
171*4882a593Smuzhiyun  * @dev:	Device to adjust
172*4882a593Smuzhiyun  * @ch:		Character to write
173*4882a593Smuzhiyun  * @return 0 if OK, -ve on error
174*4882a593Smuzhiyun  */
175*4882a593Smuzhiyun int vidconsole_put_char(struct udevice *dev, char ch);
176*4882a593Smuzhiyun 
177*4882a593Smuzhiyun /**
178*4882a593Smuzhiyun  * vidconsole_position_cursor() - Move the text cursor
179*4882a593Smuzhiyun  *
180*4882a593Smuzhiyun  * @dev:	Device to adjust
181*4882a593Smuzhiyun  * @col:	New cursor text column
182*4882a593Smuzhiyun  * @row:	New cursor text row
183*4882a593Smuzhiyun  * @return 0 if OK, -ve on error
184*4882a593Smuzhiyun  */
185*4882a593Smuzhiyun void vidconsole_position_cursor(struct udevice *dev, unsigned col,
186*4882a593Smuzhiyun 				unsigned row);
187*4882a593Smuzhiyun 
188*4882a593Smuzhiyun #endif
189