2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2014-12-08 15:14:45 +00:00
|
|
|
/*
|
2015-03-27 07:01:38 +00:00
|
|
|
* (C) Copyright 2001-2015
|
2014-12-08 15:14:45 +00:00
|
|
|
* DENX Software Engineering -- wd@denx.de
|
|
|
|
* Compulab Ltd - http://compulab.co.il/
|
2015-03-27 07:01:38 +00:00
|
|
|
* Bernecker & Rainer Industrieelektronik GmbH - http://www.br-automation.com
|
2014-12-08 15:14:45 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <lcd.h>
|
|
|
|
#include <video_font.h> /* Get font data, width and height */
|
2015-03-27 07:01:38 +00:00
|
|
|
#if defined(CONFIG_LCD_LOGO)
|
|
|
|
#include <bmp_logo.h>
|
|
|
|
#endif
|
2014-12-08 15:14:45 +00:00
|
|
|
|
2015-03-27 07:01:37 +00:00
|
|
|
static struct console_t cons;
|
2014-12-08 15:14:45 +00:00
|
|
|
|
|
|
|
void lcd_set_col(short col)
|
|
|
|
{
|
2015-03-27 07:01:37 +00:00
|
|
|
cons.curr_col = col;
|
2014-12-08 15:14:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void lcd_set_row(short row)
|
|
|
|
{
|
2015-03-27 07:01:37 +00:00
|
|
|
cons.curr_row = row;
|
2014-12-08 15:14:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void lcd_position_cursor(unsigned col, unsigned row)
|
|
|
|
{
|
2015-03-27 07:01:37 +00:00
|
|
|
cons.curr_col = min_t(short, col, cons.cols - 1);
|
|
|
|
cons.curr_row = min_t(short, row, cons.rows - 1);
|
2014-12-08 15:14:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int lcd_get_screen_rows(void)
|
|
|
|
{
|
2015-03-27 07:01:37 +00:00
|
|
|
return cons.rows;
|
2014-12-08 15:14:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int lcd_get_screen_columns(void)
|
|
|
|
{
|
2015-03-27 07:01:37 +00:00
|
|
|
return cons.cols;
|
2014-12-08 15:14:45 +00:00
|
|
|
}
|
|
|
|
|
2015-03-27 07:01:38 +00:00
|
|
|
static void lcd_putc_xy0(struct console_t *pcons, ushort x, ushort y, char c)
|
2014-12-08 15:14:45 +00:00
|
|
|
{
|
2015-03-27 07:01:36 +00:00
|
|
|
int fg_color = lcd_getfgcolor();
|
|
|
|
int bg_color = lcd_getbgcolor();
|
2015-03-27 07:01:38 +00:00
|
|
|
int i, row;
|
|
|
|
fbptr_t *dst = (fbptr_t *)pcons->fbbase +
|
|
|
|
y * pcons->lcdsizex +
|
|
|
|
x;
|
|
|
|
|
|
|
|
for (row = 0; row < VIDEO_FONT_HEIGHT; row++) {
|
|
|
|
uchar bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];
|
|
|
|
for (i = 0; i < VIDEO_FONT_WIDTH; ++i) {
|
|
|
|
*dst++ = (bits & 0x80) ? fg_color : bg_color;
|
2015-03-27 07:01:35 +00:00
|
|
|
bits <<= 1;
|
2014-12-08 15:14:45 +00:00
|
|
|
}
|
2015-03-27 07:01:38 +00:00
|
|
|
dst += (pcons->lcdsizex - VIDEO_FONT_WIDTH);
|
2014-12-08 15:14:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-27 07:01:38 +00:00
|
|
|
static inline void console_setrow0(struct console_t *pcons, u32 row, int clr)
|
2014-12-08 15:14:45 +00:00
|
|
|
{
|
2015-03-27 07:01:38 +00:00
|
|
|
int i;
|
|
|
|
fbptr_t *dst = (fbptr_t *)pcons->fbbase +
|
|
|
|
row * VIDEO_FONT_HEIGHT *
|
|
|
|
pcons->lcdsizex;
|
2014-12-08 15:14:45 +00:00
|
|
|
|
2015-03-27 07:01:38 +00:00
|
|
|
for (i = 0; i < (VIDEO_FONT_HEIGHT * pcons->lcdsizex); i++)
|
|
|
|
*dst++ = clr;
|
|
|
|
}
|
2014-12-08 15:14:45 +00:00
|
|
|
|
2015-03-27 07:01:38 +00:00
|
|
|
static inline void console_moverow0(struct console_t *pcons,
|
|
|
|
u32 rowdst, u32 rowsrc)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
fbptr_t *dst = (fbptr_t *)pcons->fbbase +
|
|
|
|
rowdst * VIDEO_FONT_HEIGHT *
|
|
|
|
pcons->lcdsizex;
|
|
|
|
|
|
|
|
fbptr_t *src = (fbptr_t *)pcons->fbbase +
|
|
|
|
rowsrc * VIDEO_FONT_HEIGHT *
|
|
|
|
pcons->lcdsizex;
|
|
|
|
|
|
|
|
for (i = 0; i < (VIDEO_FONT_HEIGHT * pcons->lcdsizex); i++)
|
|
|
|
*dst++ = *src++;
|
2014-12-08 15:14:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void console_back(void)
|
|
|
|
{
|
2015-03-27 07:01:37 +00:00
|
|
|
if (--cons.curr_col < 0) {
|
|
|
|
cons.curr_col = cons.cols - 1;
|
|
|
|
if (--cons.curr_row < 0)
|
|
|
|
cons.curr_row = 0;
|
2014-12-08 15:14:45 +00:00
|
|
|
}
|
|
|
|
|
2015-03-27 07:01:38 +00:00
|
|
|
cons.fp_putc_xy(&cons,
|
|
|
|
cons.curr_col * VIDEO_FONT_WIDTH,
|
|
|
|
cons.curr_row * VIDEO_FONT_HEIGHT, ' ');
|
2014-12-08 15:14:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void console_newline(void)
|
|
|
|
{
|
2015-03-27 07:01:38 +00:00
|
|
|
const int rows = CONFIG_CONSOLE_SCROLL_LINES;
|
|
|
|
int bg_color = lcd_getbgcolor();
|
|
|
|
int i;
|
|
|
|
|
2015-03-27 07:01:37 +00:00
|
|
|
cons.curr_col = 0;
|
2014-12-08 15:14:45 +00:00
|
|
|
|
|
|
|
/* Check if we need to scroll the terminal */
|
2015-03-27 07:01:38 +00:00
|
|
|
if (++cons.curr_row >= cons.rows) {
|
|
|
|
for (i = 0; i < cons.rows-rows; i++)
|
|
|
|
cons.fp_console_moverow(&cons, i, i+rows);
|
|
|
|
for (i = 0; i < rows; i++)
|
|
|
|
cons.fp_console_setrow(&cons, cons.rows-i-1, bg_color);
|
|
|
|
cons.curr_row -= rows;
|
|
|
|
}
|
|
|
|
lcd_sync();
|
|
|
|
}
|
|
|
|
|
|
|
|
void console_calc_rowcol(struct console_t *pcons, u32 sizex, u32 sizey)
|
|
|
|
{
|
|
|
|
pcons->cols = sizex / VIDEO_FONT_WIDTH;
|
|
|
|
#if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
|
|
|
|
pcons->rows = (pcons->lcdsizey - BMP_LOGO_HEIGHT);
|
|
|
|
pcons->rows /= VIDEO_FONT_HEIGHT;
|
|
|
|
#else
|
|
|
|
pcons->rows = sizey / VIDEO_FONT_HEIGHT;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void __weak lcd_init_console_rot(struct console_t *pcons)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void lcd_init_console(void *address, int vl_cols, int vl_rows, int vl_rot)
|
|
|
|
{
|
|
|
|
memset(&cons, 0, sizeof(cons));
|
|
|
|
cons.fbbase = address;
|
|
|
|
|
|
|
|
cons.lcdsizex = vl_cols;
|
|
|
|
cons.lcdsizey = vl_rows;
|
|
|
|
cons.lcdrot = vl_rot;
|
|
|
|
|
|
|
|
cons.fp_putc_xy = &lcd_putc_xy0;
|
|
|
|
cons.fp_console_moverow = &console_moverow0;
|
|
|
|
cons.fp_console_setrow = &console_setrow0;
|
|
|
|
console_calc_rowcol(&cons, cons.lcdsizex, cons.lcdsizey);
|
|
|
|
|
|
|
|
lcd_init_console_rot(&cons);
|
|
|
|
|
|
|
|
debug("lcd_console: have %d/%d col/rws on scr %dx%d (%d deg rotated)\n",
|
|
|
|
cons.cols, cons.rows, cons.lcdsizex, cons.lcdsizey, vl_rot);
|
2014-12-08 15:14:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void lcd_putc(const char c)
|
|
|
|
{
|
|
|
|
if (!lcd_is_enabled) {
|
|
|
|
serial_putc(c);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
case '\r':
|
2015-03-27 07:01:37 +00:00
|
|
|
cons.curr_col = 0;
|
2014-12-08 15:14:45 +00:00
|
|
|
return;
|
|
|
|
case '\n':
|
|
|
|
console_newline();
|
|
|
|
|
|
|
|
return;
|
|
|
|
case '\t': /* Tab (8 chars alignment) */
|
2015-03-27 07:01:37 +00:00
|
|
|
cons.curr_col += 8;
|
|
|
|
cons.curr_col &= ~7;
|
2014-12-08 15:14:45 +00:00
|
|
|
|
2015-03-27 07:01:37 +00:00
|
|
|
if (cons.curr_col >= cons.cols)
|
2014-12-08 15:14:45 +00:00
|
|
|
console_newline();
|
|
|
|
|
|
|
|
return;
|
|
|
|
case '\b':
|
|
|
|
console_back();
|
|
|
|
|
|
|
|
return;
|
|
|
|
default:
|
2015-03-27 07:01:38 +00:00
|
|
|
cons.fp_putc_xy(&cons,
|
|
|
|
cons.curr_col * VIDEO_FONT_WIDTH,
|
|
|
|
cons.curr_row * VIDEO_FONT_HEIGHT, c);
|
2015-03-27 07:01:37 +00:00
|
|
|
if (++cons.curr_col >= cons.cols)
|
2014-12-08 15:14:45 +00:00
|
|
|
console_newline();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void lcd_puts(const char *s)
|
|
|
|
{
|
|
|
|
if (!lcd_is_enabled) {
|
|
|
|
serial_puts(s);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (*s)
|
|
|
|
lcd_putc(*s++);
|
|
|
|
|
|
|
|
lcd_sync();
|
|
|
|
}
|
|
|
|
|
|
|
|
void lcd_printf(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
char buf[CONFIG_SYS_PBSIZE];
|
|
|
|
|
|
|
|
va_start(args, fmt);
|
|
|
|
vsprintf(buf, fmt, args);
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
lcd_puts(buf);
|
|
|
|
}
|
2015-02-03 12:22:24 +00:00
|
|
|
|
|
|
|
static int do_lcd_setcursor(cmd_tbl_t *cmdtp, int flag, int argc,
|
|
|
|
char *const argv[])
|
|
|
|
{
|
|
|
|
unsigned int col, row;
|
|
|
|
|
|
|
|
if (argc != 3)
|
|
|
|
return CMD_RET_USAGE;
|
|
|
|
|
|
|
|
col = simple_strtoul(argv[1], NULL, 10);
|
|
|
|
row = simple_strtoul(argv[2], NULL, 10);
|
|
|
|
lcd_position_cursor(col, row);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-02-03 12:22:25 +00:00
|
|
|
static int do_lcd_puts(cmd_tbl_t *cmdtp, int flag, int argc,
|
|
|
|
char *const argv[])
|
|
|
|
{
|
|
|
|
if (argc != 2)
|
|
|
|
return CMD_RET_USAGE;
|
|
|
|
|
|
|
|
lcd_puts(argv[1]);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-02-03 12:22:24 +00:00
|
|
|
U_BOOT_CMD(
|
|
|
|
setcurs, 3, 1, do_lcd_setcursor,
|
|
|
|
"set cursor position within screen",
|
|
|
|
" <col> <row> in character"
|
|
|
|
);
|
2015-02-03 12:22:25 +00:00
|
|
|
|
|
|
|
U_BOOT_CMD(
|
|
|
|
lcdputs, 2, 1, do_lcd_puts,
|
|
|
|
"print string on lcd-framebuffer",
|
|
|
|
" <string>"
|
|
|
|
);
|
|
|
|
|