My Fork of F401RE-USBHost. Add USBHostMIDI functions (originaled by Kaoru Shoji http://mbed.org/users/kshoji/code/USBHostMIDI/)
Dependents: F401RE-USBHostMIDI_RecieveExample
Fork of F401RE-USBHost by
Revision 26:077ab26227c6, committed 2014-09-18
- Comitter:
- hsgw
- Date:
- Thu Sep 18 12:32:33 2014 +0000
- Parent:
- 25:c4fdd0b4e643
- Child:
- 27:23fa4e04b1db
- Commit message:
- fix miscellaneous function and cable event.
Changed in this revision
USBHostMIDI/USBHostMIDI.cpp | Show annotated file Show diff for this revision Revisions of this file |
USBHostMIDI/USBHostMIDI.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/USBHostMIDI/USBHostMIDI.cpp Thu Sep 18 11:34:43 2014 +0000 +++ b/USBHostMIDI/USBHostMIDI.cpp Thu Sep 18 12:32:33 2014 +0000 @@ -91,7 +91,8 @@ void USBHostMIDI::rxHandler() { uint8_t *midi; if (bulk_in) { - int length = bulk_in->getLengthTransferred(); + + int length = bulk_in->getLengthTransferred(); // why does this method always return 64? if (bulk_in->getState() == USB_TYPE_IDLE || bulk_in->getState() == USB_TYPE_FREE) { // MIDI event handling for (int i = 0; i < length; i += 4) { @@ -102,16 +103,22 @@ // read each four bytes midi = &buf[i]; + // process MIDI message + if (midi[0] == 0 && midi[1] == 0) { + // {0,0,0,0} may be not collect data + continue; + } + + USB_DBG("raw: %d, %d, %d, %d", midi[0]&0xf, midi[1], midi[2], midi[3]); // switch by code index number - USB_DBG("midi: %d, %d, %d, %d", midi[0]&0xf, midi[1], midi[2], midi[3]); switch (midi[0] & 0xf) { case 0: // miscellaneous function codes - //if(midi[1] == 0) break; - //miscellaneousFunctionCode(midi[1], midi[2], midi[3]); + if(midi[1] == 0) break; + miscellaneousFunctionCode(midi[1], midi[2], midi[3]); break; case 1: // cable events - //cableEvent(midi[1], midi[2], midi[3]); + cableEvent(midi[1], midi[2], midi[3]); break; case 2: // two bytes system common messages systemCommonTwoBytes(midi[1], midi[2]);
--- a/USBHostMIDI/USBHostMIDI.h Thu Sep 18 11:34:43 2014 +0000 +++ b/USBHostMIDI/USBHostMIDI.h Thu Sep 18 12:32:33 2014 +0000 @@ -52,27 +52,27 @@ */ bool connect(); -// /** -// * Attach a callback called when miscellaneous function code is received -// * @warning DISABLED -// * -// * @param ptr function pointer -// * prototype: void onMiscellaneousFunctionCode(uint8_t data1, uint8_t data2, uint8_t data3); -// */ -// inline void attachMiscellaneousFunctionCode(void (*fn)(uint8_t, uint8_t, uint8_t)) { -// miscellaneousFunctionCode = fn; -// } + /** + * Attach a callback called when miscellaneous function code is received + * @warning DISABLED + * + * @param ptr function pointer + * prototype: void onMiscellaneousFunctionCode(uint8_t data1, uint8_t data2, uint8_t data3); + */ + inline void attachMiscellaneousFunctionCode(void (*fn)(uint8_t, uint8_t, uint8_t)) { + miscellaneousFunctionCode = fn; + } -// /** -// * Attach a callback called when cable event is received -// * @warning DISABLED -// * -// * @param ptr function pointer -// * prototype: void onCableEvent(uint8_t data1, uint8_t data2, uint8_t data3); -// */ -// inline void attachCableEvent(void (*fn)(uint8_t, uint8_t, uint8_t)) { -// cableEvent = fn; -// } + /** + * Attach a callback called when cable event is received + * @warning DISABLED + * + * @param ptr function pointer + * prototype: void onCableEvent(uint8_t data1, uint8_t data2, uint8_t data3); + */ + inline void attachCableEvent(void (*fn)(uint8_t, uint8_t, uint8_t)) { + cableEvent = fn; + } /** * Attach a callback called when system exclusive is received @@ -332,8 +332,8 @@ uint16_t sysExBufferPos; uint8_t sysExBuffer[64]; -// void (*miscellaneousFunctionCode)(uint8_t, uint8_t, uint8_t); -// void (*cableEvent)(uint8_t, uint8_t, uint8_t); + void (*miscellaneousFunctionCode)(uint8_t, uint8_t, uint8_t); + void (*cableEvent)(uint8_t, uint8_t, uint8_t); void (*systemCommonTwoBytes)(uint8_t, uint8_t); void (*systemCommonThreeBytes)(uint8_t, uint8_t, uint8_t); void (*systemExclusive)(uint8_t *, uint16_t, bool);