Update CDC Class Driver character stream functions to use the correct avr-libc return...
[pub/lufa.git] / LUFA / Drivers / USB / LowLevel / Endpoint.c
index 273e190..6d59510 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
 uint8_t USB_ControlEndpointSize = ENDPOINT_CONTROLEP_DEFAULT_SIZE;\r
 #endif\r
 \r
-#if !defined(STATIC_ENDPOINT_CONFIGURATION)\r
-bool Endpoint_ConfigureEndpoint(const uint8_t  Number, const uint8_t Type, const uint8_t Direction,\r
-                                           const uint16_t Size, const uint8_t Banks)\r
+uint8_t Endpoint_BytesToEPSizeMaskDynamic(const uint16_t Size)\r
 {\r
-       Endpoint_SelectEndpoint(Number);\r
-       Endpoint_EnableEndpoint();\r
-\r
-       UECFG1X = 0;    \r
-\r
-       UECFG0X = ((Type << EPTYPE0) | Direction);\r
-       UECFG1X = ((1 << ALLOC) | Banks | Endpoint_BytesToEPSizeMask(Size));\r
-\r
-       return Endpoint_IsConfigured();\r
+       return Endpoint_BytesToEPSizeMask(Size);\r
 }\r
-#else\r
-bool Endpoint_ConfigureEndpointStatic(const uint8_t Number, const uint8_t UECFG0XData, const uint8_t UECFG1XData)\r
+\r
+bool Endpoint_ConfigureEndpoint_Prv(const uint8_t Number, const uint8_t UECFG0XData, const uint8_t UECFG1XData)\r
 {\r
        Endpoint_SelectEndpoint(Number);\r
        Endpoint_EnableEndpoint();\r
 \r
-       UECFG1X = 0;    \r
+       UECFG1X = 0;\r
 \r
        UECFG0X = UECFG0XData;\r
        UECFG1X = UECFG1XData;\r
 \r
        return Endpoint_IsConfigured();\r
 }\r
-#endif\r
 \r
 void Endpoint_ClearEndpoints(void)\r
 {\r
@@ -81,307 +71,262 @@ void Endpoint_ClearEndpoints(void)
        }\r
 }\r
 \r
-uint8_t Endpoint_WaitUntilReady(void)\r
+void Endpoint_ClearStatusStage(void)\r
 {\r
-       uint8_t TimeoutMSRem = USB_STREAM_TIMEOUT_MS;\r
-\r
-       USB_INT_Clear(USB_INT_SOFI);\r
-\r
-       while (!(Endpoint_ReadWriteAllowed()))\r
+       if (USB_ControlRequest.bmRequestType & REQDIR_DEVICETOHOST)\r
        {\r
-               if (!(USB_IsConnected))\r
-                 return ENDPOINT_READYWAIT_DeviceDisconnected;\r
-               else if (Endpoint_IsStalled())\r
-                 return ENDPOINT_READYWAIT_EndpointStalled;\r
-                         \r
-               if (USB_INT_HasOccurred(USB_INT_SOFI))\r
+               while (!(Endpoint_IsOUTReceived()))\r
                {\r
-                       USB_INT_Clear(USB_INT_SOFI);\r
-\r
-                       if (!(TimeoutMSRem--))\r
-                         return ENDPOINT_READYWAIT_Timeout;\r
+                       if (USB_DeviceState == DEVICE_STATE_Unattached)\r
+                         return;\r
                }\r
-       }\r
-       \r
-       return ENDPOINT_READYWAIT_NoError;\r
-}\r
 \r
-uint8_t Endpoint_Discard_Stream(uint16_t Length\r
-#if !defined(NO_STREAM_CALLBACKS)\r
-                                , uint8_t (* const Callback)(void)\r
-#endif\r
-                                                               )\r
-{\r
-       uint8_t  ErrorCode;\r
-       \r
-       if ((ErrorCode = Endpoint_WaitUntilReady()))\r
-         return ErrorCode;\r
-\r
-       while (Length--)\r
+               Endpoint_ClearOUT();\r
+       }\r
+       else\r
        {\r
-               if (!(Endpoint_ReadWriteAllowed()))\r
+               while (!(Endpoint_IsINReady()))\r
                {\r
-                       Endpoint_ClearCurrentBank();\r
-\r
-                       #if !defined(NO_STREAM_CALLBACKS)\r
-                       if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort))\r
-                         return ENDPOINT_RWSTREAM_ERROR_CallbackAborted;\r
-                       #endif\r
-\r
-                       if ((ErrorCode = Endpoint_WaitUntilReady()))\r
-                         return ErrorCode;\r
+                       if (USB_DeviceState == DEVICE_STATE_Unattached)\r
+                         return;\r
                }\r
