Fixed incorrect HID interface class and subclass values in the Mouse and KeyboardMous...
[pub/USBasp.git] / LUFA / Drivers / USB / LowLevel / Endpoint.c
index 273e190..b885471 100644 (file)
@@ -28,7 +28,8 @@
   this software.\r
 */\r
 \r
-#include "USBMode.h"\r
+#include "../HighLevel/USBMode.h"\r
+\r
 #if defined(USB_CAN_BE_DEVICE)\r
 \r
 #define  INCLUDE_FROM_ENDPOINT_C\r
@@ -83,12 +84,23 @@ void Endpoint_ClearEndpoints(void)
 \r
 uint8_t Endpoint_WaitUntilReady(void)\r
 {\r
-       uint8_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS;\r
+       uint16_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS;\r
 \r
        USB_INT_Clear(USB_INT_SOFI);\r
 \r
-       while (!(Endpoint_ReadWriteAllowed()))\r
+       for (;;)\r
        {\r
+               if (Endpoint_GetEndpointDirection() == ENDPOINT_DIR_IN)\r
+               {\r
+                       if (Endpoint_IsINReady())\r
+                         return ENDPOINT_READYWAIT_NoError;\r
+               }\r
+               else\r
+               {\r
+                       if (Endpoint_IsOUTReceived())\r
+                         return ENDPOINT_READYWAIT_NoError;            \r
+               }\r
+               \r
                if (!(USB_IsConnected))\r
                  return ENDPOINT_READYWAIT_DeviceDisconnected;\r
                else if (Endpoint_IsStalled())\r
@@ -102,8 +114,6 @@ uint8_t Endpoint_WaitUntilReady(void)
                          return ENDPOINT_READYWAIT_Timeout;\r
                }\r
        }\r
