xref: /rk3399_rockchip-uboot/include/video_console.h (revision 58c733a70ff1967490af1fd69aab2ba7bb86eb2c)
183510766SSimon Glass /*
283510766SSimon Glass  * Copyright (c) 2015 Google, Inc
383510766SSimon Glass  *
483510766SSimon Glass  * SPDX-License-Identifier:	GPL-2.0+
583510766SSimon Glass  */
683510766SSimon Glass 
783510766SSimon Glass #ifndef __video_console_h
883510766SSimon Glass #define __video_console_h
983510766SSimon Glass 
10f2661786SSimon Glass #define VID_FRAC_DIV	256
11f2661786SSimon Glass 
12f2661786SSimon Glass #define VID_TO_PIXEL(x)	((x) / VID_FRAC_DIV)
13f2661786SSimon Glass #define VID_TO_POS(x)	((x) * VID_FRAC_DIV)
14f2661786SSimon Glass 
1583510766SSimon Glass /**
1683510766SSimon Glass  * struct vidconsole_priv - uclass-private data about a console device
1783510766SSimon Glass  *
18f2661786SSimon Glass  * Drivers must set up @rows, @cols, @x_charsize, @y_charsize in their probe()
19f2661786SSimon Glass  * method. Drivers may set up @xstart_frac if desired.
20f2661786SSimon Glass  *
2183510766SSimon Glass  * @sdev:	stdio device, acting as an output sink
22f2661786SSimon Glass  * @xcur_frac:	Current X position, in fractional units (VID_TO_POS(x))
23f2661786SSimon Glass  * @curr_row:	Current Y position in pixels (0=top)
2483510766SSimon Glass  * @rows:	Number of text rows
2583510766SSimon Glass  * @cols:	Number of text columns
26f2661786SSimon Glass  * @x_charsize:	Character width in pixels
27f2661786SSimon Glass  * @y_charsize:	Character height in pixels
28f2661786SSimon Glass  * @tab_width_frac:	Tab width in fractional units
29f2661786SSimon Glass  * @xsize_frac:	Width of the display in fractional units
30c5b77d01SSimon Glass  * @xstart_frac:	Left margin for the text console in fractional units
31*58c733a7SSimon Glass  * @last_ch:	Last character written to the text console on this line
3283510766SSimon Glass  */
3383510766SSimon Glass struct vidconsole_priv {
3483510766SSimon Glass 	struct stdio_dev sdev;
35f2661786SSimon Glass 	int xcur_frac;
36f2661786SSimon Glass 	int ycur;
3783510766SSimon Glass 	int rows;
3883510766SSimon Glass 	int cols;
39f2661786SSimon Glass 	int x_charsize;
40f2661786SSimon Glass 	int y_charsize;
41f2661786SSimon Glass 	int tab_width_frac;
42f2661786SSimon Glass 	int xsize_frac;
43c5b77d01SSimon Glass 	int xstart_frac;
44*58c733a7SSimon Glass 	int last_ch;
4583510766SSimon Glass };
4683510766SSimon Glass 
4783510766SSimon Glass /**
4883510766SSimon Glass  * struct vidconsole_ops - Video console operations
4983510766SSimon Glass  *
5083510766SSimon Glass  * These operations work on either an absolute console position (measured
5183510766SSimon Glass  * in pixels) or a text row number (measured in rows, where each row consists
5283510766SSimon Glass  * of an entire line of text - typically 16 pixels).
5383510766SSimon Glass  */
5483510766SSimon Glass struct vidconsole_ops {
5583510766SSimon Glass 	/**
5683510766SSimon Glass 	 * putc_xy() - write a single character to a position
5783510766SSimon Glass 	 *
5883510766SSimon Glass 	 * @dev:	Device to write to
59f2661786SSimon Glass 	 * @x_frac:	Fractional pixel X position (0=left-most pixel) which
60f2661786SSimon Glass 	 *		is the X position multipled by VID_FRAC_DIV.
6183510766SSimon Glass 	 * @y:		Pixel Y position (0=top-most pixel)
6283510766SSimon Glass 	 * @ch:		Character to write
63f2661786SSimon Glass 	 * @return number of fractional pixels that the cursor should move,
64f2661786SSimon Glass 	 * if all is OK, -EAGAIN if we ran out of space on this line, other -ve
65f2661786SSimon Glass 	 * on error
6683510766SSimon Glass 	 */
67f2661786SSimon Glass 	int (*putc_xy)(struct udevice *dev, uint x_frac, uint y, char ch);
6883510766SSimon Glass 
6983510766SSimon Glass 	/**
7083510766SSimon Glass 	 * move_rows() - Move text rows from one place to another
7183510766SSimon Glass 	 *
7283510766SSimon Glass 	 * @dev:	Device to adjust
7383510766SSimon Glass 	 * @rowdst:	Destination text row (0=top)
7483510766SSimon Glass 	 * @rowsrc:	Source start text row
7583510766SSimon Glass 	 * @count:	Number of text rows to move
7683510766SSimon Glass 	 * @return 0 if OK, -ve on error
7783510766SSimon Glass 	 */
7883510766SSimon Glass 	int (*move_rows)(struct udevice *dev, uint rowdst, uint rowsrc,
7983510766SSimon Glass 			  uint count);
8083510766SSimon Glass 
8183510766SSimon Glass 	/**
8283510766SSimon Glass 	 * set_row() - Set the colour of a text row
8383510766SSimon Glass 	 *
8483510766SSimon Glass 	 * Every pixel contained within the text row is adjusted
8583510766SSimon Glass 	 *
8683510766SSimon Glass 	 * @dev:	Device to adjust
8783510766SSimon Glass 	 * @row:	Text row to adjust (0=top)
8883510766SSimon Glass 	 * @clr:	Raw colour (pixel value) to write to each pixel
8983510766SSimon Glass 	 * @return 0 if OK, -ve on error
9083510766SSimon Glass 	 */
9183510766SSimon Glass 	int (*set_row)(struct udevice *dev, uint row, int clr);
92*58c733a7SSimon Glass 
93*58c733a7SSimon Glass 	/**
94*58c733a7SSimon Glass 	 * entry_start() - Indicate that text entry is starting afresh
95*58c733a7SSimon Glass 	 *
96*58c733a7SSimon Glass 	 * Consoles which use proportional fonts need to track the position of
97*58c733a7SSimon Glass 	 * each character output so that backspace will return to the correct
98*58c733a7SSimon Glass 	 * place. This method signals to the console driver that a new entry
99*58c733a7SSimon Glass 	 * line is being start (e.g. the user pressed return to start a new
100*58c733a7SSimon Glass 	 * command). The driver can use this signal to empty its list of
101*58c733a7SSimon Glass 	 * positions.
102*58c733a7SSimon Glass 	 */
103*58c733a7SSimon Glass 	int (*entry_start)(struct udevice *dev);
10483510766SSimon Glass };
10583510766SSimon Glass 
10683510766SSimon Glass /* Get a pointer to the driver operations for a video console device */
10783510766SSimon Glass #define vidconsole_get_ops(dev)  ((struct vidconsole_ops *)(dev)->driver->ops)
10883510766SSimon Glass 
10983510766SSimon Glass /**
11083510766SSimon Glass  * vidconsole_putc_xy() - write a single character to a position
11183510766SSimon Glass  *
11283510766SSimon Glass  * @dev:	Device to write to
113f2661786SSimon Glass  * @x_frac:	Fractional pixel X position (0=left-most pixel) which
114f2661786SSimon Glass  *		is the X position multipled by VID_FRAC_DIV.
11583510766SSimon Glass  * @y:		Pixel Y position (0=top-most pixel)
11683510766SSimon Glass  * @ch:		Character to write
117f2661786SSimon Glass  * @return number of fractional pixels that the cursor should move,
118f2661786SSimon Glass  * if all is OK, -EAGAIN if we ran out of space on this line, other -ve
119f2661786SSimon Glass  * on error
12083510766SSimon Glass  */
12183510766SSimon Glass int vidconsole_putc_xy(struct udevice *dev, uint x, uint y, char ch);
12283510766SSimon Glass 
12383510766SSimon Glass /**
12483510766SSimon Glass  * vidconsole_move_rows() - Move text rows from one place to another
12583510766SSimon Glass  *
12683510766SSimon Glass  * @dev:	Device to adjust
12783510766SSimon Glass  * @rowdst:	Destination text row (0=top)
12883510766SSimon Glass  * @rowsrc:	Source start text row
12983510766SSimon Glass  * @count:	Number of text rows to move
13083510766SSimon Glass  * @return 0 if OK, -ve on error
13183510766SSimon Glass  */
13283510766SSimon Glass int vidconsole_move_rows(struct udevice *dev, uint rowdst, uint rowsrc,
13383510766SSimon Glass 			 uint count);
13483510766SSimon Glass 
13583510766SSimon Glass /**
13683510766SSimon Glass  * vidconsole_set_row() - Set the colour of a text row
13783510766SSimon Glass  *
13883510766SSimon Glass  * Every pixel contained within the text row is adjusted
13983510766SSimon Glass  *
14083510766SSimon Glass  * @dev:	Device to adjust
14183510766SSimon Glass  * @row:	Text row to adjust (0=top)
14283510766SSimon Glass  * @clr:	Raw colour (pixel value) to write to each pixel
14383510766SSimon Glass  * @return 0 if OK, -ve on error
14483510766SSimon Glass  */
14583510766SSimon Glass int vidconsole_set_row(struct udevice *dev, uint row, int clr);
14683510766SSimon Glass 
14783510766SSimon Glass /**
14883510766SSimon Glass  * vidconsole_put_char() - Output a character to the current console position
14983510766SSimon Glass  *
15083510766SSimon Glass  * Outputs a character to the console and advances the cursor. This function
15183510766SSimon Glass  * handles wrapping to new lines and scrolling the console. Special
15283510766SSimon Glass  * characters are handled also: \n, \r, \b and \t.
15383510766SSimon Glass  *
15483510766SSimon Glass  * The device always starts with the cursor at position 0,0 (top left). It
15583510766SSimon Glass  * can be adjusted manually using vidconsole_position_cursor().
15683510766SSimon Glass  *
15783510766SSimon Glass  * @dev:	Device to adjust
15883510766SSimon Glass  * @ch:		Character to write
15983510766SSimon Glass  * @return 0 if OK, -ve on error
16083510766SSimon Glass  */
16183510766SSimon Glass int vidconsole_put_char(struct udevice *dev, char ch);
16283510766SSimon Glass 
16383510766SSimon Glass /**
16483510766SSimon Glass  * vidconsole_position_cursor() - Move the text cursor
16583510766SSimon Glass  *
16683510766SSimon Glass  * @dev:	Device to adjust
16783510766SSimon Glass  * @col:	New cursor text column
16883510766SSimon Glass  * @row:	New cursor text row
16983510766SSimon Glass  * @return 0 if OK, -ve on error
17083510766SSimon Glass  */
17183510766SSimon Glass void vidconsole_position_cursor(struct udevice *dev, unsigned col,
17283510766SSimon Glass 				unsigned row);
17383510766SSimon Glass 
17483510766SSimon Glass #endif
175