183510766SSimon Glass /* 283510766SSimon Glass * Copyright (c) 2015 Google, Inc 383510766SSimon Glass * 483510766SSimon Glass * SPDX-License-Identifier: GPL-2.0+ 583510766SSimon Glass */ 683510766SSimon Glass 783510766SSimon Glass #ifndef __video_console_h 883510766SSimon Glass #define __video_console_h 983510766SSimon Glass 10f2661786SSimon Glass #define VID_FRAC_DIV 256 11f2661786SSimon Glass 12f2661786SSimon Glass #define VID_TO_PIXEL(x) ((x) / VID_FRAC_DIV) 13f2661786SSimon Glass #define VID_TO_POS(x) ((x) * VID_FRAC_DIV) 14f2661786SSimon Glass 1583510766SSimon Glass /** 1683510766SSimon Glass * struct vidconsole_priv - uclass-private data about a console device 1783510766SSimon Glass * 18f2661786SSimon Glass * Drivers must set up @rows, @cols, @x_charsize, @y_charsize in their probe() 19f2661786SSimon Glass * method. Drivers may set up @xstart_frac if desired. 20f2661786SSimon Glass * 2183510766SSimon Glass * @sdev: stdio device, acting as an output sink 22f2661786SSimon Glass * @xcur_frac: Current X position, in fractional units (VID_TO_POS(x)) 23f2661786SSimon Glass * @curr_row: Current Y position in pixels (0=top) 2483510766SSimon Glass * @rows: Number of text rows 2583510766SSimon Glass * @cols: Number of text columns 26f2661786SSimon Glass * @x_charsize: Character width in pixels 27f2661786SSimon Glass * @y_charsize: Character height in pixels 28f2661786SSimon Glass * @tab_width_frac: Tab width in fractional units 29f2661786SSimon Glass * @xsize_frac: Width of the display in fractional units 30c5b77d01SSimon Glass * @xstart_frac: Left margin for the text console in fractional units 3158c733a7SSimon Glass * @last_ch: Last character written to the text console on this line 3283510766SSimon Glass */ 3383510766SSimon Glass struct vidconsole_priv { 3483510766SSimon Glass struct stdio_dev sdev; 35f2661786SSimon Glass int xcur_frac; 36f2661786SSimon Glass int ycur; 3783510766SSimon Glass int rows; 3883510766SSimon Glass int cols; 39f2661786SSimon Glass int x_charsize; 40f2661786SSimon Glass int y_charsize; 41f2661786SSimon Glass int tab_width_frac; 42f2661786SSimon Glass int xsize_frac; 43c5b77d01SSimon Glass int xstart_frac; 4458c733a7SSimon Glass int last_ch; 4583510766SSimon Glass }; 4683510766SSimon Glass 4783510766SSimon Glass /** 4883510766SSimon Glass * struct vidconsole_ops - Video console operations 4983510766SSimon Glass * 5083510766SSimon Glass * These operations work on either an absolute console position (measured 5183510766SSimon Glass * in pixels) or a text row number (measured in rows, where each row consists 5283510766SSimon Glass * of an entire line of text - typically 16 pixels). 5383510766SSimon Glass */ 5483510766SSimon Glass struct vidconsole_ops { 5583510766SSimon Glass /** 5683510766SSimon Glass * putc_xy() - write a single character to a position 5783510766SSimon Glass * 5883510766SSimon Glass * @dev: Device to write to 59f2661786SSimon Glass * @x_frac: Fractional pixel X position (0=left-most pixel) which 60f2661786SSimon Glass * is the X position multipled by VID_FRAC_DIV. 6183510766SSimon Glass * @y: Pixel Y position (0=top-most pixel) 6283510766SSimon Glass * @ch: Character to write 63f2661786SSimon Glass * @return number of fractional pixels that the cursor should move, 64f2661786SSimon Glass * if all is OK, -EAGAIN if we ran out of space on this line, other -ve 65f2661786SSimon Glass * on error 6683510766SSimon Glass */ 67f2661786SSimon Glass int (*putc_xy)(struct udevice *dev, uint x_frac, uint y, char ch); 6883510766SSimon Glass 6983510766SSimon Glass /** 7083510766SSimon Glass * move_rows() - Move text rows from one place to another 7183510766SSimon Glass * 7283510766SSimon Glass * @dev: Device to adjust 7383510766SSimon Glass * @rowdst: Destination text row (0=top) 7483510766SSimon Glass * @rowsrc: Source start text row 7583510766SSimon Glass * @count: Number of text rows to move 7683510766SSimon Glass * @return 0 if OK, -ve on error 7783510766SSimon Glass */ 7883510766SSimon Glass int (*move_rows)(struct udevice *dev, uint rowdst, uint rowsrc, 7983510766SSimon Glass uint count); 8083510766SSimon Glass 8183510766SSimon Glass /** 8283510766SSimon Glass * set_row() - Set the colour of a text row 8383510766SSimon Glass * 8483510766SSimon Glass * Every pixel contained within the text row is adjusted 8583510766SSimon Glass * 8683510766SSimon Glass * @dev: Device to adjust 8783510766SSimon Glass * @row: Text row to adjust (0=top) 8883510766SSimon Glass * @clr: Raw colour (pixel value) to write to each pixel 8983510766SSimon Glass * @return 0 if OK, -ve on error 9083510766SSimon Glass */ 9183510766SSimon Glass int (*set_row)(struct udevice *dev, uint row, int clr); 9258c733a7SSimon Glass 9358c733a7SSimon Glass /** 9458c733a7SSimon Glass * entry_start() - Indicate that text entry is starting afresh 9558c733a7SSimon Glass * 9658c733a7SSimon Glass * Consoles which use proportional fonts need to track the position of 9758c733a7SSimon Glass * each character output so that backspace will return to the correct 9858c733a7SSimon Glass * place. This method signals to the console driver that a new entry 9958c733a7SSimon Glass * line is being start (e.g. the user pressed return to start a new 10058c733a7SSimon Glass * command). The driver can use this signal to empty its list of 10158c733a7SSimon Glass * positions. 10258c733a7SSimon Glass */ 10358c733a7SSimon Glass int (*entry_start)(struct udevice *dev); 104*7b9f7e44SSimon Glass 105*7b9f7e44SSimon Glass /** 106*7b9f7e44SSimon Glass * backspace() - Handle erasing the last character 107*7b9f7e44SSimon Glass * 108*7b9f7e44SSimon Glass * With proportional fonts the vidconsole uclass cannot itself erase 109*7b9f7e44SSimon Glass * the previous character. This optional method will be called when 110*7b9f7e44SSimon Glass * a backspace is needed. The driver should erase the previous 111*7b9f7e44SSimon Glass * character and update the cursor position (xcur_frac, ycur) to the 112*7b9f7e44SSimon Glass * start of the previous character. 113*7b9f7e44SSimon Glass * 114*7b9f7e44SSimon Glass * If not implement, default behaviour will work for fixed-width 115*7b9f7e44SSimon Glass * characters. 116*7b9f7e44SSimon Glass */ 117*7b9f7e44SSimon Glass int (*backspace)(struct udevice *dev); 11883510766SSimon Glass }; 11983510766SSimon Glass 12083510766SSimon Glass /* Get a pointer to the driver operations for a video console device */ 12183510766SSimon Glass #define vidconsole_get_ops(dev) ((struct vidconsole_ops *)(dev)->driver->ops) 12283510766SSimon Glass 12383510766SSimon Glass /** 12483510766SSimon Glass * vidconsole_putc_xy() - write a single character to a position 12583510766SSimon Glass * 12683510766SSimon Glass * @dev: Device to write to 127f2661786SSimon Glass * @x_frac: Fractional pixel X position (0=left-most pixel) which 128f2661786SSimon Glass * is the X position multipled by VID_FRAC_DIV. 12983510766SSimon Glass * @y: Pixel Y position (0=top-most pixel) 13083510766SSimon Glass * @ch: Character to write 131f2661786SSimon Glass * @return number of fractional pixels that the cursor should move, 132f2661786SSimon Glass * if all is OK, -EAGAIN if we ran out of space on this line, other -ve 133f2661786SSimon Glass * on error 13483510766SSimon Glass */ 13583510766SSimon Glass int vidconsole_putc_xy(struct udevice *dev, uint x, uint y, char ch); 13683510766SSimon Glass 13783510766SSimon Glass /** 13883510766SSimon Glass * vidconsole_move_rows() - Move text rows from one place to another 13983510766SSimon Glass * 14083510766SSimon Glass * @dev: Device to adjust 14183510766SSimon Glass * @rowdst: Destination text row (0=top) 14283510766SSimon Glass * @rowsrc: Source start text row 14383510766SSimon Glass * @count: Number of text rows to move 14483510766SSimon Glass * @return 0 if OK, -ve on error 14583510766SSimon Glass */ 14683510766SSimon Glass int vidconsole_move_rows(struct udevice *dev, uint rowdst, uint rowsrc, 14783510766SSimon Glass uint count); 14883510766SSimon Glass 14983510766SSimon Glass /** 15083510766SSimon Glass * vidconsole_set_row() - Set the colour of a text row 15183510766SSimon Glass * 15283510766SSimon Glass * Every pixel contained within the text row is adjusted 15383510766SSimon Glass * 15483510766SSimon Glass * @dev: Device to adjust 15583510766SSimon Glass * @row: Text row to adjust (0=top) 15683510766SSimon Glass * @clr: Raw colour (pixel value) to write to each pixel 15783510766SSimon Glass * @return 0 if OK, -ve on error 15883510766SSimon Glass */ 15983510766SSimon Glass int vidconsole_set_row(struct udevice *dev, uint row, int clr); 16083510766SSimon Glass 16183510766SSimon Glass /** 16283510766SSimon Glass * vidconsole_put_char() - Output a character to the current console position 16383510766SSimon Glass * 16483510766SSimon Glass * Outputs a character to the console and advances the cursor. This function 16583510766SSimon Glass * handles wrapping to new lines and scrolling the console. Special 16683510766SSimon Glass * characters are handled also: \n, \r, \b and \t. 16783510766SSimon Glass * 16883510766SSimon Glass * The device always starts with the cursor at position 0,0 (top left). It 16983510766SSimon Glass * can be adjusted manually using vidconsole_position_cursor(). 17083510766SSimon Glass * 17183510766SSimon Glass * @dev: Device to adjust 17283510766SSimon Glass * @ch: Character to write 17383510766SSimon Glass * @return 0 if OK, -ve on error 17483510766SSimon Glass */ 17583510766SSimon Glass int vidconsole_put_char(struct udevice *dev, char ch); 17683510766SSimon Glass 17783510766SSimon Glass /** 17883510766SSimon Glass * vidconsole_position_cursor() - Move the text cursor 17983510766SSimon Glass * 18083510766SSimon Glass * @dev: Device to adjust 18183510766SSimon Glass * @col: New cursor text column 18283510766SSimon Glass * @row: New cursor text row 18383510766SSimon Glass * @return 0 if OK, -ve on error 18483510766SSimon Glass */ 18583510766SSimon Glass void vidconsole_position_cursor(struct udevice *dev, unsigned col, 18683510766SSimon Glass unsigned row); 18783510766SSimon Glass 18883510766SSimon Glass #endif 189