[PATCH v3 6/9] video console: allow font size configuration at runtime

Dzmitry Sankouski dsankouski at gmail.com
Wed Feb 15 12:42:57 CET 2023


Allow font size configuration at runtime for console_simple.c
driver. This needed for unit testing different fonts.

Configuring is done by `font` command, also used for font
selection in true type console.

Signed-off-by: Dzmitry Sankouski <dsankouski at gmail.com>
---
Changes for v2: N/A
Changes for v3:
- move 8x16 font patch extracted
- implement multiple fonts patch extracted
- add static modifiers, where needed
- remove list fonts operation
- put fontdata in local var

 cmd/Kconfig                    |  8 ++++++++
 cmd/Makefile                   |  2 +-
 drivers/video/Kconfig          |  1 +
 drivers/video/console_simple.c | 30 ++++++++++++++++++++++++++++++
 4 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 2caa4af71c..f368ee7e9b 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -2226,6 +2226,14 @@ config CMD_VIDCONSOLE
 	  The name 'lcdputs' is a bit of a misnomer, but so named because the
 	  video device is often an LCD.
 
+config CMD_SELECT_FONT
+    bool "select font size"
+	depends on VIDEO
+	default n
+	help
+	  Enabling this will provide 'font' command.
+	  Allows font selection at runtime.
+
 endmenu
 
 source "cmd/ti/Kconfig"
diff --git a/cmd/Makefile b/cmd/Makefile
index 36d2daf22a..2d8bb4fc05 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -78,7 +78,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_SELECT_FONT) += font.o
 obj-$(CONFIG_CMD_FLASH) += flash.o
 obj-$(CONFIG_CMD_FPGA) += fpga.o
 obj-$(CONFIG_CMD_FPGAD) += fpgad.o
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 47428ecb6c..419c53418d 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -165,6 +165,7 @@ config CONSOLE_ROTATION
 
 config CONSOLE_TRUETYPE
 	bool "Support a console that uses TrueType fonts"
+	select CMD_SELECT_FONT
 	help
 	  TrueTrype fonts can provide outline-drawing capability rather than
 	  needing to provide a bitmap for each font and size that is needed.
diff --git a/drivers/video/console_simple.c b/drivers/video/console_simple.c
index 402d67f85f..2b39d724f4 100644
--- a/drivers/video/console_simple.c
+++ b/drivers/video/console_simple.c
@@ -56,6 +56,28 @@ static int console_set_font(struct udevice *dev, struct video_fontdata *fontdata
 	return 0;
 }
 
+static int console_simple_get_font(struct udevice *dev, int seq, struct vidfont_info *info)
+{
+	info->name = (&fonts[seq])->name;
+
+	return 0;
+}
+
+static int console_simple_select_font(struct udevice *dev, const char *name, uint size)
+{
+	console_set_font(dev, &fonts[1]);
+	struct video_fontdata *font;
+
+	for (font = fonts; font->name; font++) {
+		if (!strcmp(name, font->name)) {
+			console_set_font(dev, font);
+			return 0;
+		}
+	};
+	printf("no such font: %s, make sure it's name has <width>x<height> format\n", name);
+	return -ENOENT;
+}
+
 /**
  * Checks if bits per pixel supported.
  *
@@ -352,6 +374,8 @@ struct vidconsole_ops console_ops = {
 	.putc_xy	= console_putc_xy,
 	.move_rows	= console_move_rows,
 	.set_row	= console_set_row,
+	.get_font	= console_simple_get_font,
+	.select_font	= console_simple_select_font,
 };
 
 U_BOOT_DRIVER(vidconsole_normal) = {
@@ -612,18 +636,24 @@ struct vidconsole_ops console_ops_1 = {
 	.putc_xy	= console_putc_xy_1,
 	.move_rows	= console_move_rows_1,
 	.set_row	= console_set_row_1,
+	.get_font	= console_simple_get_font,
+	.select_font	= console_simple_select_font,
 };
 
 struct vidconsole_ops console_ops_2 = {
 	.putc_xy	= console_putc_xy_2,
 	.move_rows	= console_move_rows_2,
 	.set_row	= console_set_row_2,
+	.get_font	= console_simple_get_font,
+	.select_font	= console_simple_select_font,
 };
 
 struct vidconsole_ops console_ops_3 = {
 	.putc_xy	= console_putc_xy_3,
 	.move_rows	= console_move_rows_3,
 	.set_row	= console_set_row_3,
+	.get_font	= console_simple_get_font,
+	.select_font	= console_simple_select_font,
 };
 
 U_BOOT_DRIVER(vidconsole_1) = {
-- 
2.30.2



More information about the U-Boot mailing list