X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/9cec85bfd92a77a97e7d12625897de2682dfacd7..e0985b995009d71b80d214a66944e76f4e41aadb:/LUFA/Drivers/USB/LowLevel/Endpoint.h diff --git a/LUFA/Drivers/USB/LowLevel/Endpoint.h b/LUFA/Drivers/USB/LowLevel/Endpoint.h index 172ab33d7..aa5005a82 100644 --- a/LUFA/Drivers/USB/LowLevel/Endpoint.h +++ b/LUFA/Drivers/USB/LowLevel/Endpoint.h @@ -127,14 +127,18 @@ */ #define ENDPOINT_DOUBLEBANK_SUPPORTED(n) _ENDPOINT_GET_DOUBLEBANK(n) - #if defined(USB_FULL_CONTROLLER) || defined(USB_MODIFIED_FULL_CONTROLLER) || defined(__DOXYGEN__) - /** Total number of endpoints (including the default control endpoint at address 0) which may - * be used in the device. Different USB AVR models support different amounts of endpoints, - * this value reflects the maximum number of endpoints for the currently selected AVR model. - */ - #define ENDPOINT_TOTAL_ENDPOINTS 7 + #if !defined(CONTROL_ONLY_DEVICE) + #if defined(USB_FULL_CONTROLLER) || defined(USB_MODIFIED_FULL_CONTROLLER) || defined(__DOXYGEN__) + /** Total number of endpoints (including the default control endpoint at address 0) which may + * be used in the device. Different USB AVR models support different amounts of endpoints, + * this value reflects the maximum number of endpoints for the currently selected AVR model. + */ + #define ENDPOINT_TOTAL_ENDPOINTS 7 + #else + #define ENDPOINT_TOTAL_ENDPOINTS 5 + #endif #else - #define ENDPOINT_TOTAL_ENDPOINTS 5 + #define ENDPOINT_TOTAL_ENDPOINTS 1 #endif /** Interrupt definition for the endpoint SETUP interrupt (for CONTROL type endpoints). Should be @@ -366,9 +370,17 @@ #define Endpoint_BytesInEndpoint() UEBCLX #endif - #define Endpoint_GetCurrentEndpoint() (UENUM & ENDPOINT_EPNUM_MASK) + #if !defined(CONTROL_ONLY_DEVICE) + #define Endpoint_GetCurrentEndpoint() (UENUM & ENDPOINT_EPNUM_MASK) + #else + #define Endpoint_GetCurrentEndpoint() ENDPOINT_CONTROLEP + #endif - #define Endpoint_SelectEndpoint(epnum) MACROS{ UENUM = epnum; }MACROE + #if !defined(CONTROL_ONLY_DEVICE) + #define Endpoint_SelectEndpoint(epnum) MACROS{ UENUM = epnum; }MACROE + #else + #define Endpoint_SelectEndpoint(epnum) (void)epnum + #endif #define Endpoint_ResetFIFO(epnum) MACROS{ UERST = (1 << epnum); UERST = 0; }MACROE @@ -378,8 +390,10 @@ #define Endpoint_IsEnabled() ((UECONX & (1 << EPEN)) ? true : false) - #define Endpoint_IsReadWriteAllowed() ((UEINTX & (1 << RWAL)) ? true : false) - + #if !defined(CONTROL_ONLY_DEVICE) + #define Endpoint_IsReadWriteAllowed() ((UEINTX & (1 << RWAL)) ? true : false) + #endif + #define Endpoint_IsConfigured() ((UESTA0X & (1 << CFGOK)) ? true : false) #define Endpoint_GetEndpointInterrupts() UEINT @@ -396,11 +410,19 @@ #define Endpoint_ClearSETUP() MACROS{ UEINTX &= ~(1 << RXSTPI); }MACROE - #define Endpoint_ClearIN() MACROS{ uint8_t Temp = UEINTX; UEINTX = (Temp & ~(1 << TXINI)); \ - UEINTX = (Temp & ~(1 << FIFOCON)); }MACROE + #if !defined(CONTROL_ONLY_DEVICE) + #define Endpoint_ClearIN() MACROS{ uint8_t Temp = UEINTX; UEINTX = (Temp & ~(1 << TXINI)); \ + UEINTX = (Temp & ~(1 << FIFOCON)); }MACROE + #else + #define Endpoint_ClearIN() MACROS{ UEINTX &= ~(1 << TXINI); }MACROE + #endif - #define Endpoint_ClearOUT() MACROS{ uint8_t Temp = UEINTX; UEINTX = (Temp & ~(1 << RXOUTI)); \ - UEINTX = (Temp & ~(1 << FIFOCON)); }MACROE + #if !defined(CONTROL_ONLY_DEVICE) + #define Endpoint_ClearOUT() MACROS{ uint8_t Temp = UEINTX; UEINTX = (Temp & ~(1 << RXOUTI)); \ + UEINTX = (Temp & ~(1 << FIFOCON)); }MACROE + #else + #define Endpoint_ClearOUT() MACROS{ UEINTX &= ~(1 << RXOUTI); }MACROE + #endif #define Endpoint_StallTransaction() MACROS{ UECONX |= (1 << STALLRQ); }MACROE @@ -439,20 +461,20 @@ */ enum Endpoint_Stream_RW_ErrorCodes_t { - ENDPOINT_RWSTREAM_ERROR_NoError = 0, /**< Command completed successfully, no error. */ - ENDPOINT_RWSTREAM_ERROR_EndpointStalled = 1, /**< The endpoint was stalled during the stream - * transfer by the host or device. - */ - ENDPOINT_RWSTREAM_ERROR_DeviceDisconnected = 1, /**< Device was disconnected from the host during - * the transfer. - */ - ENDPOINT_RWSTREAM_ERROR_Timeout = 2, /**< The host failed to accept or send the next packet - * within the software timeout period set by the - * \ref USB_STREAM_TIMEOUT_MS macro. - */ - ENDPOINT_RWSTREAM_ERROR_CallbackAborted = 3, /**< Indicates that the stream's callback function - * aborted the transfer early. - */ + ENDPOINT_RWSTREAM_NoError = 0, /**< Command completed successfully, no error. */ + ENDPOINT_RWSTREAM_EndpointStalled = 1, /**< The endpoint was stalled during the stream + * transfer by the host or device. + */ + ENDPOINT_RWSTREAM_DeviceDisconnected = 1, /**< Device was disconnected from the host during + * the transfer. + */ + ENDPOINT_RWSTREAM_Timeout = 2, /**< The host failed to accept or send the next packet + * within the software timeout period set by the + * \ref USB_STREAM_TIMEOUT_MS macro. + */ + ENDPOINT_RWSTREAM_CallbackAborted = 3, /**< Indicates that the stream's callback function + * aborted the transfer early. + */ }; /** Enum for the possible error return codes of the Endpoint_*_Control_Stream_* functions.. @@ -461,8 +483,8 @@ */ enum Endpoint_ControlStream_RW_ErrorCodes_t { - ENDPOINT_RWCSTREAM_ERROR_NoError = 0, /**< Command completed successfully, no error. */ - ENDPOINT_RWCSTREAM_ERROR_HostAborted = 1, /**< The aborted the transfer prematurely. */ + ENDPOINT_RWCSTREAM_NoError = 0, /**< Command completed successfully, no error. */ + ENDPOINT_RWCSTREAM_HostAborted = 1, /**< The aborted the transfer prematurely. */ }; /* Inline Functions: */ @@ -712,11 +734,6 @@ * * The success of this routine can be determined via the \ref Endpoint_IsConfigured() macro. * - * By default, the routine is entirely dynamic, and will accept both constant and variable inputs. - * If dynamic configuration is unused, a small space savings can be made by defining the - * STATIC_ENDPOINT_CONFIGURATION macro via the -D switch to the compiler, to optimize for constant - * input values. - * * \note This routine will select the specified endpoint, and the endpoint will remain selected * once the routine completes regardless of if the endpoint configuration succeeds. * @@ -725,6 +742,8 @@ 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. * @@ -870,6 +889,8 @@ #endif ) ATTR_NON_NULL_PTR_ARG(1); + #endif + /** 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 * in both failure and success states; the user is responsible for manually clearing the setup OUT to @@ -976,38 +997,33 @@ #define ENDPOINT_DETAILS_EP4 64, true #endif - #if defined(STATIC_ENDPOINT_CONFIGURATION) - #define Endpoint_ConfigureEndpoint(Number, Type, Direction, Size, Banks) \ - Endpoint_ConfigureEndpointStatic(Number, \ - ((Type << EPTYPE0) | Direction), \ - ((1 << ALLOC) | Banks | Endpoint_BytesToEPSizeMask(Size))); - #endif - + #define Endpoint_ConfigureEndpoint(Number, Type, Direction, Size, Banks) \ + Endpoint_ConfigureEndpoint_Prv(Number, \ + ((Type << EPTYPE0) | Direction), \ + ((1 << ALLOC) | Banks | \ + (__builtin_constant_p(Size) ? \ + Endpoint_BytesToEPSizeMask(Size) : \ + Endpoint_BytesToEPSizeMaskDynamic(Size)))) + /* Function Prototypes: */ - void Endpoint_ClearEndpoints(void); - bool Endpoint_ConfigureEndpointStatic(const uint8_t Number, const uint8_t UECFG0XData, const uint8_t UECFG1XData); + void Endpoint_ClearEndpoints(void); + uint8_t Endpoint_BytesToEPSizeMaskDynamic(const uint16_t Size); + bool Endpoint_ConfigureEndpoint_Prv(const uint8_t Number, const uint8_t UECFG0XData, const uint8_t UECFG1XData); /* Inline Functions: */ static inline uint8_t Endpoint_BytesToEPSizeMask(const uint16_t Bytes) ATTR_WARN_UNUSED_RESULT ATTR_CONST ATTR_ALWAYS_INLINE; static inline uint8_t Endpoint_BytesToEPSizeMask(const uint16_t Bytes) { - if (Bytes <= 8) - return (0 << EPSIZE0); - else if (Bytes <= 16) - return (1 << EPSIZE0); - else if (Bytes <= 32) - return (2 << EPSIZE0); - #if defined(USB_LIMITED_CONTROLLER) - else - return (3 << EPSIZE0); - #else - else if (Bytes <= 64) - return (3 << EPSIZE0); - else if (Bytes <= 128) - return (4 << EPSIZE0); - else - return (5 << EPSIZE0); - #endif + uint8_t MaskVal = 0; + uint16_t CheckBytes = 8; + + while (CheckBytes < Bytes) + { + MaskVal++; + CheckBytes <<= 1; + } + + return (MaskVal << EPSIZE0); }; #endif