XOOMの動作状況を聞き処理を変えてみました。 USBケーブルを抜いた際に処理を終了するようにしました。

Dependencies:   mbed

Committer:
abe00makoto
Date:
Wed May 25 09:34:38 2011 +0000
Revision:
0:9fb6c423e32c
support ADK

Who changed what in which revision?

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