video_console.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. * Copyright (c) 2015 Google, Inc
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #ifndef __video_console_h
  7. #define __video_console_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. * struct vidconsole_priv - uclass-private data about a console device
  13. *
  14. * Drivers must set up @rows, @cols, @x_charsize, @y_charsize in their probe()
  15. * method. Drivers may set up @xstart_frac if desired.
  16. *
  17. * @sdev: stdio device, acting as an output sink
  18. * @xcur_frac: Current X position, in fractional units (VID_TO_POS(x))
  19. * @curr_row: Current Y position in pixels (0=top)
  20. * @rows: Number of text rows
  21. * @cols: Number of text columns
  22. * @x_charsize: Character width in pixels
  23. * @y_charsize: Character height in pixels
  24. * @tab_width_frac: Tab width in fractional units
  25. * @xsize_frac: Width of the display in fractional units
  26. * @xstart_frac: Left margin for the text console in fractional units
  27. * @last_ch: Last character written to the text console on this line
  28. */
  29. struct vidconsole_priv {
  30. struct stdio_dev sdev;
  31. int xcur_frac;
  32. int ycur;
  33. int rows;
  34. int cols;
  35. int x_charsize;
  36. int y_charsize;
  37. int tab_width_frac;
  38. int xsize_frac;
  39. int xstart_frac;
  40. int last_ch;
  41. };
  42. /**
  43. * struct vidconsole_ops - Video console operations
  44. *
  45. * These operations work on either an absolute console position (measured
  46. * in pixels) or a text row number (measured in rows, where each row consists
  47. * of an entire line of text - typically 16 pixels).
  48. */
  49. struct vidconsole_ops {
  50. /**
  51. * putc_xy() - write a single character to a position
  52. *
  53. * @dev: Device to write to
  54. * @x_frac: Fractional pixel X position (0=left-most pixel) which
  55. * is the X position multipled by VID_FRAC_DIV.
  56. * @y: Pixel Y position (0=top-most pixel)
  57. * @ch: Character to write
  58. * @return number of fractional pixels that the cursor should move,
  59. * if all is OK, -EAGAIN if we ran out of space on this line, other -ve
  60. * on error
  61. */
  62. int (*putc_xy)(struct udevice *dev, uint x_frac, uint y, char ch);
  63. /**
  64. * move_rows() - Move text rows from one place to another
  65. *
  66. * @dev: Device to adjust
  67. * @rowdst: Destination text row (0=top)
  68. * @rowsrc: Source start text row
  69. * @count: Number of text rows to move
  70. * @return 0 if OK, -ve on error
  71. */
  72. int (*move_rows)(struct udevice *dev, uint rowdst, uint rowsrc,
  73. uint count);
  74. /**
  75. * set_row() - Set the colour of a text row
  76. *
  77. * Every pixel contained within the text row is adjusted
  78. *
  79. * @dev: Device to adjust
  80. * @row: Text row to adjust (0=top)
  81. * @clr: Raw colour (pixel value) to write to each pixel
  82. * @return 0 if OK, -ve on error
  83. */
  84. int (*set_row)(struct udevice *dev, uint row, int clr);
  85. /**
  86. * entry_start() - Indicate that text entry is starting afresh
  87. *
  88. * Consoles which use proportional fonts need to track the position of
  89. * each character output so that backspace will return to the correct
  90. * place. This method signals to the console driver that a new entry
  91. * line is being start (e.g. the user pressed return to start a new
  92. * command). The driver can use this signal to empty its list of
  93. * positions.
  94. */
  95. int (*entry_start)(struct udevice *dev);
  96. /**
  97. * backspace() - Handle erasing the last character
  98. *
  99. * With proportional fonts the vidconsole uclass cannot itself erase
  100. * the previous character. This optional method will be called when
  101. * a backspace is needed. The driver should erase the previous
  102. * character and update the cursor position (xcur_frac, ycur) to the
  103. * start of the previous character.
  104. *
  105. * If not implement, default behaviour will work for fixed-width
  106. * characters.
  107. */
  108. int (*backspace)(struct udevice *dev);
  109. };
  110. /* Get a pointer to the driver operations for a video console device */
  111. #define vidconsole_get_ops(dev) ((struct vidconsole_ops *)(dev)->driver->ops)
  112. /**
  113. * vidconsole_putc_xy() - write a single character to a position
  114. *
  115. * @dev: Device to write to
  116. * @x_frac: Fractional pixel X position (0=left-most pixel) which
  117. * is the X position multipled by VID_FRAC_DIV.
  118. * @y: Pixel Y position (0=top-most pixel)
  119. * @ch: Character to write
  120. * @return number of fractional pixels that the cursor should move,
  121. * if all is OK, -EAGAIN if we ran out of space on this line, other -ve
  122. * on error
  123. */
  124. int vidconsole_putc_xy(struct udevice *dev, uint x, uint y, char ch);
  125. /**
  126. * vidconsole_move_rows() - Move text rows from one place to another
  127. *
  128. * @dev: Device to adjust
  129. * @rowdst: Destination text row (0=top)
  130. * @rowsrc: Source start text row
  131. * @count: Number of text rows to move
  132. * @return 0 if OK, -ve on error
  133. */
  134. int vidconsole_move_rows(struct udevice *dev, uint rowdst, uint rowsrc,
  135. uint count);
  136. /**
  137. * vidconsole_set_row() - Set the colour of a text row
  138. *
  139. * Every pixel contained within the text row is adjusted
  140. *
  141. * @dev: Device to adjust
  142. * @row: Text row to adjust (0=top)
  143. * @clr: Raw colour (pixel value) to write to each pixel
  144. * @return 0 if OK, -ve on error
  145. */
  146. int vidconsole_set_row(struct udevice *dev, uint row, int clr);
  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. * vidconsole_position_cursor() - Move the text cursor
  164. *
  165. * @dev: Device to adjust
  166. * @col: New cursor text column
  167. * @row: New cursor text row
  168. * @return 0 if OK, -ve on error
  169. */
  170. void vidconsole_position_cursor(struct udevice *dev, unsigned col,
  171. unsigned row);
  172. #endif