1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2001-2015
5 * Compulab Ltd - http://compulab.co.il/
6 * Bernecker & Rainer Industrieelektronik GmbH - http://www.br-automation.com
13 #include <video_font.h> /* Get font data, width and height */
14 #if defined(CONFIG_LCD_LOGO)
18 static struct console_t cons;
20 void lcd_set_col(short col)
25 void lcd_set_row(short row)
30 void lcd_position_cursor(unsigned col, unsigned row)
32 cons.curr_col = min_t(short, col, cons.cols - 1);
33 cons.curr_row = min_t(short, row, cons.rows - 1);
36 int lcd_get_screen_rows(void)
41 int lcd_get_screen_columns(void)
46 static void lcd_putc_xy0(struct console_t *pcons, ushort x, ushort y, char c)
48 int fg_color = lcd_getfgcolor();
49 int bg_color = lcd_getbgcolor();
51 fbptr_t *dst = (fbptr_t *)pcons->fbbase +
55 for (row = 0; row < VIDEO_FONT_HEIGHT; row++) {
56 uchar bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];
57 for (i = 0; i < VIDEO_FONT_WIDTH; ++i) {
58 *dst++ = (bits & 0x80) ? fg_color : bg_color;
61 dst += (pcons->lcdsizex - VIDEO_FONT_WIDTH);
65 static inline void console_setrow0(struct console_t *pcons, u32 row, int clr)
68 fbptr_t *dst = (fbptr_t *)pcons->fbbase +
69 row * VIDEO_FONT_HEIGHT *
72 for (i = 0; i < (VIDEO_FONT_HEIGHT * pcons->lcdsizex); i++)
76 static inline void console_moverow0(struct console_t *pcons,
77 u32 rowdst, u32 rowsrc)
80 fbptr_t *dst = (fbptr_t *)pcons->fbbase +
81 rowdst * VIDEO_FONT_HEIGHT *
84 fbptr_t *src = (fbptr_t *)pcons->fbbase +
85 rowsrc * VIDEO_FONT_HEIGHT *
88 for (i = 0; i < (VIDEO_FONT_HEIGHT * pcons->lcdsizex); i++)
92 static inline void console_back(void)
94 if (--cons.curr_col < 0) {
95 cons.curr_col = cons.cols - 1;
96 if (--cons.curr_row < 0)
100 cons.fp_putc_xy(&cons,
101 cons.curr_col * VIDEO_FONT_WIDTH,
102 cons.curr_row * VIDEO_FONT_HEIGHT, ' ');
105 static inline void console_newline(void)
107 const int rows = CONFIG_CONSOLE_SCROLL_LINES;
108 int bg_color = lcd_getbgcolor();
113 /* Check if we need to scroll the terminal */
114 if (++cons.curr_row >= cons.rows) {
115 for (i = 0; i < cons.rows-rows; i++)
116 cons.fp_console_moverow(&cons, i, i+rows);
117 for (i = 0; i < rows; i++)
118 cons.fp_console_setrow(&cons, cons.rows-i-1, bg_color);
119 cons.curr_row -= rows;
124 void console_calc_rowcol(struct console_t *pcons, u32 sizex, u32 sizey)
126 pcons->cols = sizex / VIDEO_FONT_WIDTH;
127 #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
128 pcons->rows = (pcons->lcdsizey - BMP_LOGO_HEIGHT);
129 pcons->rows /= VIDEO_FONT_HEIGHT;
131 pcons->rows = sizey / VIDEO_FONT_HEIGHT;
135 void __weak lcd_init_console_rot(struct console_t *pcons)
140 void lcd_init_console(void *address, int vl_cols, int vl_rows, int vl_rot)
142 memset(&cons, 0, sizeof(cons));
143 cons.fbbase = address;
145 cons.lcdsizex = vl_cols;
146 cons.lcdsizey = vl_rows;
147 cons.lcdrot = vl_rot;
149 cons.fp_putc_xy = &lcd_putc_xy0;
150 cons.fp_console_moverow = &console_moverow0;
151 cons.fp_console_setrow = &console_setrow0;
152 console_calc_rowcol(&cons, cons.lcdsizex, cons.lcdsizey);
154 lcd_init_console_rot(&cons);
156 debug("lcd_console: have %d/%d col/rws on scr %dx%d (%d deg rotated)\n",
157 cons.cols, cons.rows, cons.lcdsizex, cons.lcdsizey, vl_rot);
160 void lcd_putc(const char c)
162 if (!lcd_is_enabled) {
176 case '\t': /* Tab (8 chars alignment) */
180 if (cons.curr_col >= cons.cols)
189 cons.fp_putc_xy(&cons,
190 cons.curr_col * VIDEO_FONT_WIDTH,
191 cons.curr_row * VIDEO_FONT_HEIGHT, c);
192 if (++cons.curr_col >= cons.cols)
197 void lcd_puts(const char *s)
199 if (!lcd_is_enabled) {
211 void lcd_printf(const char *fmt, ...)
214 char buf[CONFIG_SYS_PBSIZE];
217 vsprintf(buf, fmt, args);
223 static int do_lcd_setcursor(struct cmd_tbl *cmdtp, int flag, int argc,
226 unsigned int col, row;
229 return CMD_RET_USAGE;
231 col = simple_strtoul(argv[1], NULL, 10);
232 row = simple_strtoul(argv[2], NULL, 10);
233 lcd_position_cursor(col, row);
238 static int do_lcd_puts(struct cmd_tbl *cmdtp, int flag, int argc,
242 return CMD_RET_USAGE;
250 setcurs, 3, 1, do_lcd_setcursor,
251 "set cursor position within screen",
252 " <col> <row> in character"
256 lcdputs, 2, 1, do_lcd_puts,
257 "print string on lcd-framebuffer",