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