Test version of BlueUSB stack. Includes SDP and RFCOMM. As Client it allows to connect to my fischertechnik TX Controller. As Server it echo\\\\\\\'s characters to Putty. PIN=1234

Dependencies:   mbed myUSBHost AvailableMemory

Dependents:   mbed_TANK_Kinect myBlueUSB_ros ftusbClass

Committer:
networker
Date:
Fri Jul 01 09:16:00 2011 +0000
Revision:
13:327622e38551
made some improvements to get massstorage functioning

Who changed what in which revision?

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