video: Provide a function to set the cursor position
authorSimon Glass <sjg@chromium.org>
Thu, 6 Oct 2022 14:36:04 +0000 (08:36 -0600)
committerAnatolij Gustschin <agust@denx.de>
Sun, 30 Oct 2022 08:53:47 +0000 (09:53 +0100)
Add an exported function which allows the cursor position to be set to
pixel granularity. Make use of this in the existing code.

Signed-off-by: Simon Glass <sjg@chromium.org>
drivers/video/vidconsole-uclass.c
include/video_console.h

index f67027c..5326358 100644 (file)
@@ -122,6 +122,15 @@ static char *parsenum(char *s, int *num)
        return end;
 }
 
+void vidconsole_set_cursor_pos(struct udevice *dev, int x, int y)
+{
+       struct vidconsole_priv *priv = dev_get_uclass_priv(dev);
+
+       priv->xcur_frac = VID_TO_POS(x);
+       priv->xstart_frac = priv->xcur_frac;
+       priv->ycur = y;
+}
+
 /**
  * set_cursor_position() - set cursor position
  *
@@ -614,12 +623,11 @@ void vidconsole_position_cursor(struct udevice *dev, unsigned col, unsigned row)
        struct vidconsole_priv *priv = dev_get_uclass_priv(dev);
        struct udevice *vid_dev = dev->parent;
        struct video_priv *vid_priv = dev_get_uclass_priv(vid_dev);
+       short x, y;
 
-       col *= priv->x_charsize;
-       row *= priv->y_charsize;
-       priv->xcur_frac = VID_TO_POS(min_t(short, col, vid_priv->xsize - 1));
-       priv->xstart_frac = priv->xcur_frac;
-       priv->ycur = min_t(short, row, vid_priv->ysize - 1);
+       x = min_t(short, col * priv->x_charsize, vid_priv->xsize - 1);
+       y = min_t(short, row * priv->y_charsize, vid_priv->ysize - 1);
+       vidconsole_set_cursor_pos(dev, x, y);
 }
 
 static int do_video_setcursor(struct cmd_tbl *cmdtp, int flag, int argc,
index 72edd41..76c4b10 100644 (file)
@@ -219,6 +219,18 @@ int vidconsole_put_string(struct udevice *dev, const char *str);
 void vidconsole_position_cursor(struct udevice *dev, unsigned col,
                                unsigned row);
 
+/**
+ * vidconsole_set_cursor_pos() - set cursor position
+ *
+ * The cursor is set to the new position and the start-of-line information is
+ * updated to the same position, so that a newline will return to @x
+ *
+ * @dev:       video console device to update
+ * @x:         x position from left in pixels
+ * @y:         y position from top in pixels
+ */
+void vidconsole_set_cursor_pos(struct udevice *dev, int x, int y);
+
 #ifdef CONFIG_VIDEO_COPY
 /**
  * vidconsole_sync_copy() - Sync back to the copy framebuffer