video console: allow font size configuration at runtime
authorDzmitry Sankouski <dsankouski@gmail.com>
Tue, 7 Mar 2023 10:21:16 +0000 (13:21 +0300)
committerAnatolij Gustschin <agust@denx.de>
Tue, 7 Mar 2023 14:59:35 +0000 (15:59 +0100)
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@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
cmd/Kconfig
cmd/Makefile
drivers/video/Kconfig
drivers/video/console_core.c
drivers/video/console_normal.c
drivers/video/console_rotate.c
drivers/video/vidconsole_internal.h

index 2caa4af..a351283 100644 (file)
@@ -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"
index 36d2daf..2d8bb4f 100644 (file)
@@ -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
index ce97eb4..e1bcc89 100644 (file)
@@ -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.
index d019b98..d4f79c6 100644 (file)
@@ -180,3 +180,33 @@ int console_probe(struct udevice *dev)
 {
        return console_set_font(dev, fonts);
 }
+
+const char *console_simple_get_font_size(struct udevice *dev, uint *sizep)
+{
+       struct console_simple_priv *priv = dev_get_priv(dev);
+
+       *sizep = priv->fontdata->width;
+
+       return priv->fontdata->name;
+}
+
+int console_simple_get_font(struct udevice *dev, int seq, struct vidfont_info *info)
+{
+       info->name = fonts[seq].name;
+
+       return 0;
+}
+
+int console_simple_select_font(struct udevice *dev, const char *name, uint size)
+{
+       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;
+}
index 03e8598..413c7ab 100644 (file)
@@ -101,6 +101,9 @@ struct vidconsole_ops console_ops = {
        .putc_xy        = console_putc_xy,
        .move_rows      = console_move_rows,
        .set_row        = console_set_row,
+       .get_font_size  = console_simple_get_font_size,
+       .get_font       = console_simple_get_font,
+       .select_font    = console_simple_select_font,
 };
 
 U_BOOT_DRIVER(vidconsole_normal) = {
index b924bc3..65358a1 100644 (file)
@@ -262,18 +262,27 @@ 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_size  = console_simple_get_font_size,
+       .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_size  = console_simple_get_font_size,
+       .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_size  = console_simple_get_font_size,
+       .get_font       = console_simple_get_font,
+       .select_font    = console_simple_select_font,
 };
 
 U_BOOT_DRIVER(vidconsole_1) = {
index 99d3c87..c41edd4 100644 (file)
@@ -100,3 +100,21 @@ int fill_char_horizontally(uchar *pfont, void **line, struct video_priv *vid_pri
  * @returns 0, if success, or else error code.
  */
 int console_probe(struct udevice *dev);
+
+/**
+ * Internal function to be used in as ops.
+ * See details in video_console.h get_font_size function
+ **/
+const char *console_simple_get_font_size(struct udevice *dev, uint *sizep);
+
+/**
+ * Internal function to be used in as ops.
+ * See details in video_console.h get_font function
+ **/
+int console_simple_get_font(struct udevice *dev, int seq, struct vidfont_info *info);
+
+/**
+ * Internal function to be used in as ops.
+ * See details in video_console.h select_font function
+ **/
+int console_simple_select_font(struct udevice *dev, const char *name, uint size);