video console: implement multiple fonts configuration

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@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
[agust: fixed build error when bmp logo disabled]
Signed-off-by: Anatolij Gustschin <agust@denx.de>
This commit is contained in:
Dzmitry Sankouski 2023-03-07 13:21:14 +03:00 committed by Anatolij Gustschin
parent 0e177d5a95
commit 39c1fa2c21
10 changed files with 202 additions and 93 deletions

View file

@ -127,9 +127,11 @@ 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)
{
struct video_fontdata __maybe_unused *fontdata = fonts;
struct udevice *dev;
char buf[DISPLAY_OPTIONS_BANNER_LENGTH];
int col, row, ret;
@ -138,9 +140,9 @@ 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;
#if IS_ENABLED(CONFIG_VIDEO_LOGO)
col = BMP_LOGO_WIDTH / fontdata->width + 1;
row = BMP_LOGO_HEIGHT / fontdata->height + 1;
#else
col = 0;
row = 0;

View file

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

View file

@ -9,8 +9,41 @@
#include <video.h>
#include <video_console.h>
#include <dm.h>
#include <video_font.h>
#include "vidconsole_internal.h"
/**
* 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;
}
int check_bpix_support(int bpix)
{
if (bpix == VIDEO_BPP8 && IS_ENABLED(CONFIG_VIDEO_BPP8))
@ -43,7 +76,7 @@ inline void fill_pixel_and_goto_next(void **dstp, u32 value, int pbytes, int ste
}
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;
@ -61,17 +94,17 @@ int fill_char_vertically(uchar *pfont, void **line, struct video_priv *vid_priv,
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];
@ -90,13 +123,13 @@ int fill_char_vertically(uchar *pfont, void **line, struct video_priv *vid_priv,
}
}
*line += line_step;
pfont += VIDEO_FONT_BYTE_WIDTH;
pfont += fontdata->byte_width;
}
return ret;
}
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;
@ -115,21 +148,20 @@ int fill_char_horizontally(uchar *pfont, void **line, struct video_priv *vid_pri
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,
@ -146,20 +178,5 @@ int fill_char_horizontally(uchar *pfont, void **line, struct video_priv *vid_pri
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;
if (vid_priv->rot % 2) {
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);
} else {
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);
}

View file

@ -16,8 +16,10 @@
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;
@ -26,7 +28,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++)
@ -44,14 +46,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;
@ -64,10 +68,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;
@ -79,7 +86,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;
@ -87,7 +94,7 @@ 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);
}
struct vidconsole_ops console_ops = {
@ -97,8 +104,9 @@ 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),
};

View file

@ -16,17 +16,19 @@
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;
}
@ -41,19 +43,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;
@ -68,10 +72,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;
@ -80,7 +87,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;
@ -89,20 +96,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++)
@ -119,17 +128,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;
}
@ -139,10 +150,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;
@ -151,7 +165,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;
@ -160,21 +174,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;
}
@ -189,17 +205,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;
@ -214,10 +232,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;
@ -226,7 +247,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 */
@ -234,7 +255,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);
return VID_TO_POS(fontdata->width);
}
struct vidconsole_ops console_ops_1 = {
@ -260,6 +281,7 @@ U_BOOT_DRIVER(vidconsole_1) = {
.id = UCLASS_VIDEO_CONSOLE,
.ops = &console_ops_1,
.probe = console_probe,
.priv_auto = sizeof(struct console_simple_priv),
};
U_BOOT_DRIVER(vidconsole_2) = {
@ -267,6 +289,7 @@ U_BOOT_DRIVER(vidconsole_2) = {
.id = UCLASS_VIDEO_CONSOLE,
.ops = &console_ops_2,
.probe = console_probe,
.priv_auto = sizeof(struct console_simple_priv),
};
U_BOOT_DRIVER(vidconsole_3) = {
@ -274,4 +297,5 @@ U_BOOT_DRIVER(vidconsole_3) = {
.id = UCLASS_VIDEO_CONSOLE,
.ops = &console_ops_3,
.probe = console_probe,
.priv_auto = sizeof(struct console_simple_priv),
};

View file

@ -6,14 +6,18 @@
* (C) Copyright 2023 Dzmitry Sankouski <dsankouski@gmail.com>
*/
#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;
};
/**
* Checks if bits per pixel supported.
*
@ -41,6 +45,7 @@ void fill_pixel_and_goto_next(void **dstp, u32 value, int pbytes, int step);
* @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:
*|-----------------------------------------------|
@ -59,7 +64,7 @@ void fill_pixel_and_goto_next(void **dstp, u32 value, int pbytes, int step);
* @returns 0, if success, or else error code.
*/
int fill_char_vertically(uchar *pfont, void **line, struct video_priv *vid_priv,
bool direction);
struct video_fontdata *fontdata, bool direction);
/**
* Fills 1 character in framebuffer horizontally.
@ -68,6 +73,7 @@ int fill_char_vertically(uchar *pfont, void **line, struct video_priv *vid_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:
*|-----------------------------------------------|
@ -84,7 +90,7 @@ int fill_char_vertically(uchar *pfont, void **line, struct video_priv *vid_priv,
* @returns 0, if success, or else error code.
*/
int fill_char_horizontally(uchar *pfont, void **line, struct video_priv *vid_priv,
bool direction);
struct video_fontdata *fontdata, bool direction);
/**
* console probe function.

View file

@ -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_8X16)
FONT_ENTRY(8, 16, 8x16),
#endif
#if defined(CONFIG_VIDEO_FONT_4X6)
FONT_ENTRY(4, 6, 4x6),
#endif
{/* list terminator */}
};
#endif /* _VIDEO_FONT_ */

View file

@ -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: ' ' */

View file

@ -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 */

31
include/video_font_data.h Normal file
View file

@ -0,0 +1,31 @@
/* SPDX-License-Identifier: GPL-2.0+ */
/*
* (C) Copyright 2023 Dzmitry Sankouski <dsankouski@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_ */