video_console.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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. * @ycur: 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. * @col_saved: Saved X position, in fractional units (VID_TO_POS(x))
  53. * @row_saved: Saved Y position in pixels (0=top)
  54. * @escape_buf: Buffer to accumulate escape sequence
  55. */
  56. struct vidconsole_priv {
  57. struct stdio_dev sdev;
  58. int xcur_frac;
  59. int ycur;
  60. int rows;
  61. int cols;
  62. int x_charsize;
  63. int y_charsize;
  64. int tab_width_frac;
  65. int xsize_frac;
  66. int xstart_frac;
  67. int last_ch;
  68. /*
  69. * ANSI escape sequences are accumulated character by character,
  70. * starting after the ESC char (0x1b) until the entire sequence
  71. * is consumed at which point it is acted upon.
  72. */
  73. int escape;
  74. int escape_len;
  75. int row_saved;
  76. int col_saved;
  77. char escape_buf[32];
  78. };
  79. /**
  80. * struct vidconsole_ops - Video console operations
  81. *
  82. * These operations work on either an absolute console position (measured
  83. * in pixels) or a text row number (measured in rows, where each row consists
  84. * of an entire line of text - typically 16 pixels).
  85. */
  86. struct vidconsole_ops {
  87. /**
  88. * putc_xy() - write a single character to a position
  89. *
  90. * @dev: Device to write to
  91. * @x_frac: Fractional pixel X position (0=left-most pixel) which
  92. * is the X position multipled by VID_FRAC_DIV.
  93. * @y: Pixel Y position (0=top-most pixel)
  94. * @ch: Character to write
  95. * @return number of fractional pixels that the cursor should move,
  96. * if all is OK, -EAGAIN if we ran out of space on this line, other -ve
  97. * on error
  98. */
  99. int (*putc_xy)(struct udevice *dev, uint x_frac, uint y, char ch);
  100. /**
  101. * move_rows() - Move text rows from one place to another
  102. *
  103. * @dev: Device to adjust
  104. * @rowdst: Destination text row (0=top)
  105. * @rowsrc: Source start text row
  106. * @count: Number of text rows to move
  107. * @return 0 if OK, -ve on error
  108. */
  109. int (*move_rows)(struct udevice *dev, uint rowdst, uint rowsrc,
  110. uint count);
  111. /**
  112. * set_row() - Set the colour of a text row
  113. *
  114. * Every pixel contained within the text row is adjusted
  115. *
  116. * @dev: Device to adjust
  117. * @row: Text row to adjust (0=top)
  118. * @clr: Raw colour (pixel value) to write to each pixel
  119. * @return 0 if OK, -ve on error
  120. */
  121. int (*set_row)(struct udevice *dev, uint row, int clr);
  122. /**
  123. * entry_start() - Indicate that text entry is starting afresh
  124. *
  125. * Consoles which use proportional fonts need to track the position of
  126. * each character output so that backspace will return to the correct
  127. * place. This method signals to the console driver that a new entry
  128. * line is being start (e.g. the user pressed return to start a new
  129. * command). The driver can use this signal to empty its list of
  130. * positions.
  131. */
  132. int (*entry_start)(struct udevice *dev);
  133. /**
  134. * backspace() - Handle erasing the last character
  135. *
  136. * With proportional fonts the vidconsole uclass cannot itself erase
  137. * the previous character. This optional method will be called when
  138. * a backspace is needed. The driver should erase the previous
  139. * character and update the cursor position (xcur_frac, ycur) to the
  140. * start of the previous character.
  141. *
  142. * If not implement, default behaviour will work for fixed-width
  143. * characters.
  144. */
  145. int (*backspace)(struct udevice *dev);
  146. };
  147. /* Get a pointer to the driver operations for a video console device */
  148. #define vidconsole_get_ops(dev) ((struct vidconsole_ops *)(dev)->driver->ops)
  149. /**
  150. * vidconsole_putc_xy() - write a single character to a position
  151. *
  152. * @dev: Device to write to
  153. * @x_frac: Fractional pixel X position (0=left-most pixel) which
  154. * is the X position multipled by VID_FRAC_DIV.
  155. * @y: Pixel Y position (0=top-most pixel)
  156. * @ch: Character to write
  157. * @return number of fractional pixels that the cursor should move,
  158. * if all is OK, -EAGAIN if we ran out of space on this line, other -ve
  159. * on error
  160. */
  161. int vidconsole_putc_xy(struct udevice *dev, uint x, uint y, char ch);
  162. /**
  163. * vidconsole_move_rows() - Move text rows from one place to another
  164. *
  165. * @dev: Device to adjust
  166. * @rowdst: Destination text row (0=top)
  167. * @rowsrc: Source start text row
  168. * @count: Number of text rows to move
  169. * @return 0 if OK, -ve on error
  170. */
  171. int vidconsole_move_rows(struct udevice *dev, uint rowdst, uint rowsrc,
  172. uint count);
  173. /**
  174. * vidconsole_set_row() - Set the colour of a text row
  175. *
  176. * Every pixel contained within the text row is adjusted
  177. *
  178. * @dev: Device to adjust
  179. * @row: Text row to adjust (0=top)
  180. * @clr: Raw colour (pixel value) to write to each pixel
  181. * @return 0 if OK, -ve on error
  182. */
  183. int vidconsole_set_row(struct udevice *dev, uint row, int clr);
  184. /**
  185. * vidconsole_put_char() - Output a character to the current console position
  186. *
  187. * Outputs a character to the console and advances the cursor. This function
  188. * handles wrapping to new lines and scrolling the console. Special
  189. * characters are handled also: \n, \r, \b and \t.
  190. *
  191. * The device always starts with the cursor at position 0,0 (top left). It
  192. * can be adjusted manually using vidconsole_position_cursor().
  193. *
  194. * @dev: Device to adjust
  195. * @ch: Character to write
  196. * @return 0 if OK, -ve on error
  197. */
  198. int vidconsole_put_char(struct udevice *dev, char ch);
  199. /**
  200. * vidconsole_put_string() - Output a string to the current console position
  201. *
  202. * Outputs a string to the console and advances the cursor. This function
  203. * handles wrapping to new lines and scrolling the console. Special
  204. * characters are handled also: \n, \r, \b and \t.
  205. *
  206. * The device always starts with the cursor at position 0,0 (top left). It
  207. * can be adjusted manually using vidconsole_position_cursor().
  208. *
  209. * @dev: Device to adjust
  210. * @str: String to write
  211. * @return 0 if OK, -ve on error
  212. */
  213. int vidconsole_put_string(struct udevice *dev, const char *str);
  214. /**
  215. * vidconsole_position_cursor() - Move the text cursor
  216. *
  217. * @dev: Device to adjust
  218. * @col: New cursor text column
  219. * @row: New cursor text row
  220. * @return 0 if OK, -ve on error
  221. */
  222. void vidconsole_position_cursor(struct udevice *dev, unsigned col,
  223. unsigned row);
  224. #ifdef CONFIG_DM_VIDEO
  225. /**
  226. * vid_console_color() - convert a color code to a pixel's internal
  227. * representation
  228. *
  229. * The caller has to guarantee that the color index is less than
  230. * VID_COLOR_COUNT.
  231. *
  232. * @priv private data of the console device
  233. * @idx color index
  234. * @return color value
  235. */
  236. u32 vid_console_color(struct video_priv *priv, unsigned int idx);
  237. #endif
  238. #endif