
Signed-off-by: Andrey Danin danindrey@mail.ru --- common/Makefile | 2 +- common/lcd.c | 24 ---------- common/lcd_console.c | 122 +++++++++++++++++++++++++++++--------------------- include/lcd_console.h | 33 ++++++++++++++ 4 files changed, 105 insertions(+), 76 deletions(-)
diff --git a/common/Makefile b/common/Makefile index 7216a13..790d76d 100644 --- a/common/Makefile +++ b/common/Makefile @@ -199,7 +199,7 @@ obj-$(CONFIG_I2C_EDID) += edid.o obj-$(CONFIG_KALLSYMS) += kallsyms.o obj-y += splash.o obj-$(CONFIG_SPLASH_SOURCE) += splash_source.o -obj-$(CONFIG_LCD) += lcd.o lcd_console.o +obj-$(CONFIG_LCD) += lcd.o lcd_console.o ansi_console.o obj-$(CONFIG_LCD_DT_SIMPLEFB) += lcd_simplefb.o obj-$(CONFIG_LYNXKDI) += lynxkdi.o obj-$(CONFIG_MENU) += menu.o diff --git a/common/lcd.c b/common/lcd.c index f33942c..d408e08 100644 --- a/common/lcd.c +++ b/common/lcd.c @@ -47,11 +47,7 @@ DECLARE_GLOBAL_DATA_PTR;
static int lcd_init(void *lcdbase); static void lcd_logo(void); -static void lcd_setfgcolor(int color); -static void lcd_setbgcolor(int color);
-static int lcd_color_fg; -static int lcd_color_bg; int lcd_line_length; char lcd_is_enabled = 0; static void *lcd_base; /* Start of framebuffer memory */ @@ -311,26 +307,6 @@ ulong lcd_setmem(ulong addr) return addr; }
-static void lcd_setfgcolor(int color) -{ - lcd_color_fg = color; -} - -int lcd_getfgcolor(void) -{ - return lcd_color_fg; -} - -static void lcd_setbgcolor(int color) -{ - lcd_color_bg = color; -} - -int lcd_getbgcolor(void) -{ - return lcd_color_bg; -} - #ifdef CONFIG_LCD_LOGO __weak void lcd_logo_set_cmap(void) { diff --git a/common/lcd_console.c b/common/lcd_console.c index 8bf83b9..b30fa3a 100644 --- a/common/lcd_console.c +++ b/common/lcd_console.c @@ -7,6 +7,7 @@ */
#include <common.h> +#include <ansi_console.h> #include <lcd.h> #include <video_font.h> /* Get font data, width and height */
@@ -14,11 +15,19 @@ #define CONSOLE_ROW_FIRST lcd_console_address #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * console_rows)
-static short console_curr_col; -static short console_curr_row; -static short console_cols; -static short console_rows; +static int console_curr_col; +static int console_curr_row; +static int console_cols; +static int console_rows; static void *lcd_console_address; +static int lcd_color_fg; +static int lcd_color_bg; + +static struct ansi_console_t ansi_console; + +static inline void lcd_putc_cr(int col, int row, const char c); +static void console_scrollup(int rows); +static inline void console_clear_line(int line, int begin, int end);
void lcd_init_console(void *address, int rows, int cols) { @@ -27,6 +36,23 @@ void lcd_init_console(void *address, int rows, int cols) console_cols = cols; console_rows = rows; lcd_console_address = address; + + memset(&ansi_console, 0, sizeof(ansi_console)); + ansi_console.putc_cr = lcd_putc_cr; + ansi_console.cols = console_cols; + ansi_console.rows = console_rows; +#if defined(CONFIG_CONSOLE_CURSOR) || defined(CONFIG_VIDEO_SW_CURSOR) +#warning Cursor is not implemented for LCD ANSI console + ansi_console.cursor_set = NULL; + ansi_console.cursor_enable = NULL; +#endif + ansi_console.sync = lcd_sync; + ansi_console.scroll = console_scrollup; + ansi_console.clear_line = console_clear_line; + ansi_console.clear = lcd_clear; + ansi_console.swap_colors = lcd_swap_colors; + ansi_console.console_col = &console_curr_col; + ansi_console.console_row = &console_curr_row; }
void lcd_set_col(short col) @@ -39,6 +65,33 @@ void lcd_set_row(short row) console_curr_row = row; }
+int lcd_getbgcolor(void) +{ + return lcd_color_bg; +} + +void lcd_setbgcolor(int color) +{ + lcd_color_bg = color; +} + +int lcd_getfgcolor(void) +{ + return lcd_color_fg; +} + +void lcd_setfgcolor(int color) +{ + lcd_color_fg = color; +} + +void lcd_swap_colors(void) +{ + int tmp = lcd_getbgcolor(); + lcd_setbgcolor(lcd_getfgcolor()); + lcd_setfgcolor(tmp); +} + void lcd_position_cursor(unsigned col, unsigned row) { console_curr_col = min_t(short, col, console_cols - 1); @@ -96,9 +149,13 @@ static inline void lcd_putc_xy(ushort x, ushort y, uchar c) lcd_drawchars(x, y, &c, 1); }
-static void console_scrollup(void) +static inline void lcd_putc_cr(int col, int row, const char c) +{ + lcd_putc_xy(col * VIDEO_FONT_WIDTH, row * VIDEO_FONT_HEIGHT, (uchar)c); +} + +static void console_scrollup(int rows) { - const int rows = CONFIG_CONSOLE_SCROLL_LINES; int bg_color = lcd_getbgcolor();
/* Copy up rows ignoring those that will be overwritten */ @@ -124,27 +181,16 @@ static void console_scrollup(void) console_curr_row -= rows; }
-static inline void console_back(void) +static inline void console_clear_line(int line, int begin, int end) { - if (--console_curr_col < 0) { - console_curr_col = console_cols - 1; - if (--console_curr_row < 0) - console_curr_row = 0; - } + short i = 0;
- lcd_putc_xy(console_curr_col * VIDEO_FONT_WIDTH, - console_curr_row * VIDEO_FONT_HEIGHT, ' '); -} + if (end == -1) + end = console_cols - 1;
-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(); + for (i = begin; i < end; ++i) + lcd_putc_xy(i * VIDEO_FONT_WIDTH, + line * VIDEO_FONT_HEIGHT, ' '); }
void lcd_putc(const char c) @@ -155,33 +201,7 @@ void lcd_putc(const char 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(); - } + ansi_putc(&ansi_console, c); }
void lcd_puts(const char *s) diff --git a/include/lcd_console.h b/include/lcd_console.h index 429214d..ea66ddb 100644 --- a/include/lcd_console.h +++ b/include/lcd_console.h @@ -40,6 +40,39 @@ void lcd_set_col(short col); void lcd_set_row(short row);
/** + * lcd_getbgcolor() - Get current background color value + * + * @return: Color value + */ +int lcd_getbgcolor(void); + +/** + * lcd_setbgcolor() - Set background color value + * + * @color: Color value + */ +void lcd_setbgcolor(int color); + +/** + * lcd_getfgcolor() - Get current foreground color value + * + * @return: Color value + */ +int lcd_getfgcolor(void); + +/** + * lcd_setfgcolor() - Set foreground color value + * + * @color: Color value + */ +void lcd_setfgcolor(int color); + +/** + * lcd_swap_colors() - Swap background and foreground color values + */ +void lcd_swap_colors(void); + +/** * lcd_position_cursor() - Position the cursor on the screen * * Position the cursor at the given coordinates on the screen.