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, bg_color;
65 dest = (uchar *)(lcd_console_address +
66 y * lcd_line_length + x * NBITS(LCD_BPP) / 8);
68 for (row = 0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) {
69 #if LCD_BPP == LCD_COLOR16
70 ushort *d = (ushort *)dest;
71 #elif LCD_BPP == LCD_COLOR32
77 fg_color = lcd_getfgcolor();
78 bg_color = lcd_getbgcolor();
81 bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];
83 for (i = 0; i < 8; ++i) {
84 *d++ = (bits & 0x80) ? fg_color : bg_color;
90 static void console_scrollup(void)
92 const int rows = CONFIG_CONSOLE_SCROLL_LINES;
93 int bg_color = lcd_getbgcolor();
95 /* Copy up rows ignoring those that will be overwritten */
96 memcpy(CONSOLE_ROW_FIRST,
97 lcd_console_address + CONSOLE_ROW_SIZE * rows,
98 CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows);
100 /* Clear the last rows */
101 #if (LCD_BPP != LCD_COLOR32)
102 memset(lcd_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows,
103 bg_color, CONSOLE_ROW_SIZE * rows);
105 u32 *ppix = lcd_console_address +
106 CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows;
109 i < (CONSOLE_ROW_SIZE * rows) / NBYTES(panel_info.vl_bpix);
115 console_curr_row -= rows;
118 static inline void console_back(void)
120 if (--console_curr_col < 0) {
121 console_curr_col = console_cols - 1;
122 if (--console_curr_row < 0)
123 console_curr_row = 0;
126 lcd_putc_xy(console_curr_col * VIDEO_FONT_WIDTH,
127 console_curr_row * VIDEO_FONT_HEIGHT, ' ');
130 static inline void console_newline(void)
132 console_curr_col = 0;
134 /* Check if we need to scroll the terminal */
135 if (++console_curr_row >= console_rows)
141 void lcd_putc(const char c)
143 if (!lcd_is_enabled) {
151 console_curr_col = 0;
158 case '\t': /* Tab (8 chars alignment) */
159 console_curr_col += 8;
160 console_curr_col &= ~7;
162 if (console_curr_col >= console_cols)
171 lcd_putc_xy(console_curr_col * VIDEO_FONT_WIDTH,
172 console_curr_row * VIDEO_FONT_HEIGHT, c);
173 if (++console_curr_col >= console_cols)
178 void lcd_puts(const char *s)
180 if (!lcd_is_enabled) {
192 void lcd_printf(const char *fmt, ...)
195 char buf[CONFIG_SYS_PBSIZE];
198 vsprintf(buf, fmt, args);
204 static int do_lcd_setcursor(cmd_tbl_t *cmdtp, int flag, int argc,
207 unsigned int col, row;
210 return CMD_RET_USAGE;
212 col = simple_strtoul(argv[1], NULL, 10);
213 row = simple_strtoul(argv[2], NULL, 10);
214 lcd_position_cursor(col, row);
219 static int do_lcd_puts(cmd_tbl_t *cmdtp, int flag, int argc,
223 return CMD_RET_USAGE;
231 setcurs, 3, 1, do_lcd_setcursor,
232 "set cursor position within screen",
233 " <col> <row> in character"
237 lcdputs, 2, 1, do_lcd_puts,
238 "print string on lcd-framebuffer",