Added new USB_DeviceState variable to keep track of the current Device mode USB state.
[pub/USBasp.git] / LUFA / Drivers / USB / LowLevel / Template / Template_Endpoint_Control_R.c
index d66edaf..b85705c 100644 (file)
@@ -14,9 +14,16 @@ uint8_t TEMPLATE_FUNC_NAME (void* Buffer, uint16_t Length)
                        \r
                        Endpoint_ClearOUT();\r
                }\r
+\r
+               if (USB_DeviceState == DEVICE_STATE_Unattached)\r
+                 return ENDPOINT_RWCSTREAM_DeviceDisconnected;\r
        }\r
        \r
-       while (!(Endpoint_IsINReady()));\r
+       while (!(Endpoint_IsINReady()))\r
+       {\r
+               if (USB_DeviceState == DEVICE_STATE_Unattached)\r
+                 return ENDPOINT_RWCSTREAM_DeviceDisconnected;\r
+       }\r
        \r
        return ENDPOINT_RWCSTREAM_NoError;\r
 }\r