Make Control Endpoint stream transfers more reliable by adding in early aborts for...
[pub/USBasp.git] / LUFA / Drivers / USB / LowLevel / Template / Template_Endpoint_Control_R.c
index b85705c..a2a0c3b 100644 (file)
@@ -4,6 +4,12 @@ uint8_t TEMPLATE_FUNC_NAME (void* Buffer, uint16_t Length)
        \r
        while (Length)\r
        {\r
+               if (Endpoint_IsSETUPReceived())\r
+                 return ENDPOINT_RWCSTREAM_HostAborted;\r
+\r
+               if (USB_DeviceState == DEVICE_STATE_Unattached)\r
+                 return ENDPOINT_RWCSTREAM_DeviceDisconnected;\r
+                 \r
                if (Endpoint_IsOUTReceived())\r
                {\r
                        while (Length && Endpoint_BytesInEndpoint())\r
@@ -13,10 +19,7 @@ uint8_t TEMPLATE_FUNC_NAME (void* Buffer, uint16_t Length)
                        }\r
                        \r
                        Endpoint_ClearOUT();\r
-               }\r
-\r
-               if (USB_DeviceState == DEVICE_STATE_Unattached)\r
-                 return ENDPOINT_RWCSTREAM_DeviceDisconnected;\r
+               }                 \r
        }\r
        \r
        while (!(Endpoint_IsINReady()))\r