Based on PS3_BlueUSB with reference to http://blog.goo.ne.jp/roboz80/e/10e7bf38d3a63b996ca2894e9fb5e3b6

Dependencies:   TextLCD mbed

Committer:
kenbumono
Date:
Tue Jul 05 08:25:40 2011 +0000
Revision:
0:44619612f575

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kenbumono 0:44619612f575 1 /*
kenbumono 0:44619612f575 2 Copyright (c) 2010 Peter Barrett
kenbumono 0:44619612f575 3
kenbumono 0:44619612f575 4 Permission is hereby granted, free of charge, to any person obtaining a copy
kenbumono 0:44619612f575 5 of this software and associated documentation files (the "Software"), to deal
kenbumono 0:44619612f575 6 in the Software without restriction, including without limitation the rights
kenbumono 0:44619612f575 7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
kenbumono 0:44619612f575 8 copies of the Software, and to permit persons to whom the Software is
kenbumono 0:44619612f575 9 furnished to do so, subject to the following conditions:
kenbumono 0:44619612f575 10
kenbumono 0:44619612f575 11 The above copyright notice and this permission notice shall be included in
kenbumono 0:44619612f575 12 all copies or substantial portions of the Software.
kenbumono 0:44619612f575 13
kenbumono 0:44619612f575 14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
kenbumono 0:44619612f575 15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
kenbumono 0:44619612f575 16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
kenbumono 0:44619612f575 17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
kenbumono 0:44619612f575 18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
kenbumono 0:44619612f575 19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
kenbumono 0:44619612f575 20 THE SOFTWARE.
kenbumono 0:44619612f575 21 */
kenbumono 0:44619612f575 22
kenbumono 0:44619612f575 23 #include "mbed.h"
kenbumono 0:44619612f575 24 #include "USBHost.h"
kenbumono 0:44619612f575 25 #include "Utils.h"
kenbumono 0:44619612f575 26 #include "FATFileSystem.h"
kenbumono 0:44619612f575 27
kenbumono 0:44619612f575 28 int MassStorage_ReadCapacity(int device, u32* blockCount, u32* blockSize);
kenbumono 0:44619612f575 29 int MassStorage_Read(int device, u32 blockAddr, u32 blockCount, u8* dst, u32 blockSize);
kenbumono 0:44619612f575 30 int MassStorage_Write(int device, u32 blockAddr, u32 blockCount, u8* dst, u32 blockSize);
kenbumono 0:44619612f575 31
kenbumono 0:44619612f575 32 class USBFileSystem : public FATFileSystem
kenbumono 0:44619612f575 33 {
kenbumono 0:44619612f575 34 int _device;
kenbumono 0:44619612f575 35 u32 _blockSize;
kenbumono 0:44619612f575 36 u32 _blockCount;
kenbumono 0:44619612f575 37
kenbumono 0:44619612f575 38 public:
kenbumono 0:44619612f575 39 USBFileSystem() : FATFileSystem("usb"),_device(0),_blockSize(0),_blockCount(0)
kenbumono 0:44619612f575 40 {
kenbumono 0:44619612f575 41 }
kenbumono 0:44619612f575 42
kenbumono 0:44619612f575 43 void SetDevice(int device)
kenbumono 0:44619612f575 44 {
kenbumono 0:44619612f575 45 _device = device;
kenbumono 0:44619612f575 46 }
kenbumono 0:44619612f575 47
kenbumono 0:44619612f575 48 virtual int disk_initialize()
kenbumono 0:44619612f575 49 {
kenbumono 0:44619612f575 50 return MassStorage_ReadCapacity(_device,&_blockCount,&_blockSize);
kenbumono 0:44619612f575 51 }
kenbumono 0:44619612f575 52
kenbumono 0:44619612f575 53 virtual int disk_write(const char *buffer, int block_number)
kenbumono 0:44619612f575 54 {
kenbumono 0:44619612f575 55 return MassStorage_Write(_device,block_number,1,(u8*)buffer,_blockSize);
kenbumono 0:44619612f575 56 }
kenbumono 0:44619612f575 57
kenbumono 0:44619612f575 58 virtual int disk_read(char *buffer, int block_number)
kenbumono 0:44619612f575 59 {
kenbumono 0:44619612f575 60 return MassStorage_Read(_device,block_number,1,(u8*)buffer,_blockSize);
kenbumono 0:44619612f575 61 }
kenbumono 0:44619612f575 62
kenbumono 0:44619612f575 63 virtual int disk_sectors()
kenbumono 0:44619612f575 64 {
kenbumono 0:44619612f575 65 return _blockCount;
kenbumono 0:44619612f575 66 }
kenbumono 0:44619612f575 67 };
kenbumono 0:44619612f575 68
kenbumono 0:44619612f575 69 void DumpFS(int depth, int count)
kenbumono 0:44619612f575 70 {
kenbumono 0:44619612f575 71 DIR *d = opendir("/usb");
kenbumono 0:44619612f575 72 if (!d)
kenbumono 0:44619612f575 73 {
kenbumono 0:44619612f575 74 printf("USB file system borked\r\n");
kenbumono 0:44619612f575 75 return;
kenbumono 0:44619612f575 76 }
kenbumono 0:44619612f575 77
kenbumono 0:44619612f575 78 printf("\nDumping root dir\r\n");
kenbumono 0:44619612f575 79 struct dirent *p;
kenbumono 0:44619612f575 80 for(;;)
kenbumono 0:44619612f575 81 {
kenbumono 0:44619612f575 82 p = readdir(d);
kenbumono 0:44619612f575 83 if (!p)
kenbumono 0:44619612f575 84 break;
kenbumono 0:44619612f575 85 int len = sizeof( dirent);
kenbumono 0:44619612f575 86 printf("%s %d\n", p->d_name, len);
kenbumono 0:44619612f575 87 }
kenbumono 0:44619612f575 88 closedir(d);
kenbumono 0:44619612f575 89 }
kenbumono 0:44619612f575 90
kenbumono 0:44619612f575 91 int OnDiskInsert(int device)
kenbumono 0:44619612f575 92 {
kenbumono 0:44619612f575 93 USBFileSystem fs;
kenbumono 0:44619612f575 94 fs.SetDevice(device);
kenbumono 0:44619612f575 95 DumpFS(0,0);
kenbumono 0:44619612f575 96 return 0;
kenbumono 0:44619612f575 97 }
kenbumono 0:44619612f575 98
kenbumono 0:44619612f575 99 /*
kenbumono 0:44619612f575 100 Simple test shell to exercise mouse,keyboard,mass storage and hubs.
kenbumono 0:44619612f575 101 Add 2 15k pulldown resistors between D+/D- and ground, attach a usb socket and have at it.
kenbumono 0:44619612f575 102 */
kenbumono 0:44619612f575 103
kenbumono 0:44619612f575 104 Serial pc(USBTX, USBRX);
kenbumono 0:44619612f575 105 int GetConsoleChar()
kenbumono 0:44619612f575 106 {
kenbumono 0:44619612f575 107 if (!pc.readable())
kenbumono 0:44619612f575 108 return -1;
kenbumono 0:44619612f575 109 char c = pc.getc();
kenbumono 0:44619612f575 110 pc.putc(c); // echo
kenbumono 0:44619612f575 111 return c;
kenbumono 0:44619612f575 112 }
kenbumono 0:44619612f575 113
kenbumono 0:44619612f575 114 void TestShell();
kenbumono 0:44619612f575 115
kenbumono 0:44619612f575 116 int main()
kenbumono 0:44619612f575 117 {
kenbumono 0:44619612f575 118 pc.baud(460800);
kenbumono 0:44619612f575 119 printf("BlueUSB\nNow get a bunch of usb or bluetooth things and plug them in\r\n");
kenbumono 0:44619612f575 120 TestShell();
kenbumono 0:44619612f575 121 }