Radio Junk Box / Mbed 2 deprecated MIDI_BlueUSB

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*
00002 Copyright (c) 2010 Peter Barrett
00003 
00004 Permission is hereby granted, free of charge, to any person obtaining a copy
00005 of this software and associated documentation files (the "Software"), to deal
00006 in the Software without restriction, including without limitation the rights
00007 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00008 copies of the Software, and to permit persons to whom the Software is
00009 furnished to do so, subject to the following conditions:
00010 
00011 The above copyright notice and this permission notice shall be included in
00012 all copies or substantial portions of the Software.
00013 
00014 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00015 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00016 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00017 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00018 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00019 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00020 THE SOFTWARE.
00021 */
00022 
00023 /* 
00024 May 11 2012 RadioJunkBox : added MIDI USB support
00025 */
00026 
00027 #include "mbed.h"
00028 #include "USBHost.h"
00029 #include "Utils.h"
00030 #include "FATFileSystem.h"
00031 
00032 int MassStorage_ReadCapacity(int device, u32* blockCount, u32* blockSize);
00033 int MassStorage_Read(int device, u32 blockAddr, u32 blockCount, u8* dst, u32 blockSize);
00034 int MassStorage_Write(int device, u32 blockAddr, u32 blockCount, u8* dst, u32 blockSize);
00035 
00036 class USBFileSystem : public FATFileSystem
00037 {
00038     int _device;
00039     u32 _blockSize;
00040     u32 _blockCount;
00041     
00042 public:
00043     USBFileSystem() : FATFileSystem("usb"),_device(0),_blockSize(0),_blockCount(0)
00044     {
00045     }
00046     
00047     void SetDevice(int device)
00048     {
00049         _device = device;
00050     }
00051     
00052     virtual int disk_initialize()
00053     {
00054         return MassStorage_ReadCapacity(_device,&_blockCount,&_blockSize);
00055     }
00056     
00057     virtual int disk_write(const char *buffer, int block_number)
00058     {
00059         return MassStorage_Write(_device,block_number,1,(u8*)buffer,_blockSize);
00060     }
00061     
00062     virtual int disk_read(char *buffer, int block_number)
00063     {
00064         return MassStorage_Read(_device,block_number,1,(u8*)buffer,_blockSize);
00065     }
00066         
00067     virtual int disk_sectors()
00068     {
00069         return _blockCount;
00070     }
00071 };
00072 
00073 void DumpFS(int depth, int count)
00074 {
00075     DIR *d = opendir("/usb");
00076     if (!d)
00077     {
00078         printf("USB file system borked\n");
00079         return;
00080     }
00081 
00082     printf("\nDumping root dir\n");
00083     struct dirent *p;
00084     for(;;)
00085     {
00086         p = readdir(d);
00087         if (!p)
00088             break;
00089         int len = sizeof( dirent);
00090         printf("%s %d\n", p->d_name, len);
00091     }
00092     closedir(d);
00093 }
00094 
00095 int OnDiskInsert(int device)
00096 {
00097     USBFileSystem fs;
00098     fs.SetDevice(device);
00099     DumpFS(0,0);
00100     return 0;
00101 }
00102 
00103 /*
00104     Simple test shell to exercise mouse,keyboard,mass storage and hubs.
00105     Add 2 15k pulldown resistors between D+/D- and ground, attach a usb socket and have at it.
00106 */
00107 
00108 Serial pc(USBTX, USBRX);
00109 int GetConsoleChar()
00110 {
00111     if (!pc.readable())
00112         return -1;
00113     char c = pc.getc();
00114     pc.putc(c); // echo
00115     return c;
00116 }
00117 
00118 void TestShell();
00119 void InitSerialMIDI();  // Added by RadioJunkBox
00120 
00121 int main()
00122 {
00123 //    pc.baud(460800);
00124     printf("BlueUSB\nNow get a bunch of usb or bluetooth things and plug them in\n");
00125     InitSerialMIDI();   // Added by RadioJunkBox
00126     TestShell();
00127 }