X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/47f6a35013b2c6a370e5dce29aa6da3a96844695..04d13d264c924d5c3380076f8977ca2dd0b14fd8:/LUFA/Drivers/USB/Class/Host/MIDIClassHost.c?ds=sidebyside diff --git a/LUFA/Drivers/USB/Class/Host/MIDIClassHost.c b/LUFA/Drivers/USB/Class/Host/MIDIClassHost.c index 0d33bfec4..544b9fa08 100644 --- a/LUFA/Drivers/USB/Class/Host/MIDIClassHost.c +++ b/LUFA/Drivers/USB/Class/Host/MIDIClassHost.c @@ -18,7 +18,7 @@ advertising or publicity pertaining to distribution of the software without specific, written prior permission. - The author disclaim all warranties with regard to this + The author disclaims all warranties with regard to this software, including all implied warranties of merchantability and fitness. In no event shall the author be liable for any special, indirect or consequential damages or any damages @@ -156,15 +156,21 @@ uint8_t MIDI_Host_Flush(USB_ClassInfo_MIDI_Host_t* const MIDIInterfaceInfo) uint8_t ErrorCode; Pipe_SelectPipe(MIDIInterfaceInfo->Config.DataOUTPipe.Address); - + Pipe_Unfreeze(); + if (Pipe_BytesInPipe()) { Pipe_ClearOUT(); if ((ErrorCode = Pipe_WaitUntilReady()) != PIPE_READYWAIT_NoError) - return ErrorCode; + { + Pipe_Freeze(); + return ErrorCode; + } } + Pipe_Freeze(); + return PIPE_READYWAIT_NoError; } @@ -177,13 +183,19 @@ uint8_t MIDI_Host_SendEventPacket(USB_ClassInfo_MIDI_Host_t* const MIDIInterface uint8_t ErrorCode; Pipe_SelectPipe(MIDIInterfaceInfo->Config.DataOUTPipe.Address); - + Pipe_Unfreeze(); + if ((ErrorCode = Pipe_Write_Stream_LE(Event, sizeof(MIDI_EventPacket_t), NULL)) != PIPE_RWSTREAM_NoError) - return ErrorCode; + { + Pipe_Freeze(); + return ErrorCode; + } if (!(Pipe_IsReadWriteAllowed())) Pipe_ClearOUT(); + Pipe_Freeze(); + return PIPE_RWSTREAM_NoError; } @@ -192,18 +204,27 @@ bool MIDI_Host_ReceiveEventPacket(USB_ClassInfo_MIDI_Host_t* const MIDIInterface { if ((USB_HostState != HOST_STATE_Configured) || !(MIDIInterfaceInfo->State.IsActive)) return HOST_SENDCONTROL_DeviceDisconnected; + + bool DataReady = false; Pipe_SelectPipe(MIDIInterfaceInfo->Config.DataINPipe.Address); + Pipe_Unfreeze(); - if (!(Pipe_IsReadWriteAllowed())) - return false; - - Pipe_Read_Stream_LE(Event, sizeof(MIDI_EventPacket_t), NULL); - - if (!(Pipe_IsReadWriteAllowed())) - Pipe_ClearIN(); + if (Pipe_IsINReceived()) + { + if (Pipe_BytesInPipe()) + { + Pipe_Read_Stream_LE(Event, sizeof(MIDI_EventPacket_t), NULL); + DataReady = true; + } - return true; + if (!(Pipe_BytesInPipe())) + Pipe_ClearIN(); + } + + Pipe_Freeze(); + + return DataReady; } #endif