USB_HostRequest renamed to USB_ControlRequest, entire control request header is now...
[pub/USBasp.git] / LUFA / Drivers / USB / LowLevel / Endpoint.c
index e196b6a..efa1a2d 100644 (file)
@@ -292,8 +292,9 @@ uint8_t Endpoint_Read_Stream_BE(void* Buffer, uint16_t Length
 \r
 uint8_t Endpoint_Write_Control_Stream_LE(const void* Buffer, uint16_t Length)\r
 {\r
-       uint8_t* DataStream = (uint8_t*)Buffer;\r
-       bool     SendZLP    = true;\r
+       uint8_t* DataStream    = (uint8_t*)Buffer;\r
+       bool     LastPacketFull = false;\r
+       bool     ShortTransfer = (Length < USB_ControlRequest.wLength);\r
        \r
        while (Length && !(Endpoint_IsOUTReceived()))\r
        {\r
@@ -306,14 +307,14 @@ uint8_t Endpoint_Write_Control_Stream_LE(const void* Buffer, uint16_t Length)
                        Length--;\r
                }\r
                \r
-               SendZLP = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize);\r
+               LastPacketFull = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize);\r
                Endpoint_ClearIN();\r
        }\r
        \r
        if (Endpoint_IsOUTReceived())\r
          return ENDPOINT_RWCSTREAM_ERROR_HostAborted;\r
        \r
-       if (SendZLP)\r
+       if (LastPacketFull || ShortTransfer)\r
        {\r
                while (!(Endpoint_IsINReady()));\r
                Endpoint_ClearIN();\r
@@ -326,8 +327,9 @@ uint8_t Endpoint_Write_Control_Stream_LE(const void* Buffer, uint16_t Length)
 \r
 uint8_t Endpoint_Write_Control_Stream_BE(const void* Buffer, uint16_t Length)\r
 {\r
-       uint8_t* DataStream = (uint8_t*)(Buffer + Length - 1);\r
-       bool     SendZLP    = true;\r
+       uint8_t* DataStream     = (uint8_t*)(Buffer + Length - 1);\r
+       bool     LastPacketFull = false;\r
+       bool     ShortTransfer  = (Length < USB_ControlRequest.wLength);\r
        \r
        while (Length && !(Endpoint_IsOUTReceived()))\r
        {\r
@@ -340,14 +342,14 @@ uint8_t Endpoint_Write_Control_Stream_BE(const void* Buffer, uint16_t Length)
                        Length--;\r
                }\r
                \r
-               SendZLP = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize);\r
+               LastPacketFull = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize);\r
                Endpoint_ClearIN();\r
        }\r
        \r
        if (Endpoint_IsOUTReceived())\r
          return ENDPOINT_RWCSTREAM_ERROR_HostAborted;\r
        \r
-       if (SendZLP)\r
+       if (LastPacketFull || ShortTransfer)\r
        {\r
                while (!(Endpoint_IsINReady()));\r
                Endpoint_ClearIN();\r