blob: eeba368d6391512ea49fbed561e7523d4e786be9 [file] [log] [blame]
Simon Glass83510762016-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 Glassf2661782016-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 Glass83510762016-01-18 19:52:17 -070015/**
16 * struct vidconsole_priv - uclass-private data about a console device
17 *
Simon Glassf2661782016-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 Glass83510762016-01-18 19:52:17 -070021 * @sdev: stdio device, acting as an output sink
Simon Glassf2661782016-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 Glass83510762016-01-18 19:52:17 -070024 * @rows: Number of text rows
25 * @cols: Number of text columns
Simon Glassf2661782016-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 Glass83510762016-01-18 19:52:17 -070030 */
31struct vidconsole_priv {
32 struct stdio_dev sdev;
Simon Glassf2661782016-01-14 18:10:37 -070033 int xcur_frac;
34 int ycur;
Simon Glass83510762016-01-18 19:52:17 -070035 int rows;
36 int cols;
Simon Glassf2661782016-01-14 18:10:37 -070037 int x_charsize;
38 int y_charsize;
39 int tab_width_frac;
40 int xsize_frac;
Simon Glass83510762016-01-18 19:52:17 -070041};
42
43/**
44 * struct vidconsole_ops - Video console operations
45 *
46 * These operations work on either an absolute console position (measured
47 * in pixels) or a text row number (measured in rows, where each row consists
48 * of an entire line of text - typically 16 pixels).
49 */
50struct vidconsole_ops {
51 /**
52 * putc_xy() - write a single character to a position
53 *
54 * @dev: Device to write to
Simon Glassf2661782016-01-14 18:10:37 -070055 * @x_frac: Fractional pixel X position (0=left-most pixel) which
56 * is the X position multipled by VID_FRAC_DIV.
Simon Glass83510762016-01-18 19:52:17 -070057 * @y: Pixel Y position (0=top-most pixel)
58 * @ch: Character to write
Simon Glassf2661782016-01-14 18:10:37 -070059 * @return number of fractional pixels that the cursor should move,
60 * if all is OK, -EAGAIN if we ran out of space on this line, other -ve
61 * on error
Simon Glass83510762016-01-18 19:52:17 -070062 */
Simon Glassf2661782016-01-14 18:10:37 -070063 int (*putc_xy)(struct udevice *dev, uint x_frac, uint y, char ch);
Simon Glass83510762016-01-18 19:52:17 -070064
65 /**
66 * move_rows() - Move text rows from one place to another
67 *
68 * @dev: Device to adjust
69 * @rowdst: Destination text row (0=top)
70 * @rowsrc: Source start text row
71 * @count: Number of text rows to move
72 * @return 0 if OK, -ve on error
73 */
74 int (*move_rows)(struct udevice *dev, uint rowdst, uint rowsrc,
75 uint count);
76
77 /**
78 * set_row() - Set the colour of a text row
79 *
80 * Every pixel contained within the text row is adjusted
81 *
82 * @dev: Device to adjust
83 * @row: Text row to adjust (0=top)
84 * @clr: Raw colour (pixel value) to write to each pixel
85 * @return 0 if OK, -ve on error
86 */
87 int (*set_row)(struct udevice *dev, uint row, int clr);
88};
89
90/* Get a pointer to the driver operations for a video console device */
91#define vidconsole_get_ops(dev) ((struct vidconsole_ops *)(dev)->driver->ops)
92
93/**
94 * vidconsole_putc_xy() - write a single character to a position
95 *
96 * @dev: Device to write to
Simon Glassf2661782016-01-14 18:10:37 -070097 * @x_frac: Fractional pixel X position (0=left-most pixel) which
98 * is the X position multipled by VID_FRAC_DIV.
Simon Glass83510762016-01-18 19:52:17 -070099 * @y: Pixel Y position (0=top-most pixel)
100 * @ch: Character to write
Simon Glassf2661782016-01-14 18:10:37 -0700101 * @return number of fractional pixels that the cursor should move,
102 * if all is OK, -EAGAIN if we ran out of space on this line, other -ve
103 * on error
Simon Glass83510762016-01-18 19:52:17 -0700104 */
105int vidconsole_putc_xy(struct udevice *dev, uint x, uint y, char ch);
106
107/**
108 * vidconsole_move_rows() - Move text rows from one place to another
109 *
110 * @dev: Device to adjust
111 * @rowdst: Destination text row (0=top)
112 * @rowsrc: Source start text row
113 * @count: Number of text rows to move
114 * @return 0 if OK, -ve on error
115 */
116int vidconsole_move_rows(struct udevice *dev, uint rowdst, uint rowsrc,
117 uint count);
118
119/**
120 * vidconsole_set_row() - Set the colour of a text row
121 *
122 * Every pixel contained within the text row is adjusted
123 *
124 * @dev: Device to adjust
125 * @row: Text row to adjust (0=top)
126 * @clr: Raw colour (pixel value) to write to each pixel
127 * @return 0 if OK, -ve on error
128 */
129int vidconsole_set_row(struct udevice *dev, uint row, int clr);
130
131/**
132 * vidconsole_put_char() - Output a character to the current console position
133 *
134 * Outputs a character to the console and advances the cursor. This function
135 * handles wrapping to new lines and scrolling the console. Special
136 * characters are handled also: \n, \r, \b and \t.
137 *
138 * The device always starts with the cursor at position 0,0 (top left). It
139 * can be adjusted manually using vidconsole_position_cursor().
140 *
141 * @dev: Device to adjust
142 * @ch: Character to write
143 * @return 0 if OK, -ve on error
144 */
145int vidconsole_put_char(struct udevice *dev, char ch);
146
147/**
148 * vidconsole_position_cursor() - Move the text cursor
149 *
150 * @dev: Device to adjust
151 * @col: New cursor text column
152 * @row: New cursor text row
153 * @return 0 if OK, -ve on error
154 */
155void vidconsole_position_cursor(struct udevice *dev, unsigned col,
156 unsigned row);
157
158#endif