
BlueUSB and Waveplayer merged
Dependencies: SDFileSystem mbed-rtos mbed wave_player
Fork of z_test_BlueUSBv1 by
main.cpp@4:9ed8c7187958, 2014-11-18 (annotated)
- Committer:
- ballaw
- Date:
- Tue Nov 18 22:30:37 2014 +0000
- Revision:
- 4:9ed8c7187958
- Parent:
- 3:146802bc7bb8
dgf
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
peterbarrett1967 | 0:606b230e5b4a | 1 | /* |
peterbarrett1967 | 0:606b230e5b4a | 2 | Copyright (c) 2010 Peter Barrett |
peterbarrett1967 | 0:606b230e5b4a | 3 | |
peterbarrett1967 | 0:606b230e5b4a | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy |
peterbarrett1967 | 0:606b230e5b4a | 5 | of this software and associated documentation files (the "Software"), to deal |
peterbarrett1967 | 0:606b230e5b4a | 6 | in the Software without restriction, including without limitation the rights |
peterbarrett1967 | 0:606b230e5b4a | 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
peterbarrett1967 | 0:606b230e5b4a | 8 | copies of the Software, and to permit persons to whom the Software is |
peterbarrett1967 | 0:606b230e5b4a | 9 | furnished to do so, subject to the following conditions: |
peterbarrett1967 | 0:606b230e5b4a | 10 | |
peterbarrett1967 | 0:606b230e5b4a | 11 | The above copyright notice and this permission notice shall be included in |
peterbarrett1967 | 0:606b230e5b4a | 12 | all copies or substantial portions of the Software. |
peterbarrett1967 | 0:606b230e5b4a | 13 | |
peterbarrett1967 | 0:606b230e5b4a | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
peterbarrett1967 | 0:606b230e5b4a | 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
peterbarrett1967 | 0:606b230e5b4a | 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
peterbarrett1967 | 0:606b230e5b4a | 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
peterbarrett1967 | 0:606b230e5b4a | 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
peterbarrett1967 | 0:606b230e5b4a | 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
peterbarrett1967 | 0:606b230e5b4a | 20 | THE SOFTWARE. |
peterbarrett1967 | 0:606b230e5b4a | 21 | */ |
peterbarrett1967 | 0:606b230e5b4a | 22 | |
peterbarrett1967 | 0:606b230e5b4a | 23 | #include "mbed.h" |
peterbarrett1967 | 0:606b230e5b4a | 24 | #include "USBHost.h" |
peterbarrett1967 | 0:606b230e5b4a | 25 | #include "Utils.h" |
ballaw | 2:7f4915fe5708 | 26 | //#include "FATFileSystem.h" |
peterbarrett1967 | 0:606b230e5b4a | 27 | |
peterbarrett1967 | 0:606b230e5b4a | 28 | int MassStorage_ReadCapacity(int device, u32* blockCount, u32* blockSize); |
peterbarrett1967 | 0:606b230e5b4a | 29 | int MassStorage_Read(int device, u32 blockAddr, u32 blockCount, u8* dst, u32 blockSize); |
peterbarrett1967 | 0:606b230e5b4a | 30 | int MassStorage_Write(int device, u32 blockAddr, u32 blockCount, u8* dst, u32 blockSize); |
ballaw | 2:7f4915fe5708 | 31 | /* |
peterbarrett1967 | 0:606b230e5b4a | 32 | class USBFileSystem : public FATFileSystem |
peterbarrett1967 | 0:606b230e5b4a | 33 | { |
peterbarrett1967 | 0:606b230e5b4a | 34 | int _device; |
peterbarrett1967 | 0:606b230e5b4a | 35 | u32 _blockSize; |
peterbarrett1967 | 0:606b230e5b4a | 36 | u32 _blockCount; |
peterbarrett1967 | 0:606b230e5b4a | 37 | |
peterbarrett1967 | 0:606b230e5b4a | 38 | public: |
peterbarrett1967 | 0:606b230e5b4a | 39 | USBFileSystem() : FATFileSystem("usb"),_device(0),_blockSize(0),_blockCount(0) |
peterbarrett1967 | 0:606b230e5b4a | 40 | { |
peterbarrett1967 | 0:606b230e5b4a | 41 | } |
peterbarrett1967 | 0:606b230e5b4a | 42 | |
peterbarrett1967 | 0:606b230e5b4a | 43 | void SetDevice(int device) |
peterbarrett1967 | 0:606b230e5b4a | 44 | { |
peterbarrett1967 | 0:606b230e5b4a | 45 | _device = device; |
peterbarrett1967 | 0:606b230e5b4a | 46 | } |
peterbarrett1967 | 0:606b230e5b4a | 47 | |
peterbarrett1967 | 0:606b230e5b4a | 48 | virtual int disk_initialize() |
peterbarrett1967 | 0:606b230e5b4a | 49 | { |
peterbarrett1967 | 0:606b230e5b4a | 50 | return MassStorage_ReadCapacity(_device,&_blockCount,&_blockSize); |
peterbarrett1967 | 0:606b230e5b4a | 51 | } |
peterbarrett1967 | 0:606b230e5b4a | 52 | |
peterbarrett1967 | 0:606b230e5b4a | 53 | virtual int disk_write(const char *buffer, int block_number) |
peterbarrett1967 | 0:606b230e5b4a | 54 | { |
peterbarrett1967 | 0:606b230e5b4a | 55 | return MassStorage_Write(_device,block_number,1,(u8*)buffer,_blockSize); |
peterbarrett1967 | 0:606b230e5b4a | 56 | } |
peterbarrett1967 | 0:606b230e5b4a | 57 | |
peterbarrett1967 | 0:606b230e5b4a | 58 | virtual int disk_read(char *buffer, int block_number) |
peterbarrett1967 | 0:606b230e5b4a | 59 | { |
peterbarrett1967 | 0:606b230e5b4a | 60 | return MassStorage_Read(_device,block_number,1,(u8*)buffer,_blockSize); |
peterbarrett1967 | 0:606b230e5b4a | 61 | } |
peterbarrett1967 | 0:606b230e5b4a | 62 | |
peterbarrett1967 | 0:606b230e5b4a | 63 | virtual int disk_sectors() |
peterbarrett1967 | 0:606b230e5b4a | 64 | { |
peterbarrett1967 | 0:606b230e5b4a | 65 | return _blockCount; |
peterbarrett1967 | 0:606b230e5b4a | 66 | } |
peterbarrett1967 | 0:606b230e5b4a | 67 | }; |
peterbarrett1967 | 0:606b230e5b4a | 68 | |
peterbarrett1967 | 0:606b230e5b4a | 69 | void DumpFS(int depth, int count) |
peterbarrett1967 | 0:606b230e5b4a | 70 | { |
peterbarrett1967 | 0:606b230e5b4a | 71 | DIR *d = opendir("/usb"); |
peterbarrett1967 | 0:606b230e5b4a | 72 | if (!d) |
peterbarrett1967 | 0:606b230e5b4a | 73 | { |
peterbarrett1967 | 0:606b230e5b4a | 74 | printf("USB file system borked\n"); |
peterbarrett1967 | 0:606b230e5b4a | 75 | return; |
peterbarrett1967 | 0:606b230e5b4a | 76 | } |
peterbarrett1967 | 0:606b230e5b4a | 77 | |
peterbarrett1967 | 0:606b230e5b4a | 78 | printf("\nDumping root dir\n"); |
peterbarrett1967 | 0:606b230e5b4a | 79 | struct dirent *p; |
peterbarrett1967 | 0:606b230e5b4a | 80 | for(;;) |
peterbarrett1967 | 0:606b230e5b4a | 81 | { |
peterbarrett1967 | 0:606b230e5b4a | 82 | p = readdir(d); |
peterbarrett1967 | 0:606b230e5b4a | 83 | if (!p) |
peterbarrett1967 | 0:606b230e5b4a | 84 | break; |
peterbarrett1967 | 0:606b230e5b4a | 85 | int len = sizeof( dirent); |
peterbarrett1967 | 0:606b230e5b4a | 86 | printf("%s %d\n", p->d_name, len); |
peterbarrett1967 | 0:606b230e5b4a | 87 | } |
peterbarrett1967 | 0:606b230e5b4a | 88 | closedir(d); |
peterbarrett1967 | 0:606b230e5b4a | 89 | } |
peterbarrett1967 | 0:606b230e5b4a | 90 | |
peterbarrett1967 | 0:606b230e5b4a | 91 | int OnDiskInsert(int device) |
peterbarrett1967 | 0:606b230e5b4a | 92 | { |
peterbarrett1967 | 0:606b230e5b4a | 93 | USBFileSystem fs; |
peterbarrett1967 | 0:606b230e5b4a | 94 | fs.SetDevice(device); |
peterbarrett1967 | 0:606b230e5b4a | 95 | DumpFS(0,0); |
peterbarrett1967 | 0:606b230e5b4a | 96 | return 0; |
peterbarrett1967 | 0:606b230e5b4a | 97 | } |
ballaw | 2:7f4915fe5708 | 98 | */ |
peterbarrett1967 | 0:606b230e5b4a | 99 | /* |
peterbarrett1967 | 0:606b230e5b4a | 100 | Simple test shell to exercise mouse,keyboard,mass storage and hubs. |
peterbarrett1967 | 0:606b230e5b4a | 101 | Add 2 15k pulldown resistors between D+/D- and ground, attach a usb socket and have at it. |
peterbarrett1967 | 0:606b230e5b4a | 102 | */ |
peterbarrett1967 | 0:606b230e5b4a | 103 | |
peterbarrett1967 | 0:606b230e5b4a | 104 | Serial pc(USBTX, USBRX); |
peterbarrett1967 | 0:606b230e5b4a | 105 | int GetConsoleChar() |
peterbarrett1967 | 0:606b230e5b4a | 106 | { |
peterbarrett1967 | 0:606b230e5b4a | 107 | if (!pc.readable()) |
peterbarrett1967 | 0:606b230e5b4a | 108 | return -1; |
peterbarrett1967 | 0:606b230e5b4a | 109 | char c = pc.getc(); |
peterbarrett1967 | 0:606b230e5b4a | 110 | pc.putc(c); // echo |
peterbarrett1967 | 0:606b230e5b4a | 111 | return c; |
peterbarrett1967 | 0:606b230e5b4a | 112 | } |
peterbarrett1967 | 0:606b230e5b4a | 113 | |
peterbarrett1967 | 0:606b230e5b4a | 114 | void TestShell(); |
ballaw | 3:146802bc7bb8 | 115 | /* |
ballaw | 3:146802bc7bb8 | 116 | int main() |
ballaw | 3:146802bc7bb8 | 117 | { |
ballaw | 3:146802bc7bb8 | 118 | pc.baud(230400); |
ballaw | 3:146802bc7bb8 | 119 | printf("BlueUSBv1\nNow get a bunch of usb or bluetooth things and plug them in\n"); |
ballaw | 3:146802bc7bb8 | 120 | TestShell(); |
ballaw | 3:146802bc7bb8 | 121 | }*/ |
ballaw | 3:146802bc7bb8 | 122 | |
ballaw | 3:146802bc7bb8 | 123 | |
ballaw | 3:146802bc7bb8 | 124 | #include "SDFileSystem.h" |
ballaw | 3:146802bc7bb8 | 125 | #include "wave_player.h" |
ballaw | 3:146802bc7bb8 | 126 | |
ballaw | 3:146802bc7bb8 | 127 | |
ballaw | 3:146802bc7bb8 | 128 | |
ballaw | 3:146802bc7bb8 | 129 | SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card |
ballaw | 3:146802bc7bb8 | 130 | |
ballaw | 3:146802bc7bb8 | 131 | AnalogOut DACout(p18); |
ballaw | 3:146802bc7bb8 | 132 | |
ballaw | 3:146802bc7bb8 | 133 | wave_player waver(&DACout); |
ballaw | 3:146802bc7bb8 | 134 | |
ballaw | 3:146802bc7bb8 | 135 | |
peterbarrett1967 | 0:606b230e5b4a | 136 | |
peterbarrett1967 | 0:606b230e5b4a | 137 | int main() |
peterbarrett1967 | 0:606b230e5b4a | 138 | { |
acorness | 1:12422708d6c8 | 139 | pc.baud(230400); |
acorness | 1:12422708d6c8 | 140 | printf("BlueUSBv1\nNow get a bunch of usb or bluetooth things and plug them in\n"); |
peterbarrett1967 | 0:606b230e5b4a | 141 | TestShell(); |
ballaw | 3:146802bc7bb8 | 142 | |
ballaw | 3:146802bc7bb8 | 143 | FILE *wave_file; |
ballaw | 3:146802bc7bb8 | 144 | printf("r\nr\nr\nHello, wave world!r\n"); |
ballaw | 3:146802bc7bb8 | 145 | waver.set_verbosity(0); |
ballaw | 3:146802bc7bb8 | 146 | while(1) { |
ballaw | 3:146802bc7bb8 | 147 | wave_file=fopen("/sd/mydir/mega.wav", "r");//mega.wav","r");//donkey.wav", "r");//aliens.wav", "r");//birds.wav","r"); |
ballaw | 3:146802bc7bb8 | 148 | waver.play(wave_file); |
ballaw | 3:146802bc7bb8 | 149 | fclose(wave_file); |
ballaw | 3:146802bc7bb8 | 150 | printf("\r\nDONE!\r\n"); |
ballaw | 3:146802bc7bb8 | 151 | wait(3); |
ballaw | 3:146802bc7bb8 | 152 | } |
peterbarrett1967 | 0:606b230e5b4a | 153 | } |
ballaw | 3:146802bc7bb8 | 154 |