Applied STATIC_ENDPOINT_CONFIGURATION and FIXED_CONTROL_SIZE tokens to all Device...
[pub/lufa.git] / LUFA / Drivers / USB / LowLevel / Endpoint.c
index b885471..efa1a2d 100644 (file)
@@ -59,7 +59,7 @@ bool Endpoint_ConfigureEndpointStatic(const uint8_t Number, const uint8_t UECFG0
        Endpoint_SelectEndpoint(Number);\r
        Endpoint_EnableEndpoint();\r
 \r
-       UECFG1X = 0;    \r
+       UECFG1X = 0;\r
 \r
        UECFG0X = UECFG0XData;\r
        UECFG1X = UECFG1XData;\r
@@ -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,17 +307,17 @@ uint8_t Endpoint_Write_Control_Stream_LE(const void* Buffer, uint16_t Length)
                        Length--;\r
                }\r
                \r
-               SendZLP = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize);\r
-               Endpoint_ClearControlIN();\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_ClearControlIN();\r
+               Endpoint_ClearIN();\r
        }\r
        \r
        while (!(Endpoint_IsOUTReceived()));\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,17 +342,17 @@ uint8_t Endpoint_Write_Control_Stream_BE(const void* Buffer, uint16_t Length)
                        Length--;\r
                }\r
                \r
-               SendZLP = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize);\r
-               Endpoint_ClearControlIN();\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_ClearControlIN();\r
+               Endpoint_ClearIN();\r
        }\r
        \r
        while (!(Endpoint_IsOUTReceived()));\r
@@ -373,7 +375,7 @@ uint8_t Endpoint_Read_Control_Stream_LE(void* Buffer, uint16_t Length)
                        Length--;\r
                }\r
                \r
-               Endpoint_ClearControlOUT();\r
+               Endpoint_ClearOUT();\r
        }\r
        \r
        while (!(Endpoint_IsINReady()));\r
@@ -396,7 +398,7 @@ uint8_t Endpoint_Read_Control_Stream_BE(void* Buffer, uint16_t Length)
                        Length--;\r
                }\r
                \r
-               Endpoint_ClearControlOUT();\r
+               Endpoint_ClearOUT();\r
        }\r
        \r
        while (!(Endpoint_IsINReady()));\r