From 0b4c70381368c32298b24460b4cb6029a164d536 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Sun, 28 Jan 2018 13:47:03 +0100 Subject: [PATCH] bootloader: update booting ui --- embed/bootloader/bootui.c | 51 +++++++++++++++++++++++---------------- embed/bootloader/main.c | 10 +++++--- 2 files changed, 37 insertions(+), 24 deletions(-) diff --git a/embed/bootloader/bootui.c b/embed/bootloader/bootui.c index 9e26cdc4..c922171c 100644 --- a/embed/bootloader/bootui.c +++ b/embed/bootloader/bootui.c @@ -50,39 +50,48 @@ static const char *format_ver(const char *format, uint32_t version) // boot UI -void ui_screen_boot(const vendor_header *vhdr, const image_header *hdr) -{ - const uint8_t *vimg = vhdr->vimg; - const char *vstr = ((vhdr->vtrust & VTRUST_STRING) == 0) ? vhdr->vstr : 0; - const uint32_t vstr_len = ((vhdr->vtrust & VTRUST_STRING) == 0) ? vhdr->vstr_len : 0; - const uint32_t fw_version = hdr->version; - const uint16_t background = ((vhdr->vtrust & VTRUST_RED) == 0) ? RGB16(0xFF, 0x00, 0x00) : COLOR_BLACK; +static uint16_t boot_background; + +void ui_screen_boot(const vendor_header * const vhdr, const image_header * const hdr) +{ + const int show_string = ((vhdr->vtrust & VTRUST_STRING) == 0); + if ((vhdr->vtrust & VTRUST_RED) == 0) { + boot_background = COLOR_BL_FAIL; + } else { + boot_background = COLOR_BLACK; + } + + const uint8_t *vimg = vhdr->vimg; + const uint32_t fw_version = hdr->version; + + display_bar(0, 0, DISPLAY_RESX, DISPLAY_RESY, boot_background); + + int image_top = show_string ? 30 : (DISPLAY_RESY - 120) / 2; - display_bar(0, 0, DISPLAY_RESX, DISPLAY_RESY, background); // check whether vendor image is 120x120 - if (memcmp(vimg, "TOIf\x78\x00\x78\x00", 4) != 0) { - return; + if (memcmp(vimg, "TOIf\x78\x00\x78\x00", 4) == 0) { + uint32_t datalen = *(uint32_t *)(vimg + 8); + display_image((DISPLAY_RESX - 120) / 2, image_top, 120, 120, vimg + 12, datalen); } - uint32_t datalen = *(uint32_t *)(vimg + 8); - display_image((DISPLAY_RESX - 120) / 2, 32, 120, 120, vimg + 12, datalen); - if (vstr && vstr_len) { - display_text_center(DISPLAY_RESX / 2, DISPLAY_RESY - 48, vstr, vstr_len, FONT_NORMAL, COLOR_WHITE, background, 0); + + if (show_string) { + display_text_center(DISPLAY_RESX / 2, DISPLAY_RESY - 5 - 50, vhdr->vstr, vhdr->vstr_len, FONT_NORMAL, COLOR_WHITE, boot_background, 0); + const char *ver_str = format_ver("%d.%d.%d.%d", fw_version); + display_text_center(DISPLAY_RESX / 2, DISPLAY_RESY - 5 - 25, ver_str, -1, FONT_NORMAL, COLOR_WHITE, boot_background, 0); } - const char *ver_str = format_ver("%d.%d.%d.%d", fw_version); - display_text_center(DISPLAY_RESX / 2, DISPLAY_RESY - 25, ver_str, -1, FONT_NORMAL, COLOR_BL_GRAY, background, 0); } void ui_screen_boot_wait(int wait_seconds) { char wait_str[16]; - mini_snprintf(wait_str, sizeof(wait_str), "waiting for %ds", wait_seconds); - display_bar(0, DISPLAY_RESY - 2 - 18, DISPLAY_RESX, 2 + 18, COLOR_BLACK); - display_text_center(DISPLAY_RESX / 2, DISPLAY_RESY - 2, wait_str, -1, FONT_NORMAL, COLOR_BL_GRAY, COLOR_BLACK, 0); + mini_snprintf(wait_str, sizeof(wait_str), "starting in %d s", wait_seconds); + display_bar(0, DISPLAY_RESY - 5 - 20, DISPLAY_RESX, 5 + 20, boot_background); + display_text_center(DISPLAY_RESX / 2, DISPLAY_RESY - 5, wait_str, -1, FONT_NORMAL, COLOR_WHITE, boot_background, 0); } void ui_screen_boot_click(void) { - display_bar(0, DISPLAY_RESY - 2 - 18, DISPLAY_RESX, 2 + 18, COLOR_BLACK); - display_text_center(DISPLAY_RESX / 2, DISPLAY_RESY - 2, "click to continue ...", -1, FONT_NORMAL, COLOR_BL_GRAY, COLOR_BLACK, 0); + display_bar(0, DISPLAY_RESY - 5 - 20, DISPLAY_RESX, 5 + 20, boot_background); + display_text_center(DISPLAY_RESX / 2, DISPLAY_RESY - 5, "click to continue ...", -1, FONT_NORMAL, COLOR_WHITE, boot_background, 0); } // welcome UI diff --git a/embed/bootloader/main.c b/embed/bootloader/main.c index 0adea4bd..f733b1a4 100644 --- a/embed/bootloader/main.c +++ b/embed/bootloader/main.c @@ -361,10 +361,14 @@ main_start: ui_fadein(); int delay = (vhdr.vtrust & VTRUST_WAIT) ^ VTRUST_WAIT; - while (delay > 0) { - ui_screen_boot_wait(delay); + if (delay > 1) { + while (delay > 0) { + ui_screen_boot_wait(delay); + hal_delay(1000); + delay--; + } + } else if (delay == 1) { hal_delay(1000); - delay--; } if ((vhdr.vtrust & VTRUST_CLICK) == 0) {