video_console.h 6.9 KB

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