-\r
-               Endpoint_Discard_Byte();\r
+               \r
+               Endpoint_ClearIN();\r
        }\r
-       \r
-       return ENDPOINT_RWSTREAM_ERROR_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
-#endif\r
-                                                                )\r
+#if !defined(CONTROL_ONLY_DEVICE)\r
+uint8_t Endpoint_WaitUntilReady(void)\r
 {\r
-       uint8_t* DataStream   = (uint8_t*)Buffer;\r
-       uint8_t  ErrorCode;\r
-       \r
-       if ((ErrorCode = Endpoint_WaitUntilReady()))\r
-         return ErrorCode;\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
+       #endif\r
 \r
-       while (Length--)\r
+       for (;;)\r
        {\r
-               if (!(Endpoint_ReadWriteAllowed()))\r
+               if (Endpoint_GetEndpointDirection() == ENDPOINT_DIR_IN)\r
                {\r
-                       Endpoint_ClearCurrentBank();\r
-                       \r
-                       #if !defined(NO_STREAM_CALLBACKS)\r
-                       if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort))\r
-                         return ENDPOINT_RWSTREAM_ERROR_CallbackAborted;\r
-                       #endif\r
-\r
-                       if ((ErrorCode = Endpoint_WaitUntilReady()))\r
-                         return ErrorCode;\r
+                       if (Endpoint_IsINReady())\r
+                         return ENDPOINT_READYWAIT_NoError;\r
                }\r
-\r
-               Endpoint_Write_Byte(*(DataStream++));\r
-       }\r
-       \r
-       return ENDPOINT_RWSTREAM_ERROR_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
-#endif\r
-                                                                )\r
-{\r
-       uint8_t* DataStream = (uint8_t*)(Buffer + Length - 1);\r
-       uint8_t  ErrorCode;\r
-       \r
-       if ((ErrorCode = Endpoint_WaitUntilReady()))\r
-         return ErrorCode;\r
-\r
-       while (Length--)\r
-       {\r
-               if (!(Endpoint_ReadWriteAllowed()))\r
+               else\r
                {\r
-                       Endpoint_ClearCurrentBank();\r
-\r
-                       #if !defined(NO_STREAM_CALLBACKS)\r
-                       if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort))\r
-                         return ENDPOINT_RWSTREAM_ERROR_CallbackAborted;\r
-                       #endif\r
-\r
-                       if ((ErrorCode = Endpoint_WaitUntilReady()))\r
-                         return ErrorCode;\r
+                       if (Endpoint_IsOUTReceived())\r
+                         return ENDPOINT_READYWAIT_NoError;            \r
                }\r
+               \r
+               if (USB_DeviceState == DEVICE_STATE_Unattached)\r
+                 return ENDPOINT_READYWAIT_DeviceDisconnected;\r
+               else if (Endpoint_IsStalled())\r
+                 return ENDPOINT_READYWAIT_EndpointStalled;\r
+                         \r
+               if (USB_INT_HasOccurred(USB_INT_SOFI))\r
+               {\r
+                       USB_INT_Clear(USB_INT_SOFI);\r
 \r
-               Endpoint_Write_Byte(*(DataStream--));\r
+                       if (!(TimeoutMSRem--))\r
+                         return ENDPOINT_READYWAIT_Timeout;\r
+               }\r
        }\r
-       \r
-       return ENDPOINT_RWSTREAM_ERROR_NoError;\r
 }\r
 \r
