Blame view
common/lcd.c
17.6 KB
8655b6f86
|
1 |
/* |
c8d2febcc
|
2 |
* Common LCD routines |
8655b6f86
|
3 4 5 6 |
* * (C) Copyright 2001-2002 * Wolfgang Denk, DENX Software Engineering -- wd@denx.de * |
3765b3e7b
|
7 |
* SPDX-License-Identifier: GPL-2.0+ |
8655b6f86
|
8 |
*/ |
8655b6f86
|
9 |
/* #define DEBUG */ |
8655b6f86
|
10 11 12 |
#include <config.h> #include <common.h> #include <command.h> |
c08804853
|
13 |
#include <env_callback.h> |
8655b6f86
|
14 |
#include <linux/types.h> |
52cb4d4fb
|
15 |
#include <stdio_dev.h> |
8655b6f86
|
16 |
#include <lcd.h> |
0eb25b619
|
17 |
#include <mapmem.h> |
8b0bfc680
|
18 |
#include <watchdog.h> |
dca2a1c18
|
19 |
#include <asm/unaligned.h> |
dd4425e85
|
20 |
#include <splash.h> |
7d95f2a32
|
21 22 |
#include <asm/io.h> #include <asm/unaligned.h> |
c8d2febcc
|
23 |
#include <video_font.h> |
dd4425e85
|
24 |
|
88804d19e
|
25 |
#ifdef CONFIG_LCD_LOGO |
c8d2febcc
|
26 27 28 29 30 |
#include <bmp_logo.h> #include <bmp_logo_data.h> #if (CONSOLE_COLOR_WHITE >= BMP_LOGO_OFFSET) && (LCD_BPP != LCD_COLOR16) #error Default Color Map overlaps with Logo Color Map #endif |
88804d19e
|
31 |
#endif |
8655b6f86
|
32 |
|
676d319ef
|
33 34 35 |
#ifndef CONFIG_LCD_ALIGNMENT #define CONFIG_LCD_ALIGNMENT PAGE_SIZE #endif |
d87080b72
|
36 |
DECLARE_GLOBAL_DATA_PTR; |
8655b6f86
|
37 |
|
8f47d917c
|
38 |
static int lcd_init(void *lcdbase); |
7bf71d1f5
|
39 |
static void lcd_logo(void); |
8f47d917c
|
40 41 |
static void lcd_setfgcolor(int color); static void lcd_setbgcolor(int color); |
8655b6f86
|
42 |
|
46d1d5dd4
|
43 44 |
static int lcd_color_fg; static int lcd_color_bg; |
f1d205a19
|
45 |
int lcd_line_length; |
8655b6f86
|
46 |
char lcd_is_enabled = 0; |
00a0ca598
|
47 |
static void *lcd_base; /* Start of framebuffer memory */ |
9a8efc460
|
48 |
static char lcd_flush_dcache; /* 1 to flush dcache after each lcd update */ |
8655b6f86
|
49 |
|
9a8efc460
|
50 51 52 53 54 55 56 57 58 59 60 61 |
/* Flush LCD activity to the caches */ void lcd_sync(void) { /* * flush_dcache_range() is declared in common.h but it seems that some * architectures do not actually implement it. Is there a way to find * out whether it exists? For now, ARM is safe. */ #if defined(CONFIG_ARM) && !defined(CONFIG_SYS_DCACHE_OFF) int line_length; if (lcd_flush_dcache) |
f8f58fbb0
|
62 63 |
flush_dcache_range((ulong)lcd_base, (ulong)(lcd_base + lcd_get_size(&line_length))); |
9a8efc460
|
64 65 66 67 68 69 70 |
#endif } void lcd_set_flush_dcache(int flush) { lcd_flush_dcache = (flush != 0); } |
709ea543b
|
71 72 73 74 |
static void lcd_stub_putc(struct stdio_dev *dev, const char c) { lcd_putc(c); } |
709ea543b
|
75 76 77 78 |
static void lcd_stub_puts(struct stdio_dev *dev, const char *s) { lcd_puts(s); } |
c8d2febcc
|
79 |
/* Small utility to check that you got the colours right */ |
8655b6f86
|
80 |
#ifdef LCD_TEST_PATTERN |
e32951b52
|
81 |
#if LCD_BPP == LCD_COLOR8 |
8655b6f86
|
82 83 |
#define N_BLK_VERT 2 #define N_BLK_HOR 3 |
6b035141f
|
84 |
static int test_colors[N_BLK_HOR * N_BLK_VERT] = { |
8655b6f86
|
85 86 |
CONSOLE_COLOR_RED, CONSOLE_COLOR_GREEN, CONSOLE_COLOR_YELLOW, CONSOLE_COLOR_BLUE, CONSOLE_COLOR_MAGENTA, CONSOLE_COLOR_CYAN, |
e32951b52
|
87 88 89 90 91 92 93 94 95 |
}; /*LCD_BPP == LCD_COLOR8 */ #elif LCD_BPP == LCD_COLOR16 #define N_BLK_VERT 2 #define N_BLK_HOR 4 static int test_colors[N_BLK_HOR * N_BLK_VERT] = { CONSOLE_COLOR_RED, CONSOLE_COLOR_GREEN, CONSOLE_COLOR_YELLOW, CONSOLE_COLOR_BLUE, CONSOLE_COLOR_MAGENTA, CONSOLE_COLOR_CYAN, CONSOLE_COLOR_GREY, CONSOLE_COLOR_WHITE, |
8655b6f86
|
96 |
}; |
e32951b52
|
97 |
#endif /*LCD_BPP == LCD_COLOR16 */ |
8655b6f86
|
98 |
|
8f47d917c
|
99 |
static void test_pattern(void) |
8655b6f86
|
100 101 102 103 104 105 |
{ ushort v_max = panel_info.vl_row; ushort h_max = panel_info.vl_col; ushort v_step = (v_max + N_BLK_VERT - 1) / N_BLK_VERT; ushort h_step = (h_max + N_BLK_HOR - 1) / N_BLK_HOR; ushort v, h; |
e32951b52
|
106 |
#if LCD_BPP == LCD_COLOR8 |
8655b6f86
|
107 |
uchar *pix = (uchar *)lcd_base; |
e32951b52
|
108 109 110 |
#elif LCD_BPP == LCD_COLOR16 ushort *pix = (ushort *)lcd_base; #endif |
8655b6f86
|
111 |
|
8f47d917c
|
112 113 |
printf("[LCD] Test Pattern: %d x %d [%d x %d] ", |
8655b6f86
|
114 |
h_max, v_max, h_step, v_step); |
8f47d917c
|
115 |
for (v = 0; v < v_max; ++v) { |
8655b6f86
|
116 |
uchar iy = v / v_step; |
8f47d917c
|
117 |
for (h = 0; h < h_max; ++h) { |
6b035141f
|
118 |
uchar ix = N_BLK_HOR * iy + h / h_step; |
8655b6f86
|
119 120 121 122 123 |
*pix++ = test_colors[ix]; } } } #endif /* LCD_TEST_PATTERN */ |
cefa47171
|
124 125 126 127 128 129 130 |
/* * With most lcd drivers the line length is set up * by calculating it from panel_info parameters. Some * drivers need to calculate the line length differently, * so make the function weak to allow overriding it. */ __weak int lcd_get_size(int *line_length) |
676d319ef
|
131 132 133 134 |
{ *line_length = (panel_info.vl_col * NBITS(panel_info.vl_bpix)) / 8; return *line_length * panel_info.vl_row; } |
6b035141f
|
135 |
int drv_lcd_init(void) |
8655b6f86
|
136 |
{ |
52cb4d4fb
|
137 |
struct stdio_dev lcddev; |
8655b6f86
|
138 |
int rc; |
7d95f2a32
|
139 |
lcd_base = map_sysmem(gd->fb_base, 0); |
8655b6f86
|
140 |
|
c8d2febcc
|
141 |
lcd_init(lcd_base); |
8655b6f86
|
142 143 |
/* Device initialization */ |
8f47d917c
|
144 |
memset(&lcddev, 0, sizeof(lcddev)); |
8655b6f86
|
145 |
|
8f47d917c
|
146 |
strcpy(lcddev.name, "lcd"); |
8655b6f86
|
147 148 |
lcddev.ext = 0; /* No extensions */ lcddev.flags = DEV_FLAGS_OUTPUT; /* Output only */ |
709ea543b
|
149 150 |
lcddev.putc = lcd_stub_putc; /* 'putc' function */ lcddev.puts = lcd_stub_puts; /* 'puts' function */ |
8655b6f86
|
151 |
|
6b035141f
|
152 |
rc = stdio_register(&lcddev); |
8655b6f86
|
153 154 155 |
return (rc == 0) ? 1 : rc; } |
02110903a
|
156 |
void lcd_clear(void) |
8655b6f86
|
157 |
{ |
7bf71d1f5
|
158 159 160 |
char *s; ulong addr; static int do_splash = 1; |
21bf1c38b
|
161 162 163 164 165 |
#if LCD_BPP == LCD_MONOCHROME /* Setting the palette */ lcd_initcolregs(); #elif LCD_BPP == LCD_COLOR8 |
8655b6f86
|
166 |
/* Setting the palette */ |
8f47d917c
|
167 168 169 170 171 172 173 174 175 |
lcd_setcolreg(CONSOLE_COLOR_BLACK, 0, 0, 0); lcd_setcolreg(CONSOLE_COLOR_RED, 0xFF, 0, 0); lcd_setcolreg(CONSOLE_COLOR_GREEN, 0, 0xFF, 0); lcd_setcolreg(CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0); lcd_setcolreg(CONSOLE_COLOR_BLUE, 0, 0, 0xFF); lcd_setcolreg(CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF); lcd_setcolreg(CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF); lcd_setcolreg(CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA); lcd_setcolreg(CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF); |
8655b6f86
|
176 |
#endif |
6d0f6bcf3
|
177 |
#ifndef CONFIG_SYS_WHITE_ON_BLACK |
8f47d917c
|
178 179 |
lcd_setfgcolor(CONSOLE_COLOR_BLACK); lcd_setbgcolor(CONSOLE_COLOR_WHITE); |
8655b6f86
|
180 |
#else |
8f47d917c
|
181 182 |
lcd_setfgcolor(CONSOLE_COLOR_WHITE); lcd_setbgcolor(CONSOLE_COLOR_BLACK); |
6d0f6bcf3
|
183 |
#endif /* CONFIG_SYS_WHITE_ON_BLACK */ |
8655b6f86
|
184 185 186 187 188 |
#ifdef LCD_TEST_PATTERN test_pattern(); #else /* set framebuffer to background color */ |
57d76a89b
|
189 |
#if (LCD_BPP != LCD_COLOR32) |
21bf1c38b
|
190 191 |
memset((char *)lcd_base, COLOR_MASK(lcd_getbgcolor()), lcd_line_length * panel_info.vl_row); |
57d76a89b
|
192 193 194 195 196 197 |
#else u32 *ppix = lcd_base; u32 i; for (i = 0; i < (lcd_line_length * panel_info.vl_row)/NBYTES(panel_info.vl_bpix); i++) { |
21bf1c38b
|
198 |
*ppix++ = COLOR_MASK(lcd_getbgcolor()); |
57d76a89b
|
199 200 |
} #endif |
8655b6f86
|
201 |
#endif |
604c7d4a5
|
202 203 204 205 206 207 208 |
/* setup text-console */ debug("[LCD] setting up console... "); lcd_init_console(lcd_base, panel_info.vl_col, panel_info.vl_row, panel_info.vl_rot); |
8655b6f86
|
209 |
/* Paint the logo and retrieve LCD base address */ |
8f47d917c
|
210 211 |
debug("[LCD] Drawing the logo... "); |
7bf71d1f5
|
212 |
if (do_splash) { |
00caae6d4
|
213 |
s = env_get("splashimage"); |
7bf71d1f5
|
214 215 216 217 218 219 220 221 222 223 224 225 226 |
if (s) { do_splash = 0; addr = simple_strtoul(s, NULL, 16); if (lcd_splash(addr) == 0) { lcd_sync(); return; } } } lcd_logo(); #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO) addr = (ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length; |
3b96b9096
|
227 228 |
lcd_init_console((void *)addr, panel_info.vl_col, panel_info.vl_row, panel_info.vl_rot); |
7bf71d1f5
|
229 |
#endif |
9a8efc460
|
230 231 232 233 234 235 236 237 |
lcd_sync(); } static int do_lcd_clear(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) { lcd_clear(); return 0; |
8655b6f86
|
238 |
} |
c8d2febcc
|
239 |
U_BOOT_CMD(cls, 1, 1, do_lcd_clear, "clear screen", ""); |
8655b6f86
|
240 |
|
8f47d917c
|
241 |
static int lcd_init(void *lcdbase) |
8655b6f86
|
242 |
{ |
8f47d917c
|
243 244 |
debug("[LCD] Initializing LCD frambuffer at %p ", lcdbase); |
8f47d917c
|
245 |
lcd_ctrl_init(lcdbase); |
1d3dea12e
|
246 247 |
/* |
9316e1440
|
248 |
* lcd_ctrl_init() of some drivers (i.e. bcm2835 on rpi) ignores |
1d3dea12e
|
249 250 251 252 |
* the 'lcdbase' argument and uses custom lcd base address * by setting up gd->fb_base. Check for this condition and fixup * 'lcd_base' address. */ |
7d95f2a32
|
253 254 |
if (map_to_sysmem(lcdbase) != gd->fb_base) lcd_base = map_sysmem(gd->fb_base, 0); |
1d3dea12e
|
255 256 257 |
debug("[LCD] Using LCD frambuffer at %p ", lcd_base); |
6d3307195
|
258 |
lcd_get_size(&lcd_line_length); |
6f93d2b8f
|
259 |
lcd_is_enabled = 1; |
02110903a
|
260 |
lcd_clear(); |
6b035141f
|
261 |
lcd_enable(); |
8655b6f86
|
262 263 |
/* Initialize the console */ |
140beb943
|
264 |
lcd_set_col(0); |
88804d19e
|
265 |
#ifdef CONFIG_LCD_INFO_BELOW_LOGO |
140beb943
|
266 |
lcd_set_row(7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT); |
8655b6f86
|
267 |
#else |
140beb943
|
268 |
lcd_set_row(1); /* leave 1 blank line below logo */ |
8655b6f86
|
269 |
#endif |
8655b6f86
|
270 271 272 |
return 0; } |
8655b6f86
|
273 274 275 276 277 278 279 |
/* * This is called early in the system initialization to grab memory * for the LCD controller. * Returns new address for monitor, after reserving LCD buffer memory * * Note that this is running from ROM, so no write access to global data. */ |
8f47d917c
|
280 |
ulong lcd_setmem(ulong addr) |
8655b6f86
|
281 282 |
{ ulong size; |
676d319ef
|
283 |
int line_length; |
8655b6f86
|
284 |
|
d855bc0b7
|
285 286 |
debug("LCD panel info: %lu x %lu, %d bit/pix ", panel_info.vl_col, |
8f47d917c
|
287 |
panel_info.vl_row, NBITS(panel_info.vl_bpix)); |
8655b6f86
|
288 |
|
676d319ef
|
289 |
size = lcd_get_size(&line_length); |
8655b6f86
|
290 |
|
676d319ef
|
291 292 293 |
/* Round up to nearest full page, or MMU section if defined */ size = ALIGN(size, CONFIG_LCD_ALIGNMENT); addr = ALIGN(addr - CONFIG_LCD_ALIGNMENT + 1, CONFIG_LCD_ALIGNMENT); |
8655b6f86
|
294 295 296 |
/* Allocate pages for the frame buffer. */ addr -= size; |
6b035141f
|
297 298 299 |
debug("Reserving %ldk for LCD Framebuffer at: %08lx ", size >> 10, addr); |
8655b6f86
|
300 |
|
8f47d917c
|
301 |
return addr; |
8655b6f86
|
302 |
} |
8f47d917c
|
303 |
static void lcd_setfgcolor(int color) |
8655b6f86
|
304 |
{ |
39cf48048
|
305 |
lcd_color_fg = color; |
8655b6f86
|
306 |
} |
4d03634e5
|
307 308 309 310 |
int lcd_getfgcolor(void) { return lcd_color_fg; } |
8f47d917c
|
311 |
static void lcd_setbgcolor(int color) |
8655b6f86
|
312 |
{ |
39cf48048
|
313 |
lcd_color_bg = color; |
8655b6f86
|
314 |
} |
4d03634e5
|
315 316 317 318 |
int lcd_getbgcolor(void) { return lcd_color_bg; } |
8655b6f86
|
319 |
#ifdef CONFIG_LCD_LOGO |
a02e94813
|
320 321 |
__weak void lcd_logo_set_cmap(void) { |
2306457c4
|
322 323 324 325 326 |
int i; ushort *cmap = configuration_get_cmap(); for (i = 0; i < ARRAY_SIZE(bmp_logo_palette); ++i) *cmap++ = bmp_logo_palette[i]; |
a02e94813
|
327 |
} |
bf21a5deb
|
328 |
void lcd_logo_plot(int x, int y) |
8655b6f86
|
329 |
{ |
8655b6f86
|
330 |
ushort i, j; |
c8d2febcc
|
331 |
uchar *bmap = &bmp_logo_bitmap[0]; |
317461c1d
|
332 |
unsigned bpix = NBITS(panel_info.vl_bpix); |
c8d2febcc
|
333 334 |
uchar *fb = (uchar *)(lcd_base + y * lcd_line_length + x * bpix / 8); ushort *fb16; |
8655b6f86
|
335 |
|
2306457c4
|
336 337 338 |
debug("Logo: width %d height %d colors %d ", BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS); |
8655b6f86
|
339 |
|
317461c1d
|
340 |
if (bpix < 12) { |
8655b6f86
|
341 |
WATCHDOG_RESET(); |
a02e94813
|
342 |
lcd_logo_set_cmap(); |
8655b6f86
|
343 |
WATCHDOG_RESET(); |
8f47d917c
|
344 345 |
for (i = 0; i < BMP_LOGO_HEIGHT; ++i) { memcpy(fb, bmap, BMP_LOGO_WIDTH); |
8655b6f86
|
346 |
bmap += BMP_LOGO_WIDTH; |
6b035141f
|
347 |
fb += panel_info.vl_col; |
8655b6f86
|
348 349 350 |
} } else { /* true color mode */ |
acb138689
|
351 |
u16 col16; |
317461c1d
|
352 |
fb16 = (ushort *)fb; |
8f47d917c
|
353 354 |
for (i = 0; i < BMP_LOGO_HEIGHT; ++i) { for (j = 0; j < BMP_LOGO_WIDTH; j++) { |
acb138689
|
355 356 357 358 359 |
col16 = bmp_logo_palette[(bmap[j]-16)]; fb16[j] = ((col16 & 0x000F) << 1) | ((col16 & 0x00F0) << 3) | ((col16 & 0x0F00) << 4); |
8655b6f86
|
360 361 362 363 364 365 366 |
} bmap += BMP_LOGO_WIDTH; fb16 += panel_info.vl_col; } } WATCHDOG_RESET(); |
9a8efc460
|
367 |
lcd_sync(); |
8655b6f86
|
368 |
} |
2b5cb3d33
|
369 |
#else |
bf21a5deb
|
370 |
static inline void lcd_logo_plot(int x, int y) {} |
8655b6f86
|
371 |
#endif /* CONFIG_LCD_LOGO */ |
c3517f919
|
372 |
#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN) |
1ca298ced
|
373 374 |
#ifdef CONFIG_SPLASH_SCREEN_ALIGN #define BMP_ALIGN_CENTER 0x7FFF |
7c7e280aa
|
375 376 377 378 379 380 381 382 383 384 385 386 387 |
static void splash_align_axis(int *axis, unsigned long panel_size, unsigned long picture_size) { unsigned long panel_picture_delta = panel_size - picture_size; unsigned long axis_alignment; if (*axis == BMP_ALIGN_CENTER) axis_alignment = panel_picture_delta / 2; else if (*axis < 0) axis_alignment = panel_picture_delta + *axis + 1; else return; |
b41411954
|
388 |
*axis = max(0, (int)axis_alignment); |
7c7e280aa
|
389 |
} |
1ca298ced
|
390 |
#endif |
45d7f5251
|
391 |
#ifdef CONFIG_LCD_BMP_RLE8 |
45d7f5251
|
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 |
#define BMP_RLE8_ESCAPE 0 #define BMP_RLE8_EOL 0 #define BMP_RLE8_EOBMP 1 #define BMP_RLE8_DELTA 2 static void draw_unencoded_bitmap(ushort **fbp, uchar *bmap, ushort *cmap, int cnt) { while (cnt > 0) { *(*fbp)++ = cmap[*bmap++]; cnt--; } } static void draw_encoded_bitmap(ushort **fbp, ushort c, int cnt) { ushort *fb = *fbp; int cnt_8copy = cnt >> 3; cnt -= cnt_8copy << 3; while (cnt_8copy > 0) { *fb++ = c; *fb++ = c; *fb++ = c; *fb++ = c; *fb++ = c; *fb++ = c; *fb++ = c; *fb++ = c; cnt_8copy--; } while (cnt > 0) { *fb++ = c; cnt--; } |
6b035141f
|
427 |
*fbp = fb; |
45d7f5251
|
428 429 430 |
} /* |
6b035141f
|
431 |
* Do not call this function directly, must be called from lcd_display_bitmap. |
45d7f5251
|
432 |
*/ |
1c3dbe56f
|
433 434 |
static void lcd_display_rle8_bitmap(struct bmp_image *bmp, ushort *cmap, uchar *fb, int x_off, int y_off) |
45d7f5251
|
435 436 437 438 439 440 |
{ uchar *bmap; ulong width, height; ulong cnt, runlen; int x, y; int decode = 1; |
dca2a1c18
|
441 442 443 |
width = get_unaligned_le32(&bmp->header.width); height = get_unaligned_le32(&bmp->header.height); bmap = (uchar *)bmp + get_unaligned_le32(&bmp->header.data_offset); |
45d7f5251
|
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 |
x = 0; y = height - 1; while (decode) { if (bmap[0] == BMP_RLE8_ESCAPE) { switch (bmap[1]) { case BMP_RLE8_EOL: /* end of line */ bmap += 2; x = 0; y--; /* 16bpix, 2-byte per pixel, width should *2 */ fb -= (width * 2 + lcd_line_length); break; case BMP_RLE8_EOBMP: /* end of bitmap */ decode = 0; break; case BMP_RLE8_DELTA: /* delta run */ x += bmap[2]; y -= bmap[3]; /* 16bpix, 2-byte per pixel, x should *2 */ fb = (uchar *) (lcd_base + (y + y_off - 1) * lcd_line_length + (x + x_off) * 2); bmap += 4; break; default: /* unencoded run */ runlen = bmap[1]; bmap += 2; if (y < height) { if (x < width) { if (x + runlen > width) cnt = width - x; else cnt = runlen; draw_unencoded_bitmap( (ushort **)&fb, bmap, cmap, cnt); } x += runlen; } bmap += runlen; if (runlen & 1) bmap++; } } else { /* encoded run */ if (y < height) { runlen = bmap[0]; if (x < width) { /* aggregate the same code */ while (bmap[0] == 0xff && bmap[2] != BMP_RLE8_ESCAPE && bmap[1] == bmap[3]) { runlen += bmap[2]; bmap += 2; } if (x + runlen > width) cnt = width - x; else cnt = runlen; draw_encoded_bitmap((ushort **)&fb, cmap[bmap[1]], cnt); } x += runlen; } bmap += 2; } } } #endif |
27fad01b7
|
518 519 520 521 |
__weak void fb_put_byte(uchar **fb, uchar **from) { *(*fb)++ = *(*from)++; } |
bfdcc65e1
|
522 523 |
#if defined(CONFIG_BMP_16BPP) |
b3d12e9bc
|
524 |
__weak void fb_put_word(uchar **fb, uchar **from) |
bfdcc65e1
|
525 526 527 528 |
{ *(*fb)++ = *(*from)++; *(*fb)++ = *(*from)++; } |
bfdcc65e1
|
529 |
#endif /* CONFIG_BMP_16BPP */ |
1c3dbe56f
|
530 |
__weak void lcd_set_cmap(struct bmp_image *bmp, unsigned colors) |
0b29a8969
|
531 532 |
{ int i; |
1c3dbe56f
|
533 |
struct bmp_color_table_entry cte; |
0b29a8969
|
534 535 536 537 538 539 540 |
ushort *cmap = configuration_get_cmap(); for (i = 0; i < colors; ++i) { cte = bmp->color_table[i]; *cmap = (((cte.red) << 8) & 0xf800) | (((cte.green) << 3) & 0x07e0) | (((cte.blue) >> 3) & 0x001f); |
0b29a8969
|
541 |
cmap++; |
0b29a8969
|
542 543 |
} } |
8655b6f86
|
544 545 |
int lcd_display_bitmap(ulong bmp_image, int x, int y) { |
00cc5595a
|
546 |
ushort *cmap_base = NULL; |
8655b6f86
|
547 548 |
ushort i, j; uchar *fb; |
1c3dbe56f
|
549 |
struct bmp_image *bmp = (struct bmp_image *)map_sysmem(bmp_image, 0); |
8655b6f86
|
550 |
uchar *bmap; |
fecac46cf
|
551 |
ushort padded_width; |
b245e65ee
|
552 |
unsigned long width, height, byte_width; |
e8143e72e
|
553 |
unsigned long pwidth = panel_info.vl_col; |
b245e65ee
|
554 |
unsigned colors, bpix, bmp_bpix; |
8d379f179
|
555 |
int hdr_size; |
021414a33
|
556 |
struct bmp_color_table_entry *palette; |
8655b6f86
|
557 |
|
6b035141f
|
558 559 |
if (!bmp || !(bmp->header.signature[0] == 'B' && bmp->header.signature[1] == 'M')) { |
8f47d917c
|
560 561 |
printf("Error: no valid bmp image at %lx ", bmp_image); |
8655b6f86
|
562 |
return 1; |
b245e65ee
|
563 |
} |
8655b6f86
|
564 |
|
021414a33
|
565 |
palette = bmp->color_table; |
dca2a1c18
|
566 567 568 |
width = get_unaligned_le32(&bmp->header.width); height = get_unaligned_le32(&bmp->header.height); bmp_bpix = get_unaligned_le16(&bmp->header.bit_count); |
8d379f179
|
569 570 571 |
hdr_size = get_unaligned_le16(&bmp->header.size); debug("hdr_size=%d, bmp_bpix=%d ", hdr_size, bmp_bpix); |
dca2a1c18
|
572 |
|
b245e65ee
|
573 |
colors = 1 << bmp_bpix; |
8655b6f86
|
574 575 |
bpix = NBITS(panel_info.vl_bpix); |
6b035141f
|
576 |
if (bpix != 1 && bpix != 8 && bpix != 16 && bpix != 32) { |
b245e65ee
|
577 578 579 |
printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel ", bpix, bmp_bpix); |
8f47d917c
|
580 |
|
8655b6f86
|
581 582 |
return 1; } |
a305fb155
|
583 584 585 586 587 588 589 |
/* * We support displaying 8bpp BMPs on 16bpp LCDs * and displaying 24bpp BMPs on 32bpp LCDs * */ if (bpix != bmp_bpix && !(bmp_bpix == 8 && bpix == 16) && !(bmp_bpix == 24 && bpix == 32)) { |
8655b6f86
|
590 591 |
printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel ", |
dca2a1c18
|
592 |
bpix, get_unaligned_le16(&bmp->header.bit_count)); |
8655b6f86
|
593 594 |
return 1; } |
8d379f179
|
595 596 597 |
debug("Display-bmp: %d x %d with %d colors, display %d ", (int)width, (int)height, (int)colors, 1 << bpix); |
8655b6f86
|
598 |
|
0b29a8969
|
599 600 |
if (bmp_bpix == 8) lcd_set_cmap(bmp, colors); |
e8143e72e
|
601 |
|
6b035141f
|
602 |
padded_width = (width & 0x3 ? (width & ~0x3) + 4 : width); |
1ca298ced
|
603 604 |
#ifdef CONFIG_SPLASH_SCREEN_ALIGN |
7c7e280aa
|
605 606 |
splash_align_axis(&x, pwidth, width); splash_align_axis(&y, panel_info.vl_row, height); |
1ca298ced
|
607 |
#endif /* CONFIG_SPLASH_SCREEN_ALIGN */ |
8f47d917c
|
608 |
if ((x + width) > pwidth) |
e8143e72e
|
609 |
width = pwidth - x; |
8f47d917c
|
610 |
if ((y + height) > panel_info.vl_row) |
8655b6f86
|
611 |
height = panel_info.vl_row - y; |
dca2a1c18
|
612 613 |
bmap = (uchar *)bmp + get_unaligned_le32(&bmp->header.data_offset); fb = (uchar *)(lcd_base + |
8d46d5b18
|
614 |
(y + height - 1) * lcd_line_length + x * bpix / 8); |
a303dfb0e
|
615 |
|
b245e65ee
|
616 |
switch (bmp_bpix) { |
c8d2febcc
|
617 |
case 1: |
0156444cf
|
618 |
case 8: { |
0b29a8969
|
619 |
cmap_base = configuration_get_cmap(); |
45d7f5251
|
620 |
#ifdef CONFIG_LCD_BMP_RLE8 |
dca2a1c18
|
621 |
u32 compression = get_unaligned_le32(&bmp->header.compression); |
8d379f179
|
622 623 |
debug("compressed %d %d ", compression, BMP_BI_RLE8); |
dca2a1c18
|
624 |
if (compression == BMP_BI_RLE8) { |
45d7f5251
|
625 626 627 628 629 630 631 632 633 |
if (bpix != 16) { /* TODO implement render code for bpix != 16 */ printf("Error: only support 16 bpix"); return 1; } lcd_display_rle8_bitmap(bmp, cmap_base, fb, x, y); break; } #endif |
b245e65ee
|
634 635 636 637 |
if (bpix != 16) byte_width = width; else byte_width = width * 2; |
a303dfb0e
|
638 639 |
for (i = 0; i < height; ++i) { WATCHDOG_RESET(); |
b245e65ee
|
640 641 |
for (j = 0; j < width; j++) { if (bpix != 16) { |
27fad01b7
|
642 |
fb_put_byte(&fb, &bmap); |
b245e65ee
|
643 |
} else { |
8d379f179
|
644 645 646 647 648 649 650 651 652 653 654 655 656 |
struct bmp_color_table_entry *entry; uint val; if (cmap_base) { val = cmap_base[*bmap]; } else { entry = &palette[*bmap]; val = entry->blue >> 3 | entry->green >> 2 << 5 | entry->red >> 3 << 11; } *(uint16_t *)fb = val; bmap++; |
b245e65ee
|
657 658 659 |
fb += sizeof(uint16_t) / sizeof(*fb); } } |
fecac46cf
|
660 |
bmap += (padded_width - width); |
6b035141f
|
661 |
fb -= byte_width + lcd_line_length; |
a303dfb0e
|
662 663 |
} break; |
0156444cf
|
664 |
} |
a303dfb0e
|
665 666 667 668 |
#if defined(CONFIG_BMP_16BPP) case 16: for (i = 0; i < height; ++i) { WATCHDOG_RESET(); |
bfdcc65e1
|
669 670 |
for (j = 0; j < width; j++) fb_put_word(&fb, &bmap); |
fecac46cf
|
671 |
bmap += (padded_width - width) * 2; |
6b035141f
|
672 |
fb -= width * 2 + lcd_line_length; |
a303dfb0e
|
673 674 675 |
} break; #endif /* CONFIG_BMP_16BPP */ |
10ba6b333
|
676 |
#if defined(CONFIG_BMP_24BPP) |
a305fb155
|
677 678 679 680 681 682 683 684 685 686 687 |
case 24: for (i = 0; i < height; ++i) { for (j = 0; j < width; j++) { *(fb++) = *(bmap++); *(fb++) = *(bmap++); *(fb++) = *(bmap++); *(fb++) = 0; } fb -= lcd_line_length + width * (bpix / 8); } break; |
10ba6b333
|
688 |
#endif /* CONFIG_BMP_24BPP */ |
fb6a9aab7
|
689 690 691 692 693 694 695 696 697 |
#if defined(CONFIG_BMP_32BPP) case 32: for (i = 0; i < height; ++i) { for (j = 0; j < width; j++) { *(fb++) = *(bmap++); *(fb++) = *(bmap++); *(fb++) = *(bmap++); *(fb++) = *(bmap++); } |
6b035141f
|
698 |
fb -= lcd_line_length + width * (bpix / 8); |
fb6a9aab7
|
699 700 701 |
} break; #endif /* CONFIG_BMP_32BPP */ |
a303dfb0e
|
702 703 704 |
default: break; }; |
8655b6f86
|
705 |
|
9a8efc460
|
706 |
lcd_sync(); |
8f47d917c
|
707 |
return 0; |
8655b6f86
|
708 |
} |
c3517f919
|
709 |
#endif |
8655b6f86
|
710 |
|
7bf71d1f5
|
711 |
static void lcd_logo(void) |
8655b6f86
|
712 |
{ |
bf21a5deb
|
713 |
lcd_logo_plot(0, 0); |
8655b6f86
|
714 |
|
6b59e03e0
|
715 |
#ifdef CONFIG_LCD_INFO |
140beb943
|
716 717 |
lcd_set_col(LCD_INFO_X / VIDEO_FONT_WIDTH); lcd_set_row(LCD_INFO_Y / VIDEO_FONT_HEIGHT); |
6b59e03e0
|
718 719 |
lcd_show_board_info(); #endif /* CONFIG_LCD_INFO */ |
8655b6f86
|
720 |
} |
c08804853
|
721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 |
#ifdef CONFIG_SPLASHIMAGE_GUARD static int on_splashimage(const char *name, const char *value, enum env_op op, int flags) { ulong addr; int aligned; if (op == env_op_delete) return 0; addr = simple_strtoul(value, NULL, 16); /* See README.displaying-bmps */ aligned = (addr % 4 == 2); if (!aligned) { printf("Invalid splashimage value. Value must be 16 bit aligned, but not 32 bit aligned "); return -1; } return 0; } U_BOOT_ENV_CALLBACK(splashimage, on_splashimage); #endif |
395166cff
|
745 746 747 748 749 750 751 752 753 |
int lcd_get_pixel_width(void) { return panel_info.vl_col; } int lcd_get_pixel_height(void) { return panel_info.vl_row; } |