mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-11-10 15:14:43 +00:00
video: Add commands to list and change fonts
Add a new 'font' command which allows the fonts to be listed as well as selecting a different font and size. Allow the test to run on sandbox, where multiple font/size combinations are supported, as well as sandbox_flattree, where they are not. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
3f425f9ca7
commit
430e1676a7
11 changed files with 240 additions and 0 deletions
|
@ -74,6 +74,7 @@ obj-$(CONFIG_CMD_EXT2) += ext2.o
|
|||
obj-$(CONFIG_CMD_FAT) += fat.o
|
||||
obj-$(CONFIG_CMD_FDT) += fdt.o
|
||||
obj-$(CONFIG_CMD_SQUASHFS) += sqfs.o
|
||||
obj-$(CONFIG_CONSOLE_TRUETYPE) += font.o
|
||||
obj-$(CONFIG_CMD_FLASH) += flash.o
|
||||
obj-$(CONFIG_CMD_FPGA) += fpga.o
|
||||
obj-$(CONFIG_CMD_FPGAD) += fpgad.o
|
||||
|
|
81
cmd/font.c
Normal file
81
cmd/font.c
Normal file
|
@ -0,0 +1,81 @@
|
|||
// SPDX-License-Identifier: GPL-2.0+
|
||||
/*
|
||||
* video commands
|
||||
*
|
||||
* Copyright 2022 Google LLC
|
||||
* Written by Simon Glass <sjg@chromium.org>
|
||||
*/
|
||||
|
||||
#include <common.h>
|
||||
#include <command.h>
|
||||
#include <dm.h>
|
||||
#include <video.h>
|
||||
#include <video_console.h>
|
||||
|
||||
static int do_font_list(struct cmd_tbl *cmdtp, int flag, int argc,
|
||||
char *const argv[])
|
||||
{
|
||||
vidconsole_list_fonts();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int do_font_select(struct cmd_tbl *cmdtp, int flag, int argc,
|
||||
char *const argv[])
|
||||
{
|
||||
struct udevice *dev;
|
||||
const char *name;
|
||||
uint size = 0;
|
||||
int ret;
|
||||
|
||||
if (argc < 2)
|
||||
return CMD_RET_USAGE;
|
||||
|
||||
if (uclass_first_device_err(UCLASS_VIDEO_CONSOLE, &dev))
|
||||
return CMD_RET_FAILURE;
|
||||
name = argv[1];
|
||||
if (argc == 3)
|
||||
size = dectoul(argv[2], NULL);
|
||||
ret = vidconsole_select_font(dev, name, size);
|
||||
if (ret) {
|
||||
printf("Failed (error %d)\n", ret);
|
||||
return CMD_RET_FAILURE;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
static int do_font_size(struct cmd_tbl *cmdtp, int flag, int argc,
|
||||
char *const argv[])
|
||||
{
|
||||
struct udevice *dev;
|
||||
uint size;
|
||||
int ret;
|
||||
|
||||
if (argc != 2)
|
||||
return CMD_RET_USAGE;
|
||||
|
||||
if (uclass_first_device_err(UCLASS_VIDEO_CONSOLE, &dev))
|
||||
return CMD_RET_FAILURE;
|
||||
|
||||
size = dectoul(argv[1], NULL);
|
||||
ret = vidconsole_select_font(dev, NULL, size);
|
||||
if (ret) {
|
||||
printf("Failed (error %d)\n", ret);
|
||||
return CMD_RET_FAILURE;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#ifdef CONFIG_SYS_LONGHELP
|
||||
static char font_help_text[] =
|
||||
"list - list available fonts\n"
|
||||
"font select <name> [<size>] - select font to use\n"
|
||||
"font size <size> - select font size to";
|
||||
#endif
|
||||
|
||||
U_BOOT_CMD_WITH_SUBCMDS(font, "Fonts", font_help_text,
|
||||
U_BOOT_SUBCMD_MKENT(list, 1, 1, do_font_list),
|
||||
U_BOOT_SUBCMD_MKENT(select, 3, 1, do_font_select),
|
||||
U_BOOT_SUBCMD_MKENT(size, 2, 1, do_font_size));
|
|
@ -298,6 +298,7 @@ CONFIG_DM_VIDEO=y
|
|||
CONFIG_VIDEO_COPY=y
|
||||
CONFIG_CONSOLE_ROTATION=y
|
||||
CONFIG_CONSOLE_TRUETYPE=y
|
||||
CONFIG_CONSOLE_TRUETYPE_MAX_METRICS=10
|
||||
CONFIG_CONSOLE_TRUETYPE_CANTORAONE=y
|
||||
CONFIG_I2C_EDID=y
|
||||
CONFIG_VIDEO_SANDBOX_SDL=y
|
||||
|
|
52
doc/usage/cmd/font.rst
Normal file
52
doc/usage/cmd/font.rst
Normal file
|
@ -0,0 +1,52 @@
|
|||
.. SPDX-License-Identifier: GPL-2.0+:
|
||||
|
||||
font command
|
||||
============
|
||||
|
||||
Synopis
|
||||
-------
|
||||
|
||||
::
|
||||
|
||||
font list
|
||||
font select <name> [<size>]
|
||||
font size <size>
|
||||
|
||||
|
||||
Description
|
||||
-----------
|
||||
|
||||
The *font* command allows selection of the font to use on the video console.
|
||||
This is available when the Truetype console is in use. This is the case when
|
||||
`CONFIG_CONSOLE_TRUETYPE` is enabled.
|
||||
|
||||
|
||||
font list
|
||||
~~~~~~~~~
|
||||
|
||||
This lists the available fonts, using the name of the font file in the build.
|
||||
|
||||
|
||||
font select
|
||||
~~~~~~~~~~~
|
||||
|
||||
This selects a new font and optionally changes the size.
|
||||
|
||||
|
||||
font size
|
||||
~~~~~~~~~
|
||||
|
||||
This changes the font size only.
|
||||
|
||||
|
||||
Examples
|
||||
--------
|
||||
|
||||
::
|
||||
|
||||
=> font list
|
||||
nimbus_sans_l_regular
|
||||
cantoraone_regular
|
||||
=> font size 40
|
||||
=> font select cantoraone_regular 20
|
||||
=>
|
|
@ -48,6 +48,7 @@ Shell commands
|
|||
cmd/fatinfo
|
||||
cmd/fatload
|
||||
cmd/fdt
|
||||
cmd/font
|
||||
cmd/for
|
||||
cmd/gpio
|
||||
cmd/load
|
||||
|
|
|
@ -715,6 +715,16 @@ int vidconsole_select_font(struct udevice *dev, const char *name, uint size)
|
|||
return 0;
|
||||
}
|
||||
|
||||
const char *vidconsole_get_font(struct udevice *dev, uint *sizep)
|
||||
{
|
||||
struct console_tt_priv *priv = dev_get_priv(dev);
|
||||
struct console_tt_metrics *met = priv->cur_met;
|
||||
|
||||
*sizep = met->font_size;
|
||||
|
||||
return met->font_name;
|
||||
}
|
||||
|
||||
static int console_truetype_probe(struct udevice *dev)
|
||||
{
|
||||
struct console_tt_priv *priv = dev_get_priv(dev);
|
||||
|
|
|
@ -39,6 +39,7 @@ int do_ut_compression(struct cmd_tbl *cmdtp, int flag, int argc,
|
|||
int do_ut_dm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
|
||||
int do_ut_env(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
|
||||
int do_ut_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
|
||||
int do_ut_font(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
|
||||
int do_ut_lib(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
|
||||
int do_ut_loadm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
|
||||
int do_ut_log(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[]);
|
||||
|
|
|
@ -247,6 +247,15 @@ void vidconsole_list_fonts(void);
|
|||
*/
|
||||
int vidconsole_select_font(struct udevice *dev, const char *name, uint size);
|
||||
|
||||
/**
|
||||
* vidconsole_get_font() - get the current font name and size
|
||||
*
|
||||
* @dev: vidconsole device
|
||||
* @sizep: Place to put the font size (nominal height in pixels)
|
||||
* Returns: Current font name
|
||||
*/
|
||||
const char *vidconsole_get_font(struct udevice *dev, uint *sizep);
|
||||
|
||||
#ifdef CONFIG_VIDEO_COPY
|
||||
/**
|
||||
* vidconsole_sync_copy() - Sync back to the copy framebuffer
|
||||
|
|
|
@ -11,6 +11,7 @@ endif
|
|||
obj-y += mem.o
|
||||
obj-$(CONFIG_CMD_ADDRMAP) += addrmap.o
|
||||
obj-$(CONFIG_CMD_FDT) += fdt.o
|
||||
obj-$(CONFIG_CONSOLE_TRUETYPE) += font.o
|
||||
obj-$(CONFIG_CMD_LOADM) += loadm.o
|
||||
obj-$(CONFIG_CMD_MEM_SEARCH) += mem_search.o
|
||||
obj-$(CONFIG_CMD_PINMUX) += pinmux.o
|
||||
|
|
77
test/cmd/font.c
Normal file
77
test/cmd/font.c
Normal file
|
@ -0,0 +1,77 @@
|
|||
// SPDX-License-Identifier: GPL-2.0+
|
||||
/*
|
||||
* Tests for font command
|
||||
*
|
||||
* Copyright 2022 Google LLC
|
||||
*/
|
||||
|
||||
#include <common.h>
|
||||
#include <console.h>
|
||||
#include <dm.h>
|
||||
#include <video_console.h>
|
||||
#include <test/suites.h>
|
||||
#include <test/ut.h>
|
||||
|
||||
/* Declare a new fdt test */
|
||||
#define FONT_TEST(_name, _flags) UNIT_TEST(_name, _flags, font_test)
|
||||
|
||||
/* Test 'fdt addr' resizing an fdt */
|
||||
static int font_test_base(struct unit_test_state *uts)
|
||||
{
|
||||
struct udevice *dev;
|
||||
int max_metrics;
|
||||
uint size;
|
||||
int ret;
|
||||
|
||||
ut_assertok(uclass_first_device_err(UCLASS_VIDEO, &dev));
|
||||
ut_assertok(uclass_first_device_err(UCLASS_VIDEO_CONSOLE, &dev));
|
||||
|
||||
ut_assertok(console_record_reset_enable());
|
||||
ut_assertok(run_command("font list", 0));
|
||||
ut_assert_nextline("nimbus_sans_l_regular");
|
||||
ut_assert_nextline("cantoraone_regular");
|
||||
ut_assertok(ut_check_console_end(uts));
|
||||
|
||||
ut_asserteq_str("nimbus_sans_l_regular",
|
||||
vidconsole_get_font(dev, &size));
|
||||
ut_asserteq(18, size);
|
||||
|
||||
max_metrics = 1;
|
||||
if (IS_ENABLED(CONFIG_CONSOLE_TRUETYPE))
|
||||
max_metrics = IF_ENABLED_INT(CONFIG_CONSOLE_TRUETYPE,
|
||||
CONFIG_CONSOLE_TRUETYPE_MAX_METRICS);
|
||||
|
||||
ret = run_command("font select cantoraone_regular 40", 0);
|
||||
if (max_metrics < 2) {
|
||||
ut_asserteq(1, ret);
|
||||
ut_assert_nextline("Failed (error -7)");
|
||||
ut_assertok(ut_check_console_end(uts));
|
||||
return 0;
|
||||
}
|
||||
|
||||
ut_assertok(ret);
|
||||
ut_assertok(ut_check_console_end(uts));
|
||||
|
||||
ut_asserteq_str("cantoraone_regular",
|
||||
vidconsole_get_font(dev, &size));
|
||||
ut_asserteq(40, size);
|
||||
|
||||
ut_assertok(run_command("font size 30", 0));
|
||||
ut_assertok(ut_check_console_end(uts));
|
||||
|
||||
ut_asserteq_str("cantoraone_regular",
|
||||
vidconsole_get_font(dev, &size));
|
||||
ut_asserteq(30, size);
|
||||
|
||||
return 0;
|
||||
}
|
||||
FONT_TEST(font_test_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT |
|
||||
UT_TESTF_CONSOLE_REC | UT_TESTF_DM);
|
||||
|
||||
int do_ut_font(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
|
||||
{
|
||||
struct unit_test *tests = UNIT_TEST_SUITE_START(font_Test);
|
||||
const int n_ents = UNIT_TEST_SUITE_COUNT(font_test);
|
||||
|
||||
return cmd_ut_category("font", "font_test_", tests, n_ents, argc, argv);
|
||||
}
|
|
@ -49,6 +49,9 @@ static struct cmd_tbl cmd_ut_sub[] = {
|
|||
#ifdef CONFIG_CMD_FDT
|
||||
U_BOOT_CMD_MKENT(fdt, CONFIG_SYS_MAXARGS, 1, do_ut_fdt, "", ""),
|
||||
#endif
|
||||
#ifdef CONFIG_CONSOLE_TRUETYPE
|
||||
U_BOOT_CMD_MKENT(font, CONFIG_SYS_MAXARGS, 1, do_ut_font, "", ""),
|
||||
#endif
|
||||
#ifdef CONFIG_UT_OPTEE
|
||||
U_BOOT_CMD_MKENT(optee, CONFIG_SYS_MAXARGS, 1, do_ut_optee, "", ""),
|
||||
#endif
|
||||
|
@ -144,6 +147,9 @@ static char ut_help_text[] =
|
|||
#ifdef CONFIG_CMD_FDT
|
||||
"ut fdt [test-name] - test of the fdt command\n"
|
||||
#endif
|
||||
#ifdef CONFIG_CONSOLE_TRUETYPE
|
||||
"ut font [test-name] - test of the font command\n"
|
||||
#endif
|
||||
#ifdef CONFIG_UT_LIB
|
||||
"ut lib [test-name] - test library functions\n"
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue