A USB/360deg Rotational device, communicating via blue-tooth, test code

Dependencies:   FatFileSystem mbed

Committer:
lolpcc
Date:
Fri Dec 21 11:37:38 2012 +0000
Revision:
0:87da38093be9
Used to test the Lazy Susan at work, hence the A2D code in Utils.cpp

Who changed what in which revision?

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