Added new EEPROM and FLASH buffer versions of the Endpoint and Pipe stream functions...
[pub/lufa.git] / LUFA / Drivers / USB / LowLevel / Template / Template_Endpoint_RW.c
diff --git a/LUFA/Drivers/USB/LowLevel/Template/Template_Endpoint_RW.c b/LUFA/Drivers/USB/LowLevel/Template/Template_Endpoint_RW.c
new file mode 100644 (file)
index 0000000..731c5f8
--- /dev/null
@@ -0,0 +1,76 @@
+uint8_t TEMPLATE_FUNC_NAME (void* Buffer, uint16_t Length _CALLBACK_PARAM)\r
+{\r
+       uint8_t* DataStream = (uint8_t*)(Buffer + TEMPLATE_BUFFER_OFFSET(Length));\r
+       uint8_t  ErrorCode;\r
+       \r
+       if ((ErrorCode = Endpoint_WaitUntilReady()))\r
+         return ErrorCode;\r
+\r
+       #if defined(FAST_STREAM_TRANSFERS)\r
+       uint8_t BytesRemToAlignment = (Endpoint_BytesInEndpoint() & 0x07);\r
+\r
+       if (Length >= 8)\r
+       {\r
+               Length -= BytesRemToAlignment;\r
+\r
+               switch (BytesRemToAlignment)\r
+               {\r
+                       default:\r
+                               do\r
+                               {\r
+                                       if (!(Endpoint_IsReadWriteAllowed()))\r
+                                       {\r
+                                               TEMPLATE_CLEAR_ENDPOINT();\r
+\r
+                                               #if !defined(NO_STREAM_CALLBACKS)\r
+                                               if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort))\r
+                                                 return ENDPOINT_RWSTREAM_CallbackAborted;\r
+                                               #endif\r
+\r
+                                               if ((ErrorCode = Endpoint_WaitUntilReady()))\r
+                                                 return ErrorCode;\r
+                                       }\r
+\r
+                                       Length -= 8;\r
+                                       \r
+                                       TEMPLATE_TRANSFER_BYTE(DataStream);\r
+                       case 7: TEMPLATE_TRANSFER_BYTE(DataStream);\r
+                       case 6: TEMPLATE_TRANSFER_BYTE(DataStream);\r
+                       case 5: TEMPLATE_TRANSFER_BYTE(DataStream);\r
+                       case 4: TEMPLATE_TRANSFER_BYTE(DataStream);\r
+                       case 3: TEMPLATE_TRANSFER_BYTE(DataStream);\r
+                       case 2: TEMPLATE_TRANSFER_BYTE(DataStream);\r
+                       case 1: TEMPLATE_TRANSFER_BYTE(DataStream);\r
+                               } while (Length >= 8);  \r
+               }\r
+       }\r
+       #endif\r
+\r
+       while (Length)\r
+       {\r
+               if (!(Endpoint_IsReadWriteAllowed()))\r
+               {\r
+                       TEMPLATE_CLEAR_ENDPOINT();\r
+\r
+                       #if !defined(NO_STREAM_CALLBACKS)\r
+                       if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort))\r
+                         return ENDPOINT_RWSTREAM_CallbackAborted;\r
+                       #endif\r
+\r
+                       if ((ErrorCode = Endpoint_WaitUntilReady()))\r
+                         return ErrorCode;\r
+               }\r
+               else\r
+               {\r
+                       TEMPLATE_TRANSFER_BYTE(DataStream);\r
+                       Length--;\r
+               }\r
+       }\r
+\r
+       return ENDPOINT_RWSTREAM_NoError;\r
+}\r
+\r
+#undef TEMPLATE_FUNC_NAME\r
+#undef TEMPLATE_TRANSFER_BYTE\r
+#undef TEMPLATE_CLEAR_ENDPOINT\r
+#undef TEMPLATE_BUFFER_OFFSET
\ No newline at end of file