Blame view

include/video_console.h 7.59 KB
83d290c56   Tom Rini   SPDX: Convert all...
1
  /* SPDX-License-Identifier: GPL-2.0+ */
83510766c   Simon Glass   dm: video: Add a ...
2
3
  /*
   * Copyright (c) 2015 Google, Inc
83510766c   Simon Glass   dm: video: Add a ...
4
5
6
7
   */
  
  #ifndef __video_console_h
  #define __video_console_h
5c30fbb8e   Heinrich Schuchardt   dm: video: use co...
8
  #include <video.h>
f26617869   Simon Glass   video: Use fracti...
9
10
11
12
  #define VID_FRAC_DIV	256
  
  #define VID_TO_PIXEL(x)	((x) / VID_FRAC_DIV)
  #define VID_TO_POS(x)	((x) * VID_FRAC_DIV)
5c30fbb8e   Heinrich Schuchardt   dm: video: use co...
13
  /*
9ffa4d12a   Heinrich Schuchardt   dm: video: suppor...
14
   * The 16 colors supported by the console
5c30fbb8e   Heinrich Schuchardt   dm: video: use co...
15
16
17
18
19
   */
  enum color_idx {
  	VID_BLACK = 0,
  	VID_RED,
  	VID_GREEN,
9ffa4d12a   Heinrich Schuchardt   dm: video: suppor...
20
  	VID_BROWN,
5c30fbb8e   Heinrich Schuchardt   dm: video: use co...
21
22
23
  	VID_BLUE,
  	VID_MAGENTA,
  	VID_CYAN,
9ffa4d12a   Heinrich Schuchardt   dm: video: suppor...
24
25
26
27
28
29
30
31
  	VID_LIGHT_GRAY,
  	VID_GRAY,
  	VID_LIGHT_RED,
  	VID_LIGTH_GREEN,
  	VID_YELLOW,
  	VID_LIGHT_BLUE,
  	VID_LIGHT_MAGENTA,
  	VID_LIGHT_CYAN,
5c30fbb8e   Heinrich Schuchardt   dm: video: use co...
32
33
34
35
  	VID_WHITE,
  
  	VID_COLOR_COUNT
  };
