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 cons.lcd_address
15 #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * cons.rows)
18 short curr_col
, curr_row
;
22 static struct console_t cons
;
24 void lcd_init_console(void *address
, int rows
, int cols
)
26 memset(&cons
, 0, sizeof(cons
));
29 cons
.lcd_address
= address
;
33 void lcd_set_col(short col
)
38 void lcd_set_row(short row
)
43 void lcd_position_cursor(unsigned col
, unsigned row
)
45 cons
.curr_col
= min_t(short, col
, cons
.cols
- 1);
46 cons
.curr_row
= min_t(short, row
, cons
.rows
- 1);
49 int lcd_get_screen_rows(void)
54 int lcd_get_screen_columns(void)
59 static void lcd_putc_xy(ushort x
, ushort y
, char c
)
63 int fg_color
= lcd_getfgcolor();
64 int bg_color
= lcd_getbgcolor();
67 dest
= (uchar
*)(cons
.lcd_address
+
68 y
* lcd_line_length
+ x
* NBITS(LCD_BPP
) / 8);
70 for (row
= 0; row
< VIDEO_FONT_HEIGHT
; ++row
, dest
+= lcd_line_length
) {
71 #if LCD_BPP == LCD_COLOR16
72 ushort
*d
= (ushort
*)dest
;
73 #elif LCD_BPP == LCD_COLOR32
79 bits
= video_fontdata
[c
* VIDEO_FONT_HEIGHT
+ row
];
81 for (i
= 0; i
< 8; ++i
) {
82 *d
++ = (bits
& 0x80) ? fg_color
: bg_color
;
88 static void console_scrollup(void)
90 const int rows
= CONFIG_CONSOLE_SCROLL_LINES
;
91 int bg_color
= lcd_getbgcolor();
93 /* Copy up rows ignoring those that will be overwritten */
94 memcpy(CONSOLE_ROW_FIRST
,
95 cons
.lcd_address
+ CONSOLE_ROW_SIZE
* rows
,
96 CONSOLE_SIZE
- CONSOLE_ROW_SIZE
* rows
);
98 /* Clear the last rows */
99 #if (LCD_BPP != LCD_COLOR32)
100 memset(lcd_console_address
+ CONSOLE_SIZE
- CONSOLE_ROW_SIZE
* rows
,
101 bg_color
, CONSOLE_ROW_SIZE
* rows
);
103 u32
*ppix
= cons
.lcd_address
+
104 CONSOLE_SIZE
- CONSOLE_ROW_SIZE
* rows
;
107 i
< (CONSOLE_ROW_SIZE
* rows
) / NBYTES(panel_info
.vl_bpix
);
113 cons
.curr_row
-= rows
;
116 static inline void console_back(void)
118 if (--cons
.curr_col
< 0) {
119 cons
.curr_col
= cons
.cols
- 1;
120 if (--cons
.curr_row
< 0)
124 lcd_putc_xy(cons
.curr_col
* VIDEO_FONT_WIDTH
,
125 cons
.curr_row
* VIDEO_FONT_HEIGHT
, ' ');
128 static inline void console_newline(void)
132 /* Check if we need to scroll the terminal */
133 if (++cons
.curr_row
>= cons
.rows
)
139 void lcd_putc(const char c
)
141 if (!lcd_is_enabled
) {
155 case '\t': /* Tab (8 chars alignment) */
159 if (cons
.curr_col
>= cons
.cols
)
168 lcd_putc_xy(cons
.curr_col
* VIDEO_FONT_WIDTH
,
169 cons
.curr_row
* VIDEO_FONT_HEIGHT
, c
);
170 if (++cons
.curr_col
>= cons
.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",