Blame view
common/lcd_console.c
5.52 KB
904672ee4
|
1 |
/* |
604c7d4a5
|
2 |
* (C) Copyright 2001-2015 |
904672ee4
|
3 4 |
* DENX Software Engineering -- wd@denx.de * Compulab Ltd - http://compulab.co.il/ |
604c7d4a5
|
5 |
* Bernecker & Rainer Industrieelektronik GmbH - http://www.br-automation.com |
904672ee4
|
6 7 8 9 10 11 12 |
* * SPDX-License-Identifier: GPL-2.0+ */ #include <common.h> #include <lcd.h> #include <video_font.h> /* Get font data, width and height */ |
604c7d4a5
|
13 14 15 |
#if defined(CONFIG_LCD_LOGO) #include <bmp_logo.h> #endif |
904672ee4
|
16 |
|
7471142cd
|
17 |
static struct console_t cons; |
904672ee4
|
18 |
|
904672ee4
|
19 20 |
void lcd_set_col(short col) { |
7471142cd
|
21 |
cons.curr_col = col; |
904672ee4
|
22 23 24 25 |
} void lcd_set_row(short row) { |
7471142cd
|
26 |
cons.curr_row = row; |
904672ee4
|
27 28 29 30 |
} void lcd_position_cursor(unsigned col, unsigned row) { |
7471142cd
|
31 32 |
cons.curr_col = min_t(short, col, cons.cols - 1); cons.curr_row = min_t(short, row, cons.rows - 1); |
904672ee4
|
33 34 35 36 |
} int lcd_get_screen_rows(void) { |
7471142cd
|
37 |
return cons.rows; |
904672ee4
|
38 39 40 41 |
} int lcd_get_screen_columns(void) { |
7471142cd
|
42 |
return cons.cols; |
904672ee4
|
43 |
} |
604c7d4a5
|
44 |
static void lcd_putc_xy0(struct console_t *pcons, ushort x, ushort y, char c) |
904672ee4
|
45 |
{ |
a202c5bd2
|
46 47 |
int fg_color = lcd_getfgcolor(); int bg_color = lcd_getbgcolor(); |
21bf1c38b
|
48 49 50 51 52 53 |
int row; #if LCD_BPP == LCD_MONOCHROME ushort off = x * (1 << LCD_BPP) % 8; #else int i; #endif |
604c7d4a5
|
54 55 56 57 58 59 |
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]; |
21bf1c38b
|
60 61 62 63 64 65 66 67 68 69 |
#if LCD_BPP == LCD_MONOCHROME uchar rest = *dst & -(1 << (8 - off)); uchar sym; sym = (COLOR_MASK(fg_color) & bits) | (COLOR_MASK(bg_color) & ~bits); *dst++ = rest | (sym >> off); rest = sym << (8 - off); *dst = rest | (*dst & ((1 << (8 - off)) - 1)); #else /* LCD_BPP == LCD_COLOR8 or LCD_COLOR16 or LCD_COLOR32 */ |
604c7d4a5
|
70 71 |
for (i = 0; i < VIDEO_FONT_WIDTH; ++i) { *dst++ = (bits & 0x80) ? fg_color : bg_color; |
97562c12f
|
72 |
bits <<= 1; |
904672ee4
|
73 |
} |
21bf1c38b
|
74 |
#endif |
604c7d4a5
|
75 |
dst += (pcons->lcdsizex - VIDEO_FONT_WIDTH); |
904672ee4
|
76 77 |
} } |
604c7d4a5
|
78 |
static inline void console_setrow0(struct console_t *pcons, u32 row, int clr) |
904672ee4
|
79 |
{ |
604c7d4a5
|
80 81 82 83 |
int i; fbptr_t *dst = (fbptr_t *)pcons->fbbase + row * VIDEO_FONT_HEIGHT * pcons->lcdsizex; |
904672ee4
|
84 |
|
604c7d4a5
|
85 86 87 |
for (i = 0; i < (VIDEO_FONT_HEIGHT * pcons->lcdsizex); i++) *dst++ = clr; } |
904672ee4
|
88 |
|
604c7d4a5
|
89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
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++; |
904672ee4
|
103 104 105 106 |
} static inline void console_back(void) { |
7471142cd
|
107 108 109 110 |
if (--cons.curr_col < 0) { cons.curr_col = cons.cols - 1; if (--cons.curr_row < 0) cons.curr_row = 0; |
904672ee4
|
111 |
} |
604c7d4a5
|
112 113 114 |
cons.fp_putc_xy(&cons, cons.curr_col * VIDEO_FONT_WIDTH, cons.curr_row * VIDEO_FONT_HEIGHT, ' '); |
904672ee4
|
115 116 117 118 |
} static inline void console_newline(void) { |
604c7d4a5
|
119 120 121 |
const int rows = CONFIG_CONSOLE_SCROLL_LINES; int bg_color = lcd_getbgcolor(); int i; |
7471142cd
|
122 |
cons.curr_col = 0; |
904672ee4
|
123 124 |
/* Check if we need to scroll the terminal */ |
604c7d4a5
|
125 126 127 128 |
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++) |
21bf1c38b
|
129 |
cons.fp_console_setrow(&cons, cons.rows-i-1, COLOR_MASK(bg_color)); |
604c7d4a5
|
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
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) ", cons.cols, cons.rows, cons.lcdsizex, cons.lcdsizey, vl_rot); |
904672ee4
|
170 171 172 173 174 175 176 177 178 179 180 181 |
} void lcd_putc(const char c) { if (!lcd_is_enabled) { serial_putc(c); return; } switch (c) { case '\r': |
7471142cd
|
182 |
cons.curr_col = 0; |
904672ee4
|
183 184 185 186 187 188 189 |
return; case ' ': console_newline(); return; case '\t': /* Tab (8 chars alignment) */ |
7471142cd
|
190 191 |
cons.curr_col += 8; cons.curr_col &= ~7; |
904672ee4
|
192 |
|
7471142cd
|
193 |
if (cons.curr_col >= cons.cols) |
904672ee4
|
194 195 196 197 198 199 200 201 |
console_newline(); return; case '\b': console_back(); return; default: |
604c7d4a5
|
202 203 204 |
cons.fp_putc_xy(&cons, cons.curr_col * VIDEO_FONT_WIDTH, cons.curr_row * VIDEO_FONT_HEIGHT, c); |
7471142cd
|
205 |
if (++cons.curr_col >= cons.cols) |
904672ee4
|
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
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); } |
d38d0c6a3
|
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
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; } |
1b7caf112
|
250 251 252 253 254 255 256 257 258 259 |
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; } |
d38d0c6a3
|
260 261 262 263 264 |
U_BOOT_CMD( setcurs, 3, 1, do_lcd_setcursor, "set cursor position within screen", " <col> <row> in character" ); |
1b7caf112
|
265 266 267 268 269 270 |
U_BOOT_CMD( lcdputs, 2, 1, do_lcd_puts, "print string on lcd-framebuffer", " <string>" ); |