From 73d9fafc0fe42741ad8f609dd4762e2bc14cbd01 Mon Sep 17 00:00:00 2001 From: Dean Camera Date: Mon, 13 Jul 2009 12:38:30 +0000 Subject: Added new EEPROM and FLASH buffer versions of the Endpoint and Pipe stream functions. Changed Endpoint.c and Pipe.c to use a templated system to build the seperate functions, rather than duplicating each function's code many times. --- LUFA/Drivers/USB/LowLevel/DevChapter9.c | 43 +- LUFA/Drivers/USB/LowLevel/Endpoint.c | 528 +++++---------------- LUFA/Drivers/USB/LowLevel/Endpoint.h | 284 ++++++++--- LUFA/Drivers/USB/LowLevel/Pipe.c | 370 +++------------ LUFA/Drivers/USB/LowLevel/Pipe.h | 186 +++++--- .../Template/Template_Endpoint_Control_R.c | 27 ++ .../Template/Template_Endpoint_Control_W.c | 39 ++ .../USB/LowLevel/Template/Template_Endpoint_RW.c | 76 +++ .../USB/LowLevel/Template/Template_Pipe_RW.c | 78 +++ 9 files changed, 752 insertions(+), 879 deletions(-) create mode 100644 LUFA/Drivers/USB/LowLevel/Template/Template_Endpoint_Control_R.c create mode 100644 LUFA/Drivers/USB/LowLevel/Template/Template_Endpoint_Control_W.c create mode 100644 LUFA/Drivers/USB/LowLevel/Template/Template_Endpoint_RW.c create mode 100644 LUFA/Drivers/USB/LowLevel/Template/Template_Pipe_RW.c (limited to 'LUFA/Drivers') diff --git a/LUFA/Drivers/USB/LowLevel/DevChapter9.c b/LUFA/Drivers/USB/LowLevel/DevChapter9.c index feaabce461..f49f5b39b2 100644 --- a/LUFA/Drivers/USB/LowLevel/DevChapter9.c +++ b/LUFA/Drivers/USB/LowLevel/DevChapter9.c @@ -241,47 +241,12 @@ static void USB_Device_GetDescriptor(void) #if defined(USE_RAM_DESCRIPTORS) Endpoint_Write_Control_Stream_LE(DescriptorPointer, DescriptorSize); + #elif defined(USE_EEPROM_DESCRIPTORS) + Endpoint_Write_Control_EStream_LE(DescriptorPointer, DescriptorSize); #else - bool SendZLP; - - if (USB_ControlRequest.wLength > DescriptorSize) - USB_ControlRequest.wLength = DescriptorSize; - - while (USB_ControlRequest.wLength) - { - while (!(Endpoint_IsINReady())) - { - if (Endpoint_IsOUTReceived()) - { - Endpoint_ClearOUT(); - return; - } - } - - while (USB_ControlRequest.wLength && (Endpoint_BytesInEndpoint() < USB_ControlEndpointSize)) - { - #if defined (USE_EEPROM_DESCRIPTORS) - Endpoint_Write_Byte(eeprom_read_byte(DescriptorPointer++)); - #else - Endpoint_Write_Byte(pgm_read_byte(DescriptorPointer++)); - #endif - - USB_ControlRequest.wLength--; - } - - SendZLP = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize); - Endpoint_ClearIN(); - } - - if (SendZLP) - { - while (!(Endpoint_IsINReady())); - Endpoint_ClearIN(); - } - - while (!(Endpoint_IsOUTReceived())); + Endpoint_Write_Control_PStream_LE(DescriptorPointer, DescriptorSize); #endif - + Endpoint_ClearOUT(); } diff --git a/LUFA/Drivers/USB/LowLevel/Endpoint.c b/LUFA/Drivers/USB/LowLevel/Endpoint.c index 1ff66ddfaa..f9db9cd224 100644 --- a/LUFA/Drivers/USB/LowLevel/Endpoint.c +++ b/LUFA/Drivers/USB/LowLevel/Endpoint.c @@ -183,428 +183,116 @@ uint8_t Endpoint_Discard_Stream(uint16_t Length return ENDPOINT_RWSTREAM_NoError; } -uint8_t Endpoint_Write_Stream_LE(const void* Buffer, uint16_t Length -#if !defined(NO_STREAM_CALLBACKS) - , StreamCallbackPtr_t Callback -#endif - ) -{ - uint8_t* DataStream = (uint8_t*)Buffer; - uint8_t ErrorCode; - - if ((ErrorCode = Endpoint_WaitUntilReady())) - return ErrorCode; - - #if defined(FAST_STREAM_TRANSFERS) - uint8_t BytesRemToAlignment = (Endpoint_BytesInEndpoint() & 0x07); - - if (Length >= 8) - { - Length -= BytesRemToAlignment; - - switch (BytesRemToAlignment) - { - default: - do - { - if (!(Endpoint_IsReadWriteAllowed())) - { - Endpoint_ClearIN(); - - #if !defined(NO_STREAM_CALLBACKS) - if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort)) - return ENDPOINT_RWSTREAM_CallbackAborted; - #endif - - if ((ErrorCode = Endpoint_WaitUntilReady())) - return ErrorCode; - } - - Length -= 8; - - Endpoint_Write_Byte(*(DataStream++)); - case 7: Endpoint_Write_Byte(*(DataStream++)); - case 6: Endpoint_Write_Byte(*(DataStream++)); - case 5: Endpoint_Write_Byte(*(DataStream++)); - case 4: Endpoint_Write_Byte(*(DataStream++)); - case 3: Endpoint_Write_Byte(*(DataStream++)); - case 2: Endpoint_Write_Byte(*(DataStream++)); - case 1: Endpoint_Write_Byte(*(DataStream++)); - } while (Length >= 8); - } - } - #endif +#define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_LE +#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() +#define TEMPLATE_BUFFER_OFFSET(Length) 0 +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(*(BufferPtr++)) +#include "Template/Template_Endpoint_RW.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_LE +#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() +#define TEMPLATE_BUFFER_OFFSET(Length) 0 +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(pgm_read_byte(BufferPtr++)) +#include "Template/Template_Endpoint_RW.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_LE +#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() +#define TEMPLATE_BUFFER_OFFSET(Length) 0 +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(eeprom_read_byte(BufferPtr++)) +#include "Template/Template_Endpoint_RW.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Write_Stream_BE +#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() +#define TEMPLATE_BUFFER_OFFSET(Length) Length - 1 +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(*(BufferPtr--)) +#include "Template/Template_Endpoint_RW.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Write_EStream_BE +#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() +#define TEMPLATE_BUFFER_OFFSET(Length) Length - 1 +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(eeprom_read_byte(BufferPtr--)) +#include "Template/Template_Endpoint_RW.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Write_PStream_BE +#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearIN() +#define TEMPLATE_BUFFER_OFFSET(Length) Length - 1 +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(pgm_read_byte(BufferPtr--)) +#include "Template/Template_Endpoint_RW.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_LE +#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() +#define TEMPLATE_BUFFER_OFFSET(Length) 0 +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *(BufferPtr++) = Endpoint_Read_Byte() +#include "Template/Template_Endpoint_RW.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_LE +#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() +#define TEMPLATE_BUFFER_OFFSET(Length) 0 +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_write_byte(BufferPtr++, Endpoint_Read_Byte()) +#include "Template/Template_Endpoint_RW.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Read_Stream_BE +#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() +#define TEMPLATE_BUFFER_OFFSET(Length) Length - 1 +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *(BufferPtr--) = Endpoint_Read_Byte() +#include "Template/Template_Endpoint_RW.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Read_EStream_BE +#define TEMPLATE_CLEAR_ENDPOINT() Endpoint_ClearOUT() +#define TEMPLATE_BUFFER_OFFSET(Length) Length - 1 +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_write_byte(BufferPtr--, Endpoint_Read_Byte()) +#include "Template/Template_Endpoint_RW.c" - while (Length) - { - if (!(Endpoint_IsReadWriteAllowed())) - { - Endpoint_ClearIN(); - - #if !defined(NO_STREAM_CALLBACKS) - if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort)) - return ENDPOINT_RWSTREAM_CallbackAborted; - #endif - - if ((ErrorCode = Endpoint_WaitUntilReady())) - return ErrorCode; - } - else - { - Endpoint_Write_Byte(*(DataStream++)); - Length--; - } - } - - return ENDPOINT_RWSTREAM_NoError; -} - -uint8_t Endpoint_Write_Stream_BE(const void* Buffer, uint16_t Length -#if !defined(NO_STREAM_CALLBACKS) - , StreamCallbackPtr_t Callback #endif - ) -{ - uint8_t* DataStream = (uint8_t*)(Buffer + Length - 1); - uint8_t ErrorCode; - - if ((ErrorCode = Endpoint_WaitUntilReady())) - return ErrorCode; - - #if defined(FAST_STREAM_TRANSFERS) - uint8_t BytesRemToAlignment = (Endpoint_BytesInEndpoint() & 0x07); - - if (Length >= 8) - { - Length -= BytesRemToAlignment; - - switch (BytesRemToAlignment) - { - default: - do - { - if (!(Endpoint_IsReadWriteAllowed())) - { - Endpoint_ClearIN(); - - #if !defined(NO_STREAM_CALLBACKS) - if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort)) - return ENDPOINT_RWSTREAM_CallbackAborted; - #endif - - if ((ErrorCode = Endpoint_WaitUntilReady())) - return ErrorCode; - } - - Length -= 8; - - Endpoint_Write_Byte(*(DataStream--)); - case 7: Endpoint_Write_Byte(*(DataStream--)); - case 6: Endpoint_Write_Byte(*(DataStream--)); - case 5: Endpoint_Write_Byte(*(DataStream--)); - case 4: Endpoint_Write_Byte(*(DataStream--)); - case 3: Endpoint_Write_Byte(*(DataStream--)); - case 2: Endpoint_Write_Byte(*(DataStream--)); - case 1: Endpoint_Write_Byte(*(DataStream--)); - } while (Length >= 8); - } - } - #endif - - while (Length) - { - if (!(Endpoint_IsReadWriteAllowed())) - { - Endpoint_ClearIN(); - - #if !defined(NO_STREAM_CALLBACKS) - if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort)) - return ENDPOINT_RWSTREAM_CallbackAborted; - #endif - - if ((ErrorCode = Endpoint_WaitUntilReady())) - return ErrorCode; - } - else - { - Endpoint_Write_Byte(*(DataStream--)); - Length--; - } - } - - return ENDPOINT_RWSTREAM_NoError; -} - -uint8_t Endpoint_Read_Stream_LE(void* Buffer, uint16_t Length -#if !defined(NO_STREAM_CALLBACKS) - , StreamCallbackPtr_t Callback -#endif - ) -{ - uint8_t* DataStream = (uint8_t*)Buffer; - uint8_t ErrorCode; - - if ((ErrorCode = Endpoint_WaitUntilReady())) - return ErrorCode; - - #if defined(FAST_STREAM_TRANSFERS) - uint8_t BytesRemToAlignment = (Endpoint_BytesInEndpoint() & 0x07); - - if (Length >= 8) - { - Length -= BytesRemToAlignment; - - switch (BytesRemToAlignment) - { - default: - do - { - if (!(Endpoint_IsReadWriteAllowed())) - { - Endpoint_ClearOUT(); - - #if !defined(NO_STREAM_CALLBACKS) - if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort)) - return ENDPOINT_RWSTREAM_CallbackAborted; - #endif - - if ((ErrorCode = Endpoint_WaitUntilReady())) - return ErrorCode; - } - Length -= 8; - - *(DataStream++) = Endpoint_Read_Byte(); - case 7: *(DataStream++) = Endpoint_Read_Byte(); - case 6: *(DataStream++) = Endpoint_Read_Byte(); - case 5: *(DataStream++) = Endpoint_Read_Byte(); - case 4: *(DataStream++) = Endpoint_Read_Byte(); - case 3: *(DataStream++) = Endpoint_Read_Byte(); - case 2: *(DataStream++) = Endpoint_Read_Byte(); - case 1: *(DataStream++) = Endpoint_Read_Byte(); - } while (Length >= 8); - } - } - #endif - - while (Length) - { - if (!(Endpoint_IsReadWriteAllowed())) - { - Endpoint_ClearOUT(); - - #if !defined(NO_STREAM_CALLBACKS) - if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort)) - return ENDPOINT_RWSTREAM_CallbackAborted; - #endif - - if ((ErrorCode = Endpoint_WaitUntilReady())) - return ErrorCode; - } - else - { - *(DataStream++) = Endpoint_Read_Byte(); - Length--; - } - } - - return ENDPOINT_RWSTREAM_NoError; -} - -uint8_t Endpoint_Read_Stream_BE(void* Buffer, uint16_t Length -#if !defined(NO_STREAM_CALLBACKS) - , StreamCallbackPtr_t Callback -#endif - ) -{ - uint8_t* DataStream = (uint8_t*)(Buffer + Length - 1); - uint8_t ErrorCode; - - if ((ErrorCode = Endpoint_WaitUntilReady())) - return ErrorCode; - - #if defined(FAST_STREAM_TRANSFERS) - uint8_t BytesRemToAlignment = (Endpoint_BytesInEndpoint() & 0x07); - - if (Length >= 8) - { - Length -= BytesRemToAlignment; - - switch (BytesRemToAlignment) - { - default: - do - { - if (!(Endpoint_IsReadWriteAllowed())) - { - Endpoint_ClearOUT(); - - #if !defined(NO_STREAM_CALLBACKS) - if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort)) - return ENDPOINT_RWSTREAM_CallbackAborted; - #endif - - if ((ErrorCode = Endpoint_WaitUntilReady())) - return ErrorCode; - } - - Length -= 8; - - *(DataStream--) = Endpoint_Read_Byte(); - case 7: *(DataStream--) = Endpoint_Read_Byte(); - case 6: *(DataStream--) = Endpoint_Read_Byte(); - case 5: *(DataStream--) = Endpoint_Read_Byte(); - case 4: *(DataStream--) = Endpoint_Read_Byte(); - case 3: *(DataStream--) = Endpoint_Read_Byte(); - case 2: *(DataStream--) = Endpoint_Read_Byte(); - case 1: *(DataStream--) = Endpoint_Read_Byte(); - } while (Length >= 8); - } - } - #endif - - while (Length) - { - if (!(Endpoint_IsReadWriteAllowed())) - { - Endpoint_ClearOUT(); - - #if !defined(NO_STREAM_CALLBACKS) - if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort)) - return ENDPOINT_RWSTREAM_CallbackAborted; - #endif - - if ((ErrorCode = Endpoint_WaitUntilReady())) - return ErrorCode; - } - else - { - *(DataStream--) = Endpoint_Read_Byte(); - Length--; - } - } - - return ENDPOINT_RWSTREAM_NoError; -} -#endif - -uint8_t Endpoint_Write_Control_Stream_LE(const void* Buffer, uint16_t Length) -{ - uint8_t* DataStream = (uint8_t*)Buffer; - bool LastPacketFull = false; - - if (Length > USB_ControlRequest.wLength) - Length = USB_ControlRequest.wLength; - - while (Length && !(Endpoint_IsOUTReceived())) - { - while (!(Endpoint_IsINReady())); - - while (Length && (Endpoint_BytesInEndpoint() < USB_ControlEndpointSize)) - { - Endpoint_Write_Byte(*(DataStream++)); - Length--; - } - - LastPacketFull = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize); - Endpoint_ClearIN(); - } - - if (Endpoint_IsOUTReceived()) - return ENDPOINT_RWCSTREAM_HostAborted; - - if (LastPacketFull) - { - while (!(Endpoint_IsINReady())); - Endpoint_ClearIN(); - } - - while (!(Endpoint_IsOUTReceived())); - - return ENDPOINT_RWCSTREAM_NoError; -} - -uint8_t Endpoint_Write_Control_Stream_BE(const void* Buffer, uint16_t Length) -{ - uint8_t* DataStream = (uint8_t*)(Buffer + Length - 1); - bool LastPacketFull = false; - - if (Length > USB_ControlRequest.wLength) - Length = USB_ControlRequest.wLength; - - while (Length && !(Endpoint_IsOUTReceived())) - { - if (Endpoint_IsINReady()) - { - while (Length && (Endpoint_BytesInEndpoint() < USB_ControlEndpointSize)) - { - Endpoint_Write_Byte(*(DataStream--)); - Length--; - } - - LastPacketFull = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize); - Endpoint_ClearIN(); - } - } - - if (Endpoint_IsOUTReceived()) - return ENDPOINT_RWCSTREAM_HostAborted; - - if (LastPacketFull) - { - while (!(Endpoint_IsINReady())); - Endpoint_ClearIN(); - } - - while (!(Endpoint_IsOUTReceived())); - - return ENDPOINT_RWCSTREAM_NoError; -} - -uint8_t Endpoint_Read_Control_Stream_LE(void* Buffer, uint16_t Length) -{ - uint8_t* DataStream = (uint8_t*)Buffer; - - while (Length) - { - if (Endpoint_IsOUTReceived()) - { - while (Length && Endpoint_BytesInEndpoint()) - { - *(DataStream++) = Endpoint_Read_Byte(); - Length--; - } - - Endpoint_ClearOUT(); - } - } - - while (!(Endpoint_IsINReady())); - - return ENDPOINT_RWCSTREAM_NoError; -} - -uint8_t Endpoint_Read_Control_Stream_BE(void* Buffer, uint16_t Length) -{ - uint8_t* DataStream = (uint8_t*)(Buffer + Length - 1); - - while (Length) - { - if (Endpoint_IsOUTReceived()) - { - while (Length && Endpoint_BytesInEndpoint()) - { - *(DataStream--) = Endpoint_Read_Byte(); - Length--; - } - - Endpoint_ClearOUT(); - } - } - - while (!(Endpoint_IsINReady())); - - return ENDPOINT_RWCSTREAM_NoError; -} +#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_LE +#define TEMPLATE_BUFFER_OFFSET(Length) 0 +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(*(BufferPtr++)) +#include "Template/Template_Endpoint_Control_W.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_PStream_LE +#define TEMPLATE_BUFFER_OFFSET(Length) 0 +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(pgm_read_byte(BufferPtr++)) +#include "Template/Template_Endpoint_Control_W.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_EStream_LE +#define TEMPLATE_BUFFER_OFFSET(Length) 0 +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(eeprom_read_byte(BufferPtr++)) +#include "Template/Template_Endpoint_Control_W.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_Stream_BE +#define TEMPLATE_BUFFER_OFFSET(Length) Length - 1 +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(*(BufferPtr--)) +#include "Template/Template_Endpoint_Control_W.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_PStream_BE +#define TEMPLATE_BUFFER_OFFSET(Length) Length - 1 +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(pgm_read_byte(BufferPtr--)) +#include "Template/Template_Endpoint_Control_W.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Write_Control_EStream_BE +#define TEMPLATE_BUFFER_OFFSET(Length) Length - 1 +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Endpoint_Write_Byte(eeprom_read_byte(BufferPtr--)) +#include "Template/Template_Endpoint_Control_W.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_LE +#define TEMPLATE_BUFFER_OFFSET(Length) 0 +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *(BufferPtr++) = Endpoint_Read_Byte() +#include "Template/Template_Endpoint_Control_R.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_EStream_LE +#define TEMPLATE_BUFFER_OFFSET(Length) 0 +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_write_byte(BufferPtr++, Endpoint_Read_Byte()) +#include "Template/Template_Endpoint_Control_R.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_Stream_BE +#define TEMPLATE_BUFFER_OFFSET(Length) Length - 1 +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *(BufferPtr--) = Endpoint_Read_Byte() +#include "Template/Template_Endpoint_Control_R.c" + +#define TEMPLATE_FUNC_NAME Endpoint_Read_Control_EStream_BE +#define TEMPLATE_BUFFER_OFFSET(Length) Length - 1 +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_write_byte(BufferPtr--, Endpoint_Read_Byte()) +#include "Template/Template_Endpoint_Control_R.c" #endif diff --git a/LUFA/Drivers/USB/LowLevel/Endpoint.h b/LUFA/Drivers/USB/LowLevel/Endpoint.h index 772d1feed3..2caea8343a 100644 --- a/LUFA/Drivers/USB/LowLevel/Endpoint.h +++ b/LUFA/Drivers/USB/LowLevel/Endpoint.h @@ -43,6 +43,20 @@ * Functions, macros, variables, enums and types related to data reading and writing from and to endpoints. */ +/** \ingroup Group_EndpointRW + * @defgroup Group_EndpointPrimitiveRW Read/Write of Primitive Data Types + * + * Functions, macros, variables, enums and types related to data reading and writing of primitive data types + * from and to endpoints. + */ + +/** \ingroup Group_EndpointRW + * @defgroup Group_EndpointStreamRW Read/Write of Multi-Byte Streams + * + * Functions, macros, variables, enums and types related to data reading and writing of data streams from + * and to endpoints. + */ + /** @defgroup Group_EndpointPacketManagement Endpoint Packet Management * * Functions, macros, variables, enums and types related to packet management of endpoints. @@ -53,6 +67,8 @@ /* Includes: */ #include + #include + #include #include #include "../../../Common/Common.h" @@ -407,7 +423,7 @@ /** Enum for the possible error return codes of the Endpoint_*_Stream_* functions. * - * \ingroup Group_EndpointRW + * \ingroup Group_EndpointStreamRW */ enum Endpoint_Stream_RW_ErrorCodes_t { @@ -429,7 +445,7 @@ /** Enum for the possible error return codes of the Endpoint_*_Control_Stream_* functions.. * - * \ingroup Group_EndpointRW + * \ingroup Group_EndpointStreamRW */ enum Endpoint_ControlStream_RW_ErrorCodes_t { @@ -440,7 +456,7 @@ /* Inline Functions: */ /** Reads one byte from the currently selected endpoint's bank, for OUT direction endpoints. * - * \ingroup Group_EndpointRW + * \ingroup Group_EndpointPrimitiveRW * * \return Next byte in the currently selected endpoint's FIFO buffer */ @@ -452,7 +468,7 @@ /** Writes one byte from the currently selected endpoint's bank, for IN direction endpoints. * - * \ingroup Group_EndpointRW + * \ingroup Group_EndpointPrimitiveRW * * \param[in] Byte Next byte to write into the the currently selected endpoint's FIFO buffer */ @@ -464,7 +480,7 @@ /** Discards one byte from the currently selected endpoint's bank, for OUT direction endpoints. * - * \ingroup Group_EndpointRW + * \ingroup Group_EndpointPrimitiveRW */ static inline void Endpoint_Discard_Byte(void) ATTR_ALWAYS_INLINE; static inline void Endpoint_Discard_Byte(void) @@ -477,7 +493,7 @@ /** Reads two bytes from the currently selected endpoint's bank in little endian format, for OUT * direction endpoints. * - * \ingroup Group_EndpointRW + * \ingroup Group_EndpointPrimitiveRW * * \return Next word in the currently selected endpoint's FIFO buffer */ @@ -495,7 +511,7 @@ /** Reads two bytes from the currently selected endpoint's bank in big endian format, for OUT * direction endpoints. * - * \ingroup Group_EndpointRW + * \ingroup Group_EndpointPrimitiveRW * * \return Next word in the currently selected endpoint's FIFO buffer */ @@ -513,7 +529,7 @@ /** Writes two bytes to the currently selected endpoint's bank in little endian format, for IN * direction endpoints. * - * \ingroup Group_EndpointRW + * \ingroup Group_EndpointPrimitiveRW * * \param[in] Word Next word to write to the currently selected endpoint's FIFO buffer */ @@ -527,7 +543,7 @@ /** Writes two bytes to the currently selected endpoint's bank in big endian format, for IN * direction endpoints. * - * \ingroup Group_EndpointRW + * \ingroup Group_EndpointPrimitiveRW * * \param[in] Word Next word to write to the currently selected endpoint's FIFO buffer */ @@ -540,7 +556,7 @@ /** Discards two bytes from the currently selected endpoint's bank, for OUT direction endpoints. * - * \ingroup Group_EndpointRW + * \ingroup Group_EndpointPrimitiveRW */ static inline void Endpoint_Discard_Word(void) ATTR_ALWAYS_INLINE; static inline void Endpoint_Discard_Word(void) @@ -554,7 +570,7 @@ /** Reads four bytes from the currently selected endpoint's bank in little endian format, for OUT * direction endpoints. * - * \ingroup Group_EndpointRW + * \ingroup Group_EndpointPrimitiveRW * * \return Next double word in the currently selected endpoint's FIFO buffer */ @@ -578,7 +594,7 @@ /** Reads four bytes from the currently selected endpoint's bank in big endian format, for OUT * direction endpoints. * - * \ingroup Group_EndpointRW + * \ingroup Group_EndpointPrimitiveRW * * \return Next double word in the currently selected endpoint's FIFO buffer */ @@ -602,7 +618,7 @@ /** Writes four bytes to the currently selected endpoint's bank in little endian format, for IN * direction endpoints. * - * \ingroup Group_EndpointRW + * \ingroup Group_EndpointPrimitiveRW * * \param[in] DWord Next double word to write to the currently selected endpoint's FIFO buffer */ @@ -618,7 +634,7 @@ /** Writes four bytes to the currently selected endpoint's bank in big endian format, for IN * direction endpoints. * - * \ingroup Group_EndpointRW + * \ingroup Group_EndpointPrimitiveRW * * \param[in] DWord Next double word to write to the currently selected endpoint's FIFO buffer */ @@ -633,7 +649,7 @@ /** Discards four bytes from the currently selected endpoint's bank, for OUT direction endpoints. * - * \ingroup Group_EndpointRW + * \ingroup Group_EndpointPrimitiveRW */ static inline void Endpoint_Discard_DWord(void) ATTR_ALWAYS_INLINE; static inline void Endpoint_Discard_DWord(void) @@ -669,6 +685,12 @@ #endif /* Function Prototypes: */ + #if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__) + #define _CALLBACK_PARAM , StreamCallbackPtr_t Callback + #else + #define _CALLBACK_PARAM + #endif + /** Configures the specified endpoint number with the given endpoint type, direction, bank size * and banking mode. Endpoints should be allocated in ascending order by their address in the * device (i.e. endpoint 1 should be configured before endpoint 2 and so on) to prevent fragmentation @@ -694,8 +716,6 @@ bool Endpoint_ConfigureEndpoint(const uint8_t Number, const uint8_t Type, const uint8_t Direction, const uint16_t Size, const uint8_t Banks); - #if !defined(CONTROL_ONLY_DEVICE) - /** Spinloops until the currently selected non-control endpoint is ready for the next packet of data * to be read or written to it. * @@ -720,18 +740,14 @@ * * \note This routine should not be used on CONTROL type endpoints. * - * \ingroup Group_EndpointRW + * \ingroup Group_EndpointStreamRW * * \param[in] Length Number of bytes to send via the currently selected endpoint. * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback * * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. */ - uint8_t Endpoint_Discard_Stream(uint16_t Length - #if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__) - , StreamCallbackPtr_t Callback - #endif - ); + uint8_t Endpoint_Discard_Stream(uint16_t Length _CALLBACK_PARAM); /** Writes the given number of bytes to the endpoint from the given buffer in little endian, * sending full packets to the host as needed. The last packet filled is not automatically sent; @@ -746,7 +762,7 @@ * * \note This routine should not be used on CONTROL type endpoints. * - * \ingroup Group_EndpointRW + * \ingroup Group_EndpointStreamRW * * \param[in] Buffer Pointer to the source data buffer to read from. * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. @@ -754,11 +770,33 @@ * * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. */ - uint8_t Endpoint_Write_Stream_LE(const void* Buffer, uint16_t Length - #if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__) - , StreamCallbackPtr_t Callback - #endif - ) ATTR_NON_NULL_PTR_ARG(1); + uint8_t Endpoint_Write_Stream_LE(void* Buffer, uint16_t Length _CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1); + + /** EEPROM buffer source version of \ref Endpoint_Write_Stream_LE. + * + * \ingroup Group_EndpointStreamRW + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_EStream_LE(void* Buffer, uint16_t Length _CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1); + + /** FLASH buffer source version of \ref Endpoint_Write_Stream_LE. + * + * \note The FLASH data must be located in the first 64KB of FLASH for this function to work correctly. + * + * \ingroup Group_EndpointStreamRW + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_PStream_LE(void* Buffer, uint16_t Length _CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1); /** Writes the given number of bytes to the endpoint from the given buffer in big endian, * sending full packets to the host as needed. The last packet filled is not automatically sent; @@ -773,7 +811,7 @@ * * \note This routine should not be used on CONTROL type endpoints. * - * \ingroup Group_EndpointRW + * \ingroup Group_EndpointStreamRW * * \param[in] Buffer Pointer to the source data buffer to read from. * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. @@ -781,11 +819,33 @@ * * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. */ - uint8_t Endpoint_Write_Stream_BE(const void* Buffer, uint16_t Length - #if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__) - , StreamCallbackPtr_t Callback - #endif - ) ATTR_NON_NULL_PTR_ARG(1); + uint8_t Endpoint_Write_Stream_BE(void* Buffer, uint16_t Length _CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1); + + /** EEPROM buffer source version of \ref Endpoint_Write_Stream_BE. + * + * \ingroup Group_EndpointStreamRW + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_EStream_BE(void* Buffer, uint16_t Length _CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1); + + /** FLASH buffer source version of \ref Endpoint_Write_Stream_BE. + * + * \note The FLASH data must be located in the first 64KB of FLASH for this function to work correctly. + * + * \ingroup Group_EndpointStreamRW + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_PStream_BE(void* Buffer, uint16_t Length _CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1); /** Reads the given number of bytes from the endpoint from the given buffer in little endian, * discarding fully read packets from the host as needed. The last packet is not automatically @@ -800,20 +860,28 @@ * * \note This routine should not be used on CONTROL type endpoints. * - * \ingroup Group_EndpointRW + * \ingroup Group_EndpointStreamRW * - * \param[out] Buffer Pointer to the destination data buffer to write to. + * \param[out] Buffer Pointer to the destination data buffer to write to. * \param[in] Length Number of bytes to send via the currently selected endpoint. * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback * * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. */ - uint8_t Endpoint_Read_Stream_LE(void* Buffer, uint16_t Length - #if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__) - , StreamCallbackPtr_t Callback - #endif - ) ATTR_NON_NULL_PTR_ARG(1); + uint8_t Endpoint_Read_Stream_LE(void* Buffer, uint16_t Length _CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1); + /** EEPROM buffer source version of \ref Endpoint_Read_Stream_LE. + * + * \ingroup Group_EndpointStreamRW + * + * \param[out] Buffer Pointer to the destination data buffer to write to, located in EEPROM memory space. + * \param[in] Length Number of bytes to send via the currently selected endpoint. + * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Read_EStream_LE(void* Buffer, uint16_t Length _CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1); + /** Reads the given number of bytes from the endpoint from the given buffer in big endian, * discarding fully read packets from the host as needed. The last packet is not automatically * discarded once the remaining bytes has been read; the user is responsible for manually @@ -827,7 +895,7 @@ * * \note This routine should not be used on CONTROL type endpoints. * - * \ingroup Group_EndpointRW + * \ingroup Group_EndpointStreamRW * * \param[out] Buffer Pointer to the destination data buffer to write to. * \param[in] Length Number of bytes to send via the currently selected endpoint. @@ -835,13 +903,19 @@ * * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. */ - uint8_t Endpoint_Read_Stream_BE(void* Buffer, uint16_t Length - #if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__) - , StreamCallbackPtr_t Callback - #endif - ) ATTR_NON_NULL_PTR_ARG(1); + uint8_t Endpoint_Read_Stream_BE(void* Buffer, uint16_t Length _CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1); - #endif + /** EEPROM buffer source version of \ref Endpoint_Read_Stream_BE. + * + * \ingroup Group_EndpointStreamRW + * + * \param[out] Buffer Pointer to the destination data buffer to write to, located in EEPROM memory space. + * \param[in] Length Number of bytes to send via the currently selected endpoint. + * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback + * + * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Read_EStream_BE(void* Buffer, uint16_t Length _CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1); /** Writes the given number of bytes to the CONTROL type endpoint from the given buffer in little endian, * sending full packets to the host as needed. The host OUT acknowledgement is not automatically cleared @@ -853,14 +927,48 @@ * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained * together; i.e. the entire stream data must be read or written at the one time. * - * \ingroup Group_EndpointRW + * \ingroup Group_EndpointStreamRW * * \param[in] Buffer Pointer to the source data buffer to read from. * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. * * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. */ - uint8_t Endpoint_Write_Control_Stream_LE(const void* Buffer, uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); + uint8_t Endpoint_Write_Control_Stream_LE(void* Buffer, uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); + + /** EEPROM buffer source version of Endpoint_Write_Control_Stream_LE. + * + * \note This routine should only be used on CONTROL type endpoints. + * + * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained + * together; i.e. the entire stream data must be read or written at the one time. + * + * \ingroup Group_EndpointStreamRW + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_Control_EStream_LE(void* Buffer, uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); + + /** FLASH buffer source version of \ref Endpoint_Write_Control_Stream_LE. + * + * \note The FLASH data must be located in the first 64KB of FLASH for this function to work correctly. + * + * \note This routine should only be used on CONTROL type endpoints. + * + * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained + * together; i.e. the entire stream data must be read or written at the one time. + * + * \ingroup Group_EndpointStreamRW + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_Control_PStream_LE(void* Buffer, uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); /** Writes the given number of bytes to the CONTROL type endpoint from the given buffer in big endian, * sending full packets to the host as needed. The host OUT acknowledgement is not automatically cleared @@ -872,14 +980,48 @@ * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained * together; i.e. the entire stream data must be read or written at the one time. * - * \ingroup Group_EndpointRW + * \ingroup Group_EndpointStreamRW * * \param[in] Buffer Pointer to the source data buffer to read from. * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. * * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. */ - uint8_t Endpoint_Write_Control_Stream_BE(const void* Buffer, uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); + uint8_t Endpoint_Write_Control_Stream_BE(void* Buffer, uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); + + /** EEPROM buffer source version of \ref Endpoint_Write_Control_Stream_BE. + * + * \note This routine should only be used on CONTROL type endpoints. + * + * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained + * together; i.e. the entire stream data must be read or written at the one time. + * + * \ingroup Group_EndpointStreamRW + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_Control_EStream_BE(void* Buffer, uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); + + /** FLASH buffer source version of \ref Endpoint_Write_Control_Stream_BE. + * + * \note The FLASH data must be located in the first 64KB of FLASH for this function to work correctly. + * + * \note This routine should only be used on CONTROL type endpoints. + * + * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained + * together; i.e. the entire stream data must be read or written at the one time. + * + * \ingroup Group_EndpointStreamRW + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Write_Control_PStream_BE(void* Buffer, uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); /** Reads the given number of bytes from the CONTROL endpoint from the given buffer in little endian, * discarding fully read packets from the host as needed. The device IN acknowledgement is not @@ -891,7 +1033,7 @@ * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained * together; i.e. the entire stream data must be read or written at the one time. * - * \ingroup Group_EndpointRW + * \ingroup Group_EndpointStreamRW * * \param[out] Buffer Pointer to the destination data buffer to write to. * \param[in] Length Number of bytes to send via the currently selected endpoint. @@ -900,6 +1042,22 @@ */ uint8_t Endpoint_Read_Control_Stream_LE(void* Buffer, uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); + /** EEPROM buffer source version of \ref Endpoint_Read_Control_Stream_LE. + * + * \note This routine should only be used on CONTROL type endpoints. + * + * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained + * together; i.e. the entire stream data must be read or written at the one time. + * + * \ingroup Group_EndpointStreamRW + * + * \param[out] Buffer Pointer to the destination data buffer to write to. + * \param[in] Length Number of bytes to send via the currently selected endpoint. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Read_Control_EStream_LE(void* Buffer, uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); + /** Reads the given number of bytes from the CONTROL endpoint from the given buffer in big endian, * discarding fully read packets from the host as needed. The device IN acknowledgement is not * automatically sent after success or failure states; the user is responsible for manually sending the @@ -910,7 +1068,7 @@ * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained * together; i.e. the entire stream data must be read or written at the one time. * - * \ingroup Group_EndpointRW + * \ingroup Group_EndpointStreamRW * * \param[out] Buffer Pointer to the destination data buffer to write to. * \param[in] Length Number of bytes to send via the currently selected endpoint. @@ -919,6 +1077,22 @@ */ uint8_t Endpoint_Read_Control_Stream_BE(void* Buffer, uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); + /** EEPROM buffer source version of \ref Endpoint_Read_Control_Stream_BE. + * + * \note This routine should only be used on CONTROL type endpoints. + * + * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained + * together; i.e. the entire stream data must be read or written at the one time. + * + * \ingroup Group_EndpointStreamRW + * + * \param[out] Buffer Pointer to the destination data buffer to write to. + * \param[in] Length Number of bytes to send via the currently selected endpoint. + * + * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum. + */ + uint8_t Endpoint_Read_Control_EStream_BE(void* Buffer, uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); + /* Private Interface - For use in library only: */ #if !defined(__DOXYGEN__) /* Macros: */ diff --git a/LUFA/Drivers/USB/LowLevel/Pipe.c b/LUFA/Drivers/USB/LowLevel/Pipe.c index ab092796cc..18fbc19b51 100644 --- a/LUFA/Drivers/USB/LowLevel/Pipe.c +++ b/LUFA/Drivers/USB/LowLevel/Pipe.c @@ -106,162 +106,6 @@ uint8_t Pipe_WaitUntilReady(void) } } -uint8_t Pipe_Write_Stream_LE(const void* Data, uint16_t Length -#if !defined(NO_STREAM_CALLBACKS) - , StreamCallbackPtr_t Callback -#endif - ) -{ - uint8_t* DataStream = (uint8_t*)Data; - uint8_t ErrorCode; - - Pipe_SetToken(PIPE_TOKEN_OUT); - - if ((ErrorCode = Pipe_WaitUntilReady())) - return ErrorCode; - - #if defined(FAST_STREAM_TRANSFERS) - uint8_t BytesRemToAlignment = (Pipe_BytesInPipe() & 0x07); - - if (Length >= 8) - { - Length -= BytesRemToAlignment; - - switch (BytesRemToAlignment) - { - default: - do - { - if (!(Pipe_IsReadWriteAllowed())) - { - Pipe_ClearOUT(); - - #if !defined(NO_STREAM_CALLBACKS) - if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort)) - return PIPE_RWSTREAM_CallbackAborted; - #endif - - if ((ErrorCode = Pipe_WaitUntilReady())) - return ErrorCode; - } - - Length -= 8; - - Pipe_Write_Byte(*(DataStream++)); - case 7: Pipe_Write_Byte(*(DataStream++)); - case 6: Pipe_Write_Byte(*(DataStream++)); - case 5: Pipe_Write_Byte(*(DataStream++)); - case 4: Pipe_Write_Byte(*(DataStream++)); - case 3: Pipe_Write_Byte(*(DataStream++)); - case 2: Pipe_Write_Byte(*(DataStream++)); - case 1: Pipe_Write_Byte(*(DataStream++)); - } while (Length >= 8); - } - } - #endif - - while (Length) - { - if (!(Pipe_IsReadWriteAllowed())) - { - Pipe_ClearOUT(); - - #if !defined(NO_STREAM_CALLBACKS) - if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort)) - return PIPE_RWSTREAM_CallbackAborted; - #endif - - if ((ErrorCode = Pipe_WaitUntilReady())) - return ErrorCode; - } - else - { - Pipe_Write_Byte(*(DataStream++)); - Length--; - } - } - - return PIPE_RWSTREAM_NoError; -} - -uint8_t Pipe_Write_Stream_BE(const void* Data, uint16_t Length -#if !defined(NO_STREAM_CALLBACKS) - , StreamCallbackPtr_t Callback -#endif - ) -{ - uint8_t* DataStream = (uint8_t*)(Data + Length - 1); - uint8_t ErrorCode; - - Pipe_SetToken(PIPE_TOKEN_OUT); - - if ((ErrorCode = Pipe_WaitUntilReady())) - return ErrorCode; - - #if defined(FAST_STREAM_TRANSFERS) - uint8_t BytesRemToAlignment = (Pipe_BytesInPipe() & 0x07); - - if (Length >= 8) - { - Length -= BytesRemToAlignment; - - switch (BytesRemToAlignment) - { - default: - do - { - if (!(Pipe_IsReadWriteAllowed())) - { - Pipe_ClearOUT(); - - #if !defined(NO_STREAM_CALLBACKS) - if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort)) - return PIPE_RWSTREAM_CallbackAborted; - #endif - - if ((ErrorCode = Pipe_WaitUntilReady())) - return ErrorCode; - } - - Length -= 8; - - Pipe_Write_Byte(*(DataStream--)); - case 7: Pipe_Write_Byte(*(DataStream--)); - case 6: Pipe_Write_Byte(*(DataStream--)); - case 5: Pipe_Write_Byte(*(DataStream--)); - case 4: Pipe_Write_Byte(*(DataStream--)); - case 3: Pipe_Write_Byte(*(DataStream--)); - case 2: Pipe_Write_Byte(*(DataStream--)); - case 1: Pipe_Write_Byte(*(DataStream--)); - } while (Length >= 8); - } - } - #endif - - while (Length) - { - if (!(Pipe_IsReadWriteAllowed())) - { - Pipe_ClearOUT(); - - #if !defined(NO_STREAM_CALLBACKS) - if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort)) - return PIPE_RWSTREAM_CallbackAborted; - #endif - - if ((ErrorCode = Pipe_WaitUntilReady())) - return ErrorCode; - } - else - { - Pipe_Write_Byte(*(DataStream--)); - Length--; - } - } - - return PIPE_RWSTREAM_NoError; -} - uint8_t Pipe_Discard_Stream(uint16_t Length #if !defined(NO_STREAM_CALLBACKS) , StreamCallbackPtr_t Callback @@ -339,160 +183,64 @@ uint8_t Pipe_Discard_Stream(uint16_t Length return PIPE_RWSTREAM_NoError; } -uint8_t Pipe_Read_Stream_LE(void* Buffer, uint16_t Length -#if !defined(NO_STREAM_CALLBACKS) - , StreamCallbackPtr_t Callback -#endif - ) -{ - uint8_t* DataStream = (uint8_t*)Buffer; - uint8_t ErrorCode; - - Pipe_SetToken(PIPE_TOKEN_IN); - - if ((ErrorCode = Pipe_WaitUntilReady())) - return ErrorCode; - - #if defined(FAST_STREAM_TRANSFERS) - uint8_t BytesRemToAlignment = (Pipe_BytesInPipe() & 0x07); - - if (Length >= 8) - { - Length -= BytesRemToAlignment; - - switch (BytesRemToAlignment) - { - default: - do - { - if (!(Pipe_IsReadWriteAllowed())) - { - Pipe_ClearIN(); - - #if !defined(NO_STREAM_CALLBACKS) - if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort)) - return PIPE_RWSTREAM_CallbackAborted; - #endif - - if ((ErrorCode = Pipe_WaitUntilReady())) - return ErrorCode; - } - - Length -= 8; - - *(DataStream++) = Pipe_Read_Byte(); - case 7: *(DataStream++) = Pipe_Read_Byte(); - case 6: *(DataStream++) = Pipe_Read_Byte(); - case 5: *(DataStream++) = Pipe_Read_Byte(); - case 4: *(DataStream++) = Pipe_Read_Byte(); - case 3: *(DataStream++) = Pipe_Read_Byte(); - case 2: *(DataStream++) = Pipe_Read_Byte(); - case 1: *(DataStream++) = Pipe_Read_Byte(); - } while (Length >= 8); - } - } - #endif - - while (Length) - { - if (!(Pipe_IsReadWriteAllowed())) - { - Pipe_ClearIN(); - - #if !defined(NO_STREAM_CALLBACKS) - if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort)) - return PIPE_RWSTREAM_CallbackAborted; - #endif - - if ((ErrorCode = Pipe_WaitUntilReady())) - return ErrorCode; - } - else - { - *(DataStream++) = Pipe_Read_Byte(); - Length--; - } - } - - return PIPE_RWSTREAM_NoError; -} - -uint8_t Pipe_Read_Stream_BE(void* Buffer, uint16_t Length -#if !defined(NO_STREAM_CALLBACKS) - , StreamCallbackPtr_t Callback -#endif - ) -{ - uint8_t* DataStream = (uint8_t*)(Buffer + Length - 1); - uint8_t ErrorCode; - - Pipe_SetToken(PIPE_TOKEN_IN); - - if ((ErrorCode = Pipe_WaitUntilReady())) - return ErrorCode; - - #if defined(FAST_STREAM_TRANSFERS) - uint8_t BytesRemToAlignment = (Pipe_BytesInPipe() & 0x07); - - if (Length >= 8) - { - Length -= BytesRemToAlignment; - - switch (BytesRemToAlignment) - { - default: - do - { - if (!(Pipe_IsReadWriteAllowed())) - { - Pipe_ClearIN(); - - #if !defined(NO_STREAM_CALLBACKS) - if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort)) - return PIPE_RWSTREAM_CallbackAborted; - #endif - - if ((ErrorCode = Pipe_WaitUntilReady())) - return ErrorCode; - } - - Length -= 8; - - *(DataStream--) = Pipe_Read_Byte(); - case 7: *(DataStream--) = Pipe_Read_Byte(); - case 6: *(DataStream--) = Pipe_Read_Byte(); - case 5: *(DataStream--) = Pipe_Read_Byte(); - case 4: *(DataStream--) = Pipe_Read_Byte(); - case 3: *(DataStream--) = Pipe_Read_Byte(); - case 2: *(DataStream--) = Pipe_Read_Byte(); - case 1: *(DataStream--) = Pipe_Read_Byte(); - } while (Length >= 8); - } - } - #endif - - while (Length) - { - if (!(Pipe_IsReadWriteAllowed())) - { - Pipe_ClearIN(); - - #if !defined(NO_STREAM_CALLBACKS) - if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort)) - return PIPE_RWSTREAM_CallbackAborted; - #endif - - if ((ErrorCode = Pipe_WaitUntilReady())) - return ErrorCode; - } - else - { - *(DataStream--) = Pipe_Read_Byte(); - Length--; - } - } - - return PIPE_RWSTREAM_NoError; -} +#define TEMPLATE_FUNC_NAME Pipe_Write_Stream_LE +#define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT() +#define TEMPLATE_BUFFER_OFFSET(Length) 0 +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_Byte(*(BufferPtr++)) +#include "Template/Template_Pipe_RW.c" + +#define TEMPLATE_FUNC_NAME Pipe_Write_PStream_LE +#define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT() +#define TEMPLATE_BUFFER_OFFSET(Length) 0 +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_Byte(pgm_read_byte(BufferPtr++)) +#include "Template/Template_Pipe_RW.c" + +#define TEMPLATE_FUNC_NAME Pipe_Write_EStream_LE +#define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT() +#define TEMPLATE_BUFFER_OFFSET(Length) 0 +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_Byte(eeprom_read_byte(BufferPtr++)) +#include "Template/Template_Pipe_RW.c" + +#define TEMPLATE_FUNC_NAME Pipe_Write_Stream_BE +#define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT() +#define TEMPLATE_BUFFER_OFFSET(Length) Length - 1 +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_Byte(*(BufferPtr--)) +#include "Template/Template_Pipe_RW.c" + +#define TEMPLATE_FUNC_NAME Pipe_Write_PStream_BE +#define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT() +#define TEMPLATE_BUFFER_OFFSET(Length) Length - 1 +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_Byte(pgm_read_byte(BufferPtr--)) +#include "Template/Template_Pipe_RW.c" + +#define TEMPLATE_FUNC_NAME Pipe_Write_EStream_BE +#define TEMPLATE_CLEAR_PIPE() Pipe_ClearOUT() +#define TEMPLATE_BUFFER_OFFSET(Length) Length - 1 +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) Pipe_Write_Byte(eeprom_read_byte(BufferPtr--)) +#include "Template/Template_Pipe_RW.c" + +#define TEMPLATE_FUNC_NAME Pipe_Read_Stream_LE +#define TEMPLATE_CLEAR_PIPE() Pipe_ClearIN() +#define TEMPLATE_BUFFER_OFFSET(Length) 0 +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *(BufferPtr++) = Pipe_Read_Byte() +#include "Template/Template_Pipe_RW.c" + +#define TEMPLATE_FUNC_NAME Pipe_Read_EStream_LE +#define TEMPLATE_CLEAR_PIPE() Pipe_ClearIN() +#define TEMPLATE_BUFFER_OFFSET(Length) 0 +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_write_byte(BufferPtr++, Pipe_Read_Byte()) +#include "Template/Template_Pipe_RW.c" + +#define TEMPLATE_FUNC_NAME Pipe_Read_Stream_BE +#define TEMPLATE_CLEAR_PIPE() Pipe_ClearIN() +#define TEMPLATE_BUFFER_OFFSET(Length) Length - 1 +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) *(BufferPtr--) = Pipe_Read_Byte() +#include "Template/Template_Pipe_RW.c" + +#define TEMPLATE_FUNC_NAME Pipe_Read_EStream_BE +#define TEMPLATE_CLEAR_PIPE() Pipe_ClearIN() +#define TEMPLATE_BUFFER_OFFSET(Length) Length - 1 +#define TEMPLATE_TRANSFER_BYTE(BufferPtr) eeprom_write_byte(BufferPtr--, Pipe_Read_Byte()) +#include "Template/Template_Pipe_RW.c" #endif diff --git a/LUFA/Drivers/USB/LowLevel/Pipe.h b/LUFA/Drivers/USB/LowLevel/Pipe.h index cf61eeae02..363b9fd93d 100644 --- a/LUFA/Drivers/USB/LowLevel/Pipe.h +++ b/LUFA/Drivers/USB/LowLevel/Pipe.h @@ -43,6 +43,20 @@ * Functions, macros, variables, enums and types related to data reading and writing from and to pipes. */ +/** \ingroup Group_PipeRW + * @defgroup Group_PipePrimitiveRW Read/Write of Primitive Data Types + * + * Functions, macros, variables, enums and types related to data reading and writing of primitive data types + * from and to pipes. + */ + +/** \ingroup Group_PipeRW + * @defgroup Group_PipeStreamRW Read/Write of Multi-Byte Streams + * + * Functions, macros, variables, enums and types related to data reading and writing of data streams from + * and to pipes. + */ + /** @defgroup Group_PipePacketManagement Pipe Packet Management * * Functions, macros, variables, enums and types related to packet management of pipes. @@ -61,6 +75,8 @@ /* Includes: */ #include + #include + #include #include #include "../../../Common/Common.h" @@ -502,7 +518,7 @@ /* Inline Functions: */ /** Reads one byte from the currently selected pipe's bank, for OUT direction pipes. * - * \ingroup Group_PipeRW + * \ingroup Group_PipePrimitiveRW * * \return Next byte in the currently selected pipe's FIFO buffer */ @@ -514,7 +530,7 @@ /** Writes one byte from the currently selected pipe's bank, for IN direction pipes. * - * \ingroup Group_PipeRW + * \ingroup Group_PipePrimitiveRW * * \param[in] Byte Next byte to write into the the currently selected pipe's FIFO buffer */ @@ -526,7 +542,7 @@ /** Discards one byte from the currently selected pipe's bank, for OUT direction pipes. * - * \ingroup Group_PipeRW + * \ingroup Group_PipePrimitiveRW */ static inline void Pipe_Discard_Byte(void) ATTR_ALWAYS_INLINE; static inline void Pipe_Discard_Byte(void) @@ -539,7 +555,7 @@ /** Reads two bytes from the currently selected pipe's bank in little endian format, for OUT * direction pipes. * - * \ingroup Group_PipeRW + * \ingroup Group_PipePrimitiveRW * * \return Next word in the currently selected pipe's FIFO buffer */ @@ -557,7 +573,7 @@ /** Reads two bytes from the currently selected pipe's bank in big endian format, for OUT * direction pipes. * - * \ingroup Group_PipeRW + * \ingroup Group_PipePrimitiveRW * * \return Next word in the currently selected pipe's FIFO buffer */ @@ -575,7 +591,7 @@ /** Writes two bytes to the currently selected pipe's bank in little endian format, for IN * direction pipes. * - * \ingroup Group_PipeRW + * \ingroup Group_PipePrimitiveRW * * \param[in] Word Next word to write to the currently selected pipe's FIFO buffer */ @@ -589,7 +605,7 @@ /** Writes two bytes to the currently selected pipe's bank in big endian format, for IN * direction pipes. * - * \ingroup Group_PipeRW + * \ingroup Group_PipePrimitiveRW * * \param[in] Word Next word to write to the currently selected pipe's FIFO buffer */ @@ -602,7 +618,7 @@ /** Discards two bytes from the currently selected pipe's bank, for OUT direction pipes. * - * \ingroup Group_PipeRW + * \ingroup Group_PipePrimitiveRW */ static inline void Pipe_Discard_Word(void) ATTR_ALWAYS_INLINE; static inline void Pipe_Discard_Word(void) @@ -616,7 +632,7 @@ /** Reads four bytes from the currently selected pipe's bank in little endian format, for OUT * direction pipes. * - * \ingroup Group_PipeRW + * \ingroup Group_PipePrimitiveRW * * \return Next double word in the currently selected pipe's FIFO buffer */ @@ -640,7 +656,7 @@ /** Reads four bytes from the currently selected pipe's bank in big endian format, for OUT * direction pipes. * - * \ingroup Group_PipeRW + * \ingroup Group_PipePrimitiveRW * * \return Next double word in the currently selected pipe's FIFO buffer */ @@ -664,7 +680,7 @@ /** Writes four bytes to the currently selected pipe's bank in little endian format, for IN * direction pipes. * - * \ingroup Group_PipeRW + * \ingroup Group_PipePrimitiveRW * * \param[in] DWord Next double word to write to the currently selected pipe's FIFO buffer */ @@ -678,7 +694,7 @@ /** Writes four bytes to the currently selected pipe's bank in big endian format, for IN * direction pipes. * - * \ingroup Group_PipeRW + * \ingroup Group_PipePrimitiveRW * * \param[in] DWord Next double word to write to the currently selected pipe's FIFO buffer */ @@ -691,7 +707,7 @@ /** Discards four bytes from the currently selected pipe's bank, for OUT direction pipes. * - * \ingroup Group_PipeRW + * \ingroup Group_PipePrimitiveRW */ static inline void Pipe_Discard_DWord(void) ATTR_ALWAYS_INLINE; static inline void Pipe_Discard_DWord(void) @@ -716,6 +732,12 @@ extern uint8_t USB_ControlPipeSize; /* Function Prototypes: */ + #if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__) + #define _CALLBACK_PARAM , StreamCallbackPtr_t Callback + #else + #define _CALLBACK_PARAM + #endif + /** Configures the specified pipe number with the given pipe type, token, target endpoint number in the * attached device, bank size and banking mode. Pipes should be allocated in ascending order by their * address in the device (i.e. pipe 1 should be configured before pipe 2 and so on) to prevent fragmentation @@ -756,6 +778,28 @@ */ uint8_t Pipe_WaitUntilReady(void); + /** Reads and discards the given number of bytes from the pipe, discarding fully read packets from the host + * as needed. The last packet is not automatically discarded once the remaining bytes has been read; the + * user is responsible for manually discarding the last packet from the device via the \ref Pipe_ClearIN() macro. + * Between each USB packet, the given stream callback function is executed repeatedly until the next packet is ready, + * allowing for early aborts of stream transfers. + * + * The callback routine should be created according to the information in \ref Group_StreamCallbacks. + * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are + * disabled and this function has the Callback parameter omitted. + * + * The pipe token is set automatically, thus this can be used on bi-directional pipes directly without + * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). + * + * \ingroup Group_PipeStreamRW + * + * \param[in] Length Number of bytes to send via the currently selected pipe. + * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback + * + * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Pipe_Discard_Stream(uint16_t Length _CALLBACK_PARAM); + /** Writes the given number of bytes to the pipe from the given buffer in little endian, * sending full packets to the device as needed. The last packet filled is not automatically sent; * the user is responsible for manually sending the last written packet to the host via the @@ -769,7 +813,7 @@ * The pipe token is set automatically, thus this can be used on bi-directional pipes directly without * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). * - * \ingroup Group_PipeRW + * \ingroup Group_PipeStreamRW * * \param[in] Buffer Pointer to the source data buffer to read from. * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer. @@ -777,12 +821,34 @@ * * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. */ - uint8_t Pipe_Write_Stream_LE(const void* Buffer, uint16_t Length - #if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__) - , StreamCallbackPtr_t Callback - #endif - ) ATTR_NON_NULL_PTR_ARG(1); + uint8_t Pipe_Write_Stream_LE(const void* Buffer, uint16_t Length _CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1); + /** EEPROM buffer source version of \ref Pipe_Write_Stream_LE. + * + * \ingroup Group_PipeStreamRW + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer. + * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback + * + * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Pipe_Write_EStream_LE(const void* Buffer, uint16_t Length _CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1); + + /** FLASH buffer source version of \ref Pipe_Write_Stream_LE. + * + * \note The FLASH data must be located in the first 64KB of FLASH for this function to work correctly. + * + * \ingroup Group_PipeStreamRW + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer. + * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback + * + * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Pipe_Write_PStream_LE(const void* Buffer, uint16_t Length _CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1); + /** Writes the given number of bytes to the pipe from the given buffer in big endian, * sending full packets to the device as needed. The last packet filled is not automatically sent; * the user is responsible for manually sending the last written packet to the host via the @@ -796,7 +862,7 @@ * The pipe token is set automatically, thus this can be used on bi-directional pipes directly without * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). * - * \ingroup Group_PipeRW + * \ingroup Group_PipeStreamRW * * \param[in] Buffer Pointer to the source data buffer to read from. * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer. @@ -804,37 +870,33 @@ * * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. */ - uint8_t Pipe_Write_Stream_BE(const void* Buffer, uint16_t Length - #if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__) - , StreamCallbackPtr_t Callback - #endif - ) ATTR_NON_NULL_PTR_ARG(1); + uint8_t Pipe_Write_Stream_BE(const void* Buffer, uint16_t Length _CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1); - /** Reads and discards the given number of bytes from the pipe, discarding fully read packets from the host - * as needed. The last packet is not automatically discarded once the remaining bytes has been read; the - * user is responsible for manually discarding the last packet from the device via the \ref Pipe_ClearIN() macro. - * Between each USB packet, the given stream callback function is executed repeatedly until the next packet is ready, - * allowing for early aborts of stream transfers. + /** EEPROM buffer source version of \ref Pipe_Write_Stream_BE. * - * The callback routine should be created according to the information in \ref Group_StreamCallbacks. - * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are - * disabled and this function has the Callback parameter omitted. + * \ingroup Group_PipeStreamRW * - * The pipe token is set automatically, thus this can be used on bi-directional pipes directly without - * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer. + * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback * - * \ingroup Group_PipeRW + * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Pipe_Write_EStream_BE(const void* Buffer, uint16_t Length _CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1); + + /** FLASH buffer source version of \ref Pipe_Write_Stream_BE. * - * \param[in] Length Number of bytes to send via the currently selected pipe. + * \note The FLASH data must be located in the first 64KB of FLASH for this function to work correctly. + * + * \ingroup Group_PipeStreamRW + * + * \param[in] Buffer Pointer to the source data buffer to read from. + * \param[in] Length Number of bytes to read for the currently selected pipe into the buffer. * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback * * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. */ - uint8_t Pipe_Discard_Stream(uint16_t Length - #if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__) - , StreamCallbackPtr_t Callback - #endif - ); + uint8_t Pipe_Write_PStream_BE(const void* Buffer, uint16_t Length _CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1); /** Reads the given number of bytes from the pipe into the given buffer in little endian, * sending full packets to the device as needed. The last packet filled is not automatically sent; @@ -849,7 +911,7 @@ * The pipe token is set automatically, thus this can be used on bi-directional pipes directly without * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). * - * \ingroup Group_PipeRW + * \ingroup Group_PipeStreamRW * * \param[out] Buffer Pointer to the source data buffer to write to. * \param[in] Length Number of bytes to read for the currently selected pipe to read from. @@ -857,11 +919,19 @@ * * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. */ - uint8_t Pipe_Read_Stream_LE(void* Buffer, uint16_t Length - #if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__) - , StreamCallbackPtr_t Callback - #endif - ) ATTR_NON_NULL_PTR_ARG(1); + uint8_t Pipe_Read_Stream_LE(void* Buffer, uint16_t Length _CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1); + + /** EEPROM buffer source version of \ref Pipe_Read_Stream_LE. + * + * \ingroup Group_PipeStreamRW + * + * \param[out] Buffer Pointer to the source data buffer to write to. + * \param[in] Length Number of bytes to read for the currently selected pipe to read from. + * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback + * + * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Pipe_Read_EStream_LE(void* Buffer, uint16_t Length _CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1); /** Reads the given number of bytes from the pipe into the given buffer in big endian, * sending full packets to the device as needed. The last packet filled is not automatically sent; @@ -876,7 +946,7 @@ * The pipe token is set automatically, thus this can be used on bi-directional pipes directly without * having to explicitly change the data direction with a call to \ref Pipe_SetPipeToken(). * - * \ingroup Group_PipeRW + * \ingroup Group_PipeStreamRW * * \param[out] Buffer Pointer to the source data buffer to write to. * \param[in] Length Number of bytes to read for the currently selected pipe to read from. @@ -884,12 +954,20 @@ * * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. */ - uint8_t Pipe_Read_Stream_BE(void* Buffer, uint16_t Length - #if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__) - , StreamCallbackPtr_t Callback - #endif - ) ATTR_NON_NULL_PTR_ARG(1); + uint8_t Pipe_Read_Stream_BE(void* Buffer, uint16_t Length _CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1); + /** EEPROM buffer source version of \ref Pipe_Read_Stream_BE. + * + * \ingroup Group_PipeStreamRW + * + * \param[out] Buffer Pointer to the source data buffer to write to. + * \param[in] Length Number of bytes to read for the currently selected pipe to read from. + * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback + * + * \return A value from the \ref Pipe_Stream_RW_ErrorCodes_t enum. + */ + uint8_t Pipe_Read_EStream_BE(void* Buffer, uint16_t Length _CALLBACK_PARAM) ATTR_NON_NULL_PTR_ARG(1); + /* Private Interface - For use in library only: */ #if !defined(__DOXYGEN__) /* Macros: */ diff --git a/LUFA/Drivers/USB/LowLevel/Template/Template_Endpoint_Control_R.c b/LUFA/Drivers/USB/LowLevel/Template/Template_Endpoint_Control_R.c new file mode 100644 index 0000000000..d66edafd6c --- /dev/null +++ b/LUFA/Drivers/USB/LowLevel/Template/Template_Endpoint_Control_R.c @@ -0,0 +1,27 @@ +uint8_t TEMPLATE_FUNC_NAME (void* Buffer, uint16_t Length) +{ + uint8_t* DataStream = (uint8_t*)(Buffer + TEMPLATE_BUFFER_OFFSET(Length)); + + while (Length) + { + if (Endpoint_IsOUTReceived()) + { + while (Length && Endpoint_BytesInEndpoint()) + { + TEMPLATE_TRANSFER_BYTE(DataStream); + Length--; + } + + Endpoint_ClearOUT(); + } + } + + while (!(Endpoint_IsINReady())); + + return ENDPOINT_RWCSTREAM_NoError; +} + + +#undef TEMPLATE_BUFFER_OFFSET +#undef TEMPLATE_FUNC_NAME +#undef TEMPLATE_TRANSFER_BYTE \ No newline at end of file diff --git a/LUFA/Drivers/USB/LowLevel/Template/Template_Endpoint_Control_W.c b/LUFA/Drivers/USB/LowLevel/Template/Template_Endpoint_Control_W.c new file mode 100644 index 0000000000..2796c64255 --- /dev/null +++ b/LUFA/Drivers/USB/LowLevel/Template/Template_Endpoint_Control_W.c @@ -0,0 +1,39 @@ +uint8_t TEMPLATE_FUNC_NAME (void* Buffer, uint16_t Length) +{ + uint8_t* DataStream = (uint8_t*)(Buffer + TEMPLATE_BUFFER_OFFSET(Length)); + bool LastPacketFull = false; + + if (Length > USB_ControlRequest.wLength) + Length = USB_ControlRequest.wLength; + + while (Length && !(Endpoint_IsOUTReceived())) + { + while (!(Endpoint_IsINReady())); + + while (Length && (Endpoint_BytesInEndpoint() < USB_ControlEndpointSize)) + { + TEMPLATE_TRANSFER_BYTE(DataStream); + Length--; + } + + LastPacketFull = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize); + Endpoint_ClearIN(); + } + + if (Endpoint_IsOUTReceived()) + return ENDPOINT_RWCSTREAM_HostAborted; + + if (LastPacketFull) + { + while (!(Endpoint_IsINReady())); + Endpoint_ClearIN(); + } + + while (!(Endpoint_IsOUTReceived())); + + return ENDPOINT_RWCSTREAM_NoError; +} + +#undef TEMPLATE_BUFFER_OFFSET +#undef TEMPLATE_FUNC_NAME +#undef TEMPLATE_TRANSFER_BYTE \ No newline at end of file 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 index 0000000000..731c5f8ffb --- /dev/null +++ b/LUFA/Drivers/USB/LowLevel/Template/Template_Endpoint_RW.c @@ -0,0 +1,76 @@ +uint8_t TEMPLATE_FUNC_NAME (void* Buffer, uint16_t Length _CALLBACK_PARAM) +{ + uint8_t* DataStream = (uint8_t*)(Buffer + TEMPLATE_BUFFER_OFFSET(Length)); + uint8_t ErrorCode; + + if ((ErrorCode = Endpoint_WaitUntilReady())) + return ErrorCode; + + #if defined(FAST_STREAM_TRANSFERS) + uint8_t BytesRemToAlignment = (Endpoint_BytesInEndpoint() & 0x07); + + if (Length >= 8) + { + Length -= BytesRemToAlignment; + + switch (BytesRemToAlignment) + { + default: + do + { + if (!(Endpoint_IsReadWriteAllowed())) + { + TEMPLATE_CLEAR_ENDPOINT(); + + #if !defined(NO_STREAM_CALLBACKS) + if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort)) + return ENDPOINT_RWSTREAM_CallbackAborted; + #endif + + if ((ErrorCode = Endpoint_WaitUntilReady())) + return ErrorCode; + } + + Length -= 8; + + TEMPLATE_TRANSFER_BYTE(DataStream); + case 7: TEMPLATE_TRANSFER_BYTE(DataStream); + case 6: TEMPLATE_TRANSFER_BYTE(DataStream); + case 5: TEMPLATE_TRANSFER_BYTE(DataStream); + case 4: TEMPLATE_TRANSFER_BYTE(DataStream); + case 3: TEMPLATE_TRANSFER_BYTE(DataStream); + case 2: TEMPLATE_TRANSFER_BYTE(DataStream); + case 1: TEMPLATE_TRANSFER_BYTE(DataStream); + } while (Length >= 8); + } + } + #endif + + while (Length) + { + if (!(Endpoint_IsReadWriteAllowed())) + { + TEMPLATE_CLEAR_ENDPOINT(); + + #if !defined(NO_STREAM_CALLBACKS) + if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort)) + return ENDPOINT_RWSTREAM_CallbackAborted; + #endif + + if ((ErrorCode = Endpoint_WaitUntilReady())) + return ErrorCode; + } + else + { + TEMPLATE_TRANSFER_BYTE(DataStream); + Length--; + } + } + + return ENDPOINT_RWSTREAM_NoError; +} + +#undef TEMPLATE_FUNC_NAME +#undef TEMPLATE_TRANSFER_BYTE +#undef TEMPLATE_CLEAR_ENDPOINT +#undef TEMPLATE_BUFFER_OFFSET \ No newline at end of file diff --git a/LUFA/Drivers/USB/LowLevel/Template/Template_Pipe_RW.c b/LUFA/Drivers/USB/LowLevel/Template/Template_Pipe_RW.c new file mode 100644 index 0000000000..f36f82da58 --- /dev/null +++ b/LUFA/Drivers/USB/LowLevel/Template/Template_Pipe_RW.c @@ -0,0 +1,78 @@ +uint8_t TEMPLATE_FUNC_NAME (void* Buffer, uint16_t Length _CALLBACK_PARAM) +{ + uint8_t* DataStream = (uint8_t*)(Buffer + TEMPLATE_BUFFER_OFFSET(Length)); + uint8_t ErrorCode; + + Pipe_SetToken(PIPE_TOKEN_IN); + + if ((ErrorCode = Pipe_WaitUntilReady())) + return ErrorCode; + + #if defined(FAST_STREAM_TRANSFERS) + uint8_t BytesRemToAlignment = (Pipe_BytesInPipe() & 0x07); + + if (Length >= 8) + { + Length -= BytesRemToAlignment; + + switch (BytesRemToAlignment) + { + default: + do + { + if (!(Pipe_IsReadWriteAllowed())) + { + TEMPLATE_CLEAR_PIPE(); + + #if !defined(NO_STREAM_CALLBACKS) + if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort)) + return PIPE_RWSTREAM_CallbackAborted; + #endif + + if ((ErrorCode = Pipe_WaitUntilReady())) + return ErrorCode; + } + + Length -= 8; + + TEMPLATE_TRANSFER_BYTE(DataStream); + case 7: TEMPLATE_TRANSFER_BYTE(DataStream); + case 6: TEMPLATE_TRANSFER_BYTE(DataStream); + case 5: TEMPLATE_TRANSFER_BYTE(DataStream); + case 4: TEMPLATE_TRANSFER_BYTE(DataStream); + case 3: TEMPLATE_TRANSFER_BYTE(DataStream); + case 2: TEMPLATE_TRANSFER_BYTE(DataStream); + case 1: TEMPLATE_TRANSFER_BYTE(DataStream); + } while (Length >= 8); + } + } + #endif + + while (Length) + { + if (!(Pipe_IsReadWriteAllowed())) + { + TEMPLATE_CLEAR_PIPE(); + + #if !defined(NO_STREAM_CALLBACKS) + if ((Callback != NULL) && (Callback() == STREAMCALLBACK_Abort)) + return PIPE_RWSTREAM_CallbackAborted; + #endif + + if ((ErrorCode = Pipe_WaitUntilReady())) + return ErrorCode; + } + else + { + TEMPLATE_TRANSFER_BYTE(DataStream); + Length--; + } + } + + return PIPE_RWSTREAM_NoError; +} + +#undef TEMPLATE_FUNC_NAME +#undef TEMPLATE_TRANSFER_BYTE +#undef TEMPLATE_CLEAR_PIPE +#undef TEMPLATE_BUFFER_OFFSET \ No newline at end of file -- cgit v1.2.3