Skip to content
Snippets Groups Projects
Verified Commit 384fcfb1 authored by rahix's avatar rahix
Browse files

refactor(bootloader): Factor out display code into separate file


Signed-off-by: default avatarRahix <rahix@rahix.de>
parent cbff1426
No related branches found
No related tags found
No related merge requests found
#include "bootloader.h"
#include "GUI_Paint.h"
#include "display.h"
/*
* Initialize the display.
*/
void bootloader_display_init(void)
{
;
}
/*
* Show the bootloader version on the display.
*/
void bootloader_display_header(void)
{
Paint_Clear(0x0000);
Paint_DrawString_EN(0, 16 * 0, "Bootloader", &Font16, 0x0000, 0xffff);
Paint_DrawString_EN(0, 16 * 1, __DATE__, &Font16, 0x0000, 0xffff);
LCD_Update();
}
/*
* Display a line of text on the display.
*/
void bootloader_display_line(int line, char *string, uint16_t color)
{
Paint_DrawString_EN(0, 16 * line, string, &Font16, 0x0000, color);
LCD_Update();
}
...@@ -41,8 +41,6 @@ ...@@ -41,8 +41,6 @@
#include "bootloader.h" #include "bootloader.h"
#include "descriptors.h" #include "descriptors.h"
#include "display.h"
#include "GUI_Paint.h"
#include "card10.h" #include "card10.h"
#include "led.h" #include "led.h"
...@@ -125,14 +123,12 @@ void bootloader_stop(void) ...@@ -125,14 +123,12 @@ void bootloader_stop(void)
void bootloader_dirty(void) void bootloader_dirty(void)
{ {
Paint_DrawString_EN(0, 16 * 3, "Writing.", &Font16, 0x0000, 0xf000); bootloader_display_line(3, "Writing.", 0xf000);
LCD_Update();
} }
void bootloader_clean(void) void bootloader_clean(void)
{ {
Paint_DrawString_EN(0, 16 * 3, "Ready. ", &Font16, 0x0000, 0xffff); bootloader_display_line(3, "Ready. ", 0xffff);
LCD_Update();
} }
/******************************************************************************/ /******************************************************************************/
......
#pragma once #pragma once
void run_usbmsc(void); #include <stdint.h>
/* Display */
void bootloader_display_init(void);
void bootloader_display_header(void);
void bootloader_display_line(int line, char *string, uint16_t color);
/* USB */
void run_usbmsc(void);
void bootloader_stop(void); void bootloader_stop(void);
void bootloader_dirty(void); void bootloader_dirty(void);
void bootloader_clean(void); void bootloader_clean(void);
#include "bootloader.h" #include "bootloader.h"
#include "GUI_Paint.h"
#include "card10.h" #include "card10.h"
#include "display.h"
#include "led.h" #include "led.h"
#include "pb.h" #include "pb.h"
#include "pmic.h" #include "pmic.h"
...@@ -60,16 +58,7 @@ bool check_integrity(void) ...@@ -60,16 +58,7 @@ bool check_integrity(void)
res = f_open(&file, filename, FA_OPEN_EXISTING | FA_READ); res = f_open(&file, filename, FA_OPEN_EXISTING | FA_READ);
if (res != FR_OK) { if (res != FR_OK) {
Paint_DrawString_EN( bootloader_display_line(2, "card10.bin not found", 0xffff);
0,
16 * 2,
"card10.bin not found",
&Font16,
0x0000,
0xffff
);
LCD_Update();
printf("f_open error %d\n", res); printf("f_open error %d\n", res);
return false; return false;
} }
...@@ -90,15 +79,7 @@ bool check_integrity(void) ...@@ -90,15 +79,7 @@ bool check_integrity(void)
if (crcval == 0) { if (crcval == 0) {
return true; return true;
} else { } else {
Paint_DrawString_EN( bootloader_display_line(2, "Integrity check failed", 0xffff);
0,
16 * 2,
"Integrity check failed",
&Font16,
0x0000,
0xffff
);
LCD_Update();
printf("CRC check failed. Final CRC: %d\n", crcval); printf("CRC check failed. Final CRC: %d\n", crcval);
return false; return false;
} }
...@@ -225,20 +206,12 @@ int main(void) ...@@ -225,20 +206,12 @@ int main(void)
*/ */
pmic_set_button_callback(pmic_button); pmic_set_button_callback(pmic_button);
Paint_DrawString_EN(0, 16 * 0, "Bootloader", &Font16, 0x0000, 0xffff); bootloader_display_header();
Paint_DrawString_EN(0, 16 * 1, __DATE__, &Font16, 0x0000, 0xffff);
LCD_Update();
// If the button is pressed, we go into MSC mode. // If the button is pressed, we go into MSC mode.
if (PB_Get(3)) { if (PB_Get(3)) {
Paint_DrawString_EN( bootloader_display_line(2, "USB activated.", 0xffff);
0, 16 * 2, "USB activated.", &Font16, 0x0000, 0xffff bootloader_display_line(3, "Ready.", 0xffff);
);
Paint_DrawString_EN(
0, 16 * 3, "Ready.", &Font16, 0x0000, 0xffff
);
LCD_Update();
run_usbmsc(); run_usbmsc();
// If we return, don't try to boot. Maybe rather trigger a software reset. // If we return, don't try to boot. Maybe rather trigger a software reset.
...@@ -252,16 +225,10 @@ int main(void) ...@@ -252,16 +225,10 @@ int main(void)
if (check_integrity()) { if (check_integrity()) {
printf("Found valid application image\n"); printf("Found valid application image\n");
if (is_update_needed()) { if (is_update_needed()) {
printf("Trying to update application from external flash\n"); printf("Trying to update firmware from external flash\n");
Paint_DrawString_EN( bootloader_display_line(
0, 4, "Updating ...", 0xffff
16 * 4,
"Updating...",
&Font16,
0x0000,
0xffff
); );
LCD_Update();
erase_partition(); erase_partition();
flash_partition(); flash_partition();
} else { } else {
...@@ -271,25 +238,15 @@ int main(void) ...@@ -271,25 +238,15 @@ int main(void)
printf("Integrity check failed\n"); printf("Integrity check failed\n");
} }
} else { } else {
Paint_DrawString_EN( bootloader_display_line(
0, 2, "Failed to mount filesystem", 0xffff
16 * 2,
"Failed to mount file system",
&Font16,
0x0000,
0xffff
); );
LCD_Update();
printf("Failed to mount the external flash\n"); printf("Failed to mount the external flash\n");
} }
printf("Trying to boot\n"); printf("Trying to boot\n");
Paint_DrawString_EN( bootloader_display_line(4, "Trying to boot", 0xffff);
0, 16 * 4, "Trying to boot", &Font16, 0x0000, 0xffff
);
LCD_Update();
//while(1);
// boot partition
boot((uintptr_t *)PARTITION_START); boot((uintptr_t *)PARTITION_START);
while (1) { while (1) {
......
...@@ -4,6 +4,7 @@ executable( ...@@ -4,6 +4,7 @@ executable(
name + '.elf', name + '.elf',
'main.c', 'main.c',
'mscmem.c', 'mscmem.c',
'bootloader-display.c',
'bootloader-usb.c', 'bootloader-usb.c',
'crc16-ccitt.c', 'crc16-ccitt.c',
dependencies: [ dependencies: [
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment