Quick hack to make NSX-39 (Poke-Miku) USB MIDI device to speak "mbed" from mbed which acts as an USB host.
Dependencies: FatFileSystem mbed
Fork of MIDI_BlueUSB by
Description of the project
This is quick hack to control Poke-miku (NSX-39) from mbed. The mbed acts as an USB host and controls USB MIDI device NSX-39. It speaks "mbed" if you send "s¥n" from virtual USB serial (connected to PC or Mac) or push SW connected to p21. It plays MIDI file "test.mid" on local file-system if you push SW connected to p22. You can find files that I have tested at the bottom. The standard MIDI file support is still preliminary. See TestShell.cpp for the hack. This program is derived from MIDI_BlueUSB (http://mbed.org/users/radiojunkbox/code/MIDI_BlueUSB/) by Radio Junk Box.
ポケミク(NSX-39)を無改造のままmbedから鳴らせるようにしてみました。mbedがUSB hostになって、USB MIDIデバイスのポケミクを鳴らします。mbedのバーチャルシリアル(USBシリアル)にPCからs\nを送るか、p21につないだスイッチを押すとmbedとしゃべります。p22につないだスイッチを押すと、ローカルファイルシステム(.binと同じ場所)に保存した test.mid を再生します。試したファイルは下にある test1.mid と test2.mid です。MIDIファイルのサポートはまだまだ完全とはいえません。
tested MIDI files
Video: Poke-miku speaks `mbed'
main.cpp@2:7576d1327cf1, 2014-04-27 (annotated)
- Committer:
- non
- Date:
- Sun Apr 27 01:36:30 2014 +0000
- Revision:
- 2:7576d1327cf1
- Parent:
- 1:892f8922bdc4
- Child:
- 3:31fbce33c25b
Now it plays when you push SW connected to p21.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
radiojunkbox | 0:79620c558b0c | 1 | /* |
radiojunkbox | 0:79620c558b0c | 2 | Copyright (c) 2010 Peter Barrett |
radiojunkbox | 0:79620c558b0c | 3 | |
radiojunkbox | 0:79620c558b0c | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy |
radiojunkbox | 0:79620c558b0c | 5 | of this software and associated documentation files (the "Software"), to deal |
radiojunkbox | 0:79620c558b0c | 6 | in the Software without restriction, including without limitation the rights |
radiojunkbox | 0:79620c558b0c | 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
radiojunkbox | 0:79620c558b0c | 8 | copies of the Software, and to permit persons to whom the Software is |
radiojunkbox | 0:79620c558b0c | 9 | furnished to do so, subject to the following conditions: |
radiojunkbox | 0:79620c558b0c | 10 | |
radiojunkbox | 0:79620c558b0c | 11 | The above copyright notice and this permission notice shall be included in |
radiojunkbox | 0:79620c558b0c | 12 | all copies or substantial portions of the Software. |
radiojunkbox | 0:79620c558b0c | 13 | |
radiojunkbox | 0:79620c558b0c | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
radiojunkbox | 0:79620c558b0c | 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
radiojunkbox | 0:79620c558b0c | 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
radiojunkbox | 0:79620c558b0c | 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
radiojunkbox | 0:79620c558b0c | 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
radiojunkbox | 0:79620c558b0c | 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
radiojunkbox | 0:79620c558b0c | 20 | THE SOFTWARE. |
radiojunkbox | 0:79620c558b0c | 21 | */ |
radiojunkbox | 0:79620c558b0c | 22 | |
radiojunkbox | 0:79620c558b0c | 23 | /* |
radiojunkbox | 0:79620c558b0c | 24 | May 11 2012 RadioJunkBox : added MIDI USB support |
radiojunkbox | 0:79620c558b0c | 25 | */ |
radiojunkbox | 0:79620c558b0c | 26 | |
radiojunkbox | 0:79620c558b0c | 27 | #include "mbed.h" |
radiojunkbox | 0:79620c558b0c | 28 | #include "USBHost.h" |
radiojunkbox | 0:79620c558b0c | 29 | #include "Utils.h" |
radiojunkbox | 0:79620c558b0c | 30 | #include "FATFileSystem.h" |
radiojunkbox | 0:79620c558b0c | 31 | |
non | 2:7576d1327cf1 | 32 | #include "common.h" |
non | 2:7576d1327cf1 | 33 | #include "TestShell.h" |
non | 2:7576d1327cf1 | 34 | |
radiojunkbox | 0:79620c558b0c | 35 | int MassStorage_ReadCapacity(int device, u32* blockCount, u32* blockSize); |
radiojunkbox | 0:79620c558b0c | 36 | int MassStorage_Read(int device, u32 blockAddr, u32 blockCount, u8* dst, u32 blockSize); |
radiojunkbox | 0:79620c558b0c | 37 | int MassStorage_Write(int device, u32 blockAddr, u32 blockCount, u8* dst, u32 blockSize); |
radiojunkbox | 0:79620c558b0c | 38 | |
radiojunkbox | 0:79620c558b0c | 39 | class USBFileSystem : public FATFileSystem |
radiojunkbox | 0:79620c558b0c | 40 | { |
radiojunkbox | 0:79620c558b0c | 41 | int _device; |
radiojunkbox | 0:79620c558b0c | 42 | u32 _blockSize; |
radiojunkbox | 0:79620c558b0c | 43 | u32 _blockCount; |
radiojunkbox | 0:79620c558b0c | 44 | |
radiojunkbox | 0:79620c558b0c | 45 | public: |
radiojunkbox | 0:79620c558b0c | 46 | USBFileSystem() : FATFileSystem("usb"),_device(0),_blockSize(0),_blockCount(0) |
radiojunkbox | 0:79620c558b0c | 47 | { |
radiojunkbox | 0:79620c558b0c | 48 | } |
radiojunkbox | 0:79620c558b0c | 49 | |
radiojunkbox | 0:79620c558b0c | 50 | void SetDevice(int device) |
radiojunkbox | 0:79620c558b0c | 51 | { |
radiojunkbox | 0:79620c558b0c | 52 | _device = device; |
radiojunkbox | 0:79620c558b0c | 53 | } |
radiojunkbox | 0:79620c558b0c | 54 | |
radiojunkbox | 0:79620c558b0c | 55 | virtual int disk_initialize() |
radiojunkbox | 0:79620c558b0c | 56 | { |
radiojunkbox | 0:79620c558b0c | 57 | return MassStorage_ReadCapacity(_device,&_blockCount,&_blockSize); |
radiojunkbox | 0:79620c558b0c | 58 | } |
radiojunkbox | 0:79620c558b0c | 59 | |
radiojunkbox | 0:79620c558b0c | 60 | virtual int disk_write(const char *buffer, int block_number) |
radiojunkbox | 0:79620c558b0c | 61 | { |
radiojunkbox | 0:79620c558b0c | 62 | return MassStorage_Write(_device,block_number,1,(u8*)buffer,_blockSize); |
radiojunkbox | 0:79620c558b0c | 63 | } |
radiojunkbox | 0:79620c558b0c | 64 | |
radiojunkbox | 0:79620c558b0c | 65 | virtual int disk_read(char *buffer, int block_number) |
radiojunkbox | 0:79620c558b0c | 66 | { |
radiojunkbox | 0:79620c558b0c | 67 | return MassStorage_Read(_device,block_number,1,(u8*)buffer,_blockSize); |
radiojunkbox | 0:79620c558b0c | 68 | } |
radiojunkbox | 0:79620c558b0c | 69 | |
radiojunkbox | 0:79620c558b0c | 70 | virtual int disk_sectors() |
radiojunkbox | 0:79620c558b0c | 71 | { |
radiojunkbox | 0:79620c558b0c | 72 | return _blockCount; |
radiojunkbox | 0:79620c558b0c | 73 | } |
radiojunkbox | 0:79620c558b0c | 74 | }; |
radiojunkbox | 0:79620c558b0c | 75 | |
radiojunkbox | 0:79620c558b0c | 76 | void DumpFS(int depth, int count) |
radiojunkbox | 0:79620c558b0c | 77 | { |
radiojunkbox | 0:79620c558b0c | 78 | DIR *d = opendir("/usb"); |
radiojunkbox | 0:79620c558b0c | 79 | if (!d) |
radiojunkbox | 0:79620c558b0c | 80 | { |
radiojunkbox | 0:79620c558b0c | 81 | printf("USB file system borked\n"); |
radiojunkbox | 0:79620c558b0c | 82 | return; |
radiojunkbox | 0:79620c558b0c | 83 | } |
radiojunkbox | 0:79620c558b0c | 84 | |
radiojunkbox | 0:79620c558b0c | 85 | printf("\nDumping root dir\n"); |
radiojunkbox | 0:79620c558b0c | 86 | struct dirent *p; |
radiojunkbox | 0:79620c558b0c | 87 | for(;;) |
radiojunkbox | 0:79620c558b0c | 88 | { |
radiojunkbox | 0:79620c558b0c | 89 | p = readdir(d); |
radiojunkbox | 0:79620c558b0c | 90 | if (!p) |
radiojunkbox | 0:79620c558b0c | 91 | break; |
radiojunkbox | 0:79620c558b0c | 92 | int len = sizeof( dirent); |
radiojunkbox | 0:79620c558b0c | 93 | printf("%s %d\n", p->d_name, len); |
radiojunkbox | 0:79620c558b0c | 94 | } |
radiojunkbox | 0:79620c558b0c | 95 | closedir(d); |
radiojunkbox | 0:79620c558b0c | 96 | } |
radiojunkbox | 0:79620c558b0c | 97 | |
radiojunkbox | 0:79620c558b0c | 98 | int OnDiskInsert(int device) |
radiojunkbox | 0:79620c558b0c | 99 | { |
radiojunkbox | 0:79620c558b0c | 100 | USBFileSystem fs; |
radiojunkbox | 0:79620c558b0c | 101 | fs.SetDevice(device); |
radiojunkbox | 0:79620c558b0c | 102 | DumpFS(0,0); |
radiojunkbox | 0:79620c558b0c | 103 | return 0; |
radiojunkbox | 0:79620c558b0c | 104 | } |
radiojunkbox | 0:79620c558b0c | 105 | |
radiojunkbox | 0:79620c558b0c | 106 | /* |
radiojunkbox | 0:79620c558b0c | 107 | Simple test shell to exercise mouse,keyboard,mass storage and hubs. |
radiojunkbox | 0:79620c558b0c | 108 | Add 2 15k pulldown resistors between D+/D- and ground, attach a usb socket and have at it. |
radiojunkbox | 0:79620c558b0c | 109 | */ |
radiojunkbox | 0:79620c558b0c | 110 | |
radiojunkbox | 0:79620c558b0c | 111 | Serial pc(USBTX, USBRX); |
radiojunkbox | 0:79620c558b0c | 112 | int GetConsoleChar() |
radiojunkbox | 0:79620c558b0c | 113 | { |
radiojunkbox | 0:79620c558b0c | 114 | if (!pc.readable()) |
radiojunkbox | 0:79620c558b0c | 115 | return -1; |
radiojunkbox | 0:79620c558b0c | 116 | char c = pc.getc(); |
radiojunkbox | 0:79620c558b0c | 117 | pc.putc(c); // echo |
radiojunkbox | 0:79620c558b0c | 118 | return c; |
radiojunkbox | 0:79620c558b0c | 119 | } |
radiojunkbox | 0:79620c558b0c | 120 | |
non | 2:7576d1327cf1 | 121 | bool IsConsoleReadable() |
non | 2:7576d1327cf1 | 122 | { |
non | 2:7576d1327cf1 | 123 | return pc.readable(); |
non | 2:7576d1327cf1 | 124 | } |
radiojunkbox | 0:79620c558b0c | 125 | |
non | 1:892f8922bdc4 | 126 | |
non | 2:7576d1327cf1 | 127 | static DigitalIn mySW(SWpin); |
non | 2:7576d1327cf1 | 128 | static DigitalOut myLED(LED1); |
non | 2:7576d1327cf1 | 129 | |
radiojunkbox | 0:79620c558b0c | 130 | int main() |
radiojunkbox | 0:79620c558b0c | 131 | { |
radiojunkbox | 0:79620c558b0c | 132 | // pc.baud(460800); |
radiojunkbox | 0:79620c558b0c | 133 | printf("BlueUSB\nNow get a bunch of usb or bluetooth things and plug them in\n"); |
radiojunkbox | 0:79620c558b0c | 134 | InitSerialMIDI(); // Added by RadioJunkBox |
non | 2:7576d1327cf1 | 135 | if (mySW.read() == 0) { |
non | 2:7576d1327cf1 | 136 | myLED = 1; |
non | 2:7576d1327cf1 | 137 | wait(0.5); |
non | 2:7576d1327cf1 | 138 | myLED = 0; |
non | 2:7576d1327cf1 | 139 | } |
radiojunkbox | 0:79620c558b0c | 140 | TestShell(); |
radiojunkbox | 0:79620c558b0c | 141 | } |