diff --git a/hw/AT91SAM/hardware.c b/hw/AT91SAM/hardware.c index 70f900f..afd2346 100644 --- a/hw/AT91SAM/hardware.c +++ b/hw/AT91SAM/hardware.c @@ -372,6 +372,7 @@ void InitADC(void) { PollOneADC(); PollOneADC(); PollOneADC(); + PollOneADC(); } // poll one adc channel every 25ms diff --git a/hw/AT91SAM/hardware.h b/hw/AT91SAM/hardware.h index e40d40a..a30316f 100644 --- a/hw/AT91SAM/hardware.h +++ b/hw/AT91SAM/hardware.h @@ -94,6 +94,9 @@ #define VIDEO_SD_DISABLE_VAR (*(uint8_t*)0x0020FF15) #define VIDEO_YPBPR_VAR (*(uint8_t*)0x0020FF16) +#define USB_BOOT_VALUE 0x8007F007 +#define USB_BOOT_VAR (*(int*)0x0020FF18) + #define SECTOR_BUFFER_SIZE 4096 char mmc_inserted(void); diff --git a/main.c b/main.c index 9e4d34a..e080110 100644 --- a/main.c +++ b/main.c @@ -106,6 +106,19 @@ void HandleFpga(void) { extern void inserttestfloppy(); +#ifdef USB_STORAGE +int GetUSBStorageDevices() +{ + uint32_t to = GetTimer(2000); + + // poll usb 2 seconds or until a mass storage device becomes ready + while(!storage_devices && !CheckTimer(to)) + usb_poll(); + + return storage_devices; +} +#endif + int main(void) { uint8_t mmc_ok = 0; @@ -133,30 +146,36 @@ int main(void) if(MMC_Init()) mmc_ok = 1; else spi_fast(); - // TODO: If MMC fails try to wait for USB storage - iprintf("spiclk: %u MHz\r", GetSPICLK()); usb_init(); - // mmc init failed, try to wait for usb - if(!mmc_ok) { - uint32_t to = GetTimer(2000); + InitADC(); #ifdef USB_STORAGE - // poll usb 2 seconds or until a mass storage device becomes ready - while(!storage_devices && !CheckTimer(to)) - usb_poll(); + if(UserButton()) USB_BOOT_VAR = (USB_BOOT_VAR == USB_BOOT_VALUE) ? 0 : USB_BOOT_VALUE; - // no usb storage device after 2 seconds ... - if(!storage_devices) - FatalError(1); - - fat_switch_to_usb(); // redirect file io to usb -#else - FatalError(1); + if(USB_BOOT_VAR == USB_BOOT_VALUE) + if (!GetUSBStorageDevices()) { + if(!mmc_ok) + FatalError(1); + } else + fat_switch_to_usb(); // redirect file io to usb + else { #endif + if(!mmc_ok) { +#ifdef USB_STORAGE + if(!GetUSBStorageDevices()) + FatalError(1); + + fat_switch_to_usb(); // redirect file io to usb +#else + FatalError(1); +#endif + } +#ifdef USB_STORAGE } +#endif if (!FindDrive()) FatalError(2); diff --git a/usb/hub.c b/usb/hub.c index c821b1d..8204a9c 100644 --- a/usb/hub.c +++ b/usb/hub.c @@ -33,7 +33,6 @@ static uint8_t usb_hub_get_port_status(usb_device_t *dev, uint8_t port, uint16_t } static uint8_t usb_hub_parse_conf(usb_device_t *dev, uint8_t conf, uint16_t len, ep_t *pep) { - usb_storage_info_t *info = &(dev->storage_info); uint8_t rcode; bool is_good_interface = false; diff --git a/usb/storage.c b/usb/storage.c index 8b74f09..ce54d09 100644 --- a/usb/storage.c +++ b/usb/storage.c @@ -2,6 +2,7 @@ // storage.c // +#ifdef USB_STORAGE #include #include @@ -497,3 +498,4 @@ unsigned int usb_host_storage_capacity() { const usb_device_class_config_t usb_storage_class = { usb_storage_init, usb_storage_release, usb_storage_poll }; +#endif diff --git a/user_io.c b/user_io.c index b699042..c6d618c 100644 --- a/user_io.c +++ b/user_io.c @@ -150,8 +150,6 @@ void user_io_init() { // mark remap table as unused memset(key_remap_table, 0, sizeof(key_remap_table)); - InitADC(); - if(MenuButton()) DEBUG_MODE_VAR = DEBUG_MODE ? 0 : DEBUG_MODE_VALUE; iprintf("debug_mode = %d\n", DEBUG_MODE);