1 /* 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 #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 15 /** 16 * struct vidconsole_priv - uclass-private data about a console device 17 * 18 * Drivers must set up @rows, @cols, @x_charsize, @y_charsize in their probe() 19 * method. Drivers may set up @xstart_frac if desired. 20 * 21 * @sdev: stdio device, acting as an output sink 22 * @xcur_frac: Current X position, in fractional units (VID_TO_POS(x)) 23 * @curr_row: Current Y position in pixels (0=top) 24 * @rows: Number of text rows 25 * @cols: Number of text columns 26 * @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 30 */ 31 struct vidconsole_priv { 32 struct stdio_dev sdev; 33 int xcur_frac; 34 int ycur; 35 int rows; 36 int cols; 37 int x_charsize; 38 int y_charsize; 39 int tab_width_frac; 40 int xsize_frac; 41 }; 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 */ 50 struct vidconsole_ops { 51 /** 52 * putc_xy() - write a single character to a position 53 * 54 * @dev: Device to write to 55 * @x_frac: Fractional pixel X position (0=left-most pixel) which 56 * is the X position multipled by VID_FRAC_DIV. 57 * @y: Pixel Y position (0=top-most pixel) 58 * @ch: Character to write 59 * @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 62 */ 63 int (*putc_xy)(struct udevice *dev, uint x_frac, uint y, char ch); 64 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 97 * @x_frac: Fractional pixel X position (0=left-most pixel) which 98 * is the X position multipled by VID_FRAC_DIV. 99 * @y: Pixel Y position (0=top-most pixel) 100 * @ch: Character to write 101 * @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 104 */ 105 int 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 */ 116 int 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 */ 129 int 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 */ 145 int 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 */ 155 void vidconsole_position_cursor(struct udevice *dev, unsigned col, 156 unsigned row); 157 158 #endif 159