-uint8_t Endpoint_Read_Stream_LE(void* Buffer, uint16_t Length\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
 {\r
-       uint8_t* DataStream = (uint8_t*)Buffer;\r
        uint8_t  ErrorCode;\r
        \r
        if ((ErrorCode = Endpoint_WaitUntilReady()))\r
          return ErrorCode;\r
 \r
-       while (Length--)\r
-       {\r
-               if (!(Endpoint_ReadWriteAllowed()))\r
-               {\r
-                       Endpoint_ClearCurrentBank();\r
+       #if defined(FAST_STREAM_TRANSFERS)\r
+       uint8_t BytesRemToAlignment = (Endpoint_BytesInEndpoint() & 0x07);\r
 \r
-                       #if !defined(NO_STREAM_CALLBACKS)\r
-                       if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort))\r
-                         return ENDPOINT_RWSTREAM_ERROR_CallbackAborted;\r
-                       #endif\r
+       if (Length >= 8)\r
+       {\r
+               Length -= BytesRemToAlignment;\r
 \r
-                       if ((ErrorCode = Endpoint_WaitUntilReady()))\r
-                         return ErrorCode;\r
+               switch (BytesRemToAlignment)\r
+               {\r
+                       default:\r
+                               do\r
+                               {\r
+                                       if (!(Endpoint_IsReadWriteAllowed()))\r
+                                       {\r
+                                               Endpoint_ClearOUT();\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
+                                       Endpoint_Discard_Byte();\r
+                       case 7: Endpoint_Discard_Byte();\r
+                       case 6: Endpoint_Discard_Byte();\r
+                       case 5: Endpoint_Discard_Byte();\r
+                       case 4: Endpoint_Discard_Byte();\r
+                       case 3: Endpoint_Discard_Byte();\r
+                       case 2: Endpoint_Discard_Byte();\r
+                       case 1: Endpoint_Discard_Byte();\r
+                               } while (Length >= 8);  \r
                }\r
-               \r
-               *(DataStream++) = Endpoint_Read_Byte();\r
        }\r
-       \r
-       return ENDPOINT_RWSTREAM_ERROR_NoError;\r
-}\r
+       #endif\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
-#endif\r
-                                                                )\r
-{\r
-       uint8_t* DataStream = (uint8_t*)(Buffer + Length - 1);\r
-       uint8_t  ErrorCode;\r
-       \r
-       if ((ErrorCode = Endpoint_WaitUntilReady()))\r
-         return ErrorCode;\r
-\r
-       while (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
-                         return ENDPOINT_RWSTREAM_ERROR_CallbackAborted;\r
+                         return ENDPOINT_RWSTREAM_CallbackAborted;\r
                        #endif\r
 \r
                        if ((ErrorCode = Endpoint_WaitUntilReady()))\r
                          return ErrorCode;\r
                }\r
-               \r
-               *(DataStream--) = Endpoint_Read_Byte();\r
-       }\r
-       \r
-       return ENDPOINT_RWSTREAM_ERROR_NoError;\r
-}\r
-\r
-uint8_t Endpoint_Write_Control_Stream_LE(const void* Buffer, uint16_t Length)\r
-{\r
-       uint8_t* DataStream = (uint8_t*)Buffer;\r
-       bool     SendZLP    = true;\r
-       \r
-       while (Length && !(Endpoint_IsSetupOUTReceived()))\r
-       {\r
-               while (!(Endpoint_IsSetupINReady()));\r
-               \r
-               while (Length && (Endpoint_BytesInEndpoint() < USB_ControlEndpointSize))\r
-               {\r
-                       Endpoint_Write_Byte(*(DataStream++));\r
-                       \r
-                       Length--;\r
-               }\r
-               \r
-               SendZLP = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize);\r
-               Endpoint_ClearSetupIN();\r
-       }\r
-       \r
-       if (Endpoint_IsSetupOUTReceived())\r
-         return ENDPOINT_RWCSTREAM_ERROR_HostAborted;\r
-       \r
-       if (SendZLP)\r
-       {\r
-               while (!(Endpoint_IsSetupINReady()));\r
-               Endpoint_ClearSetupIN();\r
-       }\r
-       \r
-       while (!(Endpoint_IsSetupOUTReceived()));\r
-\r
-       return ENDPOINT_RWCSTREAM_ERROR_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     SendZLP    = true;\r
-       \r
-       while (Length && !(Endpoint_IsSetupOUTReceived()))\r
-       {\r
-               while (!(Endpoint_IsSetupINReady()));\r
-               \r
-               while (Length && (Endpoint_BytesInEndpoint() < USB_ControlEndpointSize))\r
+               else\r
                {\r
-                       Endpoint_Write_Byte(*(DataStream--));\r
-                       \r
+                       Endpoint_Discard_Byte();\r
                        Length--;\r
                }\r
-               \r
-               SendZLP = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize);\r
-               Endpoint_ClearSetupIN();\r
-       }\r
-       \r
-       if (Endpoint_IsSetupOUTReceived())\r
-         return ENDPOINT_RWCSTREAM_ERROR_HostAborted;\r
-       \r
-       if (SendZLP)\r
-       {\r
-               while (!(Endpoint_IsSetupINReady()));\r
-               Endpoint_ClearSetupIN();\r
        }\r
        \r
