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