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'
Diff: TestShell.cpp
- Revision:
- 2:7576d1327cf1
- Parent:
- 1:892f8922bdc4
- Child:
- 3:31fbce33c25b
diff -r 892f8922bdc4 -r 7576d1327cf1 TestShell.cpp --- a/TestShell.cpp Sat Apr 05 06:25:43 2014 +0000 +++ b/TestShell.cpp Sun Apr 27 01:36:30 2014 +0000 @@ -31,6 +31,12 @@ #include "USBHost.h" #include "hci.h" +#include "common.h" +#include "TestShell.h" + +static DigitalOut myLED1(LED1); +static DigitalIn mySW(SWpin); + void printf(const BD_ADDR* addr) { const u8* a = addr->addr; @@ -86,13 +92,16 @@ #define WII_REMOTE 0x042500 +#define NSX39_device 1 +#define NSX39_endpoint 2 + void NoteOn(u8 ch, u8 note, u8 velocity) { static u8 d[64] = {0x09}; d[1] = 0x90 | (ch & 0x7f); d[2] = note & 0x7f; d[3] = velocity & 0x7f; - USBBulkTransfer(1, 2, d, 4, NULL, NULL); + USBBulkTransfer(NSX39_device, NSX39_endpoint, d, 4, NULL, NULL); } void NoteOff(u8 ch, u8 note, u8 velocity) @@ -101,7 +110,7 @@ d[1] = 0x80 | (ch & 0xf); d[2] = note & 0x7f; d[3] = velocity & 0x7f; - USBBulkTransfer(1, 2, d, 4, NULL, NULL); + USBBulkTransfer(NSX39_device, NSX39_endpoint, d, 4, NULL, NULL); } void Miku(u8 chr) @@ -110,7 +119,7 @@ 0x04, 0x09, 0x11, 0x0a, 0x07, 0x00, 0x00, 0xf7}; d[10] = chr; - USBBulkTransfer(1, 2, d, 12, NULL, NULL); + USBBulkTransfer(NSX39_device, NSX39_endpoint, d, 12, NULL, NULL); } @@ -221,7 +230,6 @@ #define MAX_HID_DEVICES 8 -int GetConsoleChar(); class ShellApp { char _line[64]; @@ -333,40 +341,41 @@ { for(;;) { - const char* cmd = ReadLine(); - if (strcmp(cmd,"s") == 0) { -/* - static u8 d[64] = {0x09, 0x91, 0x4e, 0x7f}; - USBBulkTransfer(1, 2, d, 4, NULL, NULL); -*/ - Miku(3); - wait(0.001); - NoteOn(0, 72, 0x7f); - wait(0.8); - NoteOff(0, 72, 0x7f); - wait(0.001); + const char* cmd = ""; + USBLoop(); + if (IsConsoleReadable()) + cmd = ReadLine(); + + if ((strcmp(cmd,"s") == 0) || (mySW == 0)) { + myLED1 = 1; + Miku(3); + wait(0.001); + NoteOn(0, 72, 0x7f); + wait(0.8); + NoteOff(0, 72, 0x7f); + wait(0.001); - Miku(124); - wait(0.001); - NoteOn(0, 74, 0x7f); - wait(0.5); - NoteOff(0, 74, 0x7f); - wait(0.001); + Miku(124); + wait(0.001); + NoteOn(0, 74, 0x7f); + wait(0.5); + NoteOff(0, 74, 0x7f); + wait(0.001); - Miku(79); - wait(0.001); - NoteOn(0, 76, 0x7f); - wait(0.5); - NoteOff(0, 76, 0x7f); + Miku(79); + wait(0.001); + NoteOn(0, 76, 0x7f); + wait(0.5); + NoteOff(0, 76, 0x7f); - wait(0.2); + wait(0.2); - Miku(50); - wait(0.001); - NoteOn(0, 76, 0x7f); - wait(0.5); - NoteOff(0, 76, 0x7f); - + Miku(50); + wait(0.001); + NoteOn(0, 76, 0x7f); + wait(0.5); + NoteOff(0, 76, 0x7f); + myLED1 = 0; } else if (strcmp(cmd,"scan") == 0 || strcmp(cmd,"inquiry") == 0) Inquiry(); @@ -380,6 +389,8 @@ { Quit(); break; + } else if (*cmd == 0) { + /* ignore */ } else { printf("eh? %s\n",cmd); }