X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/60e96412220b62a614348c287354c56f282fcc70..fc31973daffea3506051ce51a5f79383ce0867d6:/LUFA/Drivers/USB/Class/Device/MIDI.c diff --git a/LUFA/Drivers/USB/Class/Device/MIDI.c b/LUFA/Drivers/USB/Class/Device/MIDI.c index bc191d77a..d3f8f55b6 100644 --- a/LUFA/Drivers/USB/Class/Device/MIDI.c +++ b/LUFA/Drivers/USB/Class/Device/MIDI.c @@ -28,9 +28,11 @@ this software. */ +#define __INCLUDE_FROM_USB_DRIVER #include "../../HighLevel/USBMode.h" #if defined(USB_CAN_BE_DEVICE) +#define __INCLUDE_FROM_MIDI_DRIVER #include "MIDI.h" void MIDI_Device_ProcessControlRequest(USB_ClassInfo_MIDI_Device_t* const MIDIInterfaceInfo) @@ -79,12 +81,33 @@ uint8_t MIDI_Device_SendEventPacket(USB_ClassInfo_MIDI_Device_t* const MIDIInter if ((ErrorCode = Endpoint_Write_Stream_LE(Event, sizeof(MIDI_EventPacket_t), NO_STREAM_CALLBACK)) != ENDPOINT_RWSTREAM_NoError) return ErrorCode; - Endpoint_ClearIN(); + if (!(Endpoint_IsReadWriteAllowed())) + Endpoint_ClearIN(); } return ENDPOINT_RWSTREAM_NoError; } +uint8_t MIDI_Device_Flush(USB_ClassInfo_MIDI_Device_t* const MIDIInterfaceInfo) +{ + if (USB_DeviceState != DEVICE_STATE_Configured) + return ENDPOINT_RWSTREAM_DeviceDisconnected; + + uint8_t ErrorCode; + + Endpoint_SelectEndpoint(MIDIInterfaceInfo->Config.DataINEndpointNumber); + + if (Endpoint_BytesInEndpoint()) + { + Endpoint_ClearIN(); + + if ((ErrorCode = Endpoint_WaitUntilReady()) != ENDPOINT_READYWAIT_NoError) + return ErrorCode; + } + + return ENDPOINT_READYWAIT_NoError; +} + bool MIDI_Device_ReceiveEventPacket(USB_ClassInfo_MIDI_Device_t* const MIDIInterfaceInfo, MIDI_EventPacket_t* const Event) { if (USB_DeviceState != DEVICE_STATE_Configured) @@ -96,7 +119,9 @@ bool MIDI_Device_ReceiveEventPacket(USB_ClassInfo_MIDI_Device_t* const MIDIInter return false; Endpoint_Read_Stream_LE(Event, sizeof(MIDI_EventPacket_t), NO_STREAM_CALLBACK); - Endpoint_ClearOUT(); + + if (!(Endpoint_IsReadWriteAllowed())) + Endpoint_ClearOUT(); return true; }