Fixed GenericHIDHost demo report write routine incorrect for control type requests...
[pub/lufa.git] / LUFA / Drivers / USB / LowLevel / Endpoint.c
index aa18358..b885471 100644 (file)
@@ -88,8 +88,19 @@ uint8_t Endpoint_WaitUntilReady(void)
 \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
@@ -103,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
@@ -120,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
@@ -132,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
@@ -153,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
@@ -165,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
@@ -186,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
@@ -198,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
@@ -219,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
@@ -231,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
@@ -252,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
@@ -264,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
@@ -276,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
@@ -288,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
@@ -310,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
@@ -322,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
@@ -345,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
@@ -354,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
@@ -368,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
@@ -377,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