local fix version of myBlueUSB (http://mbed.org/users/networker/code/myBlueUSB/). - merge deleted files which are required to compile. - enable echo back of received data via RFCOMM.

Dependencies:   AvailableMemory FatFileSystem mbed myUSBHost

Committer:
nobukuma
Date:
Sun Dec 08 21:52:09 2013 +0000
Revision:
2:9f25a7fa1a54
Parent:
0:003889bc474f
???BT??????????????????; ?????????????????

Who changed what in which revision?

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