Commit 508e905d authored by Dean Camera's avatar Dean Camera
Browse files

Removed complicated logic for the Endpoint_ConfigureEndpoint() function to use...

Removed complicated logic for the Endpoint_ConfigureEndpoint() function to use inlined or function called versions depending of if the given bank size is a compile time constant, as the compiler does a better job of optimizing with basic code.

Changed over all device demos to use a clearer algorithm for the configuring of the application's endpoints.
parent be520aed
......@@ -93,16 +93,14 @@ void EVENT_USB_Device_Disconnect(void)
*/
void EVENT_USB_Device_ConfigurationChanged(void)
{
/* Indicate USB connected and ready */
LEDs_SetAllLEDs(LEDMASK_USB_READY);
bool ConfigSuccess = true;
/* Setup Joystick Report Endpoint */
if (!(Endpoint_ConfigureEndpoint(JOYSTICK_EPNUM, EP_TYPE_INTERRUPT,
ENDPOINT_DIR_IN, JOYSTICK_EPSIZE,
ENDPOINT_BANK_SINGLE)))
{
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
}
/* Setup HID Report Endpoint */
ConfigSuccess &= Endpoint_ConfigureEndpoint(JOYSTICK_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN,
JOYSTICK_EPSIZE, ENDPOINT_BANK_SINGLE);
/* Indicate endpoint configuration success or failure */
LEDs_SetAllLEDs(ConfigSuccess ? LEDMASK_USB_READY : LEDMASK_USB_ERROR);
}
/** Event handler for the USB_UnhandledControlRequest event. This is used to catch standard and class specific
......
......@@ -160,7 +160,7 @@ USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
{
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
.EndpointAddress = (ENDPOINT_DESCRIPTOR_DIR_IN | KEYBOARD_EPNUM),
.EndpointAddress = (ENDPOINT_DESCRIPTOR_DIR_IN | KEYBOARD_IN_EPNUM),
.Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
.EndpointSize = KEYBOARD_EPSIZE,
.PollingIntervalMS = 0x0A
......@@ -170,7 +170,7 @@ USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
{
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
.EndpointAddress = (ENDPOINT_DESCRIPTOR_DIR_OUT | KEYBOARD_LEDS_EPNUM),
.EndpointAddress = (ENDPOINT_DESCRIPTOR_DIR_OUT | KEYBOARD_OUT_EPNUM),
.Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
.EndpointSize = KEYBOARD_EPSIZE,
.PollingIntervalMS = 0x0A
......
......@@ -77,10 +77,10 @@
/* Macros: */
/** Endpoint number of the Keyboard HID reporting IN endpoint. */
#define KEYBOARD_EPNUM 1
#define KEYBOARD_IN_EPNUM 1
/** Endpoint number of the Keyboard HID reporting OUT endpoint. */
#define KEYBOARD_LEDS_EPNUM 2
#define KEYBOARD_OUT_EPNUM 2
/** Size in bytes of the Keyboard HID reporting IN and OUT endpoints. */
#define KEYBOARD_EPSIZE 8
......
......@@ -114,26 +114,19 @@ void EVENT_USB_Device_Disconnect(void)
*/
void EVENT_USB_Device_ConfigurationChanged(void)
{
/* Indicate USB connected and ready */
LEDs_SetAllLEDs(LEDMASK_USB_READY);
bool ConfigSuccess = true;
/* Setup Keyboard Keycode Report Endpoint */
if (!(Endpoint_ConfigureEndpoint(KEYBOARD_EPNUM, EP_TYPE_INTERRUPT,
ENDPOINT_DIR_IN, KEYBOARD_EPSIZE,
ENDPOINT_BANK_SINGLE)))
{
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
}
/* Setup Keyboard LED Report Endpoint */
if (!(Endpoint_ConfigureEndpoint(KEYBOARD_LEDS_EPNUM, EP_TYPE_INTERRUPT,
ENDPOINT_DIR_OUT, KEYBOARD_EPSIZE,
ENDPOINT_BANK_SINGLE)))
{
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
}
/* Setup HID Report Endpoints */
ConfigSuccess &= Endpoint_ConfigureEndpoint(KEYBOARD_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN,
KEYBOARD_EPSIZE, ENDPOINT_BANK_SINGLE);
ConfigSuccess &= Endpoint_ConfigureEndpoint(KEYBOARD_OUT_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_OUT,
KEYBOARD_EPSIZE, ENDPOINT_BANK_SINGLE);
/* Turn on Start-of-Frame events for tracking HID report period exiry */
USB_Device_EnableSOFEvents();
/* Indicate endpoint configuration success or failure */
LEDs_SetAllLEDs(ConfigSuccess ? LEDMASK_USB_READY : LEDMASK_USB_ERROR);
}
/** Event handler for the USB_UnhandledControlRequest event. This is used to catch standard and class specific
......@@ -332,7 +325,7 @@ void SendNextReport(void)
}
/* Select the Keyboard Report Endpoint */
Endpoint_SelectEndpoint(KEYBOARD_EPNUM);
Endpoint_SelectEndpoint(KEYBOARD_IN_EPNUM);
/* Check if Keyboard Endpoint Ready for Read/Write and if we should send a new report */
if (Endpoint_IsReadWriteAllowed() && SendReport)
......@@ -352,7 +345,7 @@ void SendNextReport(void)
void ReceiveNextReport(void)
{
/* Select the Keyboard LED Report Endpoint */
Endpoint_SelectEndpoint(KEYBOARD_LEDS_EPNUM);
Endpoint_SelectEndpoint(KEYBOARD_OUT_EPNUM);
/* Check if Keyboard LED Endpoint contains a packet */
if (Endpoint_IsOUTReceived())
......
......@@ -101,32 +101,20 @@ void EVENT_USB_Device_Disconnect(void)
*/
void EVENT_USB_Device_ConfigurationChanged(void)
{
/* Indicate USB connected and ready */
LEDs_SetAllLEDs(LEDMASK_USB_READY);
bool ConfigSuccess = true;
/* Setup Keyboard Report Endpoint */
if (!(Endpoint_ConfigureEndpoint(KEYBOARD_IN_EPNUM, EP_TYPE_INTERRUPT,
ENDPOINT_DIR_IN, HID_EPSIZE,
ENDPOINT_BANK_SINGLE)))
{
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
}
/* Setup Keyboard HID Report Endpoints */
ConfigSuccess &= Endpoint_ConfigureEndpoint(KEYBOARD_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN,
HID_EPSIZE, ENDPOINT_BANK_SINGLE);
ConfigSuccess &= Endpoint_ConfigureEndpoint(KEYBOARD_OUT_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_OUT,
HID_EPSIZE, ENDPOINT_BANK_SINGLE);
/* Setup Keyboard LED Report Endpoint */
if (!(Endpoint_ConfigureEndpoint(KEYBOARD_OUT_EPNUM, EP_TYPE_INTERRUPT,
ENDPOINT_DIR_OUT, HID_EPSIZE,
ENDPOINT_BANK_SINGLE)))
{
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
}
/* Setup Mouse HID Report Endpoint */
ConfigSuccess &= Endpoint_ConfigureEndpoint(MOUSE_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN,
HID_EPSIZE, ENDPOINT_BANK_SINGLE);
/* Setup Mouse Report Endpoint */
if (!(Endpoint_ConfigureEndpoint(MOUSE_IN_EPNUM, EP_TYPE_INTERRUPT,
ENDPOINT_DIR_IN, HID_EPSIZE,
ENDPOINT_BANK_SINGLE)))
{
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
}
/* Indicate endpoint configuration success or failure */
LEDs_SetAllLEDs(ConfigSuccess ? LEDMASK_USB_READY : LEDMASK_USB_ERROR);
}
/** Event handler for the USB_UnhandledControlPacket event. This is used to catch standard and class specific
......
......@@ -91,23 +91,16 @@ void EVENT_USB_Device_Disconnect(void)
*/
void EVENT_USB_Device_ConfigurationChanged(void)
{
/* Indicate USB connected and ready */
LEDs_SetAllLEDs(LEDMASK_USB_READY);
bool ConfigSuccess = true;
/* Setup MIDI stream endpoints */
if (!(Endpoint_ConfigureEndpoint(MIDI_STREAM_OUT_EPNUM, EP_TYPE_BULK,
ENDPOINT_DIR_OUT, MIDI_STREAM_EPSIZE,
ENDPOINT_BANK_SINGLE)))
{
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
}
/* Setup MIDI Data Endpoints */
ConfigSuccess &= Endpoint_ConfigureEndpoint(MIDI_STREAM_OUT_EPNUM, EP_TYPE_BULK, ENDPOINT_DIR_OUT,
MIDI_STREAM_EPSIZE, ENDPOINT_BANK_SINGLE);
ConfigSuccess &= Endpoint_ConfigureEndpoint(MIDI_STREAM_IN_EPNUM, EP_TYPE_BULK, ENDPOINT_DIR_IN,
MIDI_STREAM_EPSIZE, ENDPOINT_BANK_SINGLE);
if (!(Endpoint_ConfigureEndpoint(MIDI_STREAM_IN_EPNUM, EP_TYPE_BULK,
ENDPOINT_DIR_IN, MIDI_STREAM_EPSIZE,
ENDPOINT_BANK_SINGLE)))
{
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
}
/* Indicate endpoint configuration success or failure */
LEDs_SetAllLEDs(ConfigSuccess ? LEDMASK_USB_READY : LEDMASK_USB_ERROR);
}
/** Task to handle the generation of MIDI note change events in response to presses of the board joystick, and send them
......
......@@ -108,23 +108,16 @@ void EVENT_USB_Device_Disconnect(void)
*/
void EVENT_USB_Device_ConfigurationChanged(void)
{
/* Indicate USB connected and ready */
LEDs_SetAllLEDs(LEDMASK_USB_READY);
bool ConfigSuccess = true;
/* Setup Mass Storage In and Out Endpoints */
if (!(Endpoint_ConfigureEndpoint(MASS_STORAGE_IN_EPNUM, EP_TYPE_BULK,
ENDPOINT_DIR_IN, MASS_STORAGE_IO_EPSIZE,
ENDPOINT_BANK_SINGLE)))
{
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
}
/* Setup Mass Storage Data Endpoints */
ConfigSuccess &= Endpoint_ConfigureEndpoint(MASS_STORAGE_IN_EPNUM, EP_TYPE_BULK, ENDPOINT_DIR_IN,
MASS_STORAGE_IO_EPSIZE, ENDPOINT_BANK_SINGLE);
ConfigSuccess &= Endpoint_ConfigureEndpoint(MASS_STORAGE_OUT_EPNUM, EP_TYPE_BULK, ENDPOINT_DIR_OUT,
MASS_STORAGE_IO_EPSIZE, ENDPOINT_BANK_SINGLE);
if (!(Endpoint_ConfigureEndpoint(MASS_STORAGE_OUT_EPNUM, EP_TYPE_BULK,
ENDPOINT_DIR_OUT, MASS_STORAGE_IO_EPSIZE,
ENDPOINT_BANK_SINGLE)))
{
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
}
/* Indicate endpoint configuration success or failure */
LEDs_SetAllLEDs(ConfigSuccess ? LEDMASK_USB_READY : LEDMASK_USB_ERROR);
}
/** Event handler for the USB_UnhandledControlPacket event. This is used to catch standard and class specific
......
......@@ -113,18 +113,17 @@ void EVENT_USB_Device_Disconnect(void)
*/
void EVENT_USB_Device_ConfigurationChanged(void)
{
/* Indicate USB connected and ready */
LEDs_SetAllLEDs(LEDMASK_USB_READY);
bool ConfigSuccess = true;
/* Setup Mouse Report Endpoint */
if (!(Endpoint_ConfigureEndpoint(MOUSE_EPNUM, EP_TYPE_INTERRUPT,
ENDPOINT_DIR_IN, MOUSE_EPSIZE,
ENDPOINT_BANK_SINGLE)))
{
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
}
/* Setup HID Report Endpoint */
ConfigSuccess &= Endpoint_ConfigureEndpoint(MOUSE_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN,
MOUSE_EPSIZE, ENDPOINT_BANK_SINGLE);
/* Turn on Start-of-Frame events for tracking HID report period exiry */
USB_Device_EnableSOFEvents();
/* Indicate endpoint configuration success or failure */
LEDs_SetAllLEDs(ConfigSuccess ? LEDMASK_USB_READY : LEDMASK_USB_ERROR);
}
/** Event handler for the USB_UnhandledControlRequest event. This is used to catch standard and class specific
......
......@@ -98,30 +98,18 @@ void EVENT_USB_Device_Disconnect(void)
*/
void EVENT_USB_Device_ConfigurationChanged(void)
{
/* Indicate USB connected and ready */
LEDs_SetAllLEDs(LEDMASK_USB_READY);
/* Setup CDC Notification, Rx and Tx Endpoints */
if (!(Endpoint_ConfigureEndpoint(CDC_TX_EPNUM, EP_TYPE_BULK,
ENDPOINT_DIR_IN, CDC_TXRX_EPSIZE,
ENDPOINT_BANK_SINGLE)))
{
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
}
if (!(Endpoint_ConfigureEndpoint(CDC_RX_EPNUM, EP_TYPE_BULK,
ENDPOINT_DIR_OUT, CDC_TXRX_EPSIZE,
ENDPOINT_BANK_SINGLE)))
{
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
}
if (!(Endpoint_ConfigureEndpoint(CDC_NOTIFICATION_EPNUM, EP_TYPE_INTERRUPT,
ENDPOINT_DIR_IN, CDC_NOTIFICATION_EPSIZE,
ENDPOINT_BANK_SINGLE)))
{
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
}
bool ConfigSuccess = true;
/* Setup RNDIS Data Endpoints */
ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC_TX_EPNUM, EP_TYPE_BULK, ENDPOINT_DIR_IN,
CDC_TXRX_EPSIZE, ENDPOINT_BANK_SINGLE);
ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC_RX_EPNUM, EP_TYPE_BULK, ENDPOINT_DIR_OUT,
CDC_TXRX_EPSIZE, ENDPOINT_BANK_SINGLE);
ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC_NOTIFICATION_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN,
CDC_NOTIFICATION_EPSIZE, ENDPOINT_BANK_SINGLE);
/* Indicate endpoint configuration success or failure */
LEDs_SetAllLEDs(ConfigSuccess ? LEDMASK_USB_READY : LEDMASK_USB_ERROR);
}
/** Event handler for the USB_UnhandledControlRequest event. This is used to catch standard and class specific
......
......@@ -105,33 +105,21 @@ void EVENT_USB_Device_Disconnect(void)
*/
void EVENT_USB_Device_ConfigurationChanged(void)
{
/* Indicate USB connected and ready */
LEDs_SetAllLEDs(LEDMASK_USB_READY);
bool ConfigSuccess = true;
/* Setup CDC Notification, Rx and Tx Endpoints */
if (!(Endpoint_ConfigureEndpoint(CDC_NOTIFICATION_EPNUM, EP_TYPE_INTERRUPT,
ENDPOINT_DIR_IN, CDC_NOTIFICATION_EPSIZE,
ENDPOINT_BANK_SINGLE)))
{
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
}
if (!(Endpoint_ConfigureEndpoint(CDC_TX_EPNUM, EP_TYPE_BULK,
ENDPOINT_DIR_IN, CDC_TXRX_EPSIZE,
ENDPOINT_BANK_SINGLE)))
{
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
}
if (!(Endpoint_ConfigureEndpoint(CDC_RX_EPNUM, EP_TYPE_BULK,
ENDPOINT_DIR_OUT, CDC_TXRX_EPSIZE,
ENDPOINT_BANK_SINGLE)))
{
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
}
/* Setup CDC Data Endpoints */
ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC_NOTIFICATION_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN,
CDC_NOTIFICATION_EPSIZE, ENDPOINT_BANK_SINGLE);
ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC_TX_EPNUM, EP_TYPE_BULK, ENDPOINT_DIR_IN,
CDC_TXRX_EPSIZE, ENDPOINT_BANK_SINGLE);
ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC_RX_EPNUM, EP_TYPE_BULK, ENDPOINT_DIR_OUT,
CDC_TXRX_EPSIZE, ENDPOINT_BANK_SINGLE);
/* Reset line encoding baud rate so that the host knows to send new values */
LineEncoding.BaudRateBPS = 0;
/* Indicate endpoint configuration success or failure */
LEDs_SetAllLEDs(ConfigSuccess ? LEDMASK_USB_READY : LEDMASK_USB_ERROR);
}
/** Event handler for the USB_UnhandledControlRequest event. This is used to catch standard and class specific
......
......@@ -40,11 +40,6 @@
uint8_t USB_ControlEndpointSize = ENDPOINT_CONTROLEP_DEFAULT_SIZE;
#endif
uint8_t Endpoint_BytesToEPSizeMaskDynamic(const uint16_t Size)
{
return Endpoint_BytesToEPSizeMask(Size);
}
bool Endpoint_ConfigureEndpoint_Prv(const uint8_t Number,
const uint8_t UECFG0XData,
const uint8_t UECFG1XData)
......
......@@ -99,6 +99,64 @@
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
#endif
#if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__)
#define __CALLBACK_PARAM , StreamCallbackPtr_t Callback
#else
#define __CALLBACK_PARAM
#endif
/* Private Interface - For use in library only: */
#if !defined(__DOXYGEN__)
/* Macros: */
#define _ENDPOINT_GET_MAXSIZE(EPIndex) _ENDPOINT_GET_MAXSIZE2(ENDPOINT_DETAILS_EP ## EPIndex)
#define _ENDPOINT_GET_MAXSIZE2(EPDetails) _ENDPOINT_GET_MAXSIZE3(EPDetails)
#define _ENDPOINT_GET_MAXSIZE3(MaxSize, DB) (MaxSize)
#define _ENDPOINT_GET_DOUBLEBANK(EPIndex) _ENDPOINT_GET_DOUBLEBANK2(ENDPOINT_DETAILS_EP ## EPIndex)
#define _ENDPOINT_GET_DOUBLEBANK2(EPDetails) _ENDPOINT_GET_DOUBLEBANK3(EPDetails)
#define _ENDPOINT_GET_DOUBLEBANK3(MaxSize, DB) (DB)
#if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)
#define ENDPOINT_DETAILS_EP0 64, true
#define ENDPOINT_DETAILS_EP1 256, true
#define ENDPOINT_DETAILS_EP2 64, true
#define ENDPOINT_DETAILS_EP3 64, true
#define ENDPOINT_DETAILS_EP4 64, true
#define ENDPOINT_DETAILS_EP5 64, true
#define ENDPOINT_DETAILS_EP6 64, true
#else
#define ENDPOINT_DETAILS_EP0 64, true
#define ENDPOINT_DETAILS_EP1 64, false
#define ENDPOINT_DETAILS_EP2 64, false
#define ENDPOINT_DETAILS_EP3 64, true
#define ENDPOINT_DETAILS_EP4 64, true
#endif
/* 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)
{
uint8_t MaskVal = 0;
uint16_t CheckBytes = 8;
while (CheckBytes < Bytes)
{
MaskVal++;
CheckBytes <<= 1;
}
return (MaskVal << EPSIZE0);
}
/* Function Prototypes: */
void Endpoint_ClearEndpoints(void);
bool Endpoint_ConfigureEndpoint_Prv(const uint8_t Number,
const uint8_t UECFG0XData,
const uint8_t UECFG1XData);
#endif
/* Public Interface - May be used in end-application: */
/* Macros: */
/** Endpoint data direction mask for \ref Endpoint_ConfigureEndpoint(). This indicates that the endpoint
......@@ -246,6 +304,44 @@
};
/* Inline Functions: */
/** 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
* of the USB FIFO memory.
*
* The endpoint type may be one of the EP_TYPE_* macros listed in LowLevel.h and the direction
* may be either \ref ENDPOINT_DIR_OUT or \ref ENDPOINT_DIR_IN.
*
* The bank size must indicate the maximum packet size that the endpoint can handle. Different
* endpoint numbers can handle different maximum packet sizes - refer to the chosen USB AVR's
* datasheet to determine the maximum bank size for each endpoint.
*
* The banking mode may be either \ref ENDPOINT_BANK_SINGLE or \ref ENDPOINT_BANK_DOUBLE.
*
* \note The default control endpoint should not be manually configured by the user application, as
* it is automatically configured by the library internally.
* \n\n
*
* \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.
*
* \return Boolean true if the configuration succeeded, false otherwise.
*/
static inline bool Endpoint_ConfigureEndpoint(const uint8_t Number,
const uint8_t Type,
const uint8_t Direction,
const uint16_t Size,
const uint8_t Banks) ATTR_ALWAYS_INLINE;
static inline bool Endpoint_ConfigureEndpoint(const uint8_t Number,
const uint8_t Type,
const uint8_t Direction,
const uint16_t Size,
const uint8_t Banks)
{
return Endpoint_ConfigureEndpoint_Prv(Number, (((Type) << EPTYPE0) | (Direction)),
((1 << ALLOC) | Banks | Endpoint_BytesToEPSizeMask(Size)));
}
/** Indicates the number of bytes currently stored in the current endpoint's selected bank.
*
* \note The return width of this function may differ, depending on the maximum endpoint bank size
......@@ -777,41 +873,6 @@
#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
* of the USB FIFO memory.
*
* The endpoint type may be one of the EP_TYPE_* macros listed in LowLevel.h and the direction
* may be either \ref ENDPOINT_DIR_OUT or \ref ENDPOINT_DIR_IN.
*
* The bank size must indicate the maximum packet size that the endpoint can handle. Different
* endpoint numbers can handle different maximum packet sizes - refer to the chosen USB AVR's
* datasheet to determine the maximum bank size for each endpoint.
*
* The banking mode may be either \ref ENDPOINT_BANK_SINGLE or \ref ENDPOINT_BANK_DOUBLE.
*
* \note The default control endpoint should not be manually configured by the user application, as
* it is automatically configured by the library internally.
* \n\n
*
* \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.
*
* \return Boolean true if the configuration succeeded, false otherwise.
*/
bool Endpoint_ConfigureEndpoint(const uint8_t Number,
const uint8_t Type,
const uint8_t Direction,
const uint16_t Size,
const uint8_t Banks);
/** Spin-loops until the currently selected non-control endpoint is ready for the next packet of data
* to be read or written to it.
*
......@@ -1266,87 +1327,6 @@
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: */
#define _ENDPOINT_GET_MAXSIZE(n) _ENDPOINT_GET_MAXSIZE2(ENDPOINT_DETAILS_EP ## n)
#define _ENDPOINT_GET_MAXSIZE2(details) _ENDPOINT_GET_MAXSIZE3(details)
#define _ENDPOINT_GET_MAXSIZE3(maxsize, db) maxsize
#define _ENDPOINT_GET_DOUBLEBANK(n) _ENDPOINT_GET_DOUBLEBANK2(ENDPOINT_DETAILS_EP ## n)
#define _ENDPOINT_GET_DOUBLEBANK2(details) _ENDPOINT_GET_DOUBLEBANK3(details)
#define _ENDPOINT_GET_DOUBLEBANK3(maxsize, db) db
#if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)
#define ENDPOINT_DETAILS_EP0 64, true
#define ENDPOINT_DETAILS_EP1 256, true
#define ENDPOINT_DETAILS_EP2 64, true
#define ENDPOINT_DETAILS_EP3 64, true
#define ENDPOINT_DETAILS_EP4 64, true
#define ENDPOINT_DETAILS_EP5 64, true
#define ENDPOINT_DETAILS_EP6 64, true
#else
#define ENDPOINT_DETAILS_EP0 64, true
#define ENDPOINT_DETAILS_EP1 64, false
#define ENDPOINT_DETAILS_EP2 64, false
#define ENDPOINT_DETAILS_EP3 64, true
#define ENDPOINT_DETAILS_EP4 64, true
#endif
#define Endpoint_ConfigureEndpoint(Number, Type, Direction, Size, Banks) \
(__builtin_constant_p(Size) ? Endpoint_ConfigureEndpointStatic((Number), \
(Type), \
(Direction), \
Size, Banks) : \
Endpoint_ConfigureEndpointDynamic((Number), \
(Type), \
(Direction), \
Size, Banks))
/* Function Prototypes: */
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)
{
uint8_t MaskVal = 0;
uint16_t CheckBytes = 8;
while (CheckBytes < Bytes)
{
MaskVal++;
CheckBytes <<= 1;
}
return (MaskVal << EPSIZE0);
}
static inline bool Endpoint_ConfigureEndpointStatic(const uint8_t Number,
const uint8_t Type,
const uint8_t Direction,
const uint16_t Size,
const uint8_t Banks)
{
return Endpoint_ConfigureEndpoint_Prv(Number, (((Type) << EPTYPE0) | (Direction)),
((1 << ALLOC) | Banks | Endpoint_BytesToEPSizeMask(Size)));
}
static inline bool Endpoint_ConfigureEndpointDynamic(const uint8_t Number,
const uint8_t Type,
const uint8_t Direction,
const uint16_t Size,
const uint8_t Banks)
{
return Endpoint_ConfigureEndpoint_Prv(Number, (((Type) << EPTYPE0) | (Direction)),
((1 << ALLOC) | Banks | Endpoint_BytesToEPSizeMaskDynamic(Size)));
}
#endif
/* Disable C linkage for C++ Compilers: */
#if defined(__cplusplus)
}
......
......@@ -106,12 +106,10 @@
#error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
#endif
/* Private Interface - For use in library only: */
#if !defined(__DOXYGEN__)
/* Macros: */
#if !defined(ENDPOINT_CONTROLEP) && !defined(__DOXYGEN__)
#define ENDPOINT_CONTROLEP 0
#endif
#if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__)