From 37db20d0a64132a7ae3d0223de6b93167d60bea4 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sun, 1 Oct 2023 19:13:21 -0600 Subject: video: Support showing a cursor Add rudimentary support for displaying a cursor on a vidconsole. This helps the user to see where text is being entered. The implementation so far is very simple: the cursor is just a vertical bar of fixed width and cannot be erased. To erase the cursor, the text must be redrawn over it. This is good enough for expo but will need enhancement to be useful for the command-line console. For example, it could save and restore the area behind the cursor. For now, enable this only for expo, to reduce code size. Signed-off-by: Simon Glass --- include/video_console.h | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'include') diff --git a/include/video_console.h b/include/video_console.h index 87f9a588575..bde67fa9a5a 100644 --- a/include/video_console.h +++ b/include/video_console.h @@ -16,6 +16,11 @@ struct video_priv; #define VID_TO_PIXEL(x) ((x) / VID_FRAC_DIV) #define VID_TO_POS(x) ((x) * VID_FRAC_DIV) +enum { + /* cursor width in pixels */ + VIDCONSOLE_CURSOR_WIDTH = 2, +}; + /** * struct vidconsole_priv - uclass-private data about a console device * @@ -264,6 +269,21 @@ struct vidconsole_ops { * Return: 0 if OK, -ve on error */ int (*entry_restore)(struct udevice *dev, struct abuf *buf); + + /** + * set_cursor_visible() - Show or hide the cursor + * + * Shows or hides a cursor at the current position + * + * @dev: Console device to use + * @visible: true to show the cursor, false to hide it + * @x: X position in pixels + * @y: Y position in pixels + * @index: Character position (0 = at start) + * Return: 0 if OK, -ve on error + */ + int (*set_cursor_visible)(struct udevice *dev, bool visible, + uint x, uint y, uint index); }; /* Get a pointer to the driver operations for a video console device */ @@ -342,6 +362,21 @@ int vidconsole_entry_save(struct udevice *dev, struct abuf *buf); */ int vidconsole_entry_restore(struct udevice *dev, struct abuf *buf); +/** + * vidconsole_set_cursor_visible() - Show or hide the cursor + * + * Shows or hides a cursor at the current position + * + * @dev: Console device to use + * @visible: true to show the cursor, false to hide it + * @x: X position in pixels + * @y: Y position in pixels + * @index: Character position (0 = at start) + * Return: 0 if OK, -ve on error + */ +int vidconsole_set_cursor_visible(struct udevice *dev, bool visible, + uint x, uint y, uint index); + /** * vidconsole_push_colour() - Temporarily change the font colour * -- cgit v1.3.1