X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/d4ca7fb44c7d326b96cf391f0275dc323dbe24de..d11ed10c5314c44dc01c06954d1d73d4894cbff8:/LUFA/Drivers/USB/Class/Host/MIDI.c diff --git a/LUFA/Drivers/USB/Class/Host/MIDI.c b/LUFA/Drivers/USB/Class/Host/MIDI.c index e79d12101..a5ad4bf2b 100644 --- a/LUFA/Drivers/USB/Class/Host/MIDI.c +++ b/LUFA/Drivers/USB/Class/Host/MIDI.c @@ -1,13 +1,13 @@ /* LUFA Library - Copyright (C) Dean Camera, 2009. + Copyright (C) Dean Camera, 2010. dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ /* - Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) + Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com) Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted @@ -122,9 +122,24 @@ static uint8_t DComp_MIDI_Host_NextMIDIStreamingDataEndpoint(void* const Current return DESCRIPTOR_SEARCH_NotFound; } -void MIDI_Host_USBTask(USB_ClassInfo_MIDI_Host_t* const MIDIInterfaceInfo) +uint8_t MIDI_Host_Flush(USB_ClassInfo_MIDI_Host_t* const MIDIInterfaceInfo) { - (void)MIDIInterfaceInfo; + if (USB_HostState != HOST_STATE_Configured) + return PIPE_RWSTREAM_DeviceDisconnected; + + uint8_t ErrorCode; + + Pipe_SelectPipe(MIDIInterfaceInfo->Config.DataOUTPipeNumber); + + if (Pipe_BytesInPipe()) + { + Pipe_ClearOUT(); + + if ((ErrorCode = Pipe_WaitUntilReady()) != PIPE_READYWAIT_NoError) + return ErrorCode; + } + + return PIPE_READYWAIT_NoError; } uint8_t MIDI_Host_SendEventPacket(USB_ClassInfo_MIDI_Host_t* const MIDIInterfaceInfo, MIDI_EventPacket_t* const Event) @@ -141,7 +156,8 @@ uint8_t MIDI_Host_SendEventPacket(USB_ClassInfo_MIDI_Host_t* const MIDIInterface if ((ErrorCode = Pipe_Write_Stream_LE(Event, sizeof(MIDI_EventPacket_t), NO_STREAM_CALLBACK)) != PIPE_RWSTREAM_NoError) return ErrorCode; - Pipe_ClearOUT(); + if (!(Pipe_IsReadWriteAllowed())) + Pipe_ClearOUT(); } return PIPE_RWSTREAM_NoError; @@ -158,7 +174,9 @@ bool MIDI_Host_ReceiveEventPacket(USB_ClassInfo_MIDI_Host_t* const MIDIInterface return false; Pipe_Read_Stream_LE(Event, sizeof(MIDI_EventPacket_t), NO_STREAM_CALLBACK); - Pipe_ClearIN(); + + if (!(Pipe_IsReadWriteAllowed())) + Pipe_ClearIN(); return true; }