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 * @xstart_frac: Left margin for the text console in fractional units 31 * @last_ch: Last character written to the text console on this line 32 */ 33 struct vidconsole_priv { 34 struct stdio_dev sdev; 35 int xcur_frac; 36 int ycur; 37 int rows; 38 int cols; 39 int x_charsize; 40 int y_charsize; 41 int tab_width_frac; 42 int xsize_frac; 43 int xstart_frac; 44 int last_ch; 45 }; 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 */ 54 struct vidconsole_ops { 55 /** 56 * putc_xy() - write a single character to a position 57 * 58 * @dev: Device to write to 59 * @x_frac: Fractional pixel X position (0=left-most pixel) which 60 * is the X position multipled by VID_FRAC_DIV. 61 * @y: Pixel Y position (0=top-most pixel) 62 * @ch: Character to write 63 * @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 66 */ 67 int (*putc_xy)(struct udevice *dev, uint x_frac, uint y, char ch); 68 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); 92 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); 104 }; 105 106 /* Get a pointer to the driver operations for a video console device */ 107 #define vidconsole_get_ops(dev) ((struct vidconsole_ops *)(dev)->driver->ops) 108 109 /** 110 * vidconsole_putc_xy() - write a single character to a position 111 * 112 * @dev: Device to write to 113 * @x_frac: Fractional pixel X position (0=left-most pixel) which 114 * is the X position multipled by VID_FRAC_DIV. 115 * @y: Pixel Y position (0=top-most pixel) 116 * @ch: Character to write 117 * @return number of fractional pixels that the cursor should move, 118 * if all is OK, -EAGAIN if we ran out of space on this line, other -ve 119 * on error 120 */ 121 int vidconsole_putc_xy(struct udevice *dev, uint x, uint y, char ch); 122 123 /** 124 * vidconsole_move_rows() - Move text rows from one place to another 125 * 126 * @dev: Device to adjust 127 * @rowdst: Destination text row (0=top) 128 * @rowsrc: Source start text row 129 * @count: Number of text rows to move 130 * @return 0 if OK, -ve on error 131 */ 132 int vidconsole_move_rows(struct udevice *dev, uint rowdst, uint rowsrc, 133 uint count); 134 135 /** 136 * vidconsole_set_row() - Set the colour of a text row 137 * 138 * Every pixel contained within the text row is adjusted 139 * 140 * @dev: Device to adjust 141 * @row: Text row to adjust (0=top) 142 * @clr: Raw colour (pixel value) to write to each pixel 143 * @return 0 if OK, -ve on error 144 */ 145 int vidconsole_set_row(struct udevice *dev, uint row, int clr); 146 147 /** 148 * vidconsole_put_char() - Output a character to the current console position 149 * 150 * Outputs a character to the console and advances the cursor. This function 151 * handles wrapping to new lines and scrolling the console. Special 152 * characters are handled also: \n, \r, \b and \t. 153 * 154 * The device always starts with the cursor at position 0,0 (top left). It 155 * can be adjusted manually using vidconsole_position_cursor(). 156 * 157 * @dev: Device to adjust 158 * @ch: Character to write 159 * @return 0 if OK, -ve on error 160 */ 161 int vidconsole_put_char(struct udevice *dev, char ch); 162 163 /** 164 * vidconsole_position_cursor() - Move the text cursor 165 * 166 * @dev: Device to adjust 167 * @col: New cursor text column 168 * @row: New cursor text row 169 * @return 0 if OK, -ve on error 170 */ 171 void vidconsole_position_cursor(struct udevice *dev, unsigned col, 172 unsigned row); 173 174 #endif 175