-static void usb_send_func(MidiDevice * device, uint16_t cnt, uint8_t byte0, uint8_t byte1, uint8_t byte2) {
- MIDI_EventPacket_t event;
- event.Data1 = byte0;
- event.Data2 = byte1;
- event.Data3 = byte2;
-
- uint8_t cable = 0;
-
-// Endpoint_SelectEndpoint(MIDI_STREAM_IN_EPNUM);
-
- //if the length is undefined we assume it is a SYSEX message
- if (midi_packet_length(byte0) == UNDEFINED) {
- switch(cnt) {
- case 3:
- if (byte2 == SYSEX_END)
- event.Event = MIDI_EVENT(cable, SYSEX_ENDS_IN_3);
- else
- event.Event = MIDI_EVENT(cable, SYSEX_START_OR_CONT);
- break;
- case 2:
- if (byte1 == SYSEX_END)
- event.Event = MIDI_EVENT(cable, SYSEX_ENDS_IN_2);
- else
- event.Event = MIDI_EVENT(cable, SYSEX_START_OR_CONT);
- break;
- case 1:
- if (byte0 == SYSEX_END)
- event.Event = MIDI_EVENT(cable, SYSEX_ENDS_IN_1);
- else
- event.Event = MIDI_EVENT(cable, SYSEX_START_OR_CONT);
- break;
- default:
- return; //invalid cnt
- }
- } else {
- //deal with 'system common' messages
- //TODO are there any more?
- switch(byte0 & 0xF0){
- case MIDI_SONGPOSITION:
- event.Event = MIDI_EVENT(cable, SYS_COMMON_3);
- break;
- case MIDI_SONGSELECT:
- case MIDI_TC_QUARTERFRAME:
- event.Event = MIDI_EVENT(cable, SYS_COMMON_2);
- break;
- default:
- event.Event = MIDI_EVENT(cable, byte0);
- break;
- }
- }
-
-// Endpoint_Write_Stream_LE(&event, sizeof(event), NULL);
-// Endpoint_ClearIN();
-
- MIDI_Device_SendEventPacket(&USB_MIDI_Interface, &event);
- MIDI_Device_Flush(&USB_MIDI_Interface);
- MIDI_Device_USBTask(&USB_MIDI_Interface);
- USB_USBTask();
-}
-
-static void usb_get_midi(MidiDevice * device) {
- MIDI_EventPacket_t event;
- while (MIDI_Device_ReceiveEventPacket(&USB_MIDI_Interface, &event)) {
-
- midi_packet_length_t length = midi_packet_length(event.Data1);
- uint8_t input[3];
- input[0] = event.Data1;
- input[1] = event.Data2;
- input[2] = event.Data3;
- if (length == UNDEFINED) {
- //sysex
- if (event.Event == MIDI_EVENT(0, SYSEX_START_OR_CONT) || event.Event == MIDI_EVENT(0, SYSEX_ENDS_IN_3)) {
- length = 3;
- } else if (event.Event == MIDI_EVENT(0, SYSEX_ENDS_IN_2)) {
- length = 2;
- } else if(event.Event == MIDI_EVENT(0, SYSEX_ENDS_IN_1)) {
- length = 1;
- } else {
- //XXX what to do?
- }
- }
-
- //pass the data to the device input function
- if (length != UNDEFINED)
- midi_device_input(device, length, input);
- }
- MIDI_Device_USBTask(&USB_MIDI_Interface);
- USB_USBTask();
-}
-
-static void midi_usb_init(MidiDevice * device){
- midi_device_init(device);
- midi_device_set_send_func(device, usb_send_func);
- midi_device_set_pre_input_process_func(device, usb_get_midi);
-
- // SetupHardware();
- sei();
-}
-
-void MIDI_Task(void)