From a504a3a010ec2441dda0209f195492fb36e7c97b Mon Sep 17 00:00:00 2001 From: Dean Camera Date: Fri, 24 Apr 2009 07:28:51 +0000 Subject: Endpoint configuration is now refined to give better output when all configurations have static inputs - removed the now useless STATIC_ENDPOINT_CONFIGURATION compile time token. --- LUFA/Drivers/USB/Class/ConfigDescriptor.c | 2 +- LUFA/Drivers/USB/Class/ConfigDescriptor.h | 4 +-- LUFA/Drivers/USB/LowLevel/Endpoint.c | 19 +++-------- LUFA/Drivers/USB/LowLevel/Endpoint.h | 52 +++++++++++++------------------ 4 files changed, 28 insertions(+), 49 deletions(-) (limited to 'LUFA/Drivers/USB') diff --git a/LUFA/Drivers/USB/Class/ConfigDescriptor.c b/LUFA/Drivers/USB/Class/ConfigDescriptor.c index 367b28ae3..78838305a 100644 --- a/LUFA/Drivers/USB/Class/ConfigDescriptor.c +++ b/LUFA/Drivers/USB/Class/ConfigDescriptor.c @@ -114,7 +114,7 @@ void USB_GetNextDescriptorOfTypeAfter(uint16_t* const BytesRem, USB_GetNextDescriptorOfType(BytesRem, CurrConfigLoc, Type); } -uint8_t USB_GetNextDescriptorComp_P(uint16_t* BytesRem, uint8_t** CurrConfigLoc, ComparatorPtr_t ComparatorRoutine) +uint8_t USB_GetNextDescriptorComp_Prv(uint16_t* BytesRem, uint8_t** CurrConfigLoc, ComparatorPtr_t ComparatorRoutine) { uint8_t ErrorCode; diff --git a/LUFA/Drivers/USB/Class/ConfigDescriptor.h b/LUFA/Drivers/USB/Class/ConfigDescriptor.h index da38492ff..dce7de79e 100644 --- a/LUFA/Drivers/USB/Class/ConfigDescriptor.h +++ b/LUFA/Drivers/USB/Class/ConfigDescriptor.h @@ -162,7 +162,7 @@ */ uint8_t USB_GetNextDescriptorComp(uint16_t* BytesRem, uint8_t** CurrConfigLoc, ComparatorPtr_t ComparatorRoutine); #else - #define USB_GetNextDescriptorComp(DSize, DPos, DSearch) USB_GetNextDescriptorComp_P(DSize, DPos, DCOMP_##DSearch) + #define USB_GetNextDescriptorComp(DSize, DPos, DSearch) USB_GetNextDescriptorComp_Prv(DSize, DPos, DCOMP_##DSearch) #endif /* Enums: */ @@ -270,7 +270,7 @@ typedef uint8_t (* const ComparatorPtr_t)(void* const); /* Function Prototypes: */ - uint8_t USB_GetNextDescriptorComp_P(uint16_t* BytesRem, uint8_t** CurrConfigLoc, ComparatorPtr_t ComparatorRoutine); + uint8_t USB_GetNextDescriptorComp_Prv(uint16_t* BytesRem, uint8_t** CurrConfigLoc, ComparatorPtr_t ComparatorRoutine); #endif /* Disable C linkage for C++ Compilers: */ diff --git a/LUFA/Drivers/USB/LowLevel/Endpoint.c b/LUFA/Drivers/USB/LowLevel/Endpoint.c index da2925ec7..4615baa69 100644 --- a/LUFA/Drivers/USB/LowLevel/Endpoint.c +++ b/LUFA/Drivers/USB/LowLevel/Endpoint.c @@ -39,22 +39,12 @@ uint8_t USB_ControlEndpointSize = ENDPOINT_CONTROLEP_DEFAULT_SIZE; #endif -#if !defined(STATIC_ENDPOINT_CONFIGURATION) -bool Endpoint_ConfigureEndpoint(const uint8_t Number, const uint8_t Type, const uint8_t Direction, - const uint16_t Size, const uint8_t Banks) +uint8_t Endpoint_BytesToEPSizeMaskDynamic(const uint16_t Size) { - Endpoint_SelectEndpoint(Number); - Endpoint_EnableEndpoint(); - - UECFG1X = 0; - - UECFG0X = ((Type << EPTYPE0) | Direction); - UECFG1X = ((1 << ALLOC) | Banks | Endpoint_BytesToEPSizeMask(Size)); - - return Endpoint_IsConfigured(); + return Endpoint_BytesToEPSizeMask(Size); } -#else -bool Endpoint_ConfigureEndpointStatic(const uint8_t Number, const uint8_t UECFG0XData, const uint8_t UECFG1XData) + +bool Endpoint_ConfigureEndpoint_Prv(const uint8_t Number, const uint8_t UECFG0XData, const uint8_t UECFG1XData) { Endpoint_SelectEndpoint(Number); Endpoint_EnableEndpoint(); @@ -66,7 +56,6 @@ bool Endpoint_ConfigureEndpointStatic(const uint8_t Number, const uint8_t UECFG0 return Endpoint_IsConfigured(); } -#endif void Endpoint_ClearEndpoints(void) { diff --git a/LUFA/Drivers/USB/LowLevel/Endpoint.h b/LUFA/Drivers/USB/LowLevel/Endpoint.h index 1e88e0658..4d5aa538e 100644 --- a/LUFA/Drivers/USB/LowLevel/Endpoint.h +++ b/LUFA/Drivers/USB/LowLevel/Endpoint.h @@ -734,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. * @@ -1002,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 -- cgit v1.2.3