83510766c   Simon Glass   dm: video: Add a ...
36
37
38
  /**
   * struct vidconsole_priv - uclass-private data about a console device
   *
f26617869   Simon Glass   video: Use fracti...
39
40
41
   * Drivers must set up @rows, @cols, @x_charsize, @y_charsize in their probe()
   * method. Drivers may set up @xstart_frac if desired.
   *
662f381aa   Heinrich Schuchardt   dm: video: suppor...
42
43
44
45
46
47
48
   * @sdev:		stdio device, acting as an output sink
   * @xcur_frac:		Current X position, in fractional units (VID_TO_POS(x))
   * @ycur:		Current Y position in pixels (0=top)
   * @rows:		Number of text rows
   * @cols:		Number of text columns
   * @x_charsize:		Character width in pixels
   * @y_charsize:		Character height in pixels
f26617869   Simon Glass   video: Use fracti...
49
   * @tab_width_frac:	Tab width in fractional units
662f381aa   Heinrich Schuchardt   dm: video: suppor...
50
   * @xsize_frac:		Width of the display in fractional units
c5b77d01d   Simon Glass   video: Provide a ...
51
   * @xstart_frac:	Left margin for the text console in fractional units
662f381aa   Heinrich Schuchardt   dm: video: suppor...
52
53
54
55
56
57
   * @last_ch:		Last character written to the text console on this line
   * @escape:		TRUE if currently accumulating an ANSI escape sequence
   * @escape_len:		Length of accumulated escape sequence so far
   * @col_saved:		Saved X position, in fractional units (VID_TO_POS(x))
   * @row_saved:		Saved Y position in pixels (0=top)
   * @escape_buf:		Buffer to accumulate escape sequence
83510766c   Simon Glass   dm: video: Add a ...
58
59
60
   */
  struct vidconsole_priv {
  	struct stdio_dev sdev;
f26617869   Simon Glass   video: Use fracti...
61
62
  	int xcur_frac;
  	int ycur;
83510766c   Simon Glass   dm: video: Add a ...
63
64
  	int rows;
  	int cols;
f26617869   Simon Glass   video: Use fracti...
65
66
67
68
  	int x_charsize;
  	int y_charsize;
  	int tab_width_frac;
  	int xsize_frac;
c5b77d01d   Simon Glass   video: Provide a ...
69
  	int xstart_frac;
58c733a70   Simon Glass   video: Provide a ...
70
  	int last_ch;
a085aa1f2   Rob Clark   dm: video: Add ba...
71
72
73
74
75
76
77
  	/*
  	 * ANSI escape sequences are accumulated character by character,
  	 * starting after the ESC char (0x1b) until the entire sequence
  	 * is consumed at which point it is acted upon.
  	 */
  	int escape;
  	int escape_len;
662f381aa   Heinrich Schuchardt   dm: video: suppor...
78
79
  	int row_saved;
  	int col_saved;
a085aa1f2   Rob Clark   dm: video: Add ba...
80
  	char escape_buf[32];
83510766c   Simon Glass   dm: video: Add a ...
81
82
83
84
85
86
87
88
89
90
91
92
93
94
  };
  
  /**
   * struct vidconsole_ops - Video console operations
   *
   * These operations work on either an absolute console position (measured
   * in pixels) or a text row number (measured in rows, where each row consists
   * of an entire line of text - typically 16 pixels).
   */
  struct vidconsole_ops {
  	/**
  	 * putc_xy() - write a single character to a position
  	 *
  	 * @dev:	Device to write to
f26617869   Simon Glass   video: Use fracti...
95
96
  	 * @x_frac:	Fractional pixel X position (0=left-most pixel) which
  	 *		is the X position multipled by VID_FRAC_DIV.
83510766c   Simon Glass   dm: video: Add a ...
97
98
  	 * @y:		Pixel Y position (0=top-most pixel)
  	 * @ch:		Character to write
f26617869   Simon Glass   video: Use fracti...
99
100
101
  	 * @return number of fractional pixels that the cursor should move,
  	 * if all is OK, -EAGAIN if we ran out of space on this line, other -ve
  	 * on error
83510766c   Simon Glass   dm: video: Add a ...
102
  	 */
f26617869   Simon Glass   video: Use fracti...
103
  	int (*putc_xy)(struct udevice *dev, uint x_frac, uint y, char ch);
83510766c   Simon Glass   dm: video: Add a ...
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
  
  	/**
  	 * move_rows() - Move text rows from one place to another
  	 *
  	 * @dev:	Device to adjust
  	 * @rowdst:	Destination text row (0=top)
  	 * @rowsrc:	Source start text row
  	 * @count:	Number of text rows to move
  	 * @return 0 if OK, -ve on error
  	 */
  	int (*move_rows)(struct udevice *dev, uint rowdst, uint rowsrc,
  			  uint count);
  
  	/**
  	 * set_row() - Set the colour of a text row
  	 *
  	 * Every pixel contained within the text row is adjusted
  	 *
  	 * @dev:	Device to adjust
  	 * @row:	Text row to adjust (0=top)
  	 * @clr:	Raw colour (pixel value) to write to each pixel
  	 * @return 0 if OK, -ve on error
  	 */
  	int (*set_row)(struct udevice *dev, uint row, int clr);
58c733a70   Simon Glass   video: Provide a ...
128
129
130
131
132
133
134
135
136
137
138
139
  
  	/**
  	 * entry_start() - Indicate that text entry is starting afresh
  	 *
  	 * Consoles which use proportional fonts need to track the position of
  	 * each character output so that backspace will return to the correct
  	 * place. This method signals to the console driver that a new entry
  	 * line is being start (e.g. the user pressed return to start a new
  	 * command). The driver can use this signal to empty its list of
  	 * positions.
  	 */
  	int (*entry_start)(struct udevice *dev);
7b9f7e445   Simon Glass   video: Provide a ...
140
141
142
143
144
145
146
147
148
149
150
151
152
153
  
  	/**
  	 * backspace() - Handle erasing the last character
  	 *
  	 * With proportional fonts the vidconsole uclass cannot itself erase
  	 * the previous character. This optional method will be called when
  	 * a backspace is needed. The driver should erase the previous
  	 * character and update the cursor position (xcur_frac, ycur) to the
  	 * start of the previous character.
  	 *
  	 * If not implement, default behaviour will work for fixed-width
  	 * characters.
  	 */
  	int (*backspace)(struct udevice *dev);
83510766c   Simon Glass   dm: video: Add a ...
154
155
156
157
158
159
160
161
162
  };
  
  /* Get a pointer to the driver operations for a video console device */
  #define vidconsole_get_ops(dev)  ((struct vidconsole_ops *)(dev)->driver->ops)
  
  /**
   * vidconsole_putc_xy() - write a single character to a position
   *
   * @dev:	Device to write to
f26617869   Simon Glass   video: Use fracti...
163
164
   * @x_frac:	Fractional pixel X position (0=left-most pixel) which
   *		is the X position multipled by VID_FRAC_DIV.
83510766c   Simon Glass   dm: video: Add a ...
165
166
   * @y:		Pixel Y position (0=top-most pixel)
   * @ch:		Character to write
f26617869   Simon Glass   video: Use fracti...
167
168
169
   * @return number of fractional pixels that the cursor should move,
   * if all is OK, -EAGAIN if we ran out of space on this line, other -ve
   * on error
83510766c   Simon Glass   dm: video: Add a ...
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
   */
  int vidconsole_putc_xy(struct udevice *dev, uint x, uint y, char ch);
  
  /**
   * vidconsole_move_rows() - Move text rows from one place to another
   *
   * @dev:	Device to adjust
   * @rowdst:	Destination text row (0=top)
   * @rowsrc:	Source start text row
   * @count:	Number of text rows to move
   * @return 0 if OK, -ve on error
   */
  int vidconsole_move_rows(struct udevice *dev, uint rowdst, uint rowsrc,
  			 uint count);
  
  /**
   * vidconsole_set_row() - Set the colour of a text row
   *
   * Every pixel contained within the text row is adjusted
   *
   * @dev:	Device to adjust
   * @row:	Text row to adjust (0=top)
   * @clr:	Raw colour (pixel value) to write to each pixel
   * @return 0 if OK, -ve on error
   */
  int vidconsole_set_row(struct udevice *dev, uint row, int clr);
  
  /**
   * vidconsole_put_char() - Output a character to the current console position
   *
   * Outputs a character to the console and advances the cursor. This function
   * handles wrapping to new lines and scrolling the console. Special
   * characters are handled also: 
  , \r, \b and \t.
   *
   * The device always starts with the cursor at position 0,0 (top left). It
   * can be adjusted manually using vidconsole_position_cursor().
   *
   * @dev:	Device to adjust
   * @ch:		Character to write
   * @return 0 if OK, -ve on error
   */
  int vidconsole_put_char(struct udevice *dev, char ch);
  
  /**
e63168a9f   Marek Vasut   video: Factor out...
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
   * vidconsole_put_string() - Output a string to the current console position
   *
   * Outputs a string to the console and advances the cursor. This function
   * handles wrapping to new lines and scrolling the console. Special
   * characters are handled also: 
  , \r, \b and \t.
   *
   * The device always starts with the cursor at position 0,0 (top left). It
   * can be adjusted manually using vidconsole_position_cursor().
   *
   * @dev:	Device to adjust
   * @str:	String to write
   * @return 0 if OK, -ve on error
   */
  int vidconsole_put_string(struct udevice *dev, const char *str);
  
  /**
83510766c   Simon Glass   dm: video: Add a ...
232
233
234
235
236
237
238
239
240
   * vidconsole_position_cursor() - Move the text cursor
   *
   * @dev:	Device to adjust
   * @col:	New cursor text column
   * @row:	New cursor text row
   * @return 0 if OK, -ve on error
   */
  void vidconsole_position_cursor(struct udevice *dev, unsigned col,
  				unsigned row);
5c30fbb8e   Heinrich Schuchardt   dm: video: use co...
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
  #ifdef CONFIG_DM_VIDEO
  
  /**
   * vid_console_color() - convert a color code to a pixel's internal
   * representation
   *
   * The caller has to guarantee that the color index is less than
   * VID_COLOR_COUNT.
   *
   * @priv	private data of the console device
   * @idx		color index
   * @return	color value
   */
  u32 vid_console_color(struct video_priv *priv, unsigned int idx);
  
  #endif
83510766c   Simon Glass   dm: video: Add a ...
257
  #endif