blob: c0fc79273a5b41be2a6d7d39eaca6e2b64eed9d8 [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
10/**
11 * struct vidconsole_priv - uclass-private data about a console device
12 *
13 * @sdev: stdio device, acting as an output sink
14 * @curr_col: Current text column (0=left)
15 * @curr_row: Current row (0=top)
16 * @rows: Number of text rows
17 * @cols: Number of text columns
18 */
19struct vidconsole_priv {
20 struct stdio_dev sdev;
21 int curr_col;
22 int curr_row;
23 int rows;
24 int cols;
25};
26
27/**
28 * struct vidconsole_ops - Video console operations
29 *
30 * These operations work on either an absolute console position (measured
31 * in pixels) or a text row number (measured in rows, where each row consists
32 * of an entire line of text - typically 16 pixels).
33 */
34struct vidconsole_ops {
35 /**
36 * putc_xy() - write a single character to a position
37 *
38 * @dev: Device to write to
39 * @x: Pixel X position (0=left-most pixel)
40 * @y: Pixel Y position (0=top-most pixel)
41 * @ch: Character to write
42 * @return 0 if OK, -ve on error
43 */
44 int (*putc_xy)(struct udevice *dev, uint x, uint y, char ch);
45
46 /**
47 * move_rows() - Move text rows from one place to another
48 *
49 * @dev: Device to adjust
50 * @rowdst: Destination text row (0=top)
51 * @rowsrc: Source start text row
52 * @count: Number of text rows to move
53 * @return 0 if OK, -ve on error
54 */
55 int (*move_rows)(struct udevice *dev, uint rowdst, uint rowsrc,
56 uint count);
57
58 /**
59 * set_row() - Set the colour of a text row
60 *
61 * Every pixel contained within the text row is adjusted
62 *
63 * @dev: Device to adjust
64 * @row: Text row to adjust (0=top)
65 * @clr: Raw colour (pixel value) to write to each pixel
66 * @return 0 if OK, -ve on error
67 */
68 int (*set_row)(struct udevice *dev, uint row, int clr);
69};
70
71/* Get a pointer to the driver operations for a video console device */
72#define vidconsole_get_ops(dev) ((struct vidconsole_ops *)(dev)->driver->ops)
73
74/**
75 * vidconsole_putc_xy() - write a single character to a position
76 *
77 * @dev: Device to write to
78 * @x: Pixel X position (0=left-most pixel)
79 * @y: Pixel Y position (0=top-most pixel)
80 * @ch: Character to write
81 * @return 0 if OK, -ve on error
82 */
83int vidconsole_putc_xy(struct udevice *dev, uint x, uint y, char ch);
84
85/**
86 * vidconsole_move_rows() - Move text rows from one place to another
87 *
88 * @dev: Device to adjust
89 * @rowdst: Destination text row (0=top)
90 * @rowsrc: Source start text row
91 * @count: Number of text rows to move
92 * @return 0 if OK, -ve on error
93 */
94int vidconsole_move_rows(struct udevice *dev, uint rowdst, uint rowsrc,
95 uint count);
96
97/**
98 * vidconsole_set_row() - Set the colour of a text row
99 *
100 * Every pixel contained within the text row is adjusted
101 *
102 * @dev: Device to adjust
103 * @row: Text row to adjust (0=top)
104 * @clr: Raw colour (pixel value) to write to each pixel
105 * @return 0 if OK, -ve on error
106 */
107int vidconsole_set_row(struct udevice *dev, uint row, int clr);
108
109/**
110 * vidconsole_put_char() - Output a character to the current console position
111 *
112 * Outputs a character to the console and advances the cursor. This function
113 * handles wrapping to new lines and scrolling the console. Special
114 * characters are handled also: \n, \r, \b and \t.
115 *
116 * The device always starts with the cursor at position 0,0 (top left). It
117 * can be adjusted manually using vidconsole_position_cursor().
118 *
119 * @dev: Device to adjust
120 * @ch: Character to write
121 * @return 0 if OK, -ve on error
122 */
123int vidconsole_put_char(struct udevice *dev, char ch);
124
125/**
126 * vidconsole_position_cursor() - Move the text cursor
127 *
128 * @dev: Device to adjust
129 * @col: New cursor text column
130 * @row: New cursor text row
131 * @return 0 if OK, -ve on error
132 */
133void vidconsole_position_cursor(struct udevice *dev, unsigned col,
134 unsigned row);
135
136#endif