-       while (!(Endpoint_IsSetupOUTReceived()));\r
-\r
-       return ENDPOINT_RWCSTREAM_ERROR_NoError;\r
+       return ENDPOINT_RWSTREAM_NoError;\r
 }\r
 \r
-uint8_t Endpoint_Read_Control_Stream_LE(void* Buffer, uint16_t Length)\r
-{\r
-       uint8_t* DataStream = (uint8_t*)Buffer;\r
-       \r
-       while (Length)\r
-       {\r
-               while (!(Endpoint_IsSetupOUTReceived()));\r
-               \r
-               while (Length && Endpoint_BytesInEndpoint())\r
-               {\r
-                       *(DataStream++) = Endpoint_Read_Byte();\r
-                       \r
-                       Length--;\r
-               }\r
-               \r
-               Endpoint_ClearSetupOUT();\r
-       }\r
-       \r
-       while (!(Endpoint_IsSetupINReady()));\r
-       \r
-       return ENDPOINT_RWCSTREAM_ERROR_NoError;\r
-}\r
+#define  TEMPLATE_FUNC_NAME                        Endpoint_Write_Stream_LE\r
+#define  TEMPLATE_BUFFER_TYPE                      const void*\r
+#define  TEMPLATE_CLEAR_ENDPOINT()                 Endpoint_ClearIN()\r
+#define  TEMPLATE_BUFFER_OFFSET(Length)            0\r
+#define  TEMPLATE_TRANSFER_BYTE(BufferPtr)         Endpoint_Write_Byte(*((uint8_t*)BufferPtr++))\r
+#include "Template/Template_Endpoint_RW.c"\r
+\r
+#define  TEMPLATE_FUNC_NAME                        Endpoint_Write_PStream_LE\r
+#define  TEMPLATE_BUFFER_TYPE                      const void*\r
+#define  TEMPLATE_CLEAR_ENDPOINT()                 Endpoint_ClearIN()\r
+#define  TEMPLATE_BUFFER_OFFSET(Length)            0\r
+#define  TEMPLATE_TRANSFER_BYTE(BufferPtr)         Endpoint_Write_Byte(pgm_read_byte((uint8_t*)BufferPtr++))\r
+#include "Template/Template_Endpoint_RW.c"\r
+\r
+#define  TEMPLATE_FUNC_NAME                        Endpoint_Write_EStream_LE\r
+#define  TEMPLATE_BUFFER_TYPE                      const void*\r
+#define  TEMPLATE_CLEAR_ENDPOINT()                 Endpoint_ClearIN()\r
+#define  TEMPLATE_BUFFER_OFFSET(Length)            0\r
+#define  TEMPLATE_TRANSFER_BYTE(BufferPtr)         Endpoint_Write_Byte(eeprom_read_byte((uint8_t*)BufferPtr++))\r
+#include "Template/Template_Endpoint_RW.c"\r
+\r
+#define  TEMPLATE_FUNC_NAME                        Endpoint_Write_Stream_BE\r
+#define  TEMPLATE_BUFFER_TYPE                      const void*\r
+#define  TEMPLATE_CLEAR_ENDPOINT()                 Endpoint_ClearIN()\r
+#define  TEMPLATE_BUFFER_OFFSET(Length)            Length - 1\r
+#define  TEMPLATE_TRANSFER_BYTE(BufferPtr)         Endpoint_Write_Byte(*((uint8_t*)BufferPtr--))\r
+#include "Template/Template_Endpoint_RW.c"\r
+\r
+#define  TEMPLATE_FUNC_NAME                        Endpoint_Write_EStream_BE\r
+#define  TEMPLATE_BUFFER_TYPE                      const void*\r
+#define  TEMPLATE_CLEAR_ENDPOINT()                 Endpoint_ClearIN()\r
+#define  TEMPLATE_BUFFER_OFFSET(Length)            Length - 1\r
+#define  TEMPLATE_TRANSFER_BYTE(BufferPtr)         Endpoint_Write_Byte(eeprom_read_byte((uint8_t*)BufferPtr--))\r
+#include "Template/Template_Endpoint_RW.c"\r
+\r
+#define  TEMPLATE_FUNC_NAME                        Endpoint_Write_PStream_BE\r
+#define  TEMPLATE_BUFFER_TYPE                      const void*\r
+#define  TEMPLATE_CLEAR_ENDPOINT()                 Endpoint_ClearIN()\r
+#define  TEMPLATE_BUFFER_OFFSET(Length)            Length - 1\r
+#define  TEMPLATE_TRANSFER_BYTE(BufferPtr)         Endpoint_Write_Byte(pgm_read_byte((uint8_t*)BufferPtr--))\r
+#include "Template/Template_Endpoint_RW.c"\r
+\r
+#define  TEMPLATE_FUNC_NAME                        Endpoint_Read_Stream_LE\r
+#define  TEMPLATE_BUFFER_TYPE                      void*\r
+#define  TEMPLATE_CLEAR_ENDPOINT()                 Endpoint_ClearOUT()\r
+#define  TEMPLATE_BUFFER_OFFSET(Length)            0\r
+#define  TEMPLATE_TRANSFER_BYTE(BufferPtr)         *((uint8_t*)BufferPtr++) = Endpoint_Read_Byte()\r
+#include "Template/Template_Endpoint_RW.c"\r
+\r
+#define  TEMPLATE_FUNC_NAME                        Endpoint_Read_EStream_LE\r
+#define  TEMPLATE_BUFFER_TYPE                      void*\r
+#define  TEMPLATE_CLEAR_ENDPOINT()                 Endpoint_ClearOUT()\r
+#define  TEMPLATE_BUFFER_OFFSET(Length)            0\r
+#define  TEMPLATE_TRANSFER_BYTE(BufferPtr)         eeprom_write_byte((uint8_t*)BufferPtr++, Endpoint_Read_Byte())\r
+#include "Template/Template_Endpoint_RW.c"\r
+\r
+#define  TEMPLATE_FUNC_NAME                        Endpoint_Read_Stream_BE\r
+#define  TEMPLATE_BUFFER_TYPE                      void*\r
+#define  TEMPLATE_CLEAR_ENDPOINT()                 Endpoint_ClearOUT()\r
+#define  TEMPLATE_BUFFER_OFFSET(Length)            Length - 1\r
+#define  TEMPLATE_TRANSFER_BYTE(BufferPtr)         *((uint8_t*)BufferPtr--) = Endpoint_Read_Byte()\r
+#include "Template/Template_Endpoint_RW.c"\r
+\r
+#define  TEMPLATE_FUNC_NAME                        Endpoint_Read_EStream_BE\r
+#define  TEMPLATE_BUFFER_TYPE                      void*\r
+#define  TEMPLATE_CLEAR_ENDPOINT()                 Endpoint_ClearOUT()\r
+#define  TEMPLATE_BUFFER_OFFSET(Length)            Length - 1\r
+#define  TEMPLATE_TRANSFER_BYTE(BufferPtr)         eeprom_write_byte((uint8_t*)BufferPtr--, Endpoint_Read_Byte())\r
+#include "Template/Template_Endpoint_RW.c"\r
 \r
