Here's a new take on the VS1010 USB Host functionality. The USB host code has been rewritten for VS1010D. Here's a self-contained program that combines USB host functionality with a simple main loop, which repeatedly asks the user to insert a new USB flash memory stick and then plays MP3 files from the root of the flash memory stick.
VS1010>usbplaytest
Please insert USB flash..
VendorID:0781 ProductID:5567
Scan and init filesystem...
Device '15264M USB store' has FAT filesystem, good. Playing *.MP3 from root..
Crockett's Theme 12 inch.mp3
Code: Select all
ioresult main (char *params) {
int attempts = 0;
ioresult r;
PowerSetVoltages((void*)(®ulator));
VODEV('U') = &usbFlash;
while (lastReceivedCharUart0 != 27) {
printf("Please insert USB flash..\n");
while (UsbDeviceProbe()) {
DelayL(10000);
}
printf("VendorID:%04X ProductID:%04X\n",Swap16(udp->vid),Swap16(udp->pid));
printf("Scan and init filesystem...\n");
if (ioctl(&usbFlash, IOCTL_RESTART, NULL) == (IOCTL_RESULT)&FatFileSystem) {
printf("Device '%s' has FAT filesystem, good. Playing *.MP3 from root..\n", Identify(VODEV('U')));
shellcmd("play","U:*.MP3");
} else {
printf("Init error at ioctl_restart\n");
}
printf("Done, please remove USB flash..\n");
usbTotalSectors32 = 0;
Xvm((void*)resetUsbHostHw); // Set initial state
while ((PERIP(USB_UTMIR) & USB_UTMIR_LSTATE) != 0) {
//Wait for no stick
}
printf("USB device disconnected\n");
}
VODEV('U') = NULL;
return S_OK;
}