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_putc_xy(ushort x, ushort y, char c)
62 int fg_color = lcd_getfgcolor();
63 int bg_color = lcd_getbgcolor();
66 dest = (uchar *)(lcd_console_address +
67 y * lcd_line_length + x * NBITS(LCD_BPP) / 8);
69 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 bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];
80 for (i = 0; i < 8; ++i) {
81 *d++ = (bits & 0x80) ? fg_color : bg_color;
87 static void console_scrollup(void)
89 const int rows = CONFIG_CONSOLE_SCROLL_LINES;
90 int bg_color = lcd_getbgcolor();
92 /* Copy up rows ignoring those that will be overwritten */
93 memcpy(CONSOLE_ROW_FIRST,
94 lcd_console_address + CONSOLE_ROW_SIZE * rows,
95 CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows);
97 /* Clear the last rows */
98 #if (LCD_BPP != LCD_COLOR32)
99 memset(lcd_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows,
100 bg_color, CONSOLE_ROW_SIZE * rows);
102 u32 *ppix = lcd_console_address +
103 CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows;
106 i < (CONSOLE_ROW_SIZE * rows) / NBYTES(panel_info.vl_bpix);
112 console_curr_row -= rows;
115 static inline void console_back(void)
117 if (--console_curr_col < 0) {
118 console_curr_col = console_cols - 1;
119 if (--console_curr_row < 0)
120 console_curr_row = 0;
123 lcd_putc_xy(console_curr_col * VIDEO_FONT_WIDTH,
124 console_curr_row * VIDEO_FONT_HEIGHT, ' ');
127 static inline void console_newline(void)
129 console_curr_col = 0;
131 /* Check if we need to scroll the terminal */
132 if (++console_curr_row >= console_rows)
138 void lcd_putc(const char c)
140 if (!lcd_is_enabled) {
148 console_curr_col = 0;
155 case '\t': /* Tab (8 chars alignment) */
156 console_curr_col += 8;
157 console_curr_col &= ~7;
159 if (console_curr_col >= console_cols)
168 lcd_putc_xy(console_curr_col * VIDEO_FONT_WIDTH,
169 console_curr_row * VIDEO_FONT_HEIGHT, c);
170 if (++console_curr_col >= console_cols)
175 void lcd_puts(const char *s)
177 if (!lcd_is_enabled) {
189 void lcd_printf(const char *fmt, ...)
192 char buf[CONFIG_SYS_PBSIZE];
195 vsprintf(buf, fmt, args);
201 static int do_lcd_setcursor(cmd_tbl_t *cmdtp, int flag, int argc,
204 unsigned int col, row;
207 return CMD_RET_USAGE;
209 col = simple_strtoul(argv[1], NULL, 10);
210 row = simple_strtoul(argv[2], NULL, 10);
211 lcd_position_cursor(col, row);
216 static int do_lcd_puts(cmd_tbl_t *cmdtp, int flag, int argc,
220 return CMD_RET_USAGE;
228 setcurs, 3, 1, do_lcd_setcursor,
229 "set cursor position within screen",
230 " <col> <row> in character"
234 lcdputs, 2, 1, do_lcd_puts,
235 "print string on lcd-framebuffer",