X-Git-Url: http://git.linex4red.de/pub/lufa.git/blobdiff_plain/8f6b4ddf764c3a54e42d00a7502c82c5c3e71b1c..6865a7bc09e31d3bbebb33eefb6475c8713351bd:/LUFA/Drivers/USB/LowLevel/Endpoint.c diff --git a/LUFA/Drivers/USB/LowLevel/Endpoint.c b/LUFA/Drivers/USB/LowLevel/Endpoint.c index b88547177..efa1a2db4 100644 --- a/LUFA/Drivers/USB/LowLevel/Endpoint.c +++ b/LUFA/Drivers/USB/LowLevel/Endpoint.c @@ -59,7 +59,7 @@ bool Endpoint_ConfigureEndpointStatic(const uint8_t Number, const uint8_t UECFG0 Endpoint_SelectEndpoint(Number); Endpoint_EnableEndpoint(); - UECFG1X = 0; + UECFG1X = 0; UECFG0X = UECFG0XData; UECFG1X = UECFG1XData; @@ -292,8 +292,9 @@ uint8_t Endpoint_Read_Stream_BE(void* Buffer, uint16_t Length uint8_t Endpoint_Write_Control_Stream_LE(const void* Buffer, uint16_t Length) { - uint8_t* DataStream = (uint8_t*)Buffer; - bool SendZLP = true; + uint8_t* DataStream = (uint8_t*)Buffer; + bool LastPacketFull = false; + bool ShortTransfer = (Length < USB_ControlRequest.wLength); while (Length && !(Endpoint_IsOUTReceived())) { @@ -306,17 +307,17 @@ uint8_t Endpoint_Write_Control_Stream_LE(const void* Buffer, uint16_t Length) Length--; } - SendZLP = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize); - Endpoint_ClearControlIN(); + LastPacketFull = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize); + Endpoint_ClearIN(); } if (Endpoint_IsOUTReceived()) return ENDPOINT_RWCSTREAM_ERROR_HostAborted; - if (SendZLP) + if (LastPacketFull || ShortTransfer) { while (!(Endpoint_IsINReady())); - Endpoint_ClearControlIN(); + Endpoint_ClearIN(); } while (!(Endpoint_IsOUTReceived())); @@ -326,8 +327,9 @@ uint8_t Endpoint_Write_Control_Stream_LE(const void* Buffer, uint16_t Length) uint8_t Endpoint_Write_Control_Stream_BE(const void* Buffer, uint16_t Length) { - uint8_t* DataStream = (uint8_t*)(Buffer + Length - 1); - bool SendZLP = true; + uint8_t* DataStream = (uint8_t*)(Buffer + Length - 1); + bool LastPacketFull = false; + bool ShortTransfer = (Length < USB_ControlRequest.wLength); while (Length && !(Endpoint_IsOUTReceived())) { @@ -340,17 +342,17 @@ uint8_t Endpoint_Write_Control_Stream_BE(const void* Buffer, uint16_t Length) Length--; } - SendZLP = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize); - Endpoint_ClearControlIN(); + LastPacketFull = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize); + Endpoint_ClearIN(); } if (Endpoint_IsOUTReceived()) return ENDPOINT_RWCSTREAM_ERROR_HostAborted; - if (SendZLP) + if (LastPacketFull || ShortTransfer) { while (!(Endpoint_IsINReady())); - Endpoint_ClearControlIN(); + Endpoint_ClearIN(); } while (!(Endpoint_IsOUTReceived())); @@ -373,7 +375,7 @@ uint8_t Endpoint_Read_Control_Stream_LE(void* Buffer, uint16_t Length) Length--; } - Endpoint_ClearControlOUT(); + Endpoint_ClearOUT(); } while (!(Endpoint_IsINReady())); @@ -396,7 +398,7 @@ uint8_t Endpoint_Read_Control_Stream_BE(void* Buffer, uint16_t Length) Length--; } - Endpoint_ClearControlOUT(); + Endpoint_ClearOUT(); } while (!(Endpoint_IsINReady()));