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