blob: 26047934da8c59b4646caa6cb9f8a631d1ce0561 [file] [log] [blame]
Simon Glass84c7fb32016-01-18 19:52:17 -07001/*
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
Simon Glass52c10c52016-01-14 18:10:37 -070010#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
Simon Glass84c7fb32016-01-18 19:52:17 -070015/**
16 * struct vidconsole_priv - uclass-private data about a console device
17 *
Simon Glass52c10c52016-01-14 18:10:37 -070018 * Drivers must set up @rows, @cols, @x_charsize, @y_charsize in their probe()
19 * method. Drivers may set up @xstart_frac if desired.
20 *
Simon Glass84c7fb32016-01-18 19:52:17 -070021 * @sdev: stdio device, acting as an output sink
Simon Glass52c10c52016-01-14 18:10:37 -070022 * @xcur_frac: Current X position, in fractional units (VID_TO_POS(x))
23 * @curr_row: Current Y position in pixels (0=top)
Simon Glass84c7fb32016-01-18 19:52:17 -070024 * @rows: Number of text rows
25 * @cols: Number of text columns
Simon Glass52c10c52016-01-14 18:10:37 -070026 * @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
Simon Glassa74451d2016-01-14 18:10:39 -070030 * @xstart_frac: Left margin for the text console in fractional units
Simon Glassafee7432016-01-14 18:10:40 -070031 * @last_ch: Last character written to the text console on this line
Simon Glass84c7fb32016-01-18 19:52:17 -070032 */
33struct vidconsole_priv {
34 struct stdio_dev sdev;
Simon Glass52c10c52016-01-14 18:10:37 -070035 int xcur_frac;
36 int ycur;
Simon Glass84c7fb32016-01-18 19:52:17 -070037 int rows;
38 int cols;
Simon Glass52c10c52016-01-14 18:10:37 -070039 int x_charsize;
40 int y_charsize;
41 int tab_width_frac;
42 int xsize_frac;
Simon Glassa74451d2016-01-14 18:10:39 -070043 int xstart_frac;
Simon Glassafee7432016-01-14 18:10:40 -070044 int last_ch;
Simon Glass84c7fb32016-01-18 19:52:17 -070045};
46
47/**
48 * struct vidconsole_ops - Video console operations
49 *
50 * These operations work on either an absolute console position (measured
51 * in pixels) or a text row number (measured in rows, where each row consists
52 * of an entire line of text - typically 16 pixels).
53 */
54struct vidconsole_ops {
55 /**
56 * putc_xy() - write a single character to a position
57 *
58 * @dev: Device to write to
Simon Glass52c10c52016-01-14 18:10:37 -070059 * @x_frac: Fractional pixel X position (0=left-most pixel) which
60 * is the X position multipled by VID_FRAC_DIV.
Simon Glass84c7fb32016-01-18 19:52:17 -070061 * @y: Pixel Y position (0=top-most pixel)
62 * @ch: Character to write
Simon Glass52c10c52016-01-14 18:10:37 -070063 * @return number of fractional pixels that the cursor should move,
64 * if all is OK, -EAGAIN if we ran out of space on this line, other -ve
65 * on error
Simon Glass84c7fb32016-01-18 19:52:17 -070066 */
Simon Glass52c10c52016-01-14 18:10:37 -070067 int (*putc_xy)(struct udevice *dev, uint x_frac, uint y, char ch);
Simon Glass84c7fb32016-01-18 19:52:17 -070068
69 /**
70 * move_rows() - Move text rows from one place to another
71 *
72 * @dev: Device to adjust
73 * @rowdst: Destination text row (0=top)
74 * @rowsrc: Source start text row
75 * @count: Number of text rows to move
76 * @return 0 if OK, -ve on error
77 */
78 int (*move_rows)(struct udevice *dev, uint rowdst, uint rowsrc,
79 uint count);
80
81 /**
82 * set_row() - Set the colour of a text row
83 *
84 * Every pixel contained within the text row is adjusted
85 *
86 * @dev: Device to adjust
87 * @row: Text row to adjust (0=top)
88 * @clr: Raw colour (pixel value) to write to each pixel
89 * @return 0 if OK, -ve on error
90 */
91 int (*set_row)(struct udevice *dev, uint row, int clr);
Simon Glassafee7432016-01-14 18:10:40 -070092
93 /**
94 * entry_start() - Indicate that text entry is starting afresh
95 *
96 * Consoles which use proportional fonts need to track the position of
97 * each character output so that backspace will return to the correct
98 * place. This method signals to the console driver that a new entry
99 * line is being start (e.g. the user pressed return to start a new
100 * command). The driver can use this signal to empty its list of
101 * positions.
102 */
103 int (*entry_start)(struct udevice *dev);
Simon Glass33bd3b62016-01-14 18:10:41 -0700104
105 /**
106 * backspace() - Handle erasing the last character
107 *
108 * With proportional fonts the vidconsole uclass cannot itself erase
109 * the previous character. This optional method will be called when
110 * a backspace is needed. The driver should erase the previous
111 * character and update the cursor position (xcur_frac, ycur) to the
112 * start of the previous character.
113 *
114 * If not implement, default behaviour will work for fixed-width
115 * characters.
116 */
117 int (*backspace)(struct udevice *dev);
Simon Glass84c7fb32016-01-18 19:52:17 -0700118};
119
120/* Get a pointer to the driver operations for a video console device */
121#define vidconsole_get_ops(dev) ((struct vidconsole_ops *)(dev)->driver->ops)
122
123/**
124 * vidconsole_putc_xy() - write a single character to a position
125 *
126 * @dev: Device to write to
Simon Glass52c10c52016-01-14 18:10:37 -0700127 * @x_frac: Fractional pixel X position (0=left-most pixel) which
128 * is the X position multipled by VID_FRAC_DIV.
Simon Glass84c7fb32016-01-18 19:52:17 -0700129 * @y: Pixel Y position (0=top-most pixel)
130 * @ch: Character to write
Simon Glass52c10c52016-01-14 18:10:37 -0700131 * @return number of fractional pixels that the cursor should move,
132 * if all is OK, -EAGAIN if we ran out of space on this line, other -ve
133 * on error
Simon Glass84c7fb32016-01-18 19:52:17 -0700134 */
135int vidconsole_putc_xy(struct udevice *dev, uint x, uint y, char ch);
136
137/**
138 * vidconsole_move_rows() - Move text rows from one place to another
139 *
140 * @dev: Device to adjust
141 * @rowdst: Destination text row (0=top)
142 * @rowsrc: Source start text row
143 * @count: Number of text rows to move
144 * @return 0 if OK, -ve on error
145 */
146int vidconsole_move_rows(struct udevice *dev, uint rowdst, uint rowsrc,
147 uint count);
148
149/**
150 * vidconsole_set_row() - Set the colour of a text row
151 *
152 * Every pixel contained within the text row is adjusted
153 *
154 * @dev: Device to adjust
155 * @row: Text row to adjust (0=top)
156 * @clr: Raw colour (pixel value) to write to each pixel
157 * @return 0 if OK, -ve on error
158 */
159int vidconsole_set_row(struct udevice *dev, uint row, int clr);
160
161/**
162 * vidconsole_put_char() - Output a character to the current console position
163 *
164 * Outputs a character to the console and advances the cursor. This function
165 * handles wrapping to new lines and scrolling the console. Special
166 * characters are handled also: \n, \r, \b and \t.
167 *
168 * The device always starts with the cursor at position 0,0 (top left). It
169 * can be adjusted manually using vidconsole_position_cursor().
170 *
171 * @dev: Device to adjust
172 * @ch: Character to write
173 * @return 0 if OK, -ve on error
174 */
175int vidconsole_put_char(struct udevice *dev, char ch);
176
177/**
178 * vidconsole_position_cursor() - Move the text cursor
179 *
180 * @dev: Device to adjust
181 * @col: New cursor text column
182 * @row: New cursor text row
183 * @return 0 if OK, -ve on error
184 */
185void vidconsole_position_cursor(struct udevice *dev, unsigned col,
186 unsigned row);
187
188#endif