-       \r
-       return ENDPOINT_READYWAIT_NoError;\r
 }\r
 \r
 uint8_t Endpoint_Discard_Stream(uint16_t Length\r
@@ -119,9 +129,9 @@ uint8_t Endpoint_Discard_Stream(uint16_t Length
 \r
        while (Length--)\r
        {\r
-               if (!(Endpoint_ReadWriteAllowed()))\r
+               if (!(Endpoint_IsReadWriteAllowed()))\r
                {\r
-                       Endpoint_ClearCurrentBank();\r
+                       Endpoint_ClearOUT();\r
 \r
                        #if !defined(NO_STREAM_CALLBACKS)\r
                        if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort))\r
@@ -131,8 +141,10 @@ uint8_t Endpoint_Discard_Stream(uint16_t Length
                        if ((ErrorCode = Endpoint_WaitUntilReady()))\r
                          return ErrorCode;\r
                }\r
-\r
-               Endpoint_Discard_Byte();\r
+               else\r
+               {\r
+                       Endpoint_Discard_Byte();\r
+               }\r
        }\r
        \r
        return ENDPOINT_RWSTREAM_ERROR_NoError;\r
@@ -152,9 +164,9 @@ uint8_t Endpoint_Write_Stream_LE(const void* Buffer, uint16_t Length
 \r
        while (Length--)\r
        {\r
-               if (!(Endpoint_ReadWriteAllowed()))\r
+               if (!(Endpoint_IsReadWriteAllowed()))\r
                {\r
-                       Endpoint_ClearCurrentBank();\r
+                       Endpoint_ClearIN();\r
                        \r
                        #if !defined(NO_STREAM_CALLBACKS)\r
                        if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort))\r
@@ -164,8 +176,10 @@ uint8_t Endpoint_Write_Stream_LE(const void* Buffer, uint16_t Length
                        if ((ErrorCode = Endpoint_WaitUntilReady()))\r
                          return ErrorCode;\r
                }\r
-\r
-               Endpoint_Write_Byte(*(DataStream++));\r
+               else\r
+               {\r
+                       Endpoint_Write_Byte(*(DataStream++));\r
+               }\r
        }\r
        \r
        return ENDPOINT_RWSTREAM_ERROR_NoError;\r
@@ -185,9 +199,9 @@ uint8_t Endpoint_Write_Stream_BE(const void* Buffer, uint16_t Length
 \r
        while (Length--)\r
        {\r
-               if (!(Endpoint_ReadWriteAllowed()))\r
+               if (!(Endpoint_IsReadWriteAllowed()))\r
                {\r
-                       Endpoint_ClearCurrentBank();\r
+                       Endpoint_ClearIN();\r
 \r
                        #if !defined(NO_STREAM_CALLBACKS)\r
                        if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort))\r
@@ -197,8 +211,10 @@ uint8_t Endpoint_Write_Stream_BE(const void* Buffer, uint16_t Length
                        if ((ErrorCode = Endpoint_WaitUntilReady()))\r
                          return ErrorCode;\r
                }\r
-\r
-               Endpoint_Write_Byte(*(DataStream--));\r
+               else\r
+               {\r
+                       Endpoint_Write_Byte(*(DataStream--));\r
+               }\r
        }\r
        \r
        return ENDPOINT_RWSTREAM_ERROR_NoError;\r
@@ -218,9 +234,9 @@ uint8_t Endpoint_Read_Stream_LE(void* Buffer, uint16_t Length
 \r
        while (Length--)\r
        {\r
-               if (!(Endpoint_ReadWriteAllowed()))\r
+               if (!(Endpoint_IsReadWriteAllowed()))\r
                {\r
-                       Endpoint_ClearCurrentBank();\r
+                       Endpoint_ClearOUT();\r
 \r
                        #if !defined(NO_STREAM_CALLBACKS)\r
                        if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort))\r
@@ -230,8 +246,10 @@ uint8_t Endpoint_Read_Stream_LE(void* Buffer, uint16_t Length
                        if ((ErrorCode = Endpoint_WaitUntilReady()))\r
                          return ErrorCode;\r
                }\r
-               \r
-               *(DataStream++) = Endpoint_Read_Byte();\r
+               else\r
+               {\r
+                       *(DataStream++) = Endpoint_Read_Byte();\r
+               }\r
        }\r
        \r
        return ENDPOINT_RWSTREAM_ERROR_NoError;\r
@@ -251,9 +269,9 @@ uint8_t Endpoint_Read_Stream_BE(void* Buffer, uint16_t Length
 \r
        while (Length--)\r
        {\r
-               if (!(Endpoint_ReadWriteAllowed()))\r
+               if (!(Endpoint_IsReadWriteAllowed()))\r
                {\r
-                       Endpoint_ClearCurrentBank();\r
+                       Endpoint_ClearOUT();\r
 \r
                        #if !defined(NO_STREAM_CALLBACKS)\r
                        if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort))\r
@@ -263,8 +281,10 @@ uint8_t Endpoint_Read_Stream_BE(void* Buffer, uint16_t Length
                        if ((ErrorCode = Endpoint_WaitUntilReady()))\r
                          return ErrorCode;\r
                }\r
-               \r
-               *(DataStream--) = Endpoint_Read_Byte();\r
+               else\r
+               {\r
+                       *(DataStream--) = Endpoint_Read_Byte();\r
+               }\r
        }\r
        \r
        return ENDPOINT_RWSTREAM_ERROR_NoError;\r
@@ -275,9 +295,9 @@ uint8_t Endpoint_Write_Control_Stream_LE(const void* Buffer, uint16_t Length)
        uint8_t* DataStream = (uint8_t*)Buffer;\r
        bool     SendZLP    = true;\r
        \r
-       while (Length && !(Endpoint_IsSetupOUTReceived()))\r
+       while (Length && !(Endpoint_IsOUTReceived()))\r
        {\r
-               while (!(Endpoint_IsSetupINReady()));\r
+               while (!(Endpoint_IsINReady()));\r
                \r
                while (Length && (Endpoint_BytesInEndpoint() < USB_ControlEndpointSize))\r
                {\r
@@ -287,19 +307,19 @@ uint8_t Endpoint_Write_Control_Stream_LE(const void* Buffer, uint16_t Length)
                }\r
                \r
                SendZLP = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize);\r
-               Endpoint_ClearSetupIN();\r
+               Endpoint_ClearControlIN();\r
        }\r
        \r
