Based on myBlueUSB reference ver. http://mbed.org/users/networker/programs/myBlueUSB/lsm1ui

Dependencies:   mbed myUSBHost AvailableMemory rfcomm myBlueUSB sdp

Committer:
kenbumono
Date:
Tue Jul 05 08:25:59 2011 +0000
Revision:
0:8d8481ed6d49

        

Who changed what in which revision?

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