This is a for debugging \\\\\\\"BLUE USB\\\\\\\". You can connect with HCI mode. How to connect White Wizard Board TANK *White Wizard Board - Motor Driver Board * p 21 - IN_R1 * p 22 - IN_R2 * p 23 - IN_L2 * p 24 - IN_L1

Dependencies:   mbed

Committer:
halfpitch
Date:
Wed Aug 31 11:10:18 2011 +0000
Revision:
1:c56059923036
Parent:
0:a6476c138e84
Rev.B

Who changed what in which revision?

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