All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dzmitry Sankouski <dsankouski@gmail.com>
To: U-Boot Mailing List <u-boot@lists.denx.de>
Cc: Dzmitry Sankouski <dsankouski@gmail.com>,
	Simon Glass <sjg@chromium.org>,
	Alexey Romanov <avromanov@sberdevices.ru>,
	Anatolij Gustschin <agust@denx.de>,
	Heinrich Schuchardt <xypron.glpk@gmx.de>,
	Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	John Keeping <john@metanate.com>,
	Masahisa Kojima <masahisa.kojima@linaro.org>,
	Neil Armstrong <neil.armstrong@linaro.org>,
	Roger Knecht <rknecht@pm.me>
Subject: [PATCH v8 06/10] video console: allow font size configuration at runtime
Date: Tue,  7 Mar 2023 13:21:16 +0300	[thread overview]
Message-ID: <20230307102121.1925581-7-dsankouski@gmail.com> (raw)
In-Reply-To: <20230307102121.1925581-1-dsankouski@gmail.com>

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>
---

Changes in v8:
none

Changes in v7:
- (&fonts[seq])->name
- fonts[seq].name

Changes in v6:
rebase only

Changes in v5:
N/A

Changes in v4:
N/A

Changes in 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

Changes in v2:
N/A

 cmd/Kconfig                         |  8 ++++++++
 cmd/Makefile                        |  2 +-
 drivers/video/Kconfig               |  1 +
 drivers/video/console_core.c        | 30 +++++++++++++++++++++++++++++
 drivers/video/console_normal.c      |  3 +++
 drivers/video/console_rotate.c      |  9 +++++++++
 drivers/video/vidconsole_internal.h | 18 +++++++++++++++++
 7 files changed, 70 insertions(+), 1 deletion(-)

diff --git a/cmd/Kconfig b/cmd/Kconfig
index 2caa4af71c..a3512836c1 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 ce97eb4727..e1bcc89b30 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_core.c b/drivers/video/console_core.c
index d019b985b4..d4f79c656a 100644
--- a/drivers/video/console_core.c
+++ b/drivers/video/console_core.c
@@ -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;
+}
diff --git a/drivers/video/console_normal.c b/drivers/video/console_normal.c
index 03e859898c..413c7abee9 100644
--- a/drivers/video/console_normal.c
+++ b/drivers/video/console_normal.c
@@ -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) = {
diff --git a/drivers/video/console_rotate.c b/drivers/video/console_rotate.c
index b924bc3459..65358a1c6e 100644
--- a/drivers/video/console_rotate.c
+++ b/drivers/video/console_rotate.c
@@ -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) = {
diff --git a/drivers/video/vidconsole_internal.h b/drivers/video/vidconsole_internal.h
index 99d3c876d7..c41edd4524 100644
--- a/drivers/video/vidconsole_internal.h
+++ b/drivers/video/vidconsole_internal.h
@@ -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);
-- 
2.30.2


  parent reply	other threads:[~2023-03-07 10:22 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-07 10:21 [PATCH v8 00/10] vidconsole: refactoring and support for wider fonts Dzmitry Sankouski
2023-03-07 10:21 ` [PATCH v8 01/10] video console: refactoring and optimization Dzmitry Sankouski
2023-03-07 10:21 ` [PATCH v8 02/10] video console: add support for fonts wider than 1 byte Dzmitry Sankouski
2023-03-07 10:21 ` [PATCH v8 03/10] video console: move 8x16 font data in named header Dzmitry Sankouski
2023-03-07 10:21 ` [PATCH v8 04/10] video console: implement multiple fonts configuration Dzmitry Sankouski
2023-03-07 15:22   ` Anatolij Gustschin
2023-03-10  8:35     ` Dzmitry Sankouski
2023-03-10  9:24       ` Anatolij Gustschin
2023-03-07 10:21 ` [PATCH v8 05/10] video console: move vidconsole_get_font_size() logic to driver ops Dzmitry Sankouski
2023-03-07 10:21 ` Dzmitry Sankouski [this message]
2023-03-07 10:21 ` [PATCH v8 07/10] video console: add 12x22 Sun font from linux Dzmitry Sankouski
2023-03-07 10:21 ` [PATCH v8 08/10] video console: add 16x32 Terminus " Dzmitry Sankouski
2023-03-07 10:21 ` [PATCH v8 09/10] video console: sandbox: add 12x22 font defconfigs Dzmitry Sankouski
2023-03-07 10:21 ` [PATCH v8 10/10] video console: add 12x22 console simple font test Dzmitry Sankouski
2023-03-10  9:26 ` [PATCH v8 00/10] vidconsole: refactoring and support for wider fonts Anatolij Gustschin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230307102121.1925581-7-dsankouski@gmail.com \
    --to=dsankouski@gmail.com \
    --cc=agust@denx.de \
    --cc=avromanov@sberdevices.ru \
    --cc=ilias.apalodimas@linaro.org \
    --cc=john@metanate.com \
    --cc=masahisa.kojima@linaro.org \
    --cc=neil.armstrong@linaro.org \
    --cc=rknecht@pm.me \
    --cc=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    --cc=xypron.glpk@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.