-       if (Endpoint_IsSetupOUTReceived())\r
+       if (Endpoint_IsOUTReceived())\r
          return ENDPOINT_RWCSTREAM_ERROR_HostAborted;\r
        \r
        if (SendZLP)\r
        {\r
-               while (!(Endpoint_IsSetupINReady()));\r
-               Endpoint_ClearSetupIN();\r
+               while (!(Endpoint_IsINReady()));\r
+               Endpoint_ClearControlIN();\r
        }\r
        \r
-       while (!(Endpoint_IsSetupOUTReceived()));\r
+       while (!(Endpoint_IsOUTReceived()));\r
 \r
        return ENDPOINT_RWCSTREAM_ERROR_NoError;\r
 }\r
@@ -309,9 +329,9 @@ uint8_t Endpoint_Write_Control_Stream_BE(const void* Buffer, uint16_t Length)
        uint8_t* DataStream = (uint8_t*)(Buffer + Length - 1);\r
        bool     SendZLP    = true;\r
        \r
-       while (Length && !(Endpoint_IsSetupOUTReceived()))\r
+       while (Length && !(Endpoint_IsOUTReceived()))\r
        {\r
-               while (!(Endpoint_IsSetupINReady()));\r
+               while (!(Endpoint_IsINReady()));\r
                \r
                while (Length && (Endpoint_BytesInEndpoint() < USB_ControlEndpointSize))\r
                {\r
@@ -321,19 +341,19 @@ uint8_t Endpoint_Write_Control_Stream_BE(const void* Buffer, uint16_t Length)
                }\r
                \r
                SendZLP = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize);\r
-               Endpoint_ClearSetupIN();\r
+               Endpoint_ClearControlIN();\r
        }\r
        \r
-       if (Endpoint_IsSetupOUTReceived())\r
+       if (Endpoint_IsOUTReceived())\r
          return ENDPOINT_RWCSTREAM_ERROR_HostAborted;\r
        \r
        if (SendZLP)\r
        {\r
-               while (!(Endpoint_IsSetupINReady()));\r
-               Endpoint_ClearSetupIN();\r
+               while (!(Endpoint_IsINReady()));\r
+               Endpoint_ClearControlIN();\r
        }\r
        \r
-       while (!(Endpoint_IsSetupOUTReceived()));\r
+       while (!(Endpoint_IsOUTReceived()));\r
 \r
        return ENDPOINT_RWCSTREAM_ERROR_NoError;\r
 }\r
@@ -344,7 +364,7 @@ uint8_t Endpoint_Read_Control_Stream_LE(void* Buffer, uint16_t Length)
        \r
        while (Length)\r
        {\r
-               while (!(Endpoint_IsSetupOUTReceived()));\r
+               while (!(Endpoint_IsOUTReceived()));\r
                \r
                while (Length && Endpoint_BytesInEndpoint())\r
                {\r
@@ -353,10 +373,10 @@ uint8_t Endpoint_Read_Control_Stream_LE(void* Buffer, uint16_t Length)
                        Length--;\r
                }\r
                \r
-               Endpoint_ClearSetupOUT();\r
+               Endpoint_ClearControlOUT();\r
        }\r
        \r
-       while (!(Endpoint_IsSetupINReady()));\r
+       while (!(Endpoint_IsINReady()));\r
        \r
        return ENDPOINT_RWCSTREAM_ERROR_NoError;\r
 }\r
@@ -367,7 +387,7 @@ uint8_t Endpoint_Read_Control_Stream_BE(void* Buffer, uint16_t Length)
        \r
        while (Length)\r
        {\r
-               while (!(Endpoint_IsSetupOUTReceived()));\r
+               while (!(Endpoint_IsOUTReceived()));\r
                \r
                while (Length && Endpoint_BytesInEndpoint())\r
                {\r
@@ -376,10 +396,10 @@ uint8_t Endpoint_Read_Control_Stream_BE(void* Buffer, uint16_t Length)
                        Length--;\r
                }\r
                \r
-               Endpoint_ClearSetupOUT();\r
+               Endpoint_ClearControlOUT();\r
        }\r
        \r
-       while (!(Endpoint_IsSetupINReady()));\r
+       while (!(Endpoint_IsINReady()));\r
 \r
        return ENDPOINT_RWCSTREAM_ERROR_NoError;\r
 }\r