video: Add a write subcommand

This allows writing strings at particular positions on the display,
using either character or pixel positions.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
This commit is contained in:
Simon Glass
2025-10-02 09:07:46 -06:00
parent 8db8f801ae
commit 85e1dae80c
3 changed files with 105 additions and 11 deletions

View File

@@ -47,6 +47,59 @@ static int do_video_puts(struct cmd_tbl *cmdtp, int flag, int argc,
return ret ? CMD_RET_FAILURE : 0;
}
static int do_video_write(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[])
{
struct vidconsole_priv *priv;
bool use_pixels = false;
struct udevice *dev;
int ret, i;
if (argc < 3)
return CMD_RET_USAGE;
if (uclass_first_device_err(UCLASS_VIDEO_CONSOLE, &dev))
return CMD_RET_FAILURE;
priv = dev_get_uclass_priv(dev);
/* Check for -p flag */
if (!strcmp(argv[1], "-p")) {
use_pixels = true;
argc--;
argv++;
}
if (argc < 3 || !(argc % 2))
return CMD_RET_USAGE;
for (i = 1; i < argc; i += 2) {
uint col, row;
char *pos = argv[i];
char *colon = strchr(pos, ':');
if (!colon)
return CMD_RET_USAGE;
col = hextoul(pos, NULL);
row = hextoul(colon + 1, NULL);
if (use_pixels)
vidconsole_set_cursor_pos(dev, col, row);
else
vidconsole_position_cursor(dev, col, row);
ret = vidconsole_put_string(dev, argv[i + 1]);
if (ret)
return CMD_RET_FAILURE;
}
ret = video_sync(dev->parent, false);
if (ret)
return CMD_RET_FAILURE;
return 0;
}
U_BOOT_CMD(
setcurs, 3, 1, do_video_setcursor,
"set cursor position within screen",
@@ -60,9 +113,12 @@ U_BOOT_CMD(
);
U_BOOT_LONGHELP(video,
"setcursor <col> <row> - Set cursor position\n"
"video puts <string> - Write string at current position");
"setcursor <col> <row> - Set cursor position\n"
"video puts <string> - Write string at current position\n"
"video write [-p] [<col>:<row> <string>]... - Write strings at specified positions\n"
" -p: Use pixel coordinates instead of character positions");
U_BOOT_CMD_WITH_SUBCMDS(video, "Video commands", video_help_text,
U_BOOT_SUBCMD_MKENT(setcursor, 3, 1, do_video_setcursor),
U_BOOT_SUBCMD_MKENT(puts, 2, 1, do_video_puts));
U_BOOT_SUBCMD_MKENT(puts, 2, 1, do_video_puts),
U_BOOT_SUBCMD_MKENT(write, CONFIG_SYS_MAXARGS, 1, do_video_write));