More XMEGA USB AVR device port work - re-add missing Endpoint stream functions, remov...
[pub/USBasp.git] / LUFA / Drivers / USB / Core / XMEGA / EndpointStream_XMEGA.c
index 9a0a195..b1b05bf 100644 (file)
 uint8_t Endpoint_Discard_Stream(uint16_t Length,\r
                                 uint16_t* const BytesProcessed)\r
 {\r
-       return 0; // TODO\r
+       uint8_t  ErrorCode;\r
+       uint16_t BytesInTransfer = 0;\r
+       \r
+       if ((ErrorCode = Endpoint_WaitUntilReady()))\r
+         return ErrorCode;\r
+         \r
+       if (BytesProcessed != NULL)\r
+         Length -= *BytesProcessed;\r
+\r
+       while (Length)\r
+       {\r
+               if (!(Endpoint_IsReadWriteAllowed()))\r
+               {\r
+                       Endpoint_ClearOUT();\r
+\r
+                       if (BytesProcessed != NULL)\r
+                       {\r
+                               *BytesProcessed += BytesInTransfer;\r
+                               return ENDPOINT_RWSTREAM_IncompleteTransfer;\r
+                       }\r
+\r
+                       if ((ErrorCode = Endpoint_WaitUntilReady()))\r
+                         return ErrorCode;\r
+               }\r
+               else\r
+               {\r
+                       Endpoint_Discard_8();\r
+\r
+                       Length--;\r
+                       BytesInTransfer++;\r
+               }\r
+       }\r
+       \r
+       return ENDPOINT_RWSTREAM_NoError;\r
 }\r
 \r
 uint8_t Endpoint_Null_Stream(uint16_t Length,\r
                              uint16_t* const BytesProcessed)\r
 {\r
-       return 0; // TODO\r
+       uint8_t  ErrorCode;\r
+       uint16_t BytesInTransfer = 0;\r
+       \r
+       if ((ErrorCode = Endpoint_WaitUntilReady()))\r
+         return ErrorCode;\r
+         \r
+       if (BytesProcessed != NULL)\r
+         Length -= *BytesProcessed;\r
+\r
+       while (Length)\r
+       {\r
+               if (!(Endpoint_IsReadWriteAllowed()))\r
+               {\r
+                       Endpoint_ClearIN();\r
+\r
+                       if (BytesProcessed != NULL)\r
+                       {\r
+                               *BytesProcessed += BytesInTransfer;\r
+                               return ENDPOINT_RWSTREAM_IncompleteTransfer;\r
+                       }\r
+\r
+                       if ((ErrorCode = Endpoint_WaitUntilReady()))\r
+                         return ErrorCode;\r
+               }\r
+               else\r
+               {\r
+                       Endpoint_Write_8(0);\r
+\r
+                       Length--;\r
+                       BytesInTransfer++;\r
+               }\r
+       }\r
+       \r
+       return ENDPOINT_RWSTREAM_NoError;\r
 }\r
 \r
 #define  TEMPLATE_FUNC_NAME                        Endpoint_Write_Stream_LE\r