Added new USB_DeviceState variable to keep track of the current Device mode USB state.
[pub/lufa.git] / LUFA / Drivers / USB / LowLevel / Endpoint.c
index f9db9cd..e4d0140 100644 (file)
@@ -71,6 +71,30 @@ void Endpoint_ClearEndpoints(void)
        }\r
 }\r
 \r
+void Endpoint_ClearStatusStage(void)\r
+{\r
+       if (USB_ControlRequest.bmRequestType & REQDIR_DEVICETOHOST)\r
+       {\r
+               while (!(Endpoint_IsOUTReceived()))\r
+               {                               \r
+                       if (USB_DeviceState == DEVICE_STATE_Unattached)\r
+                         return;\r
+               }\r
+\r
+               Endpoint_ClearOUT();\r
+       }\r
+       else\r
+       {\r
+               while (!(Endpoint_IsINReady()))\r
+               {\r
+                       if (USB_DeviceState == DEVICE_STATE_Unattached)\r
+                         return;\r
+               }\r
+               \r
+               Endpoint_ClearIN();\r
+       }\r
+}\r
+\r
 #if !defined(CONTROL_ONLY_DEVICE)\r
 uint8_t Endpoint_WaitUntilReady(void)\r
 {\r
@@ -93,7 +117,7 @@ uint8_t Endpoint_WaitUntilReady(void)
                          return ENDPOINT_READYWAIT_NoError;            \r
                }\r
                \r
-               if (!(USB_IsConnected))\r
+               if (USB_DeviceState == DEVICE_STATE_Unattached)\r
                  return ENDPOINT_READYWAIT_DeviceDisconnected;\r
                else if (Endpoint_IsStalled())\r
                  return ENDPOINT_READYWAIT_EndpointStalled;\r