[U-Boot] [PATCH 19/25] video: Update video_set_default_colors() to support invert

Simon Glass sjg at chromium.org
Tue Nov 6 22:21:36 UTC 2018


It is useful to be able to invert the colours in some cases so that the
text matches the background colour. Add a parameter to the function to
support this.

It is strange that function takes a private data structure from another
driver as an argument. It seems better to pass the device and have the
function internally work out how to find its required information.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

 drivers/video/vidconsole-uclass.c |  2 +-
 drivers/video/video-uclass.c      | 27 +++++++++++++++++++--------
 include/video.h                   |  5 +++--
 3 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c
index 1874887f2f3..d7568bc79a5 100644
--- a/drivers/video/vidconsole-uclass.c
+++ b/drivers/video/vidconsole-uclass.c
@@ -344,7 +344,7 @@ static void vidconsole_escape_char(struct udevice *dev, char ch)
 			switch (val) {
 			case 0:
 				/* all attributes off */
-				video_set_default_colors(vid_priv);
+				video_set_default_colors(dev->parent, false);
 				break;
 			case 1:
 				/* bold */
diff --git a/drivers/video/video-uclass.c b/drivers/video/video-uclass.c
index 44dfa71b6f4..b6551b69d3a 100644
--- a/drivers/video/video-uclass.c
+++ b/drivers/video/video-uclass.c
@@ -115,18 +115,29 @@ int video_clear(struct udevice *dev)
 	return 0;
 }
 
-void video_set_default_colors(struct video_priv *priv)
+void video_set_default_colors(struct udevice *dev, bool invert)
 {
+	struct video_priv *priv = dev_get_uclass_priv(dev);
+	int fore, back;
+
 #ifdef CONFIG_SYS_WHITE_ON_BLACK
 	/* White is used when switching to bold, use light gray here */
-	priv->fg_col_idx = VID_LIGHT_GRAY;
-	priv->colour_fg = vid_console_color(priv, VID_LIGHT_GRAY);
-	priv->colour_bg = vid_console_color(priv, VID_BLACK);
+	fore = VID_LIGHT_GRAY;
+	back = VID_BLACK;
 #else
-	priv->fg_col_idx = VID_BLACK;
-	priv->colour_fg = vid_console_color(priv, VID_BLACK);
-	priv->colour_bg = vid_console_color(priv, VID_WHITE);
+	fore = VID_BLACK;
+	back = VID_WHITE;
 #endif
+	if (invert) {
+		int temp;
+
+		temp = fore;
+		fore = back;
+		back = temp;
+	}
+	priv->fg_col_idx = fore;
+	priv->colour_fg = vid_console_color(priv, fore);
+	priv->colour_bg = vid_console_color(priv, back);
 }
 
 /* Flush video activity to the caches */
@@ -219,7 +230,7 @@ static int video_post_probe(struct udevice *dev)
 	priv->fb_size = priv->line_length * priv->ysize;
 
 	/* Set up colors  */
-	video_set_default_colors(priv);
+	video_set_default_colors(dev, false);
 
 	if (!CONFIG_IS_ENABLED(NO_FB_CLEAR))
 		video_clear(dev);
diff --git a/include/video.h b/include/video.h
index 75200f0e452..3f9139eea44 100644
--- a/include/video.h
+++ b/include/video.h
@@ -191,9 +191,10 @@ void video_set_flush_dcache(struct udevice *dev, bool flush);
 /**
  * Set default colors and attributes
  *
- * @priv	device information
+ * @dev:	video device
+ * @invert	true to invert colours
  */
-void video_set_default_colors(struct video_priv *priv);
+void video_set_default_colors(struct udevice *dev, bool invert);
 
 #endif /* CONFIG_DM_VIDEO */
 
-- 
2.19.1.930.g4563a0d9d0-goog



More information about the U-Boot mailing list