Oops - restore deleted MissileLauncher project, fix all spelling errors for "missile...
[pub/USBasp.git] / LUFA / Drivers / USB / LowLevel / Endpoint.c
index a872a00..dca7554 100644 (file)
@@ -74,9 +74,11 @@ void Endpoint_ClearEndpoints(void)
 #if !defined(CONTROL_ONLY_DEVICE)\r
 uint8_t Endpoint_WaitUntilReady(void)\r
 {\r
+       #if (USB_STREAM_TIMEOUT_MS < 0xFF)\r
+       uint8_t  TimeoutMSRem = USB_STREAM_TIMEOUT_MS;  \r
+       #else\r
        uint16_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS;\r
-\r
-       USB_INT_Clear(USB_INT_SOFI);\r
+       #endif\r
 \r
        for (;;)\r
        {\r
@@ -108,7 +110,7 @@ uint8_t Endpoint_WaitUntilReady(void)
 \r
 uint8_t Endpoint_Discard_Stream(uint16_t Length\r
 #if !defined(NO_STREAM_CALLBACKS)\r
-                                , uint8_t (* const Callback)(void)\r
+                                , StreamCallbackPtr_t Callback\r
 #endif\r
                                                                )\r
 {\r
@@ -125,7 +127,7 @@ uint8_t Endpoint_Discard_Stream(uint16_t Length
 \r
                        #if !defined(NO_STREAM_CALLBACKS)\r
                        if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort))\r
-                         return ENDPOINT_RWSTREAM_ERROR_CallbackAborted;\r
+                         return ENDPOINT_RWSTREAM_CallbackAborted;\r
                        #endif\r
 \r
                        if ((ErrorCode = Endpoint_WaitUntilReady()))\r
@@ -138,12 +140,12 @@ uint8_t Endpoint_Discard_Stream(uint16_t Length
                }\r
        }\r
        \r
-       return ENDPOINT_RWSTREAM_ERROR_NoError;\r
+       return ENDPOINT_RWSTREAM_NoError;\r
 }\r
 \r
 uint8_t Endpoint_Write_Stream_LE(const void* Buffer, uint16_t Length\r
 #if !defined(NO_STREAM_CALLBACKS)\r
-                                 , uint8_t (* const Callback)(void)\r
+                                 , StreamCallbackPtr_t Callback\r
 #endif\r
                                                                 )\r
 {\r
@@ -161,7 +163,7 @@ uint8_t Endpoint_Write_Stream_LE(const void* Buffer, uint16_t Length
                        \r
                        #if !defined(NO_STREAM_CALLBACKS)\r
                        if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort))\r
-                         return ENDPOINT_RWSTREAM_ERROR_CallbackAborted;\r
+                         return ENDPOINT_RWSTREAM_CallbackAborted;\r
                        #endif\r
 \r
                        if ((ErrorCode = Endpoint_WaitUntilReady()))\r
@@ -174,12 +176,12 @@ uint8_t Endpoint_Write_Stream_LE(const void* Buffer, uint16_t Length
                }\r
        }\r
        \r
-       return ENDPOINT_RWSTREAM_ERROR_NoError;\r
+       return ENDPOINT_RWSTREAM_NoError;\r
 }\r
 \r
 uint8_t Endpoint_Write_Stream_BE(const void* Buffer, uint16_t Length\r
 #if !defined(NO_STREAM_CALLBACKS)\r
-                                 , uint8_t (* const Callback)(void)\r
+                                 , StreamCallbackPtr_t Callback\r
 #endif\r
                                                                 )\r
 {\r
@@ -197,7 +199,7 @@ uint8_t Endpoint_Write_Stream_BE(const void* Buffer, uint16_t Length
 \r
                        #if !defined(NO_STREAM_CALLBACKS)\r
                        if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort))\r
-                         return ENDPOINT_RWSTREAM_ERROR_CallbackAborted;\r
+                         return ENDPOINT_RWSTREAM_CallbackAborted;\r
                        #endif\r
 \r
                        if ((ErrorCode = Endpoint_WaitUntilReady()))\r
@@ -210,12 +212,12 @@ uint8_t Endpoint_Write_Stream_BE(const void* Buffer, uint16_t Length
                }\r
        }\r
        \r
