MP3 Player without external hardware MP3 Player without external hardware. A software based MP3 player based on a modified version of libmad. Mono output (at the moment) via AnalogOut. Files are read from an USB drive. This is a demo program, it plays only one file at the moment. Documentation is in "main.cpp" and "config.h"

Dependencies:   mbed

Committer:
Gruenfrosch
Date:
Sat Nov 27 17:27:33 2010 +0000
Revision:
2:f28cf0afd021
Parent:
0:7627c79db971
Version 3:
* moved another memory block into AHB RAM, giving more room for
* stereo buffer.
* moved content of decode() to main()
* decoding is now safe to be called multiple times (bug in older versions)
* Output routine now fills stereo buffer, DAC output sums channels,
* just for demonstration that stereo output could go here

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Gruenfrosch 0:7627c79db971 1 /* USB Mass Storage device file system
Gruenfrosch 0:7627c79db971 2 * Copyrigh (c) 2010, Igor Skochinsky
Gruenfrosch 0:7627c79db971 3 * based on SDFileStorage
Gruenfrosch 0:7627c79db971 4 * Copyright (c) 2008-2009, sford
Gruenfrosch 0:7627c79db971 5 */
Gruenfrosch 0:7627c79db971 6
Gruenfrosch 0:7627c79db971 7 /* Introduction
Gruenfrosch 0:7627c79db971 8 * ------------
Gruenfrosch 0:7627c79db971 9 * TODO: write one
Gruenfrosch 0:7627c79db971 10 * we're basically using NXP's USBHotLite sample code, just plugging in our own FAT library
Gruenfrosch 0:7627c79db971 11 */
Gruenfrosch 0:7627c79db971 12
Gruenfrosch 0:7627c79db971 13 #include "MSCFileSystem.h"
Gruenfrosch 0:7627c79db971 14 #include "usbhost_inc.h"
Gruenfrosch 0:7627c79db971 15
Gruenfrosch 0:7627c79db971 16 MSCFileSystem::MSCFileSystem(const char* name) :
Gruenfrosch 0:7627c79db971 17 FATFileSystem(name)
Gruenfrosch 0:7627c79db971 18 {
Gruenfrosch 0:7627c79db971 19 }
Gruenfrosch 0:7627c79db971 20
Gruenfrosch 0:7627c79db971 21 void print_inquiry(USB_INT08U *inqReply)
Gruenfrosch 0:7627c79db971 22 {
Gruenfrosch 0:7627c79db971 23 // see USB Mass Storage Class – UFI Command Specification,
Gruenfrosch 0:7627c79db971 24 // 4.2 INQUIRY Command
Gruenfrosch 0:7627c79db971 25 printf("Inquiry reply:\n");
Gruenfrosch 0:7627c79db971 26 uint8_t tmp = inqReply[0]&0x1F;
Gruenfrosch 0:7627c79db971 27 printf("Peripheral device type: %02Xh\n", tmp);
Gruenfrosch 0:7627c79db971 28 if ( tmp == 0 )
Gruenfrosch 0:7627c79db971 29 printf("\t- Direct access (floppy)\n");
Gruenfrosch 0:7627c79db971 30 else if ( tmp == 0x1F )
Gruenfrosch 0:7627c79db971 31 printf("\t- none (no FDD connected)\n");
Gruenfrosch 0:7627c79db971 32 else
Gruenfrosch 0:7627c79db971 33 printf("\t- unknown type\n");
Gruenfrosch 0:7627c79db971 34 tmp = inqReply[1] >> 7;
Gruenfrosch 0:7627c79db971 35 printf("Removable Media Bit: %d\n", tmp);
Gruenfrosch 0:7627c79db971 36 tmp = inqReply[2] & 3;
Gruenfrosch 0:7627c79db971 37 printf("ANSI Version: %02Xh\n", tmp);
Gruenfrosch 0:7627c79db971 38 if ( tmp != 0 )
Gruenfrosch 0:7627c79db971 39 printf("\t- warning! must be 0\n");
Gruenfrosch 0:7627c79db971 40 tmp = (inqReply[2]>>3) & 3;
Gruenfrosch 0:7627c79db971 41 printf("ECMA Version: %02Xh\n", tmp);
Gruenfrosch 0:7627c79db971 42 if ( tmp != 0 )
Gruenfrosch 0:7627c79db971 43 printf("\t- warning! should be 0\n");
Gruenfrosch 0:7627c79db971 44 tmp = inqReply[2]>>6;
Gruenfrosch 0:7627c79db971 45 printf("ISO Version: %02Xh\n", tmp);
Gruenfrosch 0:7627c79db971 46 if ( tmp != 0 )
Gruenfrosch 0:7627c79db971 47 printf("\t- warning! should be 0\n");
Gruenfrosch 0:7627c79db971 48 tmp = inqReply[3] & 0xF;
Gruenfrosch 0:7627c79db971 49 printf("Response Data Format: %02Xh\n", tmp);
Gruenfrosch 0:7627c79db971 50 if ( tmp != 1 )
Gruenfrosch 0:7627c79db971 51 printf("\t- warning! should be 1\n");
Gruenfrosch 0:7627c79db971 52 tmp = inqReply[4];
Gruenfrosch 0:7627c79db971 53 printf("Additional length: %02Xh\n", tmp);
Gruenfrosch 0:7627c79db971 54 if ( tmp != 0x1F )
Gruenfrosch 0:7627c79db971 55 printf("\t- warning! should be 1Fh\n");
Gruenfrosch 0:7627c79db971 56 printf("Vendor Information: '%.8s'\n", &inqReply[8]);
Gruenfrosch 0:7627c79db971 57 printf("Product Identification: '%.16s'\n", &inqReply[16]);
Gruenfrosch 0:7627c79db971 58 printf("Product Revision: '%.4s'\n", &inqReply[32]);
Gruenfrosch 0:7627c79db971 59 }
Gruenfrosch 0:7627c79db971 60
Gruenfrosch 0:7627c79db971 61 int MSCFileSystem::initialise_msc()
Gruenfrosch 0:7627c79db971 62 {
Gruenfrosch 0:7627c79db971 63 USB_INT32S rc;
Gruenfrosch 0:7627c79db971 64 USB_INT08U inquiryResult[INQUIRY_LENGTH];
Gruenfrosch 0:7627c79db971 65
Gruenfrosch 0:7627c79db971 66 //print_clock();
Gruenfrosch 0:7627c79db971 67 Host_Init(); /* Initialize the host controller */
Gruenfrosch 0:7627c79db971 68 rc = Host_EnumDev(); /* Enumerate the device connected */
Gruenfrosch 0:7627c79db971 69 if (rc != OK)
Gruenfrosch 0:7627c79db971 70 {
Gruenfrosch 0:7627c79db971 71 fprintf(stderr, "Could not enumerate device: %d\n", rc);
Gruenfrosch 0:7627c79db971 72 return rc;
Gruenfrosch 0:7627c79db971 73 }
Gruenfrosch 0:7627c79db971 74
Gruenfrosch 0:7627c79db971 75
Gruenfrosch 0:7627c79db971 76 /* Initialize the mass storage and scsi interfaces */
Gruenfrosch 0:7627c79db971 77 rc = MS_Init( &_blkSize, &_numBlks, inquiryResult );
Gruenfrosch 0:7627c79db971 78 if (rc != OK)
Gruenfrosch 0:7627c79db971 79 {
Gruenfrosch 0:7627c79db971 80 fprintf(stderr, "Could not initialize mass storage interface: %d\n", rc);
Gruenfrosch 0:7627c79db971 81 return rc;
Gruenfrosch 0:7627c79db971 82 }
Gruenfrosch 0:7627c79db971 83 #if defined(MSCFS_DEBUG)
Gruenfrosch 0:7627c79db971 84 printf("Successfully initialized mass storage interface; %d blocks of size %d\n", _numBlks, _blkSize);
Gruenfrosch 0:7627c79db971 85 print_inquiry(inquiryResult);
Gruenfrosch 0:7627c79db971 86 #endif
Gruenfrosch 0:7627c79db971 87 // FATFileSystem supports only 512-byte blocks
Gruenfrosch 0:7627c79db971 88 return _blkSize == 512 ? OK : 1;
Gruenfrosch 0:7627c79db971 89 }
Gruenfrosch 0:7627c79db971 90
Gruenfrosch 0:7627c79db971 91 int MSCFileSystem::disk_initialize()
Gruenfrosch 0:7627c79db971 92 {
Gruenfrosch 0:7627c79db971 93 if ( initialise_msc() != OK )
Gruenfrosch 0:7627c79db971 94 return 1;
Gruenfrosch 0:7627c79db971 95
Gruenfrosch 0:7627c79db971 96 return 0;
Gruenfrosch 0:7627c79db971 97 }
Gruenfrosch 0:7627c79db971 98
Gruenfrosch 0:7627c79db971 99 int MSCFileSystem::disk_write(const char *buffer, int block_number)
Gruenfrosch 0:7627c79db971 100 {
Gruenfrosch 0:7627c79db971 101 if ( OK == MS_BulkSend(block_number, 1, (USB_INT08U *)buffer) )
Gruenfrosch 0:7627c79db971 102 return 0;
Gruenfrosch 0:7627c79db971 103 return 1;
Gruenfrosch 0:7627c79db971 104 }
Gruenfrosch 0:7627c79db971 105
Gruenfrosch 0:7627c79db971 106 int MSCFileSystem::disk_read(char *buffer, int block_number)
Gruenfrosch 0:7627c79db971 107 {
Gruenfrosch 0:7627c79db971 108 if ( OK == MS_BulkRecv(block_number, 1, (USB_INT08U *)buffer) )
Gruenfrosch 0:7627c79db971 109 return 0;
Gruenfrosch 0:7627c79db971 110 return 1;
Gruenfrosch 0:7627c79db971 111 }
Gruenfrosch 0:7627c79db971 112
Gruenfrosch 0:7627c79db971 113 int MSCFileSystem::disk_status() { return 0; }
Gruenfrosch 0:7627c79db971 114 int MSCFileSystem::disk_sync() { return 0; }
Gruenfrosch 0:7627c79db971 115 int MSCFileSystem::disk_sectors() { return _numBlks; }