[U-Boot] [PATCH V3 09/12] lcd: introduce getters for bg/fg color

Nikita Kiryanov nikita at compulab.co.il
Mon Dec 8 16:14:43 CET 2014


Introduce lcd_getbgcolor() and lcd_getfgcolor(), and use them where
applicable.

This is a preparatory step for extracting lcd console code into its own
file.

Signed-off-by: Nikita Kiryanov <nikita at compulab.co.il>
Cc: Anatolij Gustschin <agust at denx.de>
Cc: Simon Glass <sjg at chromium.org>
---
Changes in V3:
	- Instead of invoking lcd_get(bg|fg)color() each time, do it only once
	  and cache the value. This is done in console_scrollup(),
	  lcd_drawchars(), and drv_lcd_init().

Changes in V2:
	- New patch.

 common/lcd.c  | 31 ++++++++++++++++++++++---------
 include/lcd.h | 14 ++++++++++++++
 2 files changed, 36 insertions(+), 9 deletions(-)

diff --git a/common/lcd.c b/common/lcd.c
index f98aaaf..a29e7a2 100644
--- a/common/lcd.c
+++ b/common/lcd.c
@@ -177,6 +177,7 @@ void lcd_set_row(short row)
 static void console_scrollup(void)
 {
 	const int rows = CONFIG_CONSOLE_SCROLL_LINES;
+	int bg_color = lcd_getbgcolor();
 
 	/* Copy up rows ignoring those that will be overwritten */
 	memcpy(CONSOLE_ROW_FIRST,
@@ -186,8 +187,7 @@ static void console_scrollup(void)
 	/* Clear the last rows */
 #if (LCD_BPP != LCD_COLOR32)
 	memset(lcd_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows,
-		lcd_color_bg,
-		CONSOLE_ROW_SIZE * rows);
+	       bg_color, CONSOLE_ROW_SIZE * rows);
 #else
 	u32 *ppix = lcd_console_address +
 		    CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows;
@@ -195,7 +195,7 @@ static void console_scrollup(void)
 	for (i = 0;
 	    i < (CONSOLE_ROW_SIZE * rows) / NBYTES(panel_info.vl_bpix);
 	    i++) {
-		*ppix++ = lcd_color_bg;
+		*ppix++ = bg_color;
 	}
 #endif
 	lcd_sync();
@@ -316,6 +316,7 @@ static void lcd_drawchars(ushort x, ushort y, uchar *str, int count)
 {
 	uchar *dest;
 	ushort row;
+	int fg_color, bg_color;
 
 #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
 	y += BMP_LOGO_HEIGHT;
@@ -334,6 +335,8 @@ static void lcd_drawchars(ushort x, ushort y, uchar *str, int count)
 		uchar *d = dest;
 #endif
 
+		fg_color = lcd_getfgcolor();
+		bg_color = lcd_getbgcolor();
 		for (i = 0; i < count; ++i) {
 			uchar c, bits;
 
@@ -341,8 +344,7 @@ static void lcd_drawchars(ushort x, ushort y, uchar *str, int count)
 			bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];
 
 			for (c = 0; c < 8; ++c) {
-				*d++ = (bits & 0x80) ?
-						lcd_color_fg : lcd_color_bg;
+				*d++ = (bits & 0x80) ? fg_color : bg_color;
 				bits <<= 1;
 			}
 		}
@@ -433,6 +435,7 @@ int drv_lcd_init(void)
 void lcd_clear(void)
 {
 	short console_rows, console_cols;
+	int bg_color;
 #if LCD_BPP == LCD_COLOR8
 	/* Setting the palette */
 	lcd_setcolreg(CONSOLE_COLOR_BLACK, 0, 0, 0);
@@ -449,9 +452,11 @@ void lcd_clear(void)
 #ifndef CONFIG_SYS_WHITE_ON_BLACK
 	lcd_setfgcolor(CONSOLE_COLOR_BLACK);
 	lcd_setbgcolor(CONSOLE_COLOR_WHITE);
+	bg_color = CONSOLE_COLOR_WHITE;
 #else
 	lcd_setfgcolor(CONSOLE_COLOR_WHITE);
 	lcd_setbgcolor(CONSOLE_COLOR_BLACK);
+	bg_color = CONSOLE_COLOR_BLACK;
 #endif	/* CONFIG_SYS_WHITE_ON_BLACK */
 
 #ifdef	LCD_TEST_PATTERN
@@ -459,16 +464,14 @@ void lcd_clear(void)
 #else
 	/* set framebuffer to background color */
 #if (LCD_BPP != LCD_COLOR32)
-	memset((char *)lcd_base,
-		lcd_color_bg,
-		lcd_line_length * panel_info.vl_row);
+	memset((char *)lcd_base, bg_color, lcd_line_length * panel_info.vl_row);
 #else
 	u32 *ppix = lcd_base;
 	u32 i;
 	for (i = 0;
 	   i < (lcd_line_length * panel_info.vl_row)/NBYTES(panel_info.vl_bpix);
 	   i++) {
-		*ppix++ = lcd_color_bg;
+		*ppix++ = bg_color;
 	}
 #endif
 #endif
@@ -575,6 +578,11 @@ static void lcd_setfgcolor(int color)
 	lcd_color_fg = color;
 }
 
+int lcd_getfgcolor(void)
+{
+	return lcd_color_fg;
+}
+
 /*----------------------------------------------------------------------*/
 
 static void lcd_setbgcolor(int color)
@@ -582,6 +590,11 @@ static void lcd_setbgcolor(int color)
 	lcd_color_bg = color;
 }
 
+int lcd_getbgcolor(void)
+{
+	return lcd_color_bg;
+}
+
 /************************************************************************/
 /* ** Chipset depending Bitmap / Logo stuff...                          */
 /************************************************************************/
diff --git a/include/lcd.h b/include/lcd.h
index 01609ac..2235b9b 100644
--- a/include/lcd.h
+++ b/include/lcd.h
@@ -291,6 +291,20 @@ int lcd_get_screen_rows(void);
 int lcd_get_screen_columns(void);
 
 /**
+ * Get the background color of the LCD
+ *
+ * @return background color value
+ */
+int lcd_getbgcolor(void);
+
+/**
+ * Get the foreground color of the LCD
+ *
+ * @return foreground color value
+ */
+int lcd_getfgcolor(void);
+
+/**
  * Set the position of the text cursor
  *
  * @param col	Column to place cursor (0 = left side)
-- 
1.9.1



More information about the U-Boot mailing list