Skip to content

Commit af16d62

Browse files
committed
common: devfont: add command 'print'
1 parent 9a49b92 commit af16d62

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

common/devfont.c

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,3 +399,73 @@ U_BOOT_CMD(
399399
);
400400

401401

402+
403+
int print_x = 0;
404+
int print_y = 0;
405+
406+
void do_print_char(char c)
407+
{
408+
if(gpCurFont == NULL)
409+
return;
410+
411+
int color = simple_strtoul(getenv("print_color"), NULL, 16);
412+
413+
switch(c) {
414+
case '\n':
415+
print_y += gpCurFont->font_height;
416+
// fallthrough
417+
case '\r':
418+
print_x = 0;
419+
break;
420+
default: {
421+
unsigned short ch_width;
422+
unsigned char *pFont = gpCurFont->GetFontBitmap(c, &ch_width);
423+
if((print_x + ch_width) >= g_width) {
424+
print_y += gpCurFont->font_height;
425+
print_x = 0;
426+
}
427+
DrawFont(print_x, print_y, ch_width, gpCurFont->font_height, color, pFont);
428+
print_x += ch_width + gpCurFont->font_gaps;
429+
break;
430+
}
431+
}
432+
}
433+
434+
int do_print(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
435+
{
436+
int i = 1;
437+
int newline = 1;
438+
439+
for(i = 1; i < argc; i++) {
440+
if(strcmp(argv[i], "-n") == 0) {
441+
newline = 0;
442+
} else if(strcmp(argv[i], "--") == 0) {
443+
i++;
444+
break;
445+
} else {
446+
break;
447+
}
448+
}
449+
450+
int n = 0;
451+
for(; i < argc; i++) {
452+
if (n++)
453+
do_print_char(' ');
454+
455+
char *p;
456+
for(p = argv[i]; *p; p++)
457+
do_print_char(*p);
458+
}
459+
460+
if(newline)
461+
do_print_char('\n');
462+
463+
return 0;
464+
}
465+
466+
U_BOOT_CMD(
467+
print, CONFIG_SYS_MAXARGS, 1, do_print,
468+
"Display text on the screen",
469+
"drawstr [-n] [--] <text>\n"
470+
"Draw text with '$print_color'."
471+
);

0 commit comments

Comments
 (0)