[PATCH v3 5/9] video console: implement multiple fonts configuration
Dzmitry Sankouski
dsankouski at gmail.com
Wed Feb 15 12:42:56 CET 2023
This needed for unit testing different fonts.
Configured fonts are placed in an array of fonts.
First font is selected by default upon console probe.
Signed-off-by: Dzmitry Sankouski <dsankouski at gmail.com>
---
Changes for v2: N/A
Changes for v3: N/A
common/splash.c | 17 ++-
drivers/video/Kconfig | 15 +++
drivers/video/console_simple.c | 232 ++++++++++++++++++++-------------
include/video_font.h | 17 ++-
include/video_font_4x6.h | 11 +-
include/video_font_8x16.h | 8 +-
include/video_font_data.h | 31 +++++
7 files changed, 216 insertions(+), 115 deletions(-)
create mode 100644 include/video_font_data.h
diff --git a/common/splash.c b/common/splash.c
index 245ff680eb..1cd9afae2d 100644
--- a/common/splash.c
+++ b/common/splash.c
@@ -127,6 +127,7 @@ void splash_get_pos(int *x, int *y)
#include <dm.h>
#include <video_console.h>
#include <video_font.h>
+#include <video_font_data.h>
void splash_display_banner(void)
{
@@ -138,13 +139,15 @@ void splash_display_banner(void)
if (ret)
return;
-#ifdef CONFIG_VIDEO_LOGO
- col = BMP_LOGO_WIDTH / VIDEO_FONT_WIDTH + 1;
- row = BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT + 1;
-#else
- col = 0;
- row = 0;
-#endif
+ if (IS_ENABLED(CONFIG_VIDEO_LOGO)) {
+ struct video_fontdata *fontdata = &fonts[0];
+
+ col = BMP_LOGO_WIDTH / fontdata->width + 1;
+ row = BMP_LOGO_HEIGHT / fontdata->height + 1;
+ } else {
+ col = 0;
+ row = 0;
+ }
display_options_get_banner(false, buf, sizeof(buf));
vidconsole_position_cursor(dev, col, 1);
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index f2e930ab68..47428ecb6c 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -16,6 +16,21 @@ config VIDEO
if VIDEO
+config VIDEO_FONT_4X6
+ bool "4 x 6 font size"
+ help
+ Font for video console driver, 4 x 6 pixels.
+ Provides character bitmap data in header file.
+ When selecting multiple fonts, you may want to enable CMD_SELECT_FONT too.
+
+config VIDEO_FONT_8X16
+ bool "8 x 16 font size"
+ default y
+ help
+ Font for video console driver, 8 x 16 pixels
+ Provides character bitmap data in header file.
+ When selecting multiple fonts, you may want to enable CMD_SELECT_FONT too.
+
config VIDEO_LOGO
bool "Show the U-Boot logo on the display"
default y if !SPLASH_SCREEN
diff --git a/drivers/video/console_simple.c b/drivers/video/console_simple.c
index cdc26cac30..402d67f85f 100644
--- a/drivers/video/console_simple.c
+++ b/drivers/video/console_simple.c
@@ -12,12 +12,50 @@
#include <video_console.h>
#include <video_font.h> /* Get font data, width and height */
-#define VIDEO_FONT_BYTE_WIDTH ((VIDEO_FONT_WIDTH / 8) + (VIDEO_FONT_WIDTH % 8 > 0))
-#define VIDEO_FONT_CHAR_PIXEL_BYTES (VIDEO_FONT_HEIGHT * VIDEO_FONT_BYTE_WIDTH)
-
#define FLIPPED_DIRECTION 1
#define NORMAL_DIRECTION 0
+/**
+ * struct console_simple_priv - Private data for this driver
+ *
+ * @video_fontdata font graphical representation data
+ */
+struct console_simple_priv {
+ struct video_fontdata *fontdata;
+};
+
+/**
+ * console_set_font() - prepare vidconsole for chosen font.
+ *
+ * @dev vidconsole device
+ * @fontdata pointer to font data struct
+ */
+static int console_set_font(struct udevice *dev, struct video_fontdata *fontdata)
+{
+ struct console_simple_priv *priv = dev_get_priv(dev);
+ struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
+ struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
+
+ debug("console_simple: setting %s font\n", fontdata->name);
+ debug("width: %d\n", fontdata->width);
+ debug("byte width: %d\n", fontdata->byte_width);
+ debug("height: %d\n", fontdata->height);
+
+ priv->fontdata = fontdata;
+ vc_priv->x_charsize = fontdata->width;
+ vc_priv->y_charsize = fontdata->height;
+ if (vid_priv->rot % 2) {
+ vc_priv->cols = vid_priv->ysize / fontdata->width;
+ vc_priv->rows = vid_priv->xsize / fontdata->height;
+ vc_priv->xsize_frac = VID_TO_POS(vid_priv->ysize);
+ } else {
+ vc_priv->cols = vid_priv->xsize / fontdata->width;
+ vc_priv->rows = vid_priv->ysize / fontdata->height;
+ }
+
+ return 0;
+}
+
/**
* Checks if bits per pixel supported.
*
@@ -78,6 +116,7 @@ static inline void fill_pixel_and_goto_next(void **dstp, u32 value, int pbytes,
* @param pfont a pointer to character font data.
* @param line a pointer to pointer to framebuffer. It's a point for upper left char corner
* @param vid_priv driver private data.
+ * @fontdata font graphical representation data
* @param direction controls character orientation. Can be normal or flipped.
* When normal: When flipped:
*|-----------------------------------------------|
@@ -94,7 +133,7 @@ static inline void fill_pixel_and_goto_next(void **dstp, u32 value, int pbytes,
* @returns 0, if success, or else error code.
*/
static int fill_char_horizontally(uchar *pfont, void **line, struct video_priv *vid_priv,
- bool direction)
+ struct video_fontdata *fontdata, bool direction)
{
int step, line_step, pbytes, bitcount = 8, width_remainder, ret;
void *dst;
@@ -113,21 +152,20 @@ static int fill_char_horizontally(uchar *pfont, void **line, struct video_priv *
line_step = -vid_priv->line_length;
}
- width_remainder = VIDEO_FONT_WIDTH % 8;
- for (int col = 0; col < VIDEO_FONT_BYTE_WIDTH; col++) {
+ width_remainder = fontdata->width % 8;
+ for (int col = 0; col < fontdata->byte_width; col++) {
mask = 0x80;
if (width_remainder) {
- bool is_last_iteration = (VIDEO_FONT_BYTE_WIDTH - col == 1);
+ bool is_last_col = (fontdata->byte_width - col == 1);
- if (is_last_iteration)
+ if (is_last_col)
bitcount = width_remainder;
}
for (int bit = 0; bit < bitcount; bit++) {
dst = *line;
- for (int row = 0; row < VIDEO_FONT_HEIGHT; row++) {
- u32 value = (pfont[row * VIDEO_FONT_BYTE_WIDTH] & mask) ?
- vid_priv->colour_fg :
- vid_priv->colour_bg;
+ for (int row = 0; row < fontdata->height; row++) {
+ u32 value = (pfont[row * fontdata->byte_width + col]
+ & mask) ? vid_priv->colour_fg : vid_priv->colour_bg;
fill_pixel_and_goto_next(&dst,
value,
@@ -150,6 +188,7 @@ static int fill_char_horizontally(uchar *pfont, void **line, struct video_priv *
* @param pfont a pointer to character font data.
* @param line a pointer to pointer to framebuffer. It's a point for upper left char corner
* @param vid_priv driver private data.
+ * @fontdata font graphical representation data
* @param direction controls character orientation. Can be normal or flipped.
* When normal: When flipped:
*|-----------------------------------------------|
@@ -168,7 +207,7 @@ static int fill_char_horizontally(uchar *pfont, void **line, struct video_priv *
* @returns 0, if success, or else error code.
*/
static int fill_char_vertically(uchar *pfont, void **line, struct video_priv *vid_priv,
- bool direction)
+ struct video_fontdata *fontdata, bool direction)
{
int step, line_step, pbytes, bitcount, width_remainder, ret;
void *dst;
@@ -186,17 +225,17 @@ static int fill_char_vertically(uchar *pfont, void **line, struct video_priv *vi
line_step = vid_priv->line_length;
}
- width_remainder = VIDEO_FONT_WIDTH % 8;
- for (int row = 0; row < VIDEO_FONT_HEIGHT; row++) {
+ width_remainder = fontdata->width % 8;
+ for (int row = 0; row < fontdata->height; row++) {
uchar bits;
bitcount = 8;
dst = *line;
- for (int col = 0; col < VIDEO_FONT_BYTE_WIDTH; col++) {
+ for (int col = 0; col < fontdata->byte_width; col++) {
if (width_remainder) {
- bool is_last_iteration = (VIDEO_FONT_BYTE_WIDTH - col == 1);
+ bool is_last_col = (fontdata->byte_width - col == 1);
- if (is_last_iteration)
+ if (is_last_col)
bitcount = width_remainder;
}
bits = pfont[col];
@@ -215,7 +254,7 @@ static int fill_char_vertically(uchar *pfont, void **line, struct video_priv *vi
}
}
*line += line_step;
- pfont += VIDEO_FONT_BYTE_WIDTH;
+ pfont += fontdata->byte_width;
}
return ret;
}
@@ -223,8 +262,10 @@ static int fill_char_vertically(uchar *pfont, void **line, struct video_priv *vi
static int console_set_row(struct udevice *dev, uint row, int clr)
{
struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
+ struct console_simple_priv *priv = dev_get_priv(dev);
+ struct video_fontdata *fontdata = priv->fontdata;
void *line, *dst, *end;
- int pixels = VIDEO_FONT_HEIGHT * vid_priv->xsize;
+ int pixels = fontdata->height * vid_priv->xsize;
int ret;
int i;
int pbytes;
@@ -233,7 +274,7 @@ static int console_set_row(struct udevice *dev, uint row, int clr)
if (ret)
return ret;
- line = vid_priv->fb + row * VIDEO_FONT_HEIGHT * vid_priv->line_length;
+ line = vid_priv->fb + row * fontdata->height * vid_priv->line_length;
dst = line;
pbytes = VNBYTES(vid_priv->bpix);
for (i = 0; i < pixels; i++)
@@ -251,14 +292,16 @@ static int console_move_rows(struct udevice *dev, uint rowdst,
uint rowsrc, uint count)
{
struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
+ struct console_simple_priv *priv = dev_get_priv(dev);
+ struct video_fontdata *fontdata = priv->fontdata;
void *dst;
void *src;
int size;
int ret;
- dst = vid_priv->fb + rowdst * VIDEO_FONT_HEIGHT * vid_priv->line_length;
- src = vid_priv->fb + rowsrc * VIDEO_FONT_HEIGHT * vid_priv->line_length;
- size = VIDEO_FONT_HEIGHT * vid_priv->line_length * count;
+ dst = vid_priv->fb + rowdst * fontdata->height * vid_priv->line_length;
+ src = vid_priv->fb + rowsrc * fontdata->height * vid_priv->line_length;
+ size = fontdata->height * vid_priv->line_length * count;
ret = vidconsole_memmove(dev, dst, src, size);
if (ret)
return ret;
@@ -271,10 +314,13 @@ static int console_putc_xy(struct udevice *dev, uint x_frac, uint y, char ch)
struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
struct udevice *vid = dev->parent;
struct video_priv *vid_priv = dev_get_uclass_priv(vid);
+ struct console_simple_priv *priv = dev_get_priv(dev);
+ struct video_fontdata *fontdata = priv->fontdata;
int pbytes = VNBYTES(vid_priv->bpix);
int x, linenum, ret;
void *start, *line;
- uchar *pfont = video_fontdata + (u8)ch * VIDEO_FONT_CHAR_PIXEL_BYTES;
+ uchar *pfont = fontdata->video_fontdata +
+ (u8)ch * fontdata->char_pixel_bytes;
if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
return -EAGAIN;
@@ -286,7 +332,7 @@ static int console_putc_xy(struct udevice *dev, uint x_frac, uint y, char ch)
if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
return -EAGAIN;
- ret = fill_char_vertically(pfont, &line, vid_priv, NORMAL_DIRECTION);
+ ret = fill_char_vertically(pfont, &line, vid_priv, fontdata, NORMAL_DIRECTION);
if (ret)
return ret;
@@ -294,21 +340,12 @@ static int console_putc_xy(struct udevice *dev, uint x_frac, uint y, char ch)
if (ret)
return ret;
- return VID_TO_POS(VIDEO_FONT_WIDTH);
+ return VID_TO_POS(fontdata->width);
}
static int console_probe(struct udevice *dev)
{
- struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
- struct udevice *vid_dev = dev->parent;
- struct video_priv *vid_priv = dev_get_uclass_priv(vid_dev);
-
- vc_priv->x_charsize = VIDEO_FONT_WIDTH;
- vc_priv->y_charsize = VIDEO_FONT_HEIGHT;
- vc_priv->cols = vid_priv->xsize / VIDEO_FONT_WIDTH;
- vc_priv->rows = vid_priv->ysize / VIDEO_FONT_HEIGHT;
-
- return 0;
+ return console_set_font(dev, &fonts[0]);
}
struct vidconsole_ops console_ops = {
@@ -318,27 +355,30 @@ struct vidconsole_ops console_ops = {
};
U_BOOT_DRIVER(vidconsole_normal) = {
- .name = "vidconsole0",
- .id = UCLASS_VIDEO_CONSOLE,
- .ops = &console_ops,
- .probe = console_probe,
+ .name = "vidconsole0",
+ .id = UCLASS_VIDEO_CONSOLE,
+ .ops = &console_ops,
+ .probe = console_probe,
+ .priv_auto = sizeof(struct console_simple_priv),
};
#if (CONFIG_IS_ENABLED(CONSOLE_ROTATION))
static int console_set_row_1(struct udevice *dev, uint row, int clr)
{
struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
+ struct console_simple_priv *priv = dev_get_priv(dev);
+ struct video_fontdata *fontdata = priv->fontdata;
int pbytes = VNBYTES(vid_priv->bpix);
void *start, *dst, *line;
int i, j;
int ret;
start = vid_priv->fb + vid_priv->line_length -
- (row + 1) * VIDEO_FONT_HEIGHT * pbytes;
+ (row + 1) * fontdata->height * pbytes;
line = start;
for (j = 0; j < vid_priv->ysize; j++) {
dst = line;
- for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
+ for (i = 0; i < fontdata->height; i++)
fill_pixel_and_goto_next(&dst, clr, pbytes, pbytes);
line += vid_priv->line_length;
}
@@ -353,19 +393,21 @@ static int console_move_rows_1(struct udevice *dev, uint rowdst, uint rowsrc,
uint count)
{
struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
+ struct console_simple_priv *priv = dev_get_priv(dev);
+ struct video_fontdata *fontdata = priv->fontdata;
int pbytes = VNBYTES(vid_priv->bpix);
void *dst;
void *src;
int j, ret;
dst = vid_priv->fb + vid_priv->line_length -
- (rowdst + count) * VIDEO_FONT_HEIGHT * pbytes;
+ (rowdst + count) * fontdata->height * pbytes;
src = vid_priv->fb + vid_priv->line_length -
- (rowsrc + count) * VIDEO_FONT_HEIGHT * pbytes;
+ (rowsrc + count) * fontdata->height * pbytes;
for (j = 0; j < vid_priv->ysize; j++) {
ret = vidconsole_memmove(dev, dst, src,
- VIDEO_FONT_HEIGHT * pbytes * count);
+ fontdata->height * pbytes * count);
if (ret)
return ret;
src += vid_priv->line_length;
@@ -380,10 +422,13 @@ static int console_putc_xy_1(struct udevice *dev, uint x_frac, uint y, char ch)
struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
struct udevice *vid = dev->parent;
struct video_priv *vid_priv = dev_get_uclass_priv(vid);
+ struct console_simple_priv *priv = dev_get_priv(dev);
+ struct video_fontdata *fontdata = priv->fontdata;
int pbytes = VNBYTES(vid_priv->bpix);
int x, linenum, ret;
void *start, *line;
- uchar *pfont = video_fontdata + (u8)ch * VIDEO_FONT_CHAR_PIXEL_BYTES;
+ uchar *pfont = fontdata->video_fontdata +
+ (u8)ch * fontdata->char_pixel_bytes;
if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
return -EAGAIN;
@@ -392,7 +437,7 @@ static int console_putc_xy_1(struct udevice *dev, uint x_frac, uint y, char ch)
start = vid_priv->fb + linenum * vid_priv->line_length - x * pbytes;
line = start;
- ret = fill_char_horizontally(pfont, &line, vid_priv, FLIPPED_DIRECTION);
+ ret = fill_char_horizontally(pfont, &line, vid_priv, fontdata, FLIPPED_DIRECTION);
if (ret)
return ret;
@@ -401,20 +446,22 @@ static int console_putc_xy_1(struct udevice *dev, uint x_frac, uint y, char ch)
if (ret)
return ret;
- return VID_TO_POS(VIDEO_FONT_WIDTH);
+ return VID_TO_POS(fontdata->width);
}
static int console_set_row_2(struct udevice *dev, uint row, int clr)
{
struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
+ struct console_simple_priv *priv = dev_get_priv(dev);
+ struct video_fontdata *fontdata = priv->fontdata;
void *start, *line, *dst, *end;
- int pixels = VIDEO_FONT_HEIGHT * vid_priv->xsize;
+ int pixels = fontdata->height * vid_priv->xsize;
int i, ret;
int pbytes = VNBYTES(vid_priv->bpix);
start = vid_priv->fb + vid_priv->ysize * vid_priv->line_length -
- (row + 1) * VIDEO_FONT_HEIGHT * vid_priv->line_length;
+ (row + 1) * fontdata->height * vid_priv->line_length;
line = start;
dst = line;
for (i = 0; i < pixels; i++)
@@ -431,17 +478,19 @@ static int console_move_rows_2(struct udevice *dev, uint rowdst, uint rowsrc,
uint count)
{
struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
+ struct console_simple_priv *priv = dev_get_priv(dev);
+ struct video_fontdata *fontdata = priv->fontdata;
void *dst;
void *src;
void *end;
end = vid_priv->fb + vid_priv->ysize * vid_priv->line_length;
- dst = end - (rowdst + count) * VIDEO_FONT_HEIGHT *
+ dst = end - (rowdst + count) * fontdata->height *
vid_priv->line_length;
- src = end - (rowsrc + count) * VIDEO_FONT_HEIGHT *
+ src = end - (rowsrc + count) * fontdata->height *
vid_priv->line_length;
vidconsole_memmove(dev, dst, src,
- VIDEO_FONT_HEIGHT * vid_priv->line_length * count);
+ fontdata->height * vid_priv->line_length * count);
return 0;
}
@@ -451,10 +500,13 @@ static int console_putc_xy_2(struct udevice *dev, uint x_frac, uint y, char ch)
struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
struct udevice *vid = dev->parent;
struct video_priv *vid_priv = dev_get_uclass_priv(vid);
+ struct console_simple_priv *priv = dev_get_priv(dev);
+ struct video_fontdata *fontdata = priv->fontdata;
int pbytes = VNBYTES(vid_priv->bpix);
int linenum, x, ret;
void *start, *line;
- uchar *pfont = video_fontdata + (u8)ch * VIDEO_FONT_CHAR_PIXEL_BYTES;
+ uchar *pfont = fontdata->video_fontdata +
+ (u8)ch * fontdata->char_pixel_bytes;
if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
return -EAGAIN;
@@ -463,7 +515,7 @@ static int console_putc_xy_2(struct udevice *dev, uint x_frac, uint y, char ch)
start = vid_priv->fb + linenum * vid_priv->line_length + x * pbytes;
line = start;
- ret = fill_char_vertically(pfont, &line, vid_priv, FLIPPED_DIRECTION);
+ ret = fill_char_vertically(pfont, &line, vid_priv, fontdata, FLIPPED_DIRECTION);
if (ret)
return ret;
@@ -472,21 +524,23 @@ static int console_putc_xy_2(struct udevice *dev, uint x_frac, uint y, char ch)
if (ret)
return ret;
- return VID_TO_POS(VIDEO_FONT_WIDTH);
+ return VID_TO_POS(fontdata->width);
}
static int console_set_row_3(struct udevice *dev, uint row, int clr)
{
struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
+ struct console_simple_priv *priv = dev_get_priv(dev);
+ struct video_fontdata *fontdata = priv->fontdata;
int pbytes = VNBYTES(vid_priv->bpix);
void *start, *dst, *line;
int i, j, ret;
- start = vid_priv->fb + row * VIDEO_FONT_HEIGHT * pbytes;
+ start = vid_priv->fb + row * fontdata->height * pbytes;
line = start;
for (j = 0; j < vid_priv->ysize; j++) {
dst = line;
- for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
+ for (i = 0; i < fontdata->height; i++)
fill_pixel_and_goto_next(&dst, clr, pbytes, pbytes);
line += vid_priv->line_length;
}
@@ -501,17 +555,19 @@ static int console_move_rows_3(struct udevice *dev, uint rowdst, uint rowsrc,
uint count)
{
struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
+ struct console_simple_priv *priv = dev_get_priv(dev);
+ struct video_fontdata *fontdata = priv->fontdata;
int pbytes = VNBYTES(vid_priv->bpix);
void *dst;
void *src;
int j, ret;
- dst = vid_priv->fb + rowdst * VIDEO_FONT_HEIGHT * pbytes;
- src = vid_priv->fb + rowsrc * VIDEO_FONT_HEIGHT * pbytes;
+ dst = vid_priv->fb + rowdst * fontdata->height * pbytes;
+ src = vid_priv->fb + rowsrc * fontdata->height * pbytes;
for (j = 0; j < vid_priv->ysize; j++) {
ret = vidconsole_memmove(dev, dst, src,
- VIDEO_FONT_HEIGHT * pbytes * count);
+ fontdata->height * pbytes * count);
if (ret)
return ret;
src += vid_priv->line_length;
@@ -526,10 +582,13 @@ static int console_putc_xy_3(struct udevice *dev, uint x_frac, uint y, char ch)
struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
struct udevice *vid = dev->parent;
struct video_priv *vid_priv = dev_get_uclass_priv(vid);
+ struct console_simple_priv *priv = dev_get_priv(dev);
+ struct video_fontdata *fontdata = priv->fontdata;
int pbytes = VNBYTES(vid_priv->bpix);
int linenum, x, ret;
void *start, *line;
- uchar *pfont = video_fontdata + (u8)ch * VIDEO_FONT_CHAR_PIXEL_BYTES;
+ uchar *pfont = fontdata->video_fontdata +
+ (u8)ch * fontdata->char_pixel_bytes;
if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac)
return -EAGAIN;
@@ -538,7 +597,7 @@ static int console_putc_xy_3(struct udevice *dev, uint x_frac, uint y, char ch)
start = vid_priv->fb + linenum * vid_priv->line_length + y * pbytes;
line = start;
- ret = fill_char_horizontally(pfont, &line, vid_priv, NORMAL_DIRECTION);
+ ret = fill_char_horizontally(pfont, &line, vid_priv, fontdata, NORMAL_DIRECTION);
if (ret)
return ret;
/* Add a line to allow for the first pixels writen */
@@ -546,23 +605,7 @@ static int console_putc_xy_3(struct udevice *dev, uint x_frac, uint y, char ch)
if (ret)
return ret;
- return VID_TO_POS(VIDEO_FONT_WIDTH);
-}
-
-
-static int console_probe_1_3(struct udevice *dev)
-{
- struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
- struct udevice *vid_dev = dev->parent;
- struct video_priv *vid_priv = dev_get_uclass_priv(vid_dev);
-
- vc_priv->x_charsize = VIDEO_FONT_WIDTH;
- vc_priv->y_charsize = VIDEO_FONT_HEIGHT;
- vc_priv->cols = vid_priv->ysize / VIDEO_FONT_WIDTH;
- vc_priv->rows = vid_priv->xsize / VIDEO_FONT_HEIGHT;
- vc_priv->xsize_frac = VID_TO_POS(vid_priv->ysize);
-
- return 0;
+ return VID_TO_POS(fontdata->width);
}
struct vidconsole_ops console_ops_1 = {
@@ -584,23 +627,26 @@ struct vidconsole_ops console_ops_3 = {
};
U_BOOT_DRIVER(vidconsole_1) = {
- .name = "vidconsole1",
- .id = UCLASS_VIDEO_CONSOLE,
- .ops = &console_ops_1,
- .probe = console_probe_1_3,
+ .name = "vidconsole1",
+ .id = UCLASS_VIDEO_CONSOLE,
+ .ops = &console_ops_1,
+ .probe = console_probe,
+ .priv_auto = sizeof(struct console_simple_priv),
};
U_BOOT_DRIVER(vidconsole_2) = {
- .name = "vidconsole2",
- .id = UCLASS_VIDEO_CONSOLE,
- .ops = &console_ops_2,
- .probe = console_probe,
+ .name = "vidconsole2",
+ .id = UCLASS_VIDEO_CONSOLE,
+ .ops = &console_ops_2,
+ .probe = console_probe,
+ .priv_auto = sizeof(struct console_simple_priv),
};
U_BOOT_DRIVER(vidconsole_3) = {
- .name = "vidconsole3",
- .id = UCLASS_VIDEO_CONSOLE,
- .ops = &console_ops_3,
- .probe = console_probe_1_3,
+ .name = "vidconsole3",
+ .id = UCLASS_VIDEO_CONSOLE,
+ .ops = &console_ops_3,
+ .probe = console_probe,
+ .priv_auto = sizeof(struct console_simple_priv),
};
#endif
diff --git a/include/video_font.h b/include/video_font.h
index b07c07662c..fbb58b11a0 100644
--- a/include/video_font.h
+++ b/include/video_font.h
@@ -7,10 +7,23 @@
#ifndef _VIDEO_FONT_
#define _VIDEO_FONT_
-#ifdef CONFIG_VIDEO_FONT_4X6
+#include <video_font_data.h>
+
+#if defined(CONFIG_VIDEO_FONT_4X6)
#include <video_font_4x6.h>
-#else
+#endif
+#if defined(CONFIG_VIDEO_FONT_8X16)
#include <video_font_8x16.h>
#endif
+static struct video_fontdata __maybe_unused fonts[] = {
+#if defined(CONFIG_VIDEO_FONT_4X6)
+ FONT_ENTRY(4, 6, 4x6),
+#endif
+#if defined(CONFIG_VIDEO_FONT_8X16)
+ FONT_ENTRY(8, 16, 8x16),
+#endif
+ {/* list terminator */}
+};
+
#endif /* _VIDEO_FONT_ */
diff --git a/include/video_font_4x6.h b/include/video_font_4x6.h
index c7e6351b64..1b8c02510b 100644
--- a/include/video_font_4x6.h
+++ b/include/video_font_4x6.h
@@ -38,15 +38,12 @@ __END__;
MSBit to LSBit = left to right.
*/
-#ifndef _VIDEO_FONT_DATA_
-#define _VIDEO_FONT_DATA_
+#ifndef _VIDEO_FONT_4X6_
+#define _VIDEO_FONT_4X6_
-#define VIDEO_FONT_CHARS 256
-#define VIDEO_FONT_WIDTH 4
-#define VIDEO_FONT_HEIGHT 6
-#define VIDEO_FONT_SIZE (VIDEO_FONT_CHARS * VIDEO_FONT_HEIGHT)
+#include <video_font_data.h>
-static unsigned char video_fontdata[VIDEO_FONT_SIZE] = {
+static unsigned char video_fontdata_4x6[VIDEO_FONT_SIZE(256, 4, 6)] = {
/*{*/
/* Char 0: ' ' */
diff --git a/include/video_font_8x16.h b/include/video_font_8x16.h
index d3d4295032..d8a1d90cee 100644
--- a/include/video_font_8x16.h
+++ b/include/video_font_8x16.h
@@ -9,13 +9,9 @@
#ifndef _VIDEO_FONT_8X16
#define _VIDEO_FONT_8X16
-#define VIDEO_FONT_CHARS 256
-#define VIDEO_FONT_WIDTH 8
-#define VIDEO_FONT_HEIGHT 16
-#define VIDEO_FONT_SIZE (VIDEO_FONT_CHARS * VIDEO_FONT_HEIGHT)
-
-static unsigned char __maybe_unused video_fontdata[VIDEO_FONT_SIZE] = {
+#include <video_font_data.h>
+static unsigned char video_fontdata_8x16[VIDEO_FONT_SIZE(256, 8, 16)] = {
/* 0 0x00 '^@' */
0x00, /* 00000000 */
0x00, /* 00000000 */
diff --git a/include/video_font_data.h b/include/video_font_data.h
new file mode 100644
index 0000000000..37c3e00336
--- /dev/null
+++ b/include/video_font_data.h
@@ -0,0 +1,31 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * (C) Copyright 2023 Dzmitry Sankouski <dsankouski at gmail.com>
+ */
+
+#ifndef _VIDEO_FONT_DATA_
+#define _VIDEO_FONT_DATA_
+#define VIDEO_FONT_BYTE_WIDTH(width) ((width / 8) + (width % 8 > 0))
+#define VIDEO_FONT_CHAR_PIXEL_BYTES(width, height) (height * VIDEO_FONT_BYTE_WIDTH(width))
+#define VIDEO_FONT_SIZE(chars, width, height) (chars * VIDEO_FONT_CHAR_PIXEL_BYTES(width, height))
+
+struct video_fontdata {
+ const char *name;
+ int width;
+ int height;
+ int byte_width;
+ int char_pixel_bytes;
+ unsigned char *video_fontdata;
+};
+
+#define FONT_ENTRY(_font_width, _font_height, _width_x_height) \
+{ \
+ .name = #_width_x_height, \
+ .width = _font_width, \
+ .height = _font_height, \
+ .byte_width = VIDEO_FONT_BYTE_WIDTH(_font_width), \
+ .char_pixel_bytes = VIDEO_FONT_CHAR_PIXEL_BYTES(_font_width, _font_height), \
+ .video_fontdata = video_fontdata_##_width_x_height, \
+}
+
+#endif /* _VIDEO_FONT_DATA_ */
--
2.30.2
More information about the U-Boot
mailing list