1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2001-2015
4 * DENX Software Engineering -- wd@denx.de
5 * Compulab Ltd - http://compulab.co.il/
6 * Bernecker & Rainer Industrieelektronik GmbH - http://www.br-automation.com
11 #include <video_font.h> /* Get font data, width and height */
12 #if defined(CONFIG_LCD_LOGO)
16 static struct console_t cons;
18 void lcd_set_col(short col)
23 void lcd_set_row(short row)
28 void lcd_position_cursor(unsigned col, unsigned row)
30 cons.curr_col = min_t(short, col, cons.cols - 1);
31 cons.curr_row = min_t(short, row, cons.rows - 1);
34 int lcd_get_screen_rows(void)
39 int lcd_get_screen_columns(void)
44 static void lcd_putc_xy0(struct console_t *pcons, ushort x, ushort y, char c)
46 int fg_color = lcd_getfgcolor();
47 int bg_color = lcd_getbgcolor();
49 fbptr_t *dst = (fbptr_t *)pcons->fbbase +
53 for (row = 0; row < VIDEO_FONT_HEIGHT; row++) {
54 uchar bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];
55 for (i = 0; i < VIDEO_FONT_WIDTH; ++i) {
56 *dst++ = (bits & 0x80) ? fg_color : bg_color;
59 dst += (pcons->lcdsizex - VIDEO_FONT_WIDTH);
63 static inline void console_setrow0(struct console_t *pcons, u32 row, int clr)
66 fbptr_t *dst = (fbptr_t *)pcons->fbbase +
67 row * VIDEO_FONT_HEIGHT *
70 for (i = 0; i < (VIDEO_FONT_HEIGHT * pcons->lcdsizex); i++)
74 static inline void console_moverow0(struct console_t *pcons,
75 u32 rowdst, u32 rowsrc)
78 fbptr_t *dst = (fbptr_t *)pcons->fbbase +
79 rowdst * VIDEO_FONT_HEIGHT *
82 fbptr_t *src = (fbptr_t *)pcons->fbbase +
83 rowsrc * VIDEO_FONT_HEIGHT *
86 for (i = 0; i < (VIDEO_FONT_HEIGHT * pcons->lcdsizex); i++)
90 static inline void console_back(void)
92 if (--cons.curr_col < 0) {
93 cons.curr_col = cons.cols - 1;
94 if (--cons.curr_row < 0)
98 cons.fp_putc_xy(&cons,
99 cons.curr_col * VIDEO_FONT_WIDTH,
100 cons.curr_row * VIDEO_FONT_HEIGHT, ' ');
103 static inline void console_newline(void)
105 const int rows = CONFIG_CONSOLE_SCROLL_LINES;
106 int bg_color = lcd_getbgcolor();
111 /* Check if we need to scroll the terminal */
112 if (++cons.curr_row >= cons.rows) {
113 for (i = 0; i < cons.rows-rows; i++)
114 cons.fp_console_moverow(&cons, i, i+rows);
115 for (i = 0; i < rows; i++)
116 cons.fp_console_setrow(&cons, cons.rows-i-1, bg_color);
117 cons.curr_row -= rows;
122 void console_calc_rowcol(struct console_t *pcons, u32 sizex, u32 sizey)
124 pcons->cols = sizex / VIDEO_FONT_WIDTH;
125 #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
126 pcons->rows = (pcons->lcdsizey - BMP_LOGO_HEIGHT);
127 pcons->rows /= VIDEO_FONT_HEIGHT;
129 pcons->rows = sizey / VIDEO_FONT_HEIGHT;
133 void __weak lcd_init_console_rot(struct console_t *pcons)
138 void lcd_init_console(void *address, int vl_cols, int vl_rows, int vl_rot)
140 memset(&cons, 0, sizeof(cons));
141 cons.fbbase = address;
143 cons.lcdsizex = vl_cols;
144 cons.lcdsizey = vl_rows;
145 cons.lcdrot = vl_rot;
147 cons.fp_putc_xy = &lcd_putc_xy0;
148 cons.fp_console_moverow = &console_moverow0;
149 cons.fp_console_setrow = &console_setrow0;
150 console_calc_rowcol(&cons, cons.lcdsizex, cons.lcdsizey);
152 lcd_init_console_rot(&cons);
154 debug("lcd_console: have %d/%d col/rws on scr %dx%d (%d deg rotated)\n",
155 cons.cols, cons.rows, cons.lcdsizex, cons.lcdsizey, vl_rot);
158 void lcd_putc(const char c)
160 if (!lcd_is_enabled) {
174 case '\t': /* Tab (8 chars alignment) */
178 if (cons.curr_col >= cons.cols)
187 cons.fp_putc_xy(&cons,
188 cons.curr_col * VIDEO_FONT_WIDTH,
189 cons.curr_row * VIDEO_FONT_HEIGHT, c);
190 if (++cons.curr_col >= cons.cols)
195 void lcd_puts(const char *s)
197 if (!lcd_is_enabled) {
209 void lcd_printf(const char *fmt, ...)
212 char buf[CONFIG_SYS_PBSIZE];
215 vsprintf(buf, fmt, args);
221 static int do_lcd_setcursor(cmd_tbl_t *cmdtp, int flag, int argc,
224 unsigned int col, row;
227 return CMD_RET_USAGE;
229 col = simple_strtoul(argv[1], NULL, 10);
230 row = simple_strtoul(argv[2], NULL, 10);
231 lcd_position_cursor(col, row);
236 static int do_lcd_puts(cmd_tbl_t *cmdtp, int flag, int argc,
240 return CMD_RET_USAGE;
248 setcurs, 3, 1, do_lcd_setcursor,
249 "set cursor position within screen",
250 " <col> <row> in character"
254 lcdputs, 2, 1, do_lcd_puts,
255 "print string on lcd-framebuffer",