bool USBMIDI::EP2_OUT_callback() { uint8_t buf[64]; uint32_t len; readEP(EPBULK_OUT, buf, &len, 64); if (midi_evt != NULL) { for (int i=0; i<len; i+=4) { midi_evt(MIDIMessage(buf+i)); } } // We reactivate the endpoint to receive next characters readStart(EPBULK_OUT, MAX_PACKET_SIZE_EPBULK); return true; }
bool USBMIDI::EPBULK_OUT_callback() { uint8_t buf[64]; uint32_t len; readEP(EPBULK_OUT, buf, &len, 64); if (midi_evt != NULL) { for (uint32_t i=0; i<len; i+=4) { uint8_t data_read; data_end=true; switch(buf[i]) { case 0x2: // Two-bytes System Common Message - undefined in USBMidi 1.0 data_read=2; break; case 0x4: // SysEx start or continue data_end=false; data_read=3; break; case 0x5: // Single-byte System Common Message or SysEx end with one byte data_read=1; break; case 0x6: // SysEx end with two bytes data_read=2; break; case 0xC: // Program change data_read=2; break; case 0xD: // Channel pressure data_read=2; break; case 0xF: // Single byte data_read=1; break; default: // Others three-bytes messages data_read=3; break; } for(uint8_t j=1;j<data_read+1;j++) { data[cur_data]=buf[i+j]; cur_data++; } if(data_end) { midi_evt(MIDIMessage(data,cur_data)); cur_data=0; } } } // We reactivate the endpoint to receive next characters readStart(EPBULK_OUT, MAX_PACKET_SIZE_EPBULK); return true; }