From dc6b5b3a15bd309f818420c1e564b0f5b9b19a3d Mon Sep 17 00:00:00 2001 From: Nikita Kiryanov Date: Mon, 8 Dec 2014 17:14:35 +0200 Subject: lcd: remove CONFIG_SYS_INVERT_COLORS No one is using CONFIG_SYS_INVERT_COLORS; remove related code. Signed-off-by: Nikita Kiryanov Cc: Simon Glass Cc: Anatolij Gustschin Acked-by: Simon Glass --- common/lcd.c | 8 -------- 1 file changed, 8 deletions(-) (limited to 'common') diff --git a/common/lcd.c b/common/lcd.c index 3ed504d..70b848c 100644 --- a/common/lcd.c +++ b/common/lcd.c @@ -685,11 +685,7 @@ void bitmap_plot(int x, int y) *(cmap + BMP_LOGO_OFFSET) = lut_entry; cmap++; #else /* !CONFIG_ATMEL_LCD */ -#ifdef CONFIG_SYS_INVERT_COLORS - *cmap++ = 0xffff - colreg; -#else *cmap++ = colreg; -#endif #endif /* CONFIG_ATMEL_LCD */ } @@ -967,11 +963,7 @@ int lcd_display_bitmap(ulong bmp_image, int x, int y) ( ((cte.red) << 8) & 0xf800) | ( ((cte.green) << 3) & 0x07e0) | ( ((cte.blue) >> 3) & 0x001f) ; -#ifdef CONFIG_SYS_INVERT_COLORS - *cmap = 0xffff - colreg; -#else *cmap = colreg; -#endif #if defined(CONFIG_MPC823) cmap--; #else -- cgit v1.1 From 3707ad42af9750f1c79098eab3d63e9b6b945886 Mon Sep 17 00:00:00 2001 From: Nikita Kiryanov Date: Mon, 8 Dec 2014 17:14:36 +0200 Subject: lcd: cleanup lcd_drawchars Remove code duplication from lcd_drawchars(). Signed-off-by: Nikita Kiryanov Cc: Anatolij Gustschin Cc: Simon Glass Acked-by: Simon Glass --- common/lcd.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) (limited to 'common') diff --git a/common/lcd.c b/common/lcd.c index 70b848c..80923e9 100644 --- a/common/lcd.c +++ b/common/lcd.c @@ -346,19 +346,7 @@ static void lcd_drawchars(ushort x, ushort y, uchar *str, int count) *d++ = rest | (sym >> off); rest = sym << (8-off); -#elif LCD_BPP == LCD_COLOR8 - for (c = 0; c < 8; ++c) { - *d++ = (bits & 0x80) ? - lcd_color_fg : lcd_color_bg; - bits <<= 1; - } -#elif LCD_BPP == LCD_COLOR16 - for (c = 0; c < 8; ++c) { - *d++ = (bits & 0x80) ? - lcd_color_fg : lcd_color_bg; - bits <<= 1; - } -#elif LCD_BPP == LCD_COLOR32 +#else /* LCD_BPP == LCD_COLOR8 or LCD_COLOR16 or LCD_COLOR32 */ for (c = 0; c < 8; ++c) { *d++ = (bits & 0x80) ? lcd_color_fg : lcd_color_bg; -- cgit v1.1 From f4469f50b0367820121ef2d313517d422ed70e1d Mon Sep 17 00:00:00 2001 From: Nikita Kiryanov Date: Mon, 8 Dec 2014 17:14:38 +0200 Subject: lcd: remove LCD_MONOCHROME No one is using LCD_MONOCHROME; remove related code. Signed-off-by: Nikita Kiryanov Cc: Wolfgang Denk Cc: Anatolij Gustschin Acked-by: Simon Glass --- common/lcd.c | 30 ++---------------------------- 1 file changed, 2 insertions(+), 28 deletions(-) (limited to 'common') diff --git a/common/lcd.c b/common/lcd.c index 80923e9..18f71f24 100644 --- a/common/lcd.c +++ b/common/lcd.c @@ -97,10 +97,7 @@ #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS) #define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE) -#if LCD_BPP == LCD_MONOCHROME -# define COLOR_MASK(c) ((c) | (c) << 1 | (c) << 2 | (c) << 3 | \ - (c) << 4 | (c) << 5 | (c) << 6 | (c) << 7) -#elif (LCD_BPP == LCD_COLOR8) || (LCD_BPP == LCD_COLOR16) || \ +#if (LCD_BPP == LCD_COLOR8) || (LCD_BPP == LCD_COLOR16) || \ (LCD_BPP == LCD_COLOR32) # define COLOR_MASK(c) (c) #else @@ -313,10 +310,6 @@ static void lcd_drawchars(ushort x, ushort y, uchar *str, int count) y += BMP_LOGO_HEIGHT; #endif -#if LCD_BPP == LCD_MONOCHROME - ushort off = x * (1 << LCD_BPP) % 8; -#endif - dest = (uchar *)(lcd_base + y * lcd_line_length + x * NBITS(LCD_BPP)/8); for (row = 0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) { @@ -330,33 +323,18 @@ static void lcd_drawchars(ushort x, ushort y, uchar *str, int count) uchar *d = dest; #endif -#if LCD_BPP == LCD_MONOCHROME - uchar rest = *d & -(1 << (8 - off)); - uchar sym; -#endif for (i = 0; i < count; ++i) { uchar c, bits; c = *s++; bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row]; -#if LCD_BPP == LCD_MONOCHROME - sym = (COLOR_MASK(lcd_color_fg) & bits) | - (COLOR_MASK(lcd_color_bg) & ~bits); - - *d++ = rest | (sym >> off); - rest = sym << (8-off); -#else /* LCD_BPP == LCD_COLOR8 or LCD_COLOR16 or LCD_COLOR32 */ for (c = 0; c < 8; ++c) { *d++ = (bits & 0x80) ? lcd_color_fg : lcd_color_bg; bits <<= 1; } -#endif } -#if LCD_BPP == LCD_MONOCHROME - *d = rest | (*d & ((1 << (8 - off)) - 1)); -#endif } } @@ -443,11 +421,7 @@ int drv_lcd_init(void) /*----------------------------------------------------------------------*/ void lcd_clear(void) { -#if LCD_BPP == LCD_MONOCHROME - /* Setting the palette */ - lcd_initcolregs(); - -#elif LCD_BPP == LCD_COLOR8 +#if LCD_BPP == LCD_COLOR8 /* Setting the palette */ lcd_setcolreg(CONSOLE_COLOR_BLACK, 0, 0, 0); lcd_setcolreg(CONSOLE_COLOR_RED, 0xFF, 0, 0); -- cgit v1.1 From 404e4f4a298f0062dfa405aa1b8b05cfd5be1690 Mon Sep 17 00:00:00 2001 From: Nikita Kiryanov Date: Mon, 8 Dec 2014 17:14:39 +0200 Subject: lcd: rename console_(row|col) Rename console_(row|col) to console_curr_(row|col) to better distinguish it from console_(rows|cols). This is a preparatory step for extracting lcd console code into its own file. Signed-off-by: Nikita Kiryanov Cc: Simon Glass Cc: Anatolij Gustschin Acked-by: Simon Glass Tested-by: Simon Glass --- common/lcd.c | 54 +++++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) (limited to 'common') diff --git a/common/lcd.c b/common/lcd.c index 18f71f24..b6cd58a 100644 --- a/common/lcd.c +++ b/common/lcd.c @@ -122,8 +122,8 @@ int lcd_line_length; char lcd_is_enabled = 0; -static short console_col; -static short console_row; +static short console_curr_col; +static short console_curr_row; static void *lcd_console_address; static void *lcd_base; /* Start of framebuffer memory */ @@ -188,31 +188,31 @@ static void console_scrollup(void) } #endif lcd_sync(); - console_row -= rows; + console_curr_row -= rows; } /*----------------------------------------------------------------------*/ static inline void console_back(void) { - if (--console_col < 0) { - console_col = CONSOLE_COLS-1 ; - if (--console_row < 0) - console_row = 0; + if (--console_curr_col < 0) { + console_curr_col = CONSOLE_COLS-1; + if (--console_curr_row < 0) + console_curr_row = 0; } - lcd_putc_xy(console_col * VIDEO_FONT_WIDTH, - console_row * VIDEO_FONT_HEIGHT, ' '); + lcd_putc_xy(console_curr_col * VIDEO_FONT_WIDTH, + console_curr_row * VIDEO_FONT_HEIGHT, ' '); } /*----------------------------------------------------------------------*/ static inline void console_newline(void) { - console_col = 0; + console_curr_col = 0; /* Check if we need to scroll the terminal */ - if (++console_row >= CONSOLE_ROWS) + if (++console_curr_row >= CONSOLE_ROWS) console_scrollup(); else lcd_sync(); @@ -235,7 +235,7 @@ void lcd_putc(const char c) switch (c) { case '\r': - console_col = 0; + console_curr_col = 0; return; case '\n': @@ -243,10 +243,10 @@ void lcd_putc(const char c) return; case '\t': /* Tab (8 chars alignment) */ - console_col += 8; - console_col &= ~7; + console_curr_col += 8; + console_curr_col &= ~7; - if (console_col >= CONSOLE_COLS) + if (console_curr_col >= CONSOLE_COLS) console_newline(); return; @@ -255,9 +255,9 @@ void lcd_putc(const char c) return; default: - lcd_putc_xy(console_col * VIDEO_FONT_WIDTH, - console_row * VIDEO_FONT_HEIGHT, c); - if (++console_col >= CONSOLE_COLS) + lcd_putc_xy(console_curr_col * VIDEO_FONT_WIDTH, + console_curr_row * VIDEO_FONT_HEIGHT, c); + if (++console_curr_col >= CONSOLE_COLS) console_newline(); } } @@ -464,8 +464,8 @@ void lcd_clear(void) debug("[LCD] Drawing the logo...\n"); lcd_console_address = lcd_logo(); - console_col = 0; - console_row = 0; + console_curr_col = 0; + console_curr_row = 0; lcd_sync(); } @@ -508,11 +508,11 @@ static int lcd_init(void *lcdbase) lcd_enable(); /* Initialize the console */ - console_col = 0; + console_curr_col = 0; #ifdef CONFIG_LCD_INFO_BELOW_LOGO - console_row = 7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT; + console_curr_row = 7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT; #else - console_row = 1; /* leave 1 blank line below logo */ + console_curr_row = 1; /* leave 1 blank line below logo */ #endif return 0; @@ -1062,8 +1062,8 @@ static void *lcd_logo(void) bitmap_plot(0, 0); #ifdef CONFIG_LCD_INFO - console_col = LCD_INFO_X / VIDEO_FONT_WIDTH; - console_row = LCD_INFO_Y / VIDEO_FONT_HEIGHT; + console_curr_col = LCD_INFO_X / VIDEO_FONT_WIDTH; + console_curr_row = LCD_INFO_Y / VIDEO_FONT_HEIGHT; lcd_show_board_info(); #endif /* CONFIG_LCD_INFO */ @@ -1100,8 +1100,8 @@ U_BOOT_ENV_CALLBACK(splashimage, on_splashimage); void lcd_position_cursor(unsigned col, unsigned row) { - console_col = min_t(short, col, CONSOLE_COLS - 1); - console_row = min_t(short, row, CONSOLE_ROWS - 1); + console_curr_col = min_t(short, col, CONSOLE_COLS - 1); + console_curr_row = min_t(short, row, CONSOLE_ROWS - 1); } int lcd_get_pixel_width(void) -- cgit v1.1 From efd7c4a2f8abc08c5ce2702a591ae74445aa8dd9 Mon Sep 17 00:00:00 2001 From: Nikita Kiryanov Date: Mon, 8 Dec 2014 17:14:40 +0200 Subject: lcd: replace CONSOLE_(ROWS|COLS) with variables Replace CONSOLE_(ROWS|COLS) macros with variables, and assign the original macro values. This is a preparatory step for extracting lcd console code into its own file. Signed-off-by: Nikita Kiryanov Cc: Anatolij Gustschin Cc: Simon Glass Acked-by: Simon Glass Tested-by: Simon Glass --- common/lcd.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'common') diff --git a/common/lcd.c b/common/lcd.c index b6cd58a..5d786ba 100644 --- a/common/lcd.c +++ b/common/lcd.c @@ -81,20 +81,12 @@ /************************************************************************/ /* ** CONSOLE DEFINITIONS & FUNCTIONS */ /************************************************************************/ -#if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO) -# define CONSOLE_ROWS ((panel_info.vl_row-BMP_LOGO_HEIGHT) \ - / VIDEO_FONT_HEIGHT) -#else -# define CONSOLE_ROWS (panel_info.vl_row / VIDEO_FONT_HEIGHT) -#endif - -#define CONSOLE_COLS (panel_info.vl_col / VIDEO_FONT_WIDTH) #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * lcd_line_length) #define CONSOLE_ROW_FIRST lcd_console_address #define CONSOLE_ROW_SECOND (lcd_console_address + CONSOLE_ROW_SIZE) #define CONSOLE_ROW_LAST (lcd_console_address + CONSOLE_SIZE \ - CONSOLE_ROW_SIZE) -#define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS) +#define CONSOLE_SIZE (CONSOLE_ROW_SIZE * console_rows) #define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE) #if (LCD_BPP == LCD_COLOR8) || (LCD_BPP == LCD_COLOR16) || \ @@ -124,6 +116,8 @@ char lcd_is_enabled = 0; static short console_curr_col; static short console_curr_row; +static short console_cols; +static short console_rows; static void *lcd_console_address; static void *lcd_base; /* Start of framebuffer memory */ @@ -196,7 +190,7 @@ static void console_scrollup(void) static inline void console_back(void) { if (--console_curr_col < 0) { - console_curr_col = CONSOLE_COLS-1; + console_curr_col = console_cols - 1; if (--console_curr_row < 0) console_curr_row = 0; } @@ -212,7 +206,7 @@ static inline void console_newline(void) console_curr_col = 0; /* Check if we need to scroll the terminal */ - if (++console_curr_row >= CONSOLE_ROWS) + if (++console_curr_row >= console_rows) console_scrollup(); else lcd_sync(); @@ -246,7 +240,7 @@ void lcd_putc(const char c) console_curr_col += 8; console_curr_col &= ~7; - if (console_curr_col >= CONSOLE_COLS) + if (console_curr_col >= console_cols) console_newline(); return; @@ -257,7 +251,7 @@ void lcd_putc(const char c) default: lcd_putc_xy(console_curr_col * VIDEO_FONT_WIDTH, console_curr_row * VIDEO_FONT_HEIGHT, c); - if (++console_curr_col >= CONSOLE_COLS) + if (++console_curr_col >= console_cols) console_newline(); } } @@ -464,6 +458,13 @@ void lcd_clear(void) debug("[LCD] Drawing the logo...\n"); lcd_console_address = lcd_logo(); +#if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO) + console_rows = (panel_info.vl_row - BMP_LOGO_HEIGHT); + console_rows /= VIDEO_FONT_HEIGHT; +#else + console_rows = panel_info.vl_row / VIDEO_FONT_HEIGHT; +#endif + console_cols = panel_info.vl_col / VIDEO_FONT_WIDTH; console_curr_col = 0; console_curr_row = 0; lcd_sync(); @@ -1100,8 +1101,8 @@ U_BOOT_ENV_CALLBACK(splashimage, on_splashimage); void lcd_position_cursor(unsigned col, unsigned row) { - console_curr_col = min_t(short, col, CONSOLE_COLS - 1); - console_curr_row = min_t(short, row, CONSOLE_ROWS - 1); + console_curr_col = min_t(short, col, console_cols - 1); + console_curr_row = min_t(short, row, console_rows - 1); } int lcd_get_pixel_width(void) @@ -1116,12 +1117,12 @@ int lcd_get_pixel_height(void) int lcd_get_screen_rows(void) { - return CONSOLE_ROWS; + return console_rows; } int lcd_get_screen_columns(void) { - return CONSOLE_COLS; + return console_cols; } #if defined(CONFIG_LCD_DT_SIMPLEFB) -- cgit v1.1 From 140beb9437d9a784273dfe828d701947f691f1a0 Mon Sep 17 00:00:00 2001 From: Nikita Kiryanov Date: Mon, 8 Dec 2014 17:14:41 +0200 Subject: lcd: expand console api Introduce set_console_row(), set_console_col(), and lcd_init_console(). Use these functions in lcd functions: lcd_init(), lcd_clear(), lcd_logo(). This is a preparatory step for extracting lcd console code into its own file. Signed-off-by: Nikita Kiryanov Cc: Anatolij Gustschin Cc: Simon Glass Acked-by: Simon Glass Tested-by: Simon Glass --- common/lcd.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) (limited to 'common') diff --git a/common/lcd.c b/common/lcd.c index 5d786ba..9342e0e 100644 --- a/common/lcd.c +++ b/common/lcd.c @@ -155,6 +155,25 @@ void lcd_set_flush_dcache(int flush) lcd_flush_dcache = (flush != 0); } +void lcd_init_console(void *address, int rows, int cols) +{ + console_curr_col = 0; + console_curr_row = 0; + console_cols = cols; + console_rows = rows; + lcd_console_address = address; +} + +void lcd_set_col(short col) +{ + console_curr_col = col; +} + +void lcd_set_row(short row) +{ + console_curr_row = row; +} + /*----------------------------------------------------------------------*/ static void console_scrollup(void) @@ -415,6 +434,7 @@ int drv_lcd_init(void) /*----------------------------------------------------------------------*/ void lcd_clear(void) { + short console_rows, console_cols; #if LCD_BPP == LCD_COLOR8 /* Setting the palette */ lcd_setcolreg(CONSOLE_COLOR_BLACK, 0, 0, 0); @@ -456,8 +476,6 @@ void lcd_clear(void) #endif /* Paint the logo and retrieve LCD base address */ debug("[LCD] Drawing the logo...\n"); - lcd_console_address = lcd_logo(); - #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO) console_rows = (panel_info.vl_row - BMP_LOGO_HEIGHT); console_rows /= VIDEO_FONT_HEIGHT; @@ -465,8 +483,7 @@ void lcd_clear(void) console_rows = panel_info.vl_row / VIDEO_FONT_HEIGHT; #endif console_cols = panel_info.vl_col / VIDEO_FONT_WIDTH; - console_curr_col = 0; - console_curr_row = 0; + lcd_init_console(lcd_logo(), console_rows, console_cols); lcd_sync(); } @@ -509,11 +526,11 @@ static int lcd_init(void *lcdbase) lcd_enable(); /* Initialize the console */ - console_curr_col = 0; + lcd_set_col(0); #ifdef CONFIG_LCD_INFO_BELOW_LOGO - console_curr_row = 7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT; + lcd_set_row(7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT); #else - console_curr_row = 1; /* leave 1 blank line below logo */ + lcd_set_row(1); /* leave 1 blank line below logo */ #endif return 0; @@ -1063,8 +1080,8 @@ static void *lcd_logo(void) bitmap_plot(0, 0); #ifdef CONFIG_LCD_INFO - console_curr_col = LCD_INFO_X / VIDEO_FONT_WIDTH; - console_curr_row = LCD_INFO_Y / VIDEO_FONT_HEIGHT; + lcd_set_col(LCD_INFO_X / VIDEO_FONT_WIDTH); + lcd_set_row(LCD_INFO_Y / VIDEO_FONT_HEIGHT); lcd_show_board_info(); #endif /* CONFIG_LCD_INFO */ -- cgit v1.1 From a7de2953f51e70754190d3516167d58d27d17219 Mon Sep 17 00:00:00 2001 From: Nikita Kiryanov Date: Mon, 8 Dec 2014 17:14:42 +0200 Subject: lcd: get rid of COLOR_MASK COLOR_MASK macro doesn't do anything; Remove it to reduce visual complexity. This is a preparatory step for extracting lcd console code into its own file. Signed-off-by: Nikita Kiryanov Cc: Anatolij Gustschin Cc: Simon Glass Acked-by: Simon Glass Tested-by: Simon Glass --- common/lcd.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'common') diff --git a/common/lcd.c b/common/lcd.c index 9342e0e..c0705ee 100644 --- a/common/lcd.c +++ b/common/lcd.c @@ -89,10 +89,8 @@ #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * console_rows) #define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE) -#if (LCD_BPP == LCD_COLOR8) || (LCD_BPP == LCD_COLOR16) || \ - (LCD_BPP == LCD_COLOR32) -# define COLOR_MASK(c) (c) -#else +#if (LCD_BPP != LCD_COLOR8) && (LCD_BPP != LCD_COLOR16) && \ + (LCD_BPP != LCD_COLOR32) # error Unsupported LCD BPP. #endif @@ -188,7 +186,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, - COLOR_MASK(lcd_color_bg), + lcd_color_bg, CONSOLE_ROW_SIZE * rows); #else u32 *ppix = lcd_console_address + @@ -197,7 +195,7 @@ static void console_scrollup(void) for (i = 0; i < (CONSOLE_ROW_SIZE * rows) / NBYTES(panel_info.vl_bpix); i++) { - *ppix++ = COLOR_MASK(lcd_color_bg); + *ppix++ = lcd_color_bg; } #endif lcd_sync(); @@ -462,7 +460,7 @@ void lcd_clear(void) /* set framebuffer to background color */ #if (LCD_BPP != LCD_COLOR32) memset((char *)lcd_base, - COLOR_MASK(lcd_color_bg), + lcd_color_bg, lcd_line_length * panel_info.vl_row); #else u32 *ppix = lcd_base; @@ -470,7 +468,7 @@ void lcd_clear(void) for (i = 0; i < (lcd_line_length * panel_info.vl_row)/NBYTES(panel_info.vl_bpix); i++) { - *ppix++ = COLOR_MASK(lcd_color_bg); + *ppix++ = lcd_color_bg; } #endif #endif -- cgit v1.1 From 4d03634e5da40dc092b6e5b985f74aedfe04f81e Mon Sep 17 00:00:00 2001 From: Nikita Kiryanov Date: Mon, 8 Dec 2014 17:14:43 +0200 Subject: lcd: introduce getters for bg/fg color 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 Cc: Anatolij Gustschin Cc: Simon Glass Acked-by: Simon Glass --- common/lcd.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'common') diff --git a/common/lcd.c b/common/lcd.c index c0705ee..1259446 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... */ /************************************************************************/ -- cgit v1.1 From 88b326a31e4b7c2b6550980944b9b72f40c1bda0 Mon Sep 17 00:00:00 2001 From: Nikita Kiryanov Date: Mon, 8 Dec 2014 17:14:44 +0200 Subject: lcd: make lcd_drawchars() independant of lcd_base lcd_logo() has the following return value: #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO) return (void *)((ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length); #else return (void *)lcd_base; #endif This return value gets assigned to lcd_console_address. lcd_console_address is not assigned or modified anywhere else. Thus: #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO): y' = BMP_LOGO_HEIGHT + y; lcd_base + y' * lcd_line_length == lcd_base + (BMP_LOGO_HEIGHT + y) * lcd_line_length == lcd_base + BMP_LOGO_HEIGHT * lcd_line_length + y * lcd_line_length == lcd_console_address + y * lcd_line_length #else lcd_base + y * lcd_line_length == lcd_console_address + y * lcd_line_length #endif This is a preparatory step for extracting lcd console code into its own file. Signed-off-by: Nikita Kiryanov Cc: Anatolij Gustschin Cc: Simon Glass --- common/lcd.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'common') diff --git a/common/lcd.c b/common/lcd.c index 1259446..4ff9524 100644 --- a/common/lcd.c +++ b/common/lcd.c @@ -318,11 +318,8 @@ static void lcd_drawchars(ushort x, ushort y, uchar *str, int count) ushort row; int fg_color, bg_color; -#if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO) - y += BMP_LOGO_HEIGHT; -#endif - - dest = (uchar *)(lcd_base + y * lcd_line_length + x * NBITS(LCD_BPP)/8); + dest = (uchar *)(lcd_console_address + + y * lcd_line_length + x * NBITS(LCD_BPP) / 8); for (row = 0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) { uchar *s = str; -- cgit v1.1 From 904672ee489280cf26793e0a590505a2659dae09 Mon Sep 17 00:00:00 2001 From: Nikita Kiryanov Date: Mon, 8 Dec 2014 17:14:45 +0200 Subject: lcd: refactor lcd console stuff into its own file common/lcd.c is a mix of code portions that do different but related things. To improve modularity, the various code portions should be split into their own modules. Separate lcd console code into its own file. Signed-off-by: Nikita Kiryanov Cc: Anatolij Gustschin Cc: Simon Glass Cc: Stephen Warren Acked-by: Simon Glass Tested-by: Simon Glass --- common/Makefile | 2 +- common/lcd.c | 229 --------------------------------------------------- common/lcd_console.c | 215 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 216 insertions(+), 230 deletions(-) create mode 100644 common/lcd_console.c (limited to 'common') diff --git a/common/Makefile b/common/Makefile index c668a2f..94554f2 100644 --- a/common/Makefile +++ b/common/Makefile @@ -196,7 +196,7 @@ obj-$(CONFIG_CMD_KGDB) += kgdb.o kgdb_stubs.o obj-$(CONFIG_I2C_EDID) += edid.o obj-$(CONFIG_KALLSYMS) += kallsyms.o obj-y += splash.o -obj-$(CONFIG_LCD) += lcd.o +obj-$(CONFIG_LCD) += lcd.o lcd_console.o obj-$(CONFIG_LYNXKDI) += lynxkdi.o obj-$(CONFIG_MENU) += menu.o obj-$(CONFIG_MODEM_SUPPORT) += modem.o diff --git a/common/lcd.c b/common/lcd.c index 4ff9524..cc34b8a 100644 --- a/common/lcd.c +++ b/common/lcd.c @@ -73,22 +73,6 @@ #define CONFIG_LCD_ALIGNMENT PAGE_SIZE #endif -/* By default we scroll by a single line */ -#ifndef CONFIG_CONSOLE_SCROLL_LINES -#define CONFIG_CONSOLE_SCROLL_LINES 1 -#endif - -/************************************************************************/ -/* ** CONSOLE DEFINITIONS & FUNCTIONS */ -/************************************************************************/ -#define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * lcd_line_length) -#define CONSOLE_ROW_FIRST lcd_console_address -#define CONSOLE_ROW_SECOND (lcd_console_address + CONSOLE_ROW_SIZE) -#define CONSOLE_ROW_LAST (lcd_console_address + CONSOLE_SIZE \ - - CONSOLE_ROW_SIZE) -#define CONSOLE_SIZE (CONSOLE_ROW_SIZE * console_rows) -#define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE) - #if (LCD_BPP != LCD_COLOR8) && (LCD_BPP != LCD_COLOR16) && \ (LCD_BPP != LCD_COLOR32) # error Unsupported LCD BPP. @@ -96,9 +80,6 @@ DECLARE_GLOBAL_DATA_PTR; -static void lcd_drawchars(ushort x, ushort y, uchar *str, int count); -static inline void lcd_putc_xy(ushort x, ushort y, uchar c); - static int lcd_init(void *lcdbase); static void *lcd_logo(void); @@ -112,12 +93,6 @@ int lcd_line_length; char lcd_is_enabled = 0; -static short console_curr_col; -static short console_curr_row; -static short console_cols; -static short console_rows; - -static void *lcd_console_address; static void *lcd_base; /* Start of framebuffer memory */ static char lcd_flush_dcache; /* 1 to flush dcache after each lcd update */ @@ -153,82 +128,6 @@ void lcd_set_flush_dcache(int flush) lcd_flush_dcache = (flush != 0); } -void lcd_init_console(void *address, int rows, int cols) -{ - console_curr_col = 0; - console_curr_row = 0; - console_cols = cols; - console_rows = rows; - lcd_console_address = address; -} - -void lcd_set_col(short col) -{ - console_curr_col = col; -} - -void lcd_set_row(short row) -{ - console_curr_row = 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, - lcd_console_address + CONSOLE_ROW_SIZE * rows, - CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows); - - /* Clear the last rows */ -#if (LCD_BPP != LCD_COLOR32) - memset(lcd_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows, - bg_color, CONSOLE_ROW_SIZE * rows); -#else - u32 *ppix = lcd_console_address + - CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows; - u32 i; - for (i = 0; - i < (CONSOLE_ROW_SIZE * rows) / NBYTES(panel_info.vl_bpix); - i++) { - *ppix++ = bg_color; - } -#endif - lcd_sync(); - console_curr_row -= rows; -} - -/*----------------------------------------------------------------------*/ - -static inline void console_back(void) -{ - if (--console_curr_col < 0) { - console_curr_col = console_cols - 1; - if (--console_curr_row < 0) - console_curr_row = 0; - } - - lcd_putc_xy(console_curr_col * VIDEO_FONT_WIDTH, - console_curr_row * VIDEO_FONT_HEIGHT, ' '); -} - -/*----------------------------------------------------------------------*/ - -static inline void console_newline(void) -{ - console_curr_col = 0; - - /* Check if we need to scroll the terminal */ - if (++console_curr_row >= console_rows) - console_scrollup(); - else - lcd_sync(); -} - /*----------------------------------------------------------------------*/ static void lcd_stub_putc(struct stdio_dev *dev, const char c) @@ -236,123 +135,11 @@ static void lcd_stub_putc(struct stdio_dev *dev, const char c) lcd_putc(c); } -void lcd_putc(const char c) -{ - if (!lcd_is_enabled) { - serial_putc(c); - - return; - } - - switch (c) { - case '\r': - console_curr_col = 0; - - return; - case '\n': - console_newline(); - - return; - case '\t': /* Tab (8 chars alignment) */ - console_curr_col += 8; - console_curr_col &= ~7; - - if (console_curr_col >= console_cols) - console_newline(); - - return; - case '\b': - console_back(); - - return; - default: - lcd_putc_xy(console_curr_col * VIDEO_FONT_WIDTH, - console_curr_row * VIDEO_FONT_HEIGHT, c); - if (++console_curr_col >= console_cols) - console_newline(); - } -} - -/*----------------------------------------------------------------------*/ - static void lcd_stub_puts(struct stdio_dev *dev, const char *s) { lcd_puts(s); } -void lcd_puts(const char *s) -{ - if (!lcd_is_enabled) { - serial_puts(s); - - return; - } - - while (*s) - lcd_putc(*s++); - - lcd_sync(); -} - -/*----------------------------------------------------------------------*/ - -void lcd_printf(const char *fmt, ...) -{ - va_list args; - char buf[CONFIG_SYS_PBSIZE]; - - va_start(args, fmt); - vsprintf(buf, fmt, args); - va_end(args); - - lcd_puts(buf); -} - -/************************************************************************/ -/* ** Low-Level Graphics Routines */ -/************************************************************************/ - -static void lcd_drawchars(ushort x, ushort y, uchar *str, int count) -{ - uchar *dest; - ushort row; - int fg_color, bg_color; - - dest = (uchar *)(lcd_console_address + - y * lcd_line_length + x * NBITS(LCD_BPP) / 8); - - for (row = 0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) { - uchar *s = str; - int i; -#if LCD_BPP == LCD_COLOR16 - ushort *d = (ushort *)dest; -#elif LCD_BPP == LCD_COLOR32 - u32 *d = (u32 *)dest; -#else - uchar *d = dest; -#endif - - fg_color = lcd_getfgcolor(); - bg_color = lcd_getbgcolor(); - for (i = 0; i < count; ++i) { - uchar c, bits; - - c = *s++; - bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row]; - - for (c = 0; c < 8; ++c) { - *d++ = (bits & 0x80) ? fg_color : bg_color; - bits <<= 1; - } - } - } -} - -static inline void lcd_putc_xy(ushort x, ushort y, uchar c) -{ - lcd_drawchars(x, y, &c, 1); -} - /************************************************************************/ /** Small utility to check that you got the colours right */ /************************************************************************/ @@ -1124,12 +911,6 @@ static int on_splashimage(const char *name, const char *value, enum env_op op, U_BOOT_ENV_CALLBACK(splashimage, on_splashimage); #endif -void lcd_position_cursor(unsigned col, unsigned row) -{ - console_curr_col = min_t(short, col, console_cols - 1); - console_curr_row = min_t(short, row, console_rows - 1); -} - int lcd_get_pixel_width(void) { return panel_info.vl_col; @@ -1140,16 +921,6 @@ int lcd_get_pixel_height(void) return panel_info.vl_row; } -int lcd_get_screen_rows(void) -{ - return console_rows; -} - -int lcd_get_screen_columns(void) -{ - return console_cols; -} - #if defined(CONFIG_LCD_DT_SIMPLEFB) static int lcd_dt_simplefb_configure_node(void *blob, int off) { diff --git a/common/lcd_console.c b/common/lcd_console.c new file mode 100644 index 0000000..f948e5a --- /dev/null +++ b/common/lcd_console.c @@ -0,0 +1,215 @@ +/* + * (C) Copyright 2001-2014 + * DENX Software Engineering -- wd@denx.de + * Compulab Ltd - http://compulab.co.il/ + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include +#include +#include /* Get font data, width and height */ + +#define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * lcd_line_length) +#define CONSOLE_ROW_FIRST lcd_console_address +#define CONSOLE_ROW_SECOND (lcd_console_address + CONSOLE_ROW_SIZE) +#define CONSOLE_ROW_LAST (lcd_console_address + CONSOLE_SIZE \ + - CONSOLE_ROW_SIZE) +#define CONSOLE_SIZE (CONSOLE_ROW_SIZE * console_rows) +#define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE) + +static short console_curr_col; +static short console_curr_row; +static short console_cols; +static short console_rows; +static void *lcd_console_address; + +void lcd_init_console(void *address, int rows, int cols) +{ + console_curr_col = 0; + console_curr_row = 0; + console_cols = cols; + console_rows = rows; + lcd_console_address = address; +} + +void lcd_set_col(short col) +{ + console_curr_col = col; +} + +void lcd_set_row(short row) +{ + console_curr_row = row; +} + +void lcd_position_cursor(unsigned col, unsigned row) +{ + console_curr_col = min_t(short, col, console_cols - 1); + console_curr_row = min_t(short, row, console_rows - 1); +} + +int lcd_get_screen_rows(void) +{ + return console_rows; +} + +int lcd_get_screen_columns(void) +{ + return console_cols; +} + +static void lcd_drawchars(ushort x, ushort y, uchar *str, int count) +{ + uchar *dest; + ushort row; + int fg_color, bg_color; + + dest = (uchar *)(lcd_console_address + + y * lcd_line_length + x * NBITS(LCD_BPP) / 8); + + for (row = 0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) { + uchar *s = str; + int i; +#if LCD_BPP == LCD_COLOR16 + ushort *d = (ushort *)dest; +#elif LCD_BPP == LCD_COLOR32 + u32 *d = (u32 *)dest; +#else + uchar *d = dest; +#endif + + fg_color = lcd_getfgcolor(); + bg_color = lcd_getbgcolor(); + for (i = 0; i < count; ++i) { + uchar c, bits; + + c = *s++; + bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row]; + + for (c = 0; c < 8; ++c) { + *d++ = (bits & 0x80) ? fg_color : bg_color; + bits <<= 1; + } + } + } +} + +static inline void lcd_putc_xy(ushort x, ushort y, uchar c) +{ + lcd_drawchars(x, y, &c, 1); +} + +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, + lcd_console_address + CONSOLE_ROW_SIZE * rows, + CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows); + + /* Clear the last rows */ +#if (LCD_BPP != LCD_COLOR32) + memset(lcd_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows, + bg_color, CONSOLE_ROW_SIZE * rows); +#else + u32 *ppix = lcd_console_address + + CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows; + u32 i; + for (i = 0; + i < (CONSOLE_ROW_SIZE * rows) / NBYTES(panel_info.vl_bpix); + i++) { + *ppix++ = bg_color; + } +#endif + lcd_sync(); + console_curr_row -= rows; +} + +static inline void console_back(void) +{ + if (--console_curr_col < 0) { + console_curr_col = console_cols - 1; + if (--console_curr_row < 0) + console_curr_row = 0; + } + + lcd_putc_xy(console_curr_col * VIDEO_FONT_WIDTH, + console_curr_row * VIDEO_FONT_HEIGHT, ' '); +} + +static inline void console_newline(void) +{ + console_curr_col = 0; + + /* Check if we need to scroll the terminal */ + if (++console_curr_row >= console_rows) + console_scrollup(); + else + lcd_sync(); +} + +void lcd_putc(const char c) +{ + if (!lcd_is_enabled) { + serial_putc(c); + + return; + } + + switch (c) { + case '\r': + console_curr_col = 0; + + return; + case '\n': + console_newline(); + + return; + case '\t': /* Tab (8 chars alignment) */ + console_curr_col += 8; + console_curr_col &= ~7; + + if (console_curr_col >= console_cols) + console_newline(); + + return; + case '\b': + console_back(); + + return; + default: + lcd_putc_xy(console_curr_col * VIDEO_FONT_WIDTH, + console_curr_row * VIDEO_FONT_HEIGHT, c); + if (++console_curr_col >= console_cols) + console_newline(); + } +} + +void lcd_puts(const char *s) +{ + if (!lcd_is_enabled) { + serial_puts(s); + + return; + } + + while (*s) + lcd_putc(*s++); + + lcd_sync(); +} + +void lcd_printf(const char *fmt, ...) +{ + va_list args; + char buf[CONFIG_SYS_PBSIZE]; + + va_start(args, fmt); + vsprintf(buf, fmt, args); + va_end(args); + + lcd_puts(buf); +} -- cgit v1.1 From 73b462b84568ac887ae9ad083580289175202327 Mon Sep 17 00:00:00 2001 From: Nikita Kiryanov Date: Mon, 8 Dec 2014 17:14:46 +0200 Subject: lcd_console: remove unused defines CONSOLE_ROW_SECOND, CONSOLE_ROW_LAST, and CONSOLE_SCROLL_SIZE are unused. Remove them. Signed-off-by: Nikita Kiryanov Cc: Anatolij Gustschin Cc: Simon Glass Acked-by: Simon Glass Tested-by: Simon Glass --- common/lcd_console.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'common') diff --git a/common/lcd_console.c b/common/lcd_console.c index f948e5a..74c388a 100644 --- a/common/lcd_console.c +++ b/common/lcd_console.c @@ -12,11 +12,7 @@ #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * lcd_line_length) #define CONSOLE_ROW_FIRST lcd_console_address -#define CONSOLE_ROW_SECOND (lcd_console_address + CONSOLE_ROW_SIZE) -#define CONSOLE_ROW_LAST (lcd_console_address + CONSOLE_SIZE \ - - CONSOLE_ROW_SIZE) #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * console_rows) -#define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE) static short console_curr_col; static short console_curr_row; -- cgit v1.1