-       return ENDPOINT_RWSTREAM_ERROR_NoError;\r
+       return ENDPOINT_RWSTREAM_NoError;\r
 }\r
 \r
 uint8_t Endpoint_Read_Stream_LE(void* Buffer, uint16_t Length\r
 #if !defined(NO_STREAM_CALLBACKS)\r
-                                 , uint8_t (* const Callback)(void)\r
+                                 , StreamCallbackPtr_t Callback\r
 #endif\r
                                                                 )\r
 {\r
@@ -233,7 +235,7 @@ uint8_t Endpoint_Read_Stream_LE(void* Buffer, uint16_t Length
 \r
                        #if !defined(NO_STREAM_CALLBACKS)\r
                        if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort))\r
-                         return ENDPOINT_RWSTREAM_ERROR_CallbackAborted;\r
+                         return ENDPOINT_RWSTREAM_CallbackAborted;\r
                        #endif\r
 \r
                        if ((ErrorCode = Endpoint_WaitUntilReady()))\r
@@ -246,12 +248,12 @@ uint8_t Endpoint_Read_Stream_LE(void* Buffer, uint16_t Length
                }\r
        }\r
        \r
-       return ENDPOINT_RWSTREAM_ERROR_NoError;\r
+       return ENDPOINT_RWSTREAM_NoError;\r
 }\r
 \r
 uint8_t Endpoint_Read_Stream_BE(void* Buffer, uint16_t Length\r
 #if !defined(NO_STREAM_CALLBACKS)\r
-                                 , uint8_t (* const Callback)(void)\r
+                                 , StreamCallbackPtr_t Callback\r
 #endif\r
                                                                 )\r
 {\r
@@ -269,7 +271,7 @@ uint8_t Endpoint_Read_Stream_BE(void* Buffer, uint16_t Length
 \r
                        #if !defined(NO_STREAM_CALLBACKS)\r
                        if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort))\r
-                         return ENDPOINT_RWSTREAM_ERROR_CallbackAborted;\r
+                         return ENDPOINT_RWSTREAM_CallbackAborted;\r
                        #endif\r
 \r
                        if ((ErrorCode = Endpoint_WaitUntilReady()))\r
@@ -282,15 +284,17 @@ uint8_t Endpoint_Read_Stream_BE(void* Buffer, uint16_t Length
                }\r
        }\r
        \r
-       return ENDPOINT_RWSTREAM_ERROR_NoError;\r
+       return ENDPOINT_RWSTREAM_NoError;\r
 }\r
 #endif\r
 \r
 uint8_t Endpoint_Write_Control_Stream_LE(const void* Buffer, uint16_t Length)\r
 {\r
-       uint8_t* DataStream    = (uint8_t*)Buffer;\r
+       uint8_t* DataStream     = (uint8_t*)Buffer;\r
        bool     LastPacketFull = false;\r
-       bool     ShortTransfer = (Length < USB_ControlRequest.wLength);\r
+       \r
+       if (Length > USB_ControlRequest.wLength)\r
+         Length = USB_ControlRequest.wLength;\r
        \r
        while (Length && !(Endpoint_IsOUTReceived()))\r
        {\r
@@ -307,9 +311,9 @@ uint8_t Endpoint_Write_Control_Stream_LE(const void* Buffer, uint16_t Length)
        }\r
        \r
        if (Endpoint_IsOUTReceived())\r
-         return ENDPOINT_RWCSTREAM_ERROR_HostAborted;\r
+         return ENDPOINT_RWCSTREAM_HostAborted;\r
        \r
-       if (LastPacketFull || ShortTransfer)\r
+       if (LastPacketFull)\r
        {\r
                while (!(Endpoint_IsINReady()));\r
                Endpoint_ClearIN();\r
@@ -317,33 +321,36 @@ uint8_t Endpoint_Write_Control_Stream_LE(const void* Buffer, uint16_t Length)
        \r
        while (!(Endpoint_IsOUTReceived()));\r
 \r
-       return ENDPOINT_RWCSTREAM_ERROR_NoError;\r
+       return ENDPOINT_RWCSTREAM_NoError;\r
 }\r
 \r
 uint8_t Endpoint_Write_Control_Stream_BE(const void* Buffer, uint16_t Length)\r
 {\r
        uint8_t* DataStream     = (uint8_t*)(Buffer + Length - 1);\r
        bool     LastPacketFull = false;\r
-       bool     ShortTransfer  = (Length < USB_ControlRequest.wLength);\r
        \r
+       if (Length > USB_ControlRequest.wLength)\r
+         Length = USB_ControlRequest.wLength;\r
+\r
        while (Length && !(Endpoint_IsOUTReceived()))\r
        {\r
-               while (!(Endpoint_IsINReady()));\r
-               \r
-               while (Length && (Endpoint_BytesInEndpoint() < USB_ControlEndpointSize))\r
+               if (Endpoint_IsINReady())\r
                {\r
-                       Endpoint_Write_Byte(*(DataStream--));\r
-                       Length--;\r
+                       while (Length && (Endpoint_BytesInEndpoint() < USB_ControlEndpointSize))\r
+                       {\r
+                               Endpoint_Write_Byte(*(DataStream--));\r
+                               Length--;\r
+                       }\r
+                       \r
+                       LastPacketFull = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize);\r
+                       Endpoint_ClearIN();\r
                }\r
-               \r
-               LastPacketFull = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize);\r
-               Endpoint_ClearIN();\r
        }\r
        \r
        if (Endpoint_IsOUTReceived())\r
