X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/5de364163f5a7597ba2f54e37cdea493fbd1e7ff..fc31973daffea3506051ce51a5f79383ce0867d6:/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 a2a9b8c1a..8a5be11f1 100644 --- a/LUFA/Drivers/USB/LowLevel/Template/Template_Endpoint_Control_W.c +++ b/LUFA/Drivers/USB/LowLevel/Template/Template_Endpoint_Control_W.c @@ -5,7 +5,9 @@ uint8_t TEMPLATE_FUNC_NAME (const void* Buffer, uint16_t Length) if (Length > USB_ControlRequest.wLength) Length = USB_ControlRequest.wLength; - + else if (!(Length)) + Endpoint_ClearIN(); + while (Length || LastPacketFull) { if (Endpoint_IsSETUPReceived()) @@ -16,16 +18,21 @@ uint8_t TEMPLATE_FUNC_NAME (const void* Buffer, uint16_t Length) if (USB_DeviceState == DEVICE_STATE_Unattached) return ENDPOINT_RWCSTREAM_DeviceDisconnected; + else if (USB_DeviceState == DEVICE_STATE_Suspended) + return ENDPOINT_RWCSTREAM_BusSuspended; if (Endpoint_IsINReady()) { - while (Length && (Endpoint_BytesInEndpoint() < USB_ControlEndpointSize)) + uint8_t BytesInEndpoint = Endpoint_BytesInEndpoint(); + + while (Length && (BytesInEndpoint < USB_ControlEndpointSize)) { TEMPLATE_TRANSFER_BYTE(DataStream); Length--; + BytesInEndpoint++; } - LastPacketFull = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize); + LastPacketFull = (BytesInEndpoint == USB_ControlEndpointSize); Endpoint_ClearIN(); } } @@ -33,7 +40,9 @@ uint8_t TEMPLATE_FUNC_NAME (const void* Buffer, uint16_t Length) while (!(Endpoint_IsOUTReceived())) { if (USB_DeviceState == DEVICE_STATE_Unattached) - return ENDPOINT_RWCSTREAM_DeviceDisconnected; + return ENDPOINT_RWCSTREAM_DeviceDisconnected; + else if (USB_DeviceState == DEVICE_STATE_Suspended) + return ENDPOINT_RWCSTREAM_BusSuspended; } return ENDPOINT_RWCSTREAM_NoError;