X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/73d9fafc0fe42741ad8f609dd4762e2bc14cbd01..fa8d25ef29eb9e96f9089d17eeb64b3a5edb8e66:/LUFA/Drivers/USB/LowLevel/Template/Template_Endpoint_Control_W.c diff --git a/LUFA/Drivers/USB/LowLevel/Template/Template_Endpoint_Control_W.c b/LUFA/Drivers/USB/LowLevel/Template/Template_Endpoint_Control_W.c index 2796c6425..6c1445ee0 100644 --- a/LUFA/Drivers/USB/LowLevel/Template/Template_Endpoint_Control_W.c +++ b/LUFA/Drivers/USB/LowLevel/Template/Template_Endpoint_Control_W.c @@ -6,30 +6,35 @@ uint8_t TEMPLATE_FUNC_NAME (void* Buffer, uint16_t Length) if (Length > USB_ControlRequest.wLength) Length = USB_ControlRequest.wLength; - while (Length && !(Endpoint_IsOUTReceived())) + while (Length || LastPacketFull) { - while (!(Endpoint_IsINReady())); + if (Endpoint_IsSETUPReceived()) + return ENDPOINT_RWCSTREAM_HostAborted; + + if (Endpoint_IsOUTReceived()) + break; - while (Length && (Endpoint_BytesInEndpoint() < USB_ControlEndpointSize)) + if (USB_DeviceState == DEVICE_STATE_Unattached) + return ENDPOINT_RWCSTREAM_DeviceDisconnected; + + if (Endpoint_IsINReady()) { - TEMPLATE_TRANSFER_BYTE(DataStream); - Length--; + while (Length && (Endpoint_BytesInEndpoint() < USB_ControlEndpointSize)) + { + TEMPLATE_TRANSFER_BYTE(DataStream); + Length--; + } + + LastPacketFull = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize); + Endpoint_ClearIN(); } - - LastPacketFull = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize); - Endpoint_ClearIN(); } - if (Endpoint_IsOUTReceived()) - return ENDPOINT_RWCSTREAM_HostAborted; - - if (LastPacketFull) + while (!(Endpoint_IsOUTReceived())) { - while (!(Endpoint_IsINReady())); - Endpoint_ClearIN(); + if (USB_DeviceState == DEVICE_STATE_Unattached) + return ENDPOINT_RWCSTREAM_DeviceDisconnected; } - - while (!(Endpoint_IsOUTReceived())); return ENDPOINT_RWCSTREAM_NoError; }