diff --git a/bootloader/x1000.c b/bootloader/x1000.c index 1c9f3cd2fa..bc56b8f822 100644 --- a/bootloader/x1000.c +++ b/bootloader/x1000.c @@ -56,43 +56,6 @@ #include #include -/* Flags to indicate if hardware was already initialized */ -bool usb_inited = false; - -/* Set to true if a SYS_USB_CONNECTED event is seen - * Set to false if a SYS_USB_DISCONNECTED event is seen */ -bool is_usb_connected = false; - -void init_usb(void) -{ - if(usb_inited) - return; - - usb_init(); - usb_start_monitoring(); - usb_inited = true; -} - -void usb_mode(void) -{ - init_usb(); - - if(!is_usb_connected) - splash2(0, "Waiting for USB", "Press " BL_QUIT_NAME " to go back"); - - while(!is_usb_connected) - if(get_button(TIMEOUT_BLOCK) == BL_QUIT) - return; - - splash(0, "USB mode"); - usb_acknowledge(SYS_USB_CONNECTED_ACK); - - while(is_usb_connected) - get_button(TIMEOUT_BLOCK); - - splash(3*HZ, "USB disconnected"); -} - void main(void) { system_init(); @@ -110,6 +73,9 @@ void main(void) filesystem_init(); + usb_init(); + usb_start_monitoring(); + /* It's OK if this doesn't mount anything. Any disk access should * be guarded by a call to check_disk() to see if the disk is really * present, blocking with an "insert SD card" prompt if appropriate. */ diff --git a/bootloader/x1000/recovery.c b/bootloader/x1000/recovery.c index 809bd6578a..4d806b26a4 100644 --- a/bootloader/x1000/recovery.c +++ b/bootloader/x1000/recovery.c @@ -26,8 +26,6 @@ #include "kernel.h" #include -extern void usb_mode(void); - enum { MENUITEM_HEADING, MENUITEM_ACTION, diff --git a/bootloader/x1000/utils.c b/bootloader/x1000/utils.c index f4dbac4c5e..56ac6d1fff 100644 --- a/bootloader/x1000/utils.c +++ b/bootloader/x1000/utils.c @@ -23,6 +23,13 @@ #include "storage.h" #include "button.h" #include "kernel.h" +#include "usb.h" + +/* Set to true if a SYS_USB_CONNECTED event is seen + * Set to false if a SYS_USB_DISCONNECTED event is seen + * Handled by the gui code since that's how events are delivered + * TODO: this is an ugly kludge */ +bool is_usb_connected = false; /* this is both incorrect and incredibly racy... */ int check_disk(bool wait) @@ -43,3 +50,21 @@ int check_disk(bool wait) return DISK_PRESENT; } + +void usb_mode(void) +{ + if(!is_usb_connected) + splash2(0, "Waiting for USB", "Press " BL_QUIT_NAME " to cancel"); + + while(!is_usb_connected) + if(get_button(TIMEOUT_BLOCK) == BL_QUIT) + return; + + splash(0, "USB mode"); + usb_acknowledge(SYS_USB_CONNECTED_ACK); + + while(is_usb_connected) + get_button(TIMEOUT_BLOCK); + + splash(3*HZ, "USB disconnected"); +} diff --git a/bootloader/x1000/x1000bootloader.h b/bootloader/x1000/x1000bootloader.h index bb35cd3b78..60353e59fd 100644 --- a/bootloader/x1000/x1000bootloader.h +++ b/bootloader/x1000/x1000bootloader.h @@ -104,6 +104,7 @@ enum { }; int check_disk(bool wait); +void usb_mode(void); void recovery_menu(void) __attribute__((noreturn));