xduoox3: Further bootloader improvements

* Power button is what forces entry into USB mode
   (can't use the other buttons due to the long SADC warmup)
 * Inching closer to working USB disk mode (starts then disconnects!

Change-Id: I45ff1c61f39e0e0c3615b38278f5c91b6ef2ed6c
This commit is contained in:
Solomon Peachy 2021-08-22 15:04:33 -04:00
parent 987d195134
commit 93c98606f1

View file

@ -26,7 +26,9 @@
#include "font.h" #include "font.h"
#include "lcd.h" #include "lcd.h"
#include "file.h" #include "file.h"
#ifdef HAVE_BOOTLOADER_USB_MODE
#include "usb.h" #include "usb.h"
#endif
#include "system.h" #include "system.h"
#include "button.h" #include "button.h"
#include "common.h" #include "common.h"
@ -80,7 +82,7 @@ static int usb_inited = 0;
static void usb_mode(void) static void usb_mode(void)
{ {
int button; int button = 0;
/* Init USB, but only once */ /* Init USB, but only once */
if (!usb_inited) { if (!usb_inited) {
@ -92,32 +94,28 @@ static void usb_mode(void)
init_lcd(); init_lcd();
reset_screen(); reset_screen();
/* Wait for threads to connect */ /* Wait for USB */
show_splash(HZ/2, "Waiting for USB"); show_splash(0, "Waiting for USB");
while(1) { while(1) {
button = button_get_w_tmo(HZ/2); button = button_get_w_tmo(HZ/2);
if (button == SYS_USB_CONNECTED)
break; /* Hit */
if (button == BUTTON_POWER) if (button == BUTTON_POWER)
return; return;
if (button == SYS_USB_CONNECTED)
break; /* Hit */
} }
if (button == SYS_USB_CONNECTED) {
/* Got the message - wait for disconnect */ /* Got the message - wait for disconnect */
show_splash(0, "Bootloader USB mode"); show_splash(0, "Bootloader USB mode");
usb_acknowledge(SYS_USB_CONNECTED_ACK); usb_acknowledge(SYS_USB_CONNECTED_ACK);
while (1) while(1) {
{ button = button_get_w_tmo(HZ/2);
button = button_get(true);
if (button == SYS_USB_DISCONNECTED) if (button == SYS_USB_DISCONNECTED)
break; break;
} }
}
show_splash(HZ*2, "USB disconnected");
} }
#endif #endif
@ -196,8 +194,10 @@ int main(void)
#endif #endif
button_init(); button_init();
enable_irq();
int btn = button_read_device(); int btn = button_read_device();
if(btn & BUTTON_PLAY) { if(btn & BUTTON_POWER) {
verbose = true; verbose = true;
} }
@ -209,20 +209,14 @@ int main(void)
filesystem_init(); filesystem_init();
/* Don't mount the disks yet, there could be file system/partition errors
which are fixable in USB mode */
#ifdef HAVE_BOOTLOADER_USB_MODE #ifdef HAVE_BOOTLOADER_USB_MODE
/* Enter USB mode if USB is plugged and POWER button is pressed */
/* Enter USB mode if USB is plugged and PLAY button is pressed */ if (btn & BUTTON_POWER) {
if(btn & BUTTON_PLAY) {
if(usb_detect() == USB_INSERTED)
usb_mode(); usb_mode();
reset_screen();
} }
#endif /* HAVE_BOOTLOADER_USB_MODE */ #endif /* HAVE_BOOTLOADER_USB_MODE */
reset_screen();
#ifndef SHOW_LOGO #ifndef SHOW_LOGO
printf(MODEL_NAME" Rockbox Bootloader"); printf(MODEL_NAME" Rockbox Bootloader");
printf("Version %s", rbversion); printf("Version %s", rbversion);
@ -235,15 +229,9 @@ int main(void)
printf("Error: %s", loader_strerror(rc)); printf("Error: %s", loader_strerror(rc));
} }
#if 1
/* Power off */ /* Power off */
sleep(5*HZ); sleep(5*HZ);
power_off(); power_off();
#else
/* Halt */
while (1)
core_idle();
#endif
return 0; return 0;
} }