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_SIZE (CONSOLE_ROW_SIZE * console_rows)
17 static short console_curr_col;
18 static short console_curr_row;
19 static short console_cols;
20 static short console_rows;
21 static void *lcd_console_address;
23 void lcd_init_console(void *address, int rows, int cols)
29 lcd_console_address = address;
32 void lcd_set_col(short col)
34 console_curr_col = col;
37 void lcd_set_row(short row)
39 console_curr_row = row;
42 void lcd_position_cursor(unsigned col, unsigned row)
44 console_curr_col = min_t(short, col, console_cols - 1);
45 console_curr_row = min_t(short, row, console_rows - 1);
48 int lcd_get_screen_rows(void)
53 int lcd_get_screen_columns(void)
58 static void lcd_drawchars(ushort x, ushort y, uchar *str, int count)
62 int fg_color, bg_color;
64 dest = (uchar *)(lcd_console_address +
65 y * lcd_line_length + x * NBITS(LCD_BPP) / 8);
67 for (row = 0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) {
70 #if LCD_BPP == LCD_COLOR16
71 ushort *d = (ushort *)dest;
72 #elif LCD_BPP == LCD_COLOR32
78 fg_color = lcd_getfgcolor();
79 bg_color = lcd_getbgcolor();
80 for (i = 0; i < count; ++i) {
84 bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];
86 for (c = 0; c < 8; ++c) {
87 *d++ = (bits & 0x80) ? fg_color : bg_color;
94 static inline void lcd_putc_xy(ushort x, ushort y, uchar c)
96 lcd_drawchars(x, y, &c, 1);
99 static void console_scrollup(void)
101 const int rows = CONFIG_CONSOLE_SCROLL_LINES;
102 int bg_color = lcd_getbgcolor();
104 /* Copy up rows ignoring those that will be overwritten */
105 memcpy(CONSOLE_ROW_FIRST,
106 lcd_console_address + CONSOLE_ROW_SIZE * rows,
107 CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows);
109 /* Clear the last rows */
110 #if (LCD_BPP != LCD_COLOR32)
111 memset(lcd_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows,
112 bg_color, CONSOLE_ROW_SIZE * rows);
114 u32 *ppix = lcd_console_address +
115 CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows;
118 i < (CONSOLE_ROW_SIZE * rows) / NBYTES(panel_info.vl_bpix);
124 console_curr_row -= rows;
127 static inline void console_back(void)
129 if (--console_curr_col < 0) {
130 console_curr_col = console_cols - 1;
131 if (--console_curr_row < 0)
132 console_curr_row = 0;
135 lcd_putc_xy(console_curr_col * VIDEO_FONT_WIDTH,
136 console_curr_row * VIDEO_FONT_HEIGHT, ' ');
139 static inline void console_newline(void)
141 console_curr_col = 0;
143 /* Check if we need to scroll the terminal */
144 if (++console_curr_row >= console_rows)
150 void lcd_putc(const char c)
152 if (!lcd_is_enabled) {
160 console_curr_col = 0;
167 case '\t': /* Tab (8 chars alignment) */
168 console_curr_col += 8;
169 console_curr_col &= ~7;
171 if (console_curr_col >= console_cols)
180 lcd_putc_xy(console_curr_col * VIDEO_FONT_WIDTH,
181 console_curr_row * VIDEO_FONT_HEIGHT, c);
182 if (++console_curr_col >= console_cols)
187 void lcd_puts(const char *s)
189 if (!lcd_is_enabled) {
201 void lcd_printf(const char *fmt, ...)
204 char buf[CONFIG_SYS_PBSIZE];
207 vsprintf(buf, fmt, args);
213 static int do_lcd_setcursor(cmd_tbl_t *cmdtp, int flag, int argc,
216 unsigned int col, row;
219 return CMD_RET_USAGE;
221 col = simple_strtoul(argv[1], NULL, 10);
222 row = simple_strtoul(argv[2], NULL, 10);
223 lcd_position_cursor(col, row);
228 static int do_lcd_puts(cmd_tbl_t *cmdtp, int flag, int argc,
232 return CMD_RET_USAGE;
240 setcurs, 3, 1, do_lcd_setcursor,
241 "set cursor position within screen",
242 " <col> <row> in character"
246 lcdputs, 2, 1, do_lcd_puts,
247 "print string on lcd-framebuffer",