-uint8_t Endpoint_Read_Control_Stream_BE(void* Buffer, uint16_t Length)\r
-{\r
-       uint8_t* DataStream = (uint8_t*)(Buffer + Length - 1);\r
-       \r
-       while (Length)\r
-       {\r
-               while (!(Endpoint_IsSetupOUTReceived()));\r
-               \r
-               while (Length && Endpoint_BytesInEndpoint())\r
-               {\r
-                       *(DataStream--) = Endpoint_Read_Byte();\r
-                       \r
-                       Length--;\r
-               }\r
-               \r
-               Endpoint_ClearSetupOUT();\r
-       }\r
-       \r
-       while (!(Endpoint_IsSetupINReady()));\r
+#endif\r
 \r
-       return ENDPOINT_RWCSTREAM_ERROR_NoError;\r
-}\r
+#define  TEMPLATE_FUNC_NAME                        Endpoint_Write_Control_Stream_LE\r
+#define  TEMPLATE_BUFFER_OFFSET(Length)            0\r
+#define  TEMPLATE_TRANSFER_BYTE(BufferPtr)         Endpoint_Write_Byte(*((uint8_t*)BufferPtr++))\r
+#include "Template/Template_Endpoint_Control_W.c"\r
+\r
+#define  TEMPLATE_FUNC_NAME                        Endpoint_Write_Control_PStream_LE\r
+#define  TEMPLATE_BUFFER_OFFSET(Length)            0\r
+#define  TEMPLATE_TRANSFER_BYTE(BufferPtr)         Endpoint_Write_Byte(pgm_read_byte((uint8_t*)BufferPtr++))\r
+#include "Template/Template_Endpoint_Control_W.c"\r
+\r
+#define  TEMPLATE_FUNC_NAME                        Endpoint_Write_Control_EStream_LE\r
+#define  TEMPLATE_BUFFER_OFFSET(Length)            0\r
+#define  TEMPLATE_TRANSFER_BYTE(BufferPtr)         Endpoint_Write_Byte(eeprom_read_byte((uint8_t*)BufferPtr++))\r
+#include "Template/Template_Endpoint_Control_W.c"\r
+\r
+#define  TEMPLATE_FUNC_NAME                        Endpoint_Write_Control_Stream_BE\r
+#define  TEMPLATE_BUFFER_OFFSET(Length)            Length - 1\r
+#define  TEMPLATE_TRANSFER_BYTE(BufferPtr)         Endpoint_Write_Byte(*((uint8_t*)BufferPtr--))\r
+#include "Template/Template_Endpoint_Control_W.c"\r
+\r
+#define  TEMPLATE_FUNC_NAME                        Endpoint_Write_Control_PStream_BE\r
+#define  TEMPLATE_BUFFER_OFFSET(Length)            Length - 1\r
+#define  TEMPLATE_TRANSFER_BYTE(BufferPtr)         Endpoint_Write_Byte(pgm_read_byte((uint8_t*)BufferPtr--))\r
+#include "Template/Template_Endpoint_Control_W.c"\r
+\r
+#define  TEMPLATE_FUNC_NAME                        Endpoint_Write_Control_EStream_BE\r
+#define  TEMPLATE_BUFFER_OFFSET(Length)            Length - 1\r
+#define  TEMPLATE_TRANSFER_BYTE(BufferPtr)         Endpoint_Write_Byte(eeprom_read_byte((uint8_t*)BufferPtr--))\r
+#include "Template/Template_Endpoint_Control_W.c"\r
+\r
+#define  TEMPLATE_FUNC_NAME                        Endpoint_Read_Control_Stream_LE\r
+#define  TEMPLATE_BUFFER_OFFSET(Length)            0\r
+#define  TEMPLATE_TRANSFER_BYTE(BufferPtr)         *((uint8_t*)BufferPtr++) = Endpoint_Read_Byte()\r
+#include "Template/Template_Endpoint_Control_R.c"\r
+\r
+#define  TEMPLATE_FUNC_NAME                        Endpoint_Read_Control_EStream_LE\r
+#define  TEMPLATE_BUFFER_OFFSET(Length)            0\r
+#define  TEMPLATE_TRANSFER_BYTE(BufferPtr)         eeprom_write_byte((uint8_t*)BufferPtr++, Endpoint_Read_Byte())\r
+#include "Template/Template_Endpoint_Control_R.c"\r
+\r
+#define  TEMPLATE_FUNC_NAME                        Endpoint_Read_Control_Stream_BE\r
+#define  TEMPLATE_BUFFER_OFFSET(Length)            Length - 1\r
+#define  TEMPLATE_TRANSFER_BYTE(BufferPtr)         *((uint8_t*)BufferPtr--) = Endpoint_Read_Byte()\r
+#include "Template/Template_Endpoint_Control_R.c"\r
+\r
+#define  TEMPLATE_FUNC_NAME                        Endpoint_Read_Control_EStream_BE\r
+#define  TEMPLATE_BUFFER_OFFSET(Length)            Length - 1\r
+#define  TEMPLATE_TRANSFER_BYTE(BufferPtr)         eeprom_write_byte((uint8_t*)BufferPtr--, Endpoint_Read_Byte())\r
+#include "Template/Template_Endpoint_Control_R.c"\r
 \r
 #endif\r