2 * (C) Copyright 2001-2014
3 * DENX Software Engineering -- wd@denx.de
4 * Compulab Ltd - http://compulab.co.il/
6 * SPDX-License-Identifier: GPL-2.0+
11 #include <video_font.h> /* Get font data, width and height */
13 #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * lcd_line_length)
14 #define CONSOLE_ROW_FIRST lcd_console_address
15 #define CONSOLE_ROW_SECOND (lcd_console_address + CONSOLE_ROW_SIZE)
16 #define CONSOLE_ROW_LAST (lcd_console_address + CONSOLE_SIZE \
18 #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * console_rows)
19 #define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
21 static short console_curr_col;
22 static short console_curr_row;
23 static short console_cols;
24 static short console_rows;
25 static void *lcd_console_address;
27 void lcd_init_console(void *address, int rows, int cols)
33 lcd_console_address = address;
36 void lcd_set_col(short col)
38 console_curr_col = col;
41 void lcd_set_row(short row)
43 console_curr_row = row;
46 void lcd_position_cursor(unsigned col, unsigned row)
48 console_curr_col = min_t(short, col, console_cols - 1);
49 console_curr_row = min_t(short, row, console_rows - 1);
52 int lcd_get_screen_rows(void)
57 int lcd_get_screen_columns(void)
62 static void lcd_drawchars(ushort x, ushort y, uchar *str, int count)
66 int fg_color, bg_color;
68 dest = (uchar *)(lcd_console_address +
69 y * lcd_line_length + x * NBITS(LCD_BPP) / 8);
71 for (row = 0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) {
74 #if LCD_BPP == LCD_COLOR16
75 ushort *d = (ushort *)dest;
76 #elif LCD_BPP == LCD_COLOR32
82 fg_color = lcd_getfgcolor();
83 bg_color = lcd_getbgcolor();
84 for (i = 0; i < count; ++i) {
88 bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];
90 for (c = 0; c < 8; ++c) {
91 *d++ = (bits & 0x80) ? fg_color : bg_color;
98 static inline void lcd_putc_xy(ushort x, ushort y, uchar c)
100 lcd_drawchars(x, y, &c, 1);
103 static void console_scrollup(void)
105 const int rows = CONFIG_CONSOLE_SCROLL_LINES;
106 int bg_color = lcd_getbgcolor();
108 /* Copy up rows ignoring those that will be overwritten */
109 memcpy(CONSOLE_ROW_FIRST,
110 lcd_console_address + CONSOLE_ROW_SIZE * rows,
111 CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows);
113 /* Clear the last rows */
114 #if (LCD_BPP != LCD_COLOR32)
115 memset(lcd_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows,
116 bg_color, CONSOLE_ROW_SIZE * rows);
118 u32 *ppix = lcd_console_address +
119 CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows;
122 i < (CONSOLE_ROW_SIZE * rows) / NBYTES(panel_info.vl_bpix);
128 console_curr_row -= rows;
131 static inline void console_back(void)
133 if (--console_curr_col < 0) {
134 console_curr_col = console_cols - 1;
135 if (--console_curr_row < 0)
136 console_curr_row = 0;
139 lcd_putc_xy(console_curr_col * VIDEO_FONT_WIDTH,
140 console_curr_row * VIDEO_FONT_HEIGHT, ' ');
143 static inline void console_newline(void)
145 console_curr_col = 0;
147 /* Check if we need to scroll the terminal */
148 if (++console_curr_row >= console_rows)
154 void lcd_putc(const char c)
156 if (!lcd_is_enabled) {
164 console_curr_col = 0;
171 case '\t': /* Tab (8 chars alignment) */
172 console_curr_col += 8;
173 console_curr_col &= ~7;
175 if (console_curr_col >= console_cols)
184 lcd_putc_xy(console_curr_col * VIDEO_FONT_WIDTH,
185 console_curr_row * VIDEO_FONT_HEIGHT, c);
186 if (++console_curr_col >= console_cols)
191 void lcd_puts(const char *s)
193 if (!lcd_is_enabled) {
205 void lcd_printf(const char *fmt, ...)
208 char buf[CONFIG_SYS_PBSIZE];
211 vsprintf(buf, fmt, args);