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
14 #include <video_font.h> /* Get font data, width and height */
15 #if defined(CONFIG_LCD_LOGO)
19 static struct console_t cons;
21 void lcd_set_col(short col)
26 void lcd_set_row(short row)
31 void lcd_position_cursor(unsigned col, unsigned row)
33 cons.curr_col = min_t(short, col, cons.cols - 1);
34 cons.curr_row = min_t(short, row, cons.rows - 1);
37 int lcd_get_screen_rows(void)
42 int lcd_get_screen_columns(void)
47 static void lcd_putc_xy0(struct console_t *pcons, ushort x, ushort y, char c)
49 int fg_color = lcd_getfgcolor();
50 int bg_color = lcd_getbgcolor();
52 fbptr_t *dst = (fbptr_t *)pcons->fbbase +
56 for (row = 0; row < VIDEO_FONT_HEIGHT; row++) {
57 uchar bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];
58 for (i = 0; i < VIDEO_FONT_WIDTH; ++i) {
59 *dst++ = (bits & 0x80) ? fg_color : bg_color;
62 dst += (pcons->lcdsizex - VIDEO_FONT_WIDTH);
66 static inline void console_setrow0(struct console_t *pcons, u32 row, int clr)
69 fbptr_t *dst = (fbptr_t *)pcons->fbbase +
70 row * VIDEO_FONT_HEIGHT *
73 for (i = 0; i < (VIDEO_FONT_HEIGHT * pcons->lcdsizex); i++)
77 static inline void console_moverow0(struct console_t *pcons,
78 u32 rowdst, u32 rowsrc)
81 fbptr_t *dst = (fbptr_t *)pcons->fbbase +
82 rowdst * VIDEO_FONT_HEIGHT *
85 fbptr_t *src = (fbptr_t *)pcons->fbbase +
86 rowsrc * VIDEO_FONT_HEIGHT *
89 for (i = 0; i < (VIDEO_FONT_HEIGHT * pcons->lcdsizex); i++)
93 static inline void console_back(void)
95 if (--cons.curr_col < 0) {
96 cons.curr_col = cons.cols - 1;
97 if (--cons.curr_row < 0)
101 cons.fp_putc_xy(&cons,
102 cons.curr_col * VIDEO_FONT_WIDTH,
103 cons.curr_row * VIDEO_FONT_HEIGHT, ' ');
106 static inline void console_newline(void)
108 const int rows = CONFIG_CONSOLE_SCROLL_LINES;
109 int bg_color = lcd_getbgcolor();
114 /* Check if we need to scroll the terminal */
115 if (++cons.curr_row >= cons.rows) {
116 for (i = 0; i < cons.rows-rows; i++)
117 cons.fp_console_moverow(&cons, i, i+rows);
118 for (i = 0; i < rows; i++)
119 cons.fp_console_setrow(&cons, cons.rows-i-1, bg_color);
120 cons.curr_row -= rows;
125 void console_calc_rowcol(struct console_t *pcons, u32 sizex, u32 sizey)
127 pcons->cols = sizex / VIDEO_FONT_WIDTH;
128 #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
129 pcons->rows = (pcons->lcdsizey - BMP_LOGO_HEIGHT);
130 pcons->rows /= VIDEO_FONT_HEIGHT;
132 pcons->rows = sizey / VIDEO_FONT_HEIGHT;
136 void __weak lcd_init_console_rot(struct console_t *pcons)
141 void lcd_init_console(void *address, int vl_cols, int vl_rows, int vl_rot)
143 memset(&cons, 0, sizeof(cons));
144 cons.fbbase = address;
146 cons.lcdsizex = vl_cols;
147 cons.lcdsizey = vl_rows;
148 cons.lcdrot = vl_rot;
150 cons.fp_putc_xy = &lcd_putc_xy0;
151 cons.fp_console_moverow = &console_moverow0;
152 cons.fp_console_setrow = &console_setrow0;
153 console_calc_rowcol(&cons, cons.lcdsizex, cons.lcdsizey);
155 lcd_init_console_rot(&cons);
157 debug("lcd_console: have %d/%d col/rws on scr %dx%d (%d deg rotated)\n",
158 cons.cols, cons.rows, cons.lcdsizex, cons.lcdsizey, vl_rot);
161 void lcd_putc(const char c)
163 if (!lcd_is_enabled) {
177 case '\t': /* Tab (8 chars alignment) */
181 if (cons.curr_col >= cons.cols)
190 cons.fp_putc_xy(&cons,
191 cons.curr_col * VIDEO_FONT_WIDTH,
192 cons.curr_row * VIDEO_FONT_HEIGHT, c);
193 if (++cons.curr_col >= cons.cols)
198 void lcd_puts(const char *s)
200 if (!lcd_is_enabled) {
212 void lcd_printf(const char *fmt, ...)
215 char buf[CONFIG_SYS_PBSIZE];
218 vsprintf(buf, fmt, args);
224 static int do_lcd_setcursor(struct cmd_tbl *cmdtp, int flag, int argc,
227 unsigned int col, row;
230 return CMD_RET_USAGE;
232 col = simple_strtoul(argv[1], NULL, 10);
233 row = simple_strtoul(argv[2], NULL, 10);
234 lcd_position_cursor(col, row);
239 static int do_lcd_puts(struct cmd_tbl *cmdtp, int flag, int argc,
243 return CMD_RET_USAGE;
251 setcurs, 3, 1, do_lcd_setcursor,
252 "set cursor position within screen",
253 " <col> <row> in character"
257 lcdputs, 2, 1, do_lcd_puts,
258 "print string on lcd-framebuffer",