- get rid of code duplications in switch across bpp values
- extract common pixel fill logic in two functions one per
horizontal and vertical filling
- rearrange statements in put_xy* methods in unified way
- replace types - uint*_t to u*
Signed-off-by: Dzmitry Sankouski
---
Changes for v2:
- move width and pixel data size macros to console_simple.c
- performance: move if statement out of pixel fill loops
- document new functions
- remove console_probe_2 function
- make fill_pixel_and_goto_next void
- fix video unit tests failures
Changes for v3: none
drivers/video/console_simple.c | 598 ++---
1 file changed, 258 insertions(+), 340 deletions(-)
diff --git a/drivers/video/console_simple.c b/drivers/video/console_simple.c
index a4b3cfe3d8..1eb47be449 100644
--- a/drivers/video/console_simple.c
+++ b/drivers/video/console_simple.c
@@ -3,6 +3,7 @@
* Copyright (c) 2015 Google, Inc
* (C) Copyright 2015
* Bernecker & Rainer Industrieelektronik GmbH - http://www.br-automation.com
+ * (C) Copyright 2023 Dzmitry Sankouski
*/
#include
@@ -11,46 +12,209 @@
#include
#include /* Get font data, width and height */
-static int console_normal_set_row(struct udevice *dev, uint row, int clr)
-{
- struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
- void *line, *end;
- int pixels = VIDEO_FONT_HEIGHT * vid_priv->xsize;
- int ret;
- int i;
+#define VIDEO_FONT_BYTE_WIDTH ((VIDEO_FONT_WIDTH / 8) + (VIDEO_FONT_WIDTH % 8
> 0))
- line = vid_priv->fb + row * VIDEO_FONT_HEIGHT * vid_priv->line_length;
- switch (vid_priv->bpix) {
- case VIDEO_BPP8:
- if (IS_ENABLED(CONFIG_VIDEO_BPP8)) {
- uint8_t *dst = line;
+#define FLIPPED_DIRECTION 1
+#define NORMAL_DIRECTION 0
- for (i = 0; i < pixels; i++)
- *dst++ = clr;
- end = dst;
- break;
- }
+/**
+ * Checks if bits per pixel supported.
+ *
+ * @param bpix framebuffer bits per pixel.
+ *
+ * @returns 0, if supported, or else -ENOSYS.
+ */
+static int check_bpix_support(int bpix)
+{
+ switch (bpix) {
+ case VIDEO_BPP8:
+ if (IS_ENABLED(CONFIG_VIDEO_BPP8))
+ return 0;
case VIDEO_BPP16:
- if (IS_ENABLED(CONFIG_VIDEO_BPP16)) {
- uint16_t *dst = line;
+ if (IS_ENABLED(CONFIG_VIDEO_BPP16))
+ return 0;
+ case VIDEO_BPP32:
+ if (IS_ENABLED(CONFIG_VIDEO_BPP32))
+ return 0;
+ default:
+ return -ENOSYS;
+ }
+}
+
+/**
+ * Fill 1 pixel in framebuffer, and go to next one.
+ *
+ * @param dstp a pointer to pointer to framebuffer.
+ * @param valuevalue to write to framebuffer.
+ * @param pbytes framebuffer bytes per pixel.
+ * @param step framebuffer pointer increment. Usually is equal to
pbytes,
+ * and may be negative to control filling direction.
+ */
+static inline void fill_pixel_and_goto_next(void **dstp, u32 value, int
pbytes, int step)
+{
+ u8 *dst_byte = *dstp;
+
+ if (pbytes == 4) {
+ u32 *dst = *dstp;
+ *dst = value;
+ }
+ if (pbytes == 2) {
+ u16 *dst = *dstp;
+ *dst = value;
+ }
+ if (pbytes == 1) {
+ u8 *dst = *dstp;
+ *dst = value;
+ }
+ *dstp = dst_byte + step;
+}
+
+#if (CONFIG_IS_ENABLED(CONSOLE_ROTATION))
+/**
+ * Fills 1 character in framebuffer horizontally.
+ * Horizontally means we're filling char font data columns across the lines.
+ *
+ * @param pfonta 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.
+ * @param directioncontrols character orientation. Can be normal or
flipped.
+ * When normal: When flipped:
+ *|---|
+ *| *| line stepping |
+ *|^ * * * * *| | |
+ *||* *| v * *|
+ *|| | * * * * * |
+ *| line stepping | * |
+ *|| |
+ *| stepping -> |<- stepping |
+ *|---!!we're starting from upper left char corner|
+ *|---|
+ *
+ * @returns 0, if success, or else error code.
+ */
+static int fill_char_horizontally(uchar *pfont, void **line, struct video_priv
*vid_priv,
+ bool direction)
+{
+ int step, line_step, pbytes, ret;
+ void *dst;
+ u8 mask = 0x80;
+
+ ret = check_bpix_support(vid_priv->bpix);
+