-         return ENDPOINT_RWCSTREAM_ERROR_HostAborted;\r
+         return ENDPOINT_RWCSTREAM_HostAborted;\r
        \r
-       if (LastPacketFull || ShortTransfer)\r
+       if (LastPacketFull)\r
        {\r
                while (!(Endpoint_IsINReady()));\r
                Endpoint_ClearIN();\r
@@ -351,7 +358,7 @@ uint8_t Endpoint_Write_Control_Stream_BE(const void* Buffer, uint16_t Length)
        \r
        while (!(Endpoint_IsOUTReceived()));\r
 \r
-       return ENDPOINT_RWCSTREAM_ERROR_NoError;\r
+       return ENDPOINT_RWCSTREAM_NoError;\r
 }\r
 \r
 uint8_t Endpoint_Read_Control_Stream_LE(void* Buffer, uint16_t Length)\r
@@ -360,20 +367,21 @@ uint8_t Endpoint_Read_Control_Stream_LE(void* Buffer, uint16_t Length)
        \r
        while (Length)\r
        {\r
-               while (!(Endpoint_IsOUTReceived()));\r
-               \r
-               while (Length && Endpoint_BytesInEndpoint())\r
+               if (Endpoint_IsOUTReceived())\r
                {\r
-                       *(DataStream++) = Endpoint_Read_Byte();\r
-                       Length--;\r
+                       while (Length && Endpoint_BytesInEndpoint())\r
+                       {\r
+                               *(DataStream++) = Endpoint_Read_Byte();\r
+                               Length--;\r
+                       }\r
+                       \r
+                       Endpoint_ClearOUT();\r
                }\r
-               \r
-               Endpoint_ClearOUT();\r
        }\r
        \r
        while (!(Endpoint_IsINReady()));\r
        \r
-       return ENDPOINT_RWCSTREAM_ERROR_NoError;\r
+       return ENDPOINT_RWCSTREAM_NoError;\r
 }\r
 \r
 uint8_t Endpoint_Read_Control_Stream_BE(void* Buffer, uint16_t Length)\r
@@ -382,20 +390,21 @@ uint8_t Endpoint_Read_Control_Stream_BE(void* Buffer, uint16_t Length)
        \r
        while (Length)\r
        {\r
-               while (!(Endpoint_IsOUTReceived()));\r
-               \r
-               while (Length && Endpoint_BytesInEndpoint())\r
+               if (Endpoint_IsOUTReceived())\r
                {\r
-                       *(DataStream--) = Endpoint_Read_Byte();\r
-                       Length--;\r
+                       while (Length && Endpoint_BytesInEndpoint())\r
+                       {\r
+                               *(DataStream--) = Endpoint_Read_Byte();\r
+                               Length--;\r
+                       }\r
+                       \r
+                       Endpoint_ClearOUT();\r
                }\r
-               \r
-               Endpoint_ClearOUT();\r
        }\r
        \r
        while (!(Endpoint_IsINReady()));\r
 \r
-       return ENDPOINT_RWCSTREAM_ERROR_NoError;\r
+       return ENDPOINT_RWCSTREAM_NoError;\r
 }\r
 \r
 #endif\r