X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/c7bc3ec391da3904f0db6398171c7fed37d4f836..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 1cdfa498b..a5ad4bf2b 100644 --- a/LUFA/Drivers/USB/Class/Host/MIDI.c +++ b/LUFA/Drivers/USB/Class/Host/MIDI.c @@ -1,21 +1,21 @@ /* 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) - - Permission to use, copy, modify, and distribute this software - and its documentation for any purpose and without fee is hereby - granted, provided that the above copyright notice appear in all - copies and that both that the copyright notice and this - permission notice and warranty disclaimer appear in supporting - documentation, and that the name of the author not be used in - advertising or publicity pertaining to distribution of the + 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 + without fee, provided that the above copyright notice appear in + all copies and that both that the copyright notice and this + permission notice and warranty disclaimer appear in supporting + documentation, and that the name of the author not be used in + advertising or publicity pertaining to distribution of the software without specific, written prior permission. The author disclaim all warranties with regard to this @@ -35,7 +35,7 @@ #include "MIDI.h" uint8_t MIDI_Host_ConfigurePipes(USB_ClassInfo_MIDI_Host_t* const MIDIInterfaceInfo, uint16_t ConfigDescriptorSize, - uint8_t* ConfigDescriptorData) + void* ConfigDescriptorData) { uint8_t FoundEndpoints = 0; @@ -63,7 +63,8 @@ uint8_t MIDI_Host_ConfigurePipes(USB_ClassInfo_MIDI_Host_t* const MIDIInterfaceI if (EndpointData->EndpointAddress & ENDPOINT_DESCRIPTOR_DIR_IN) { Pipe_ConfigurePipe(MIDIInterfaceInfo->Config.DataINPipeNumber, EP_TYPE_BULK, PIPE_TOKEN_IN, - EndpointData->EndpointAddress, EndpointData->EndpointSize, PIPE_BANK_SINGLE); + EndpointData->EndpointAddress, EndpointData->EndpointSize, + MIDIInterfaceInfo->Config.DataINPipeDoubleBank ? PIPE_BANK_DOUBLE : PIPE_BANK_SINGLE); MIDIInterfaceInfo->State.DataINPipeSize = EndpointData->EndpointSize; FoundEndpoints |= MIDI_FOUND_DATAPIPE_IN; @@ -71,7 +72,8 @@ uint8_t MIDI_Host_ConfigurePipes(USB_ClassInfo_MIDI_Host_t* const MIDIInterfaceI else { Pipe_ConfigurePipe(MIDIInterfaceInfo->Config.DataOUTPipeNumber, EP_TYPE_BULK, PIPE_TOKEN_OUT, - EndpointData->EndpointAddress, EndpointData->EndpointSize, PIPE_BANK_SINGLE); + EndpointData->EndpointAddress, EndpointData->EndpointSize, + MIDIInterfaceInfo->Config.DataOUTPipeDoubleBank ? PIPE_BANK_DOUBLE : PIPE_BANK_SINGLE); MIDIInterfaceInfo->State.DataOUTPipeSize = EndpointData->EndpointSize; FoundEndpoints |= MIDI_FOUND_DATAPIPE_OUT; @@ -82,7 +84,7 @@ uint8_t MIDI_Host_ConfigurePipes(USB_ClassInfo_MIDI_Host_t* const MIDIInterfaceI return MIDI_ENUMERROR_NoError; } -static uint8_t DComp_MIDI_Host_NextMIDIStreamingInterface(void* CurrentDescriptor) +static uint8_t DComp_MIDI_Host_NextMIDIStreamingInterface(void* const CurrentDescriptor) { if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Interface) { @@ -100,7 +102,7 @@ static uint8_t DComp_MIDI_Host_NextMIDIStreamingInterface(void* CurrentDescripto return DESCRIPTOR_SEARCH_NotFound; } -static uint8_t DComp_MIDI_Host_NextMIDIStreamingDataEndpoint(void* CurrentDescriptor) +static uint8_t DComp_MIDI_Host_NextMIDIStreamingDataEndpoint(void* const CurrentDescriptor) { if (DESCRIPTOR_TYPE(CurrentDescriptor) == DTYPE_Endpoint) { @@ -120,26 +122,42 @@ static uint8_t DComp_MIDI_Host_NextMIDIStreamingDataEndpoint(void* CurrentDescri 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) { + 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) { if ((USB_HostState != HOST_STATE_Configured) || !(MIDIInterfaceInfo->State.IsActive)) - return HOST_SENDCONTROL_DeviceDisconnect; + return HOST_SENDCONTROL_DeviceDisconnected; Pipe_SelectPipe(MIDIInterfaceInfo->Config.DataOUTPipeNumber); - if (Pipe_IsReadWriteAllowed()); + if (Pipe_IsReadWriteAllowed()) { uint8_t ErrorCode; 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; @@ -148,7 +166,7 @@ uint8_t MIDI_Host_SendEventPacket(USB_ClassInfo_MIDI_Host_t* const MIDIInterface bool MIDI_Host_ReceiveEventPacket(USB_ClassInfo_MIDI_Host_t* const MIDIInterfaceInfo, MIDI_EventPacket_t* const Event) { if ((USB_HostState != HOST_STATE_Configured) || !(MIDIInterfaceInfo->State.IsActive)) - return HOST_SENDCONTROL_DeviceDisconnect; + return HOST_SENDCONTROL_DeviceDisconnected; Pipe_SelectPipe(MIDIInterfaceInfo->Config.DataINPipeNumber); @@ -156,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; }