From patchwork Thu Oct 2 15:45:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 477 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759419997; bh=I6c1TUK/11KcHPf0pa2J+ANzjj4bjiL57pWLWna2AbU=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=jwMWAGlrJ4pJF3Pz6P+APVAox/Qn/3EvTaU+hnE4B7ao56Gv/EE0XSUUxjBMfIv7n h4KYBjUOTwy64te2k564Fl83V9RL0rbfbZSUQQS6dV9yBlnN5JAf+FpglYaca1Agxg AQjv3mvxd0dX4iJpggEhx0VSkDQmNEmcknsfwcqFa8/ClPIq17LhqCoNPYysINwi47 jIqhH3kgEXxRj8ybv2fgspJPdNa4sb2nLZkBgnhz9NuwTWZNIWtzvl+H4+1bCN6m2W GShsgei9RzL6D0aeSQfccROYH3T/ENpc3RDJqcDKhY1hlc1laPQjPULvpuGrZJ2Ipt PNgvlmdxDy9Zw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 2084167EC6 for ; Thu, 2 Oct 2025 09:46:37 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id bxxiCMyYC_gS for ; Thu, 2 Oct 2025 09:46:37 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759419997; bh=I6c1TUK/11KcHPf0pa2J+ANzjj4bjiL57pWLWna2AbU=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=jwMWAGlrJ4pJF3Pz6P+APVAox/Qn/3EvTaU+hnE4B7ao56Gv/EE0XSUUxjBMfIv7n h4KYBjUOTwy64te2k564Fl83V9RL0rbfbZSUQQS6dV9yBlnN5JAf+FpglYaca1Agxg AQjv3mvxd0dX4iJpggEhx0VSkDQmNEmcknsfwcqFa8/ClPIq17LhqCoNPYysINwi47 jIqhH3kgEXxRj8ybv2fgspJPdNa4sb2nLZkBgnhz9NuwTWZNIWtzvl+H4+1bCN6m2W GShsgei9RzL6D0aeSQfccROYH3T/ENpc3RDJqcDKhY1hlc1laPQjPULvpuGrZJ2Ipt PNgvlmdxDy9Zw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 0CE7467F15 for ; Thu, 2 Oct 2025 09:46:37 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759419994; bh=qpi7yLBS+90JjYFjVO5RGqfAoHFE9+GZswQuHlGtBoQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=w5k5Xeqa61UhDxbsR83K9bb7zqwmfXoF793e79r6kg9mSV4g4rXeJd18vV0JOqJ3j A03uarjtF2QNaPeac2zRSAVSBfvCCKoGZQisMKJjimbW4pXML2m48ZM7jutQ7Ff1uT FhhFOziQjsmoxXUmpYihLM5HjAoC9/oFyi+jNPHIaOl98wXeZp1n1yYwT+BMgCfSKz lz17PRboL4GR9MTeHN7FRUikwncWzeNGT3tIKO1Oagm1O163uOMjvgluISEilCJ/O8 a8Lo2Cd4Iw9I4sr8ggp2My8PB4E83AkLhaw05ovv5c7Gencyryvnz7RiI7iLEfDQJ0 1UeufXPthLq5A== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 3A52267E66; Thu, 2 Oct 2025 09:46:34 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id W2GC3DM1v9B3; Thu, 2 Oct 2025 09:46:34 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759419990; bh=UpfE8fXGvbYFe5V6Z5UemBotxpprdKOM+ykjGp7X/Oo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GjV5ccc77MlSfQu3fmhT8E4TQluZh+JZvInHFNK2of5xc2q+1pR+XVR10/lgeTfPx J1ZH6QF5S8UnG+KYK746N1Km2dlN8FVLt+Lw/EnZegS1XF8sThXwk7SZMZFWVlKFoy TR00xGtMMXTqTzWKcxkkF3Jt/1TuZ2LrKEgjSbH1wXTKY/85TIyND7WB9pLPvdGsr7 Zd8vuGQRowQL7mot0Kg/RskJK+HwzyPfSTHZsMHfCj2hqzAhFpoLB7awMMsATnBzyI 3lAH/3f08QES/U5wRjLG9hQudPP4iaRVgN0E0C0xPFuBnvxhEJLM7BPhAuc2yL24WV mAXmpD8YN/GbQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id B644E67F17; Thu, 2 Oct 2025 09:46:29 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Thu, 2 Oct 2025 09:45:45 -0600 Message-ID: <20251002154554.4129220-6-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251002154554.4129220-1-sjg@u-boot.org> References: <20251002154554.4129220-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 6XNNP565F4YPJ7IVDVC35F5BY2TOSRLO X-Message-ID-Hash: 6XNNP565F4YPJ7IVDVC35F5BY2TOSRLO X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt , Simon Glass , Claude , Heinrich Schuchardt X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH v2 5/9] video: Add a write subcommand List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass This allows writing strings at particular positions on the display, using either character or pixel positions. Co-developed-by: Claude Signed-off-by: Simon Glass Suggested-by: Heinrich Schuchardt --- (no changes since v1) cmd/video.c | 62 +++++++++++++++++++++++++++++++++++++++-- doc/usage/cmd/video.rst | 45 ++++++++++++++++++++++++------ test/dm/video.c | 9 ++++++ 3 files changed, 105 insertions(+), 11 deletions(-) diff --git a/cmd/video.c b/cmd/video.c index 9f3a91959df..503433b9a63 100644 --- a/cmd/video.c +++ b/cmd/video.c @@ -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 - Set cursor position\n" - "video puts - Write string at current position"); + "setcursor - Set cursor position\n" + "video puts - Write string at current position\n" + "video write [-p] [: ]... - 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)); diff --git a/doc/usage/cmd/video.rst b/doc/usage/cmd/video.rst index 1e7c7f0c050..288260bd979 100644 --- a/doc/usage/cmd/video.rst +++ b/doc/usage/cmd/video.rst @@ -13,18 +13,13 @@ Synopsis video setcursor video puts + video write [: ]... Description ----------- -The video command provides access to the video-console subsystem. - -video setcursor -~~~~~~~~~~~~~~~ - - video setcursor - -Set the cursor position on the video console. +The video command provides access to the video-console subsystem. Common +arguments are as follows: col Column position in hex, with 0 being the left side. Note that this is the @@ -36,6 +31,13 @@ row text-row position, so the number of pixels per position depends on the font size. +video setcursor +~~~~~~~~~~~~~~~ + + video setcursor + +Set the cursor position on the video console. + video puts ~~~~~~~~~~ @@ -46,6 +48,24 @@ Write a string to the video console at the current cursor position. string Text string to display +video write +~~~~~~~~~~~ + + video write [-p] [: ]... + +Write one or more strings to the video console at specified positions. Each +position/string pair sets the cursor to the specified location and writes the +string. Multiple position/string pairs can be provided to write to multiple +locations in a single command. + +-p + Use pixel coordinates instead of character positions. When specified, the + col and row values are interpreted as pixel offsets and converted to + character positions based on the current font size. + +string + Text string to display at the specified position + Examples -------- @@ -61,6 +81,15 @@ Print at different positions:: => video setcursor 0 10 => video puts "Line 16" +Write text at multiple positions:: + + => video write 0:0 "Top left" 0:a "Line 10" + => video write 0:a "First column in line10" 2a:0 "Text column 42" + +Write text using pixel coordinates:: + + => video write -p 0:0 "Top left corner" a0:80 "Pixel position" + Configuration ------------- diff --git a/test/dm/video.c b/test/dm/video.c index af305e60268..598e71411f5 100644 --- a/test/dm/video.c +++ b/test/dm/video.c @@ -1102,6 +1102,15 @@ static int dm_test_video_cmd(struct unit_test_state *uts) ut_asserteq(272, video_compress_fb(uts, dev, false)); ut_assertok(video_check_copy_fb(uts, dev)); + ut_assertok(run_command( + "video write 14:6 \"Multi\" 19:7 \"Write\"", 0)); + ut_asserteq(381, video_compress_fb(uts, dev, false)); + ut_assertok(video_check_copy_fb(uts, dev)); + + ut_assertok(run_command("video write -p a3:34 \"Pixels\"", 0)); + ut_asserteq(440, video_compress_fb(uts, dev, false)); + ut_assertok(video_check_copy_fb(uts, dev)); + return 0; } DM_TEST(dm_test_video_cmd, UTF_SCAN_PDATA | UTF_SCAN_FDT);