mirror of
https://github.com/mist-devel/mist-firmware.git
synced 2026-02-03 14:53:05 +00:00
Merge pull request #94 from retrofun/usb-storage
Switch boot from SD/USB with User Button
This commit is contained in:
@@ -372,6 +372,7 @@ void InitADC(void) {
|
||||
PollOneADC();
|
||||
PollOneADC();
|
||||
PollOneADC();
|
||||
PollOneADC();
|
||||
}
|
||||
|
||||
// poll one adc channel every 25ms
|
||||
|
||||
@@ -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);
|
||||
|
||||
49
main.c
49
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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// storage.c
|
||||
//
|
||||
|
||||
#ifdef USB_STORAGE
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user