3 Copyright (C) Dean Camera, 2010.
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
10 Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com)
12 Permission to use, copy, modify, distribute, and sell this
13 software and its documentation for any purpose is hereby granted
14 without fee, provided that the above copyright notice appear in
15 all copies and that both that the copyright notice and this
16 permission notice and warranty disclaimer appear in supporting
17 documentation, and that the name of the author not be used in
18 advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.
21 The author disclaim all warranties with regard to this
22 software, including all implied warranties of merchantability
23 and fitness. In no event shall the author be liable for any
24 special, indirect or consequential damages or any damages
25 whatsoever resulting from loss of use, data or profits, whether
26 in an action of contract, negligence or other tortious action,
27 arising out of or in connection with the use or performance of
31 /** \ingroup Group_USB
32 * @defgroup Group_EndpointManagement Endpoint Management
34 * Functions, macros and enums related to endpoint management when in USB Device mode. This
35 * module contains the endpoint management macros, as well as endpoint interrupt and data
36 * send/receive functions for various data types.
41 /** @defgroup Group_EndpointRW Endpoint Data Reading and Writing
43 * Functions, macros, variables, enums and types related to data reading and writing from and to endpoints.
46 /** \ingroup Group_EndpointRW
47 * @defgroup Group_EndpointPrimitiveRW Read/Write of Primitive Data Types
49 * Functions, macros, variables, enums and types related to data reading and writing of primitive data types
50 * from and to endpoints.
53 /** \ingroup Group_EndpointRW
54 * @defgroup Group_EndpointStreamRW Read/Write of Multi-Byte Streams
56 * Functions, macros, variables, enums and types related to data reading and writing of data streams from
60 /** @defgroup Group_EndpointPacketManagement Endpoint Packet Management
62 * Functions, macros, variables, enums and types related to packet management of endpoints.
65 #ifndef __ENDPOINT_H__
66 #define __ENDPOINT_H__
70 #include <avr/pgmspace.h>
71 #include <avr/eeprom.h>
74 #include "../../../Common/Common.h"
75 #include "../HighLevel/USBTask.h"
77 #if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__)
78 #include "../HighLevel/StreamCallbacks.h"
81 /* Enable C linkage for C++ Compilers: */
82 #if defined(__cplusplus)
86 /* Preprocessor Checks: */
87 #if !defined(__INCLUDE_FROM_USB_DRIVER)
88 #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
91 /* Public Interface - May be used in end-application: */
93 /** Endpoint data direction mask for \ref Endpoint_ConfigureEndpoint(). This indicates that the endpoint
94 * should be initialized in the OUT direction - i.e. data flows from host to device.
96 #define ENDPOINT_DIR_OUT (0 << EPDIR)
98 /** Endpoint data direction mask for \ref Endpoint_ConfigureEndpoint(). This indicates that the endpoint
99 * should be initialized in the IN direction - i.e. data flows from device to host.
101 #define ENDPOINT_DIR_IN (1 << EPDIR)
103 /** Mask for the bank mode selection for the \ref Endpoint_ConfigureEndpoint() macro. This indicates
104 * that the endpoint should have one single bank, which requires less USB FIFO memory but results
105 * in slower transfers as only one USB device (the AVR or the host) can access the endpoint's
106 * bank at the one time.
108 #define ENDPOINT_BANK_SINGLE (0 << EPBK0)
110 /** Mask for the bank mode selection for the \ref Endpoint_ConfigureEndpoint() macro. This indicates
111 * that the endpoint should have two banks, which requires more USB FIFO memory but results
112 * in faster transfers as one USB device (the AVR or the host) can access one bank while the other
113 * accesses the second bank.
115 #define ENDPOINT_BANK_DOUBLE (1 << EPBK0)
117 /** Endpoint address for the default control endpoint, which always resides in address 0. This is
118 * defined for convenience to give more readable code when used with the endpoint macros.
120 #define ENDPOINT_CONTROLEP 0
122 #if (!defined(FIXED_CONTROL_ENDPOINT_SIZE) || defined(__DOXYGEN__))
123 /** Default size of the default control endpoint's bank, until altered by the Endpoint0Size value
124 * in the device descriptor. Not available if the FIXED_CONTROL_ENDPOINT_SIZE token is defined.
126 #define ENDPOINT_CONTROLEP_DEFAULT_SIZE 8
129 /** Endpoint number mask, for masking against endpoint addresses to retrieve the endpoint's
130 * numerical address in the device.
132 #define ENDPOINT_EPNUM_MASK 0x07
134 /** Endpoint direction mask, for masking against endpoint addresses to retrieve the endpoint's
135 * direction for comparing with the ENDPOINT_DESCRIPTOR_DIR_* masks.
137 #define ENDPOINT_EPDIR_MASK 0x80
139 /** Endpoint bank size mask, for masking against endpoint addresses to retrieve the endpoint's
140 * bank size in the device.
142 #define ENDPOINT_EPSIZE_MASK 0x7FF
144 /** Maximum size in bytes of a given endpoint.
146 * \param[in] n Endpoint number, a value between 0 and (ENDPOINT_TOTAL_ENDPOINTS - 1)
148 #define ENDPOINT_MAX_SIZE(n) _ENDPOINT_GET_MAXSIZE(n)
150 /** Indicates if the given endpoint supports double banking.
152 * \param[in] n Endpoint number, a value between 0 and (ENDPOINT_TOTAL_ENDPOINTS - 1)
154 #define ENDPOINT_DOUBLEBANK_SUPPORTED(n) _ENDPOINT_GET_DOUBLEBANK(n)
156 #if !defined(CONTROL_ONLY_DEVICE)
157 #if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR) || defined(__DOXYGEN__)
158 /** Total number of endpoints (including the default control endpoint at address 0) which may
159 * be used in the device. Different USB AVR models support different amounts of endpoints,
160 * this value reflects the maximum number of endpoints for the currently selected AVR model.
162 #define ENDPOINT_TOTAL_ENDPOINTS 7
164 #define ENDPOINT_TOTAL_ENDPOINTS 5
167 #define ENDPOINT_TOTAL_ENDPOINTS 1
170 /* Pseudo-Function Macros: */
171 #if defined(__DOXYGEN__)
172 /** Indicates the number of bytes currently stored in the current endpoint's selected bank.
174 * \note The return width of this function may differ, depending on the maximum endpoint bank size
175 * of the selected AVR model.
177 * \ingroup Group_EndpointRW
179 * \return Total number of bytes in the currently selected Endpoint's FIFO buffer
181 static inline uint16_t Endpoint_BytesInEndpoint(void);
183 /** Get the endpoint address of the currently selected endpoint. This is typically used to save
184 * the currently selected endpoint number so that it can be restored after another endpoint has
187 * \return Index of the currently selected endpoint
189 static inline uint8_t Endpoint_GetCurrentEndpoint(void);
191 /** Selects the given endpoint number. If the address from the device descriptors is used, the
192 * value should be masked with the \ref ENDPOINT_EPNUM_MASK constant to extract only the endpoint
193 * number (and discarding the endpoint direction bit).
195 * Any endpoint operations which do not require the endpoint number to be indicated will operate on
196 * the currently selected endpoint.
198 * \param[in] EndpointNumber Endpoint number to select
200 static inline void Endpoint_SelectEndpoint(uint8_t EndpointNumber
);
202 /** Resets the endpoint bank FIFO. This clears all the endpoint banks and resets the USB controller's
203 * In and Out pointers to the bank's contents.
205 * \param[in] EndpointNumber Endpoint number whose FIFO buffers are to be reset
207 static inline void Endpoint_ResetFIFO(uint8_t EndpointNumber
);
209 /** Enables the currently selected endpoint so that data can be sent and received through it to
212 * \note Endpoints must first be configured properly via \ref Endpoint_ConfigureEndpoint().
214 static inline void Endpoint_EnableEndpoint(void);
216 /** Disables the currently selected endpoint so that data cannot be sent and received through it
217 * to and from a host.
219 static inline void Endpoint_DisableEndpoint(void);
221 /** Determines if the currently selected endpoint is enabled, but not necessarily configured.
223 * \return Boolean True if the currently selected endpoint is enabled, false otherwise
225 static inline bool Endpoint_IsEnabled(void);
227 /** Determines if the currently selected endpoint may be read from (if data is waiting in the endpoint
228 * bank and the endpoint is an OUT direction, or if the bank is not yet full if the endpoint is an IN
229 * direction). This function will return false if an error has occurred in the endpoint, if the endpoint
230 * is an OUT direction and no packet (or an empty packet) has been received, or if the endpoint is an IN
231 * direction and the endpoint bank is full.
233 * \ingroup Group_EndpointPacketManagement
235 * \return Boolean true if the currently selected endpoint may be read from or written to, depending on its direction
237 static inline bool Endpoint_IsReadWriteAllowed(void);
239 /** Determines if the currently selected endpoint is configured.
241 * \return Boolean true if the currently selected endpoint has been configured, false otherwise
243 static inline bool Endpoint_IsConfigured(void);
245 /** Returns a mask indicating which INTERRUPT type endpoints have interrupted - i.e. their
246 * interrupt duration has elapsed. Which endpoints have interrupted can be determined by
247 * masking the return value against (1 << {Endpoint Number}).
249 * \return Mask whose bits indicate which endpoints have interrupted
251 static inline uint8_t Endpoint_GetEndpointInterrupts(void);
253 /** Determines if the specified endpoint number has interrupted (valid only for INTERRUPT type
256 * \param[in] EndpointNumber Index of the endpoint whose interrupt flag should be tested
258 * \return Boolean true if the specified endpoint has interrupted, false otherwise
260 static inline bool Endpoint_HasEndpointInterrupted(uint8_t EndpointNumber
);
262 /** Determines if the selected IN endpoint is ready for a new packet.
264 * \ingroup Group_EndpointPacketManagement
266 * \return Boolean true if the current endpoint is ready for an IN packet, false otherwise.
268 static inline bool Endpoint_IsINReady(void);
270 /** Determines if the selected OUT endpoint has received new packet.
272 * \ingroup Group_EndpointPacketManagement
274 * \return Boolean true if current endpoint is has received an OUT packet, false otherwise.
276 static inline bool Endpoint_IsOUTReceived(void);
278 /** Determines if the current CONTROL type endpoint has received a SETUP packet.
280 * \ingroup Group_EndpointPacketManagement
282 * \return Boolean true if the selected endpoint has received a SETUP packet, false otherwise.
284 static inline bool Endpoint_IsSETUPReceived(void);
286 /** Clears a received SETUP packet on the currently selected CONTROL type endpoint, freeing up the
287 * endpoint for the next packet.
289 * \ingroup Group_EndpointPacketManagement
291 * \note This is not applicable for non CONTROL type endpoints.
293 static inline void Endpoint_ClearSETUP(void);
295 /** Sends an IN packet to the host on the currently selected endpoint, freeing up the endpoint for the
296 * next packet and switching to the alternative endpoint bank if double banked.
298 * \ingroup Group_EndpointPacketManagement
300 static inline void Endpoint_ClearIN(void);
302 /** Acknowledges an OUT packet to the host on the currently selected endpoint, freeing up the endpoint
303 * for the next packet and switching to the alternative endpoint bank if double banked.
305 * \ingroup Group_EndpointPacketManagement
307 static inline void Endpoint_ClearOUT(void);
309 /** Stalls the current endpoint, indicating to the host that a logical problem occurred with the
310 * indicated endpoint and that the current transfer sequence should be aborted. This provides a
311 * way for devices to indicate invalid commands to the host so that the current transfer can be
312 * aborted and the host can begin its own recovery sequence.
314 * The currently selected endpoint remains stalled until either the \ref Endpoint_ClearStall() macro
315 * is called, or the host issues a CLEAR FEATURE request to the device for the currently selected
318 * \ingroup Group_EndpointPacketManagement
320 static inline void Endpoint_StallTransaction(void);
322 /** Clears the STALL condition on the currently selected endpoint.
324 * \ingroup Group_EndpointPacketManagement
326 static inline void Endpoint_ClearStall(void);
328 /** Determines if the currently selected endpoint is stalled, false otherwise.
330 * \ingroup Group_EndpointPacketManagement
332 * \return Boolean true if the currently selected endpoint is stalled, false otherwise
334 static inline bool Endpoint_IsStalled(void);
336 /** Resets the data toggle of the currently selected endpoint. */
337 static inline void Endpoint_ResetDataToggle(void);
339 /** Determines the currently selected endpoint's direction.
341 * \return The currently selected endpoint's direction, as a ENDPOINT_DIR_* mask.
343 static inline uint8_t Endpoint_GetEndpointDirection(void);
345 /** Sets the direction of the currently selected endpoint.
347 * \param[in] DirectionMask New endpoint direction, as a ENDPOINT_DIR_* mask.
349 static inline void Endpoint_SetEndpointDirection(uint8_t DirectionMask
);
351 #if defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)
352 #define Endpoint_BytesInEndpoint() UEBCX
353 #elif defined(USB_SERIES_4_AVR)
354 #define Endpoint_BytesInEndpoint() (((uint16_t)UEBCHX << 8) | UEBCLX)
355 #elif defined(USB_SERIES_2_AVR)
356 #define Endpoint_BytesInEndpoint() UEBCLX
359 #if !defined(CONTROL_ONLY_DEVICE)
360 #define Endpoint_GetCurrentEndpoint() (UENUM & ENDPOINT_EPNUM_MASK)
362 #define Endpoint_GetCurrentEndpoint() ENDPOINT_CONTROLEP
365 #if !defined(CONTROL_ONLY_DEVICE)
366 #define Endpoint_SelectEndpoint(epnum) MACROS{ UENUM = (epnum); }MACROE
368 #define Endpoint_SelectEndpoint(epnum) (void)(epnum)
371 #define Endpoint_ResetFIFO(epnum) MACROS{ UERST = (1 << (epnum)); UERST = 0; }MACROE
373 #define Endpoint_EnableEndpoint() MACROS{ UECONX |= (1 << EPEN); }MACROE
375 #define Endpoint_DisableEndpoint() MACROS{ UECONX &= ~(1 << EPEN); }MACROE
377 #define Endpoint_IsEnabled() ((UECONX & (1 << EPEN)) ? true : false)
379 #if !defined(CONTROL_ONLY_DEVICE)
380 #define Endpoint_IsReadWriteAllowed() ((UEINTX & (1 << RWAL)) ? true : false)
383 #define Endpoint_IsConfigured() ((UESTA0X & (1 << CFGOK)) ? true : false)
385 #define Endpoint_GetEndpointInterrupts() UEINT
387 #define Endpoint_HasEndpointInterrupted(n) ((UEINT & (1 << (n))) ? true : false)
389 #define Endpoint_IsINReady() ((UEINTX & (1 << TXINI)) ? true : false)
391 #define Endpoint_IsOUTReceived() ((UEINTX & (1 << RXOUTI)) ? true : false)
393 #define Endpoint_IsSETUPReceived() ((UEINTX & (1 << RXSTPI)) ? true : false)
395 #define Endpoint_ClearSETUP() MACROS{ UEINTX &= ~(1 << RXSTPI); }MACROE
397 #if !defined(CONTROL_ONLY_DEVICE)
398 #define Endpoint_ClearIN() MACROS{ uint8_t Temp = UEINTX; UEINTX = (Temp & ~(1 << TXINI)); \
399 UEINTX = (Temp & ~(1 << FIFOCON)); }MACROE
401 #define Endpoint_ClearIN() MACROS{ UEINTX &= ~(1 << TXINI); }MACROE
404 #if !defined(CONTROL_ONLY_DEVICE)
405 #define Endpoint_ClearOUT() MACROS{ uint8_t Temp = UEINTX; UEINTX = (Temp & ~(1 << RXOUTI)); \
406 UEINTX = (Temp & ~(1 << FIFOCON)); }MACROE
408 #define Endpoint_ClearOUT() MACROS{ UEINTX &= ~(1 << RXOUTI); }MACROE
411 #define Endpoint_StallTransaction() MACROS{ UECONX |= (1 << STALLRQ); }MACROE
413 #define Endpoint_ClearStall() MACROS{ UECONX |= (1 << STALLRQC); }MACROE
415 #define Endpoint_IsStalled() ((UECONX & (1 << STALLRQ)) ? true : false)
417 #define Endpoint_ResetDataToggle() MACROS{ UECONX |= (1 << RSTDT); }MACROE
419 #define Endpoint_GetEndpointDirection() (UECFG0X & ENDPOINT_DIR_IN)
421 #define Endpoint_SetEndpointDirection(dir) MACROS{ UECFG0X = ((UECFG0X & ~ENDPOINT_DIR_IN) | (dir)); }MACROE
425 /** Enum for the possible error return codes of the \ref Endpoint_WaitUntilReady() function.
427 * \ingroup Group_EndpointRW
429 enum Endpoint_WaitUntilReady_ErrorCodes_t
431 ENDPOINT_READYWAIT_NoError
= 0, /**< Endpoint is ready for next packet, no error. */
432 ENDPOINT_READYWAIT_EndpointStalled
= 1, /**< The endpoint was stalled during the stream
433 * transfer by the host or device.
435 ENDPOINT_READYWAIT_DeviceDisconnected
= 2, /**< Device was disconnected from the host while
436 * waiting for the endpoint to become ready.
438 ENDPOINT_READYWAIT_Timeout
= 3, /**< The host failed to accept or send the next packet
439 * within the software timeout period set by the
440 * \ref USB_STREAM_TIMEOUT_MS macro.
444 /** Enum for the possible error return codes of the Endpoint_*_Stream_* functions.
446 * \ingroup Group_EndpointStreamRW
448 enum Endpoint_Stream_RW_ErrorCodes_t
450 ENDPOINT_RWSTREAM_NoError
= 0, /**< Command completed successfully, no error. */
451 ENDPOINT_RWSTREAM_EndpointStalled
= 1, /**< The endpoint was stalled during the stream
452 * transfer by the host or device.
454 ENDPOINT_RWSTREAM_DeviceDisconnected
= 2, /**< Device was disconnected from the host during
457 ENDPOINT_RWSTREAM_Timeout
= 3, /**< The host failed to accept or send the next packet
458 * within the software timeout period set by the
459 * \ref USB_STREAM_TIMEOUT_MS macro.
461 ENDPOINT_RWSTREAM_CallbackAborted
= 4, /**< Indicates that the stream's callback function
462 * aborted the transfer early.
466 /** Enum for the possible error return codes of the Endpoint_*_Control_Stream_* functions..
468 * \ingroup Group_EndpointStreamRW
470 enum Endpoint_ControlStream_RW_ErrorCodes_t
472 ENDPOINT_RWCSTREAM_NoError
= 0, /**< Command completed successfully, no error. */
473 ENDPOINT_RWCSTREAM_HostAborted
= 1, /**< The aborted the transfer prematurely. */
474 ENDPOINT_RWCSTREAM_DeviceDisconnected
= 2, /**< Device was disconnected from the host during
479 /* Inline Functions: */
480 /** Reads one byte from the currently selected endpoint's bank, for OUT direction endpoints.
482 * \ingroup Group_EndpointPrimitiveRW
484 * \return Next byte in the currently selected endpoint's FIFO buffer
486 static inline uint8_t Endpoint_Read_Byte(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE
;
487 static inline uint8_t Endpoint_Read_Byte(void)
492 /** Writes one byte from the currently selected endpoint's bank, for IN direction endpoints.
494 * \ingroup Group_EndpointPrimitiveRW
496 * \param[in] Byte Next byte to write into the the currently selected endpoint's FIFO buffer
498 static inline void Endpoint_Write_Byte(const uint8_t Byte
) ATTR_ALWAYS_INLINE
;
499 static inline void Endpoint_Write_Byte(const uint8_t Byte
)
504 /** Discards one byte from the currently selected endpoint's bank, for OUT direction endpoints.
506 * \ingroup Group_EndpointPrimitiveRW
508 static inline void Endpoint_Discard_Byte(void) ATTR_ALWAYS_INLINE
;
509 static inline void Endpoint_Discard_Byte(void)
516 /** Reads two bytes from the currently selected endpoint's bank in little endian format, for OUT
517 * direction endpoints.
519 * \ingroup Group_EndpointPrimitiveRW
521 * \return Next word in the currently selected endpoint's FIFO buffer
523 static inline uint16_t Endpoint_Read_Word_LE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE
;
524 static inline uint16_t Endpoint_Read_Word_LE(void)
532 Data
.Bytes
[0] = UEDATX
;
533 Data
.Bytes
[1] = UEDATX
;
538 /** Reads two bytes from the currently selected endpoint's bank in big endian format, for OUT
539 * direction endpoints.
541 * \ingroup Group_EndpointPrimitiveRW
543 * \return Next word in the currently selected endpoint's FIFO buffer
545 static inline uint16_t Endpoint_Read_Word_BE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE
;
546 static inline uint16_t Endpoint_Read_Word_BE(void)
554 Data
.Bytes
[1] = UEDATX
;
555 Data
.Bytes
[0] = UEDATX
;
560 /** Writes two bytes to the currently selected endpoint's bank in little endian format, for IN
561 * direction endpoints.
563 * \ingroup Group_EndpointPrimitiveRW
565 * \param[in] Word Next word to write to the currently selected endpoint's FIFO buffer
567 static inline void Endpoint_Write_Word_LE(const uint16_t Word
) ATTR_ALWAYS_INLINE
;
568 static inline void Endpoint_Write_Word_LE(const uint16_t Word
)
570 UEDATX
= (Word
& 0xFF);
571 UEDATX
= (Word
>> 8);
574 /** Writes two bytes to the currently selected endpoint's bank in big endian format, for IN
575 * direction endpoints.
577 * \ingroup Group_EndpointPrimitiveRW
579 * \param[in] Word Next word to write to the currently selected endpoint's FIFO buffer
581 static inline void Endpoint_Write_Word_BE(const uint16_t Word
) ATTR_ALWAYS_INLINE
;
582 static inline void Endpoint_Write_Word_BE(const uint16_t Word
)
584 UEDATX
= (Word
>> 8);
585 UEDATX
= (Word
& 0xFF);
588 /** Discards two bytes from the currently selected endpoint's bank, for OUT direction endpoints.
590 * \ingroup Group_EndpointPrimitiveRW
592 static inline void Endpoint_Discard_Word(void) ATTR_ALWAYS_INLINE
;
593 static inline void Endpoint_Discard_Word(void)
601 /** Reads four bytes from the currently selected endpoint's bank in little endian format, for OUT
602 * direction endpoints.
604 * \ingroup Group_EndpointPrimitiveRW
606 * \return Next double word in the currently selected endpoint's FIFO buffer
608 static inline uint32_t Endpoint_Read_DWord_LE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE
;
609 static inline uint32_t Endpoint_Read_DWord_LE(void)
617 Data
.Bytes
[0] = UEDATX
;
618 Data
.Bytes
[1] = UEDATX
;
619 Data
.Bytes
[2] = UEDATX
;
620 Data
.Bytes
[3] = UEDATX
;
625 /** Reads four bytes from the currently selected endpoint's bank in big endian format, for OUT
626 * direction endpoints.
628 * \ingroup Group_EndpointPrimitiveRW
630 * \return Next double word in the currently selected endpoint's FIFO buffer
632 static inline uint32_t Endpoint_Read_DWord_BE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE
;
633 static inline uint32_t Endpoint_Read_DWord_BE(void)
641 Data
.Bytes
[3] = UEDATX
;
642 Data
.Bytes
[2] = UEDATX
;
643 Data
.Bytes
[1] = UEDATX
;
644 Data
.Bytes
[0] = UEDATX
;
649 /** Writes four bytes to the currently selected endpoint's bank in little endian format, for IN
650 * direction endpoints.
652 * \ingroup Group_EndpointPrimitiveRW
654 * \param[in] DWord Next double word to write to the currently selected endpoint's FIFO buffer
656 static inline void Endpoint_Write_DWord_LE(const uint32_t DWord
) ATTR_ALWAYS_INLINE
;
657 static inline void Endpoint_Write_DWord_LE(const uint32_t DWord
)
659 UEDATX
= (DWord
& 0xFF);
660 UEDATX
= (DWord
>> 8);
661 UEDATX
= (DWord
>> 16);
662 UEDATX
= (DWord
>> 24);
665 /** Writes four bytes to the currently selected endpoint's bank in big endian format, for IN
666 * direction endpoints.
668 * \ingroup Group_EndpointPrimitiveRW
670 * \param[in] DWord Next double word to write to the currently selected endpoint's FIFO buffer
672 static inline void Endpoint_Write_DWord_BE(const uint32_t DWord
) ATTR_ALWAYS_INLINE
;
673 static inline void Endpoint_Write_DWord_BE(const uint32_t DWord
)
675 UEDATX
= (DWord
>> 24);
676 UEDATX
= (DWord
>> 16);
677 UEDATX
= (DWord
>> 8);
678 UEDATX
= (DWord
& 0xFF);
681 /** Discards four bytes from the currently selected endpoint's bank, for OUT direction endpoints.
683 * \ingroup Group_EndpointPrimitiveRW
685 static inline void Endpoint_Discard_DWord(void) ATTR_ALWAYS_INLINE
;
686 static inline void Endpoint_Discard_DWord(void)
696 /* External Variables: */
697 /** Global indicating the maximum packet size of the default control endpoint located at address
698 * 0 in the device. This value is set to the value indicated in the device descriptor in the user
699 * project once the USB interface is initialized into device mode.
701 * If space is an issue, it is possible to fix this to a static value by defining the control
702 * endpoint size in the FIXED_CONTROL_ENDPOINT_SIZE token passed to the compiler in the makefile
703 * via the -D switch. When a fixed control endpoint size is used, the size is no longer dynamically
704 * read from the descriptors at runtime and instead fixed to the given value. When used, it is
705 * important that the descriptor control endpoint size value matches the size given as the
706 * FIXED_CONTROL_ENDPOINT_SIZE token - it is recommended that the FIXED_CONTROL_ENDPOINT_SIZE token
707 * be used in the descriptors to ensure this.
709 * \note This variable should be treated as read-only in the user application, and never manually
712 #if (!defined(FIXED_CONTROL_ENDPOINT_SIZE) || defined(__DOXYGEN__))
713 extern uint8_t USB_ControlEndpointSize
;
715 #define USB_ControlEndpointSize FIXED_CONTROL_ENDPOINT_SIZE
718 /* Function Prototypes: */
719 #if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__)
720 #define __CALLBACK_PARAM , StreamCallbackPtr_t Callback
722 #define __CALLBACK_PARAM
725 /** Configures the specified endpoint number with the given endpoint type, direction, bank size
726 * and banking mode. Endpoints should be allocated in ascending order by their address in the
727 * device (i.e. endpoint 1 should be configured before endpoint 2 and so on) to prevent fragmentation
728 * of the USB FIFO memory.
730 * The endpoint type may be one of the EP_TYPE_* macros listed in LowLevel.h and the direction
731 * may be either \ref ENDPOINT_DIR_OUT or \ref ENDPOINT_DIR_IN.
733 * The bank size must indicate the maximum packet size that the endpoint can handle. Different
734 * endpoint numbers can handle different maximum packet sizes - refer to the chosen USB AVR's
735 * datasheet to determine the maximum bank size for each endpoint.
737 * The banking mode may be either \ref ENDPOINT_BANK_SINGLE or \ref ENDPOINT_BANK_DOUBLE.
739 * \note The default control endpoint does not have to be manually configured, as it is automatically
740 * configured by the library internally.
742 * \note This routine will select the specified endpoint, and the endpoint will remain selected
743 * once the routine completes regardless of if the endpoint configuration succeeds.
745 * \return Boolean true if the configuration succeeded, false otherwise
747 bool Endpoint_ConfigureEndpoint(const uint8_t Number
, const uint8_t Type
, const uint8_t Direction
,
748 const uint16_t Size
, const uint8_t Banks
);
750 /** Spin-loops until the currently selected non-control endpoint is ready for the next packet of data
751 * to be read or written to it.
753 * \note This routine should not be called on CONTROL type endpoints.
755 * \ingroup Group_EndpointRW
757 * \return A value from the \ref Endpoint_WaitUntilReady_ErrorCodes_t enum.
759 uint8_t Endpoint_WaitUntilReady(void);
761 /** Completes the status stage of a control transfer on a CONTROL type endpoint automatically,
762 * with respect to the data direction. This is a convenience function which can be used to
763 * simplify user control request handling.
765 void Endpoint_ClearStatusStage(void);
767 /** Reads and discards the given number of bytes from the endpoint from the given buffer,
768 * discarding fully read packets from the host as needed. The last packet is not automatically
769 * discarded once the remaining bytes has been read; the user is responsible for manually
770 * discarding the last packet from the host via the \ref Endpoint_ClearOUT() macro. Between
771 * each USB packet, the given stream callback function is executed repeatedly until the next
772 * packet is ready, allowing for early aborts of stream transfers.
774 * The callback routine should be created according to the information in \ref Group_StreamCallbacks.
775 * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are
776 * disabled and this function has the Callback parameter omitted.
778 * \note This routine should not be used on CONTROL type endpoints.
780 * \ingroup Group_EndpointStreamRW
782 * \param[in] Length Number of bytes to send via the currently selected endpoint.
783 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
785 * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
787 uint8_t Endpoint_Discard_Stream(uint16_t Length __CALLBACK_PARAM
);
789 /** Writes the given number of bytes to the endpoint from the given buffer in little endian,
790 * sending full packets to the host as needed. The last packet filled is not automatically sent;
791 * the user is responsible for manually sending the last written packet to the host via the
792 * \ref Endpoint_ClearIN() macro. Between each USB packet, the given stream callback function
793 * is executed repeatedly until the endpoint is ready to accept the next packet, allowing for early
794 * aborts of stream transfers.
796 * The callback routine should be created according to the information in \ref Group_StreamCallbacks.
797 * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are
798 * disabled and this function has the Callback parameter omitted.
800 * \note This routine should not be used on CONTROL type endpoints.
802 * \ingroup Group_EndpointStreamRW
804 * \param[in] Buffer Pointer to the source data buffer to read from.
805 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
806 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
808 * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
810 uint8_t Endpoint_Write_Stream_LE(const void* Buffer
, uint16_t Length __CALLBACK_PARAM
) ATTR_NON_NULL_PTR_ARG(1);
812 /** EEPROM buffer source version of \ref Endpoint_Write_Stream_LE().
814 * \ingroup Group_EndpointStreamRW
816 * \param[in] Buffer Pointer to the source data buffer to read from.
817 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
818 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
820 * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
822 uint8_t Endpoint_Write_EStream_LE(const void* Buffer
, uint16_t Length __CALLBACK_PARAM
) ATTR_NON_NULL_PTR_ARG(1);
824 /** FLASH buffer source version of \ref Endpoint_Write_Stream_LE().
826 * \note The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.
828 * \ingroup Group_EndpointStreamRW
830 * \param[in] Buffer Pointer to the source data buffer to read from.
831 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
832 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
834 * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
836 uint8_t Endpoint_Write_PStream_LE(const void* Buffer
, uint16_t Length __CALLBACK_PARAM
) ATTR_NON_NULL_PTR_ARG(1);
838 /** Writes the given number of bytes to the endpoint from the given buffer in big endian,
839 * sending full packets to the host as needed. The last packet filled is not automatically sent;
840 * the user is responsible for manually sending the last written packet to the host via the
841 * \ref Endpoint_ClearIN() macro. Between each USB packet, the given stream callback function
842 * is executed repeatedly until the endpoint is ready to accept the next packet, allowing for early
843 * aborts of stream transfers.
845 * The callback routine should be created according to the information in \ref Group_StreamCallbacks.
846 * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are
847 * disabled and this function has the Callback parameter omitted.
849 * \note This routine should not be used on CONTROL type endpoints.
851 * \ingroup Group_EndpointStreamRW
853 * \param[in] Buffer Pointer to the source data buffer to read from.
854 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
855 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
857 * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
859 uint8_t Endpoint_Write_Stream_BE(const void* Buffer
, uint16_t Length __CALLBACK_PARAM
) ATTR_NON_NULL_PTR_ARG(1);
861 /** EEPROM buffer source version of \ref Endpoint_Write_Stream_BE().
863 * \ingroup Group_EndpointStreamRW
865 * \param[in] Buffer Pointer to the source data buffer to read from.
866 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
867 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
869 * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
871 uint8_t Endpoint_Write_EStream_BE(const void* Buffer
, uint16_t Length __CALLBACK_PARAM
) ATTR_NON_NULL_PTR_ARG(1);
873 /** FLASH buffer source version of \ref Endpoint_Write_Stream_BE().
875 * \note The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.
877 * \ingroup Group_EndpointStreamRW
879 * \param[in] Buffer Pointer to the source data buffer to read from.
880 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
881 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
883 * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
885 uint8_t Endpoint_Write_PStream_BE(const void* Buffer
, uint16_t Length __CALLBACK_PARAM
) ATTR_NON_NULL_PTR_ARG(1);
887 /** Reads the given number of bytes from the endpoint from the given buffer in little endian,
888 * discarding fully read packets from the host as needed. The last packet is not automatically
889 * discarded once the remaining bytes has been read; the user is responsible for manually
890 * discarding the last packet from the host via the \ref Endpoint_ClearOUT() macro. Between
891 * each USB packet, the given stream callback function is executed repeatedly until the endpoint
892 * is ready to accept the next packet, allowing for early aborts of stream transfers.
894 * The callback routine should be created according to the information in \ref Group_StreamCallbacks.
895 * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are
896 * disabled and this function has the Callback parameter omitted.
898 * \note This routine should not be used on CONTROL type endpoints.
900 * \ingroup Group_EndpointStreamRW
902 * \param[out] Buffer Pointer to the destination data buffer to write to.
903 * \param[in] Length Number of bytes to send via the currently selected endpoint.
904 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
906 * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
908 uint8_t Endpoint_Read_Stream_LE(void* Buffer
, uint16_t Length __CALLBACK_PARAM
) ATTR_NON_NULL_PTR_ARG(1);
910 /** EEPROM buffer source version of \ref Endpoint_Read_Stream_LE().
912 * \ingroup Group_EndpointStreamRW
914 * \param[out] Buffer Pointer to the destination data buffer to write to, located in EEPROM memory space.
915 * \param[in] Length Number of bytes to send via the currently selected endpoint.
916 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
918 * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
920 uint8_t Endpoint_Read_EStream_LE(void* Buffer
, uint16_t Length __CALLBACK_PARAM
) ATTR_NON_NULL_PTR_ARG(1);
922 /** Reads the given number of bytes from the endpoint from the given buffer in big endian,
923 * discarding fully read packets from the host as needed. The last packet is not automatically
924 * discarded once the remaining bytes has been read; the user is responsible for manually
925 * discarding the last packet from the host via the \ref Endpoint_ClearOUT() macro. Between
926 * each USB packet, the given stream callback function is executed repeatedly until the endpoint
927 * is ready to accept the next packet, allowing for early aborts of stream transfers.
929 * The callback routine should be created according to the information in \ref Group_StreamCallbacks.
930 * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are
931 * disabled and this function has the Callback parameter omitted.
933 * \note This routine should not be used on CONTROL type endpoints.
935 * \ingroup Group_EndpointStreamRW
937 * \param[out] Buffer Pointer to the destination data buffer to write to.
938 * \param[in] Length Number of bytes to send via the currently selected endpoint.
939 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
941 * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
943 uint8_t Endpoint_Read_Stream_BE(void* Buffer
, uint16_t Length __CALLBACK_PARAM
) ATTR_NON_NULL_PTR_ARG(1);
945 /** EEPROM buffer source version of \ref Endpoint_Read_Stream_BE().
947 * \ingroup Group_EndpointStreamRW
949 * \param[out] Buffer Pointer to the destination data buffer to write to, located in EEPROM memory space.
950 * \param[in] Length Number of bytes to send via the currently selected endpoint.
951 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
953 * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
955 uint8_t Endpoint_Read_EStream_BE(void* Buffer
, uint16_t Length __CALLBACK_PARAM
) ATTR_NON_NULL_PTR_ARG(1);
957 /** Writes the given number of bytes to the CONTROL type endpoint from the given buffer in little endian,
958 * sending full packets to the host as needed. The host OUT acknowledgement is not automatically cleared
959 * in both failure and success states; the user is responsible for manually clearing the setup OUT to
960 * finalize the transfer via the \ref Endpoint_ClearOUT() macro.
962 * \note This function automatically clears the control transfer's status stage. Do not manually attempt
963 * to clear the status stage when using this routine in a control transaction.
965 * \note This routine should only be used on CONTROL type endpoints.
967 * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
968 * together; i.e. the entire stream data must be read or written at the one time.
970 * \ingroup Group_EndpointStreamRW
972 * \param[in] Buffer Pointer to the source data buffer to read from.
973 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
975 * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
977 uint8_t Endpoint_Write_Control_Stream_LE(const void* Buffer
, uint16_t Length
) ATTR_NON_NULL_PTR_ARG(1);
979 /** EEPROM buffer source version of Endpoint_Write_Control_Stream_LE.
981 * \note This function automatically clears the control transfer's status stage. Do not manually attempt
982 * to clear the status stage when using this routine in a control transaction.
984 * \note This routine should only be used on CONTROL type endpoints.
986 * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
987 * together; i.e. the entire stream data must be read or written at the one time.
989 * \ingroup Group_EndpointStreamRW
991 * \param[in] Buffer Pointer to the source data buffer to read from.
992 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
994 * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
996 uint8_t Endpoint_Write_Control_EStream_LE(const void* Buffer
, uint16_t Length
) ATTR_NON_NULL_PTR_ARG(1);
998 /** FLASH buffer source version of \ref Endpoint_Write_Control_Stream_LE().
1000 * \note This function automatically clears the control transfer's status stage. Do not manually attempt
1001 * to clear the status stage when using this routine in a control transaction.
1003 * \note The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.
1005 * \note This routine should only be used on CONTROL type endpoints.
1007 * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
1008 * together; i.e. the entire stream data must be read or written at the one time.
1010 * \ingroup Group_EndpointStreamRW
1012 * \param[in] Buffer Pointer to the source data buffer to read from.
1013 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
1015 * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
1017 uint8_t Endpoint_Write_Control_PStream_LE(const void* Buffer
, uint16_t Length
) ATTR_NON_NULL_PTR_ARG(1);
1019 /** Writes the given number of bytes to the CONTROL type endpoint from the given buffer in big endian,
1020 * sending full packets to the host as needed. The host OUT acknowledgement is not automatically cleared
1021 * in both failure and success states; the user is responsible for manually clearing the setup OUT to
1022 * finalize the transfer via the \ref Endpoint_ClearOUT() macro.
1024 * \note This function automatically clears the control transfer's status stage. Do not manually attempt
1025 * to clear the status stage when using this routine in a control transaction.
1027 * \note This routine should only be used on CONTROL type endpoints.
1029 * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
1030 * together; i.e. the entire stream data must be read or written at the one time.
1032 * \ingroup Group_EndpointStreamRW
1034 * \param[in] Buffer Pointer to the source data buffer to read from.
1035 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
1037 * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
1039 uint8_t Endpoint_Write_Control_Stream_BE(const void* Buffer
, uint16_t Length
) ATTR_NON_NULL_PTR_ARG(1);
1041 /** EEPROM buffer source version of \ref Endpoint_Write_Control_Stream_BE().
1043 * \note This function automatically clears the control transfer's status stage. Do not manually attempt
1044 * to clear the status stage when using this routine in a control transaction.
1046 * \note This routine should only be used on CONTROL type endpoints.
1048 * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
1049 * together; i.e. the entire stream data must be read or written at the one time.
1051 * \ingroup Group_EndpointStreamRW
1053 * \param[in] Buffer Pointer to the source data buffer to read from.
1054 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
1056 * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
1058 uint8_t Endpoint_Write_Control_EStream_BE(const void* Buffer
, uint16_t Length
) ATTR_NON_NULL_PTR_ARG(1);
1060 /** FLASH buffer source version of \ref Endpoint_Write_Control_Stream_BE().
1062 * \note This function automatically clears the control transfer's status stage. Do not manually attempt
1063 * to clear the status stage when using this routine in a control transaction.
1065 * \note The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.
1067 * \note This routine should only be used on CONTROL type endpoints.
1069 * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
1070 * together; i.e. the entire stream data must be read or written at the one time.
1072 * \ingroup Group_EndpointStreamRW
1074 * \param[in] Buffer Pointer to the source data buffer to read from.
1075 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
1077 * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
1079 uint8_t Endpoint_Write_Control_PStream_BE(const void* Buffer
, uint16_t Length
) ATTR_NON_NULL_PTR_ARG(1);
1081 /** Reads the given number of bytes from the CONTROL endpoint from the given buffer in little endian,
1082 * discarding fully read packets from the host as needed. The device IN acknowledgement is not
1083 * automatically sent after success or failure states; the user is responsible for manually sending the
1084 * setup IN to finalize the transfer via the \ref Endpoint_ClearIN() macro.
1086 * \note This function automatically clears the control transfer's status stage. Do not manually attempt
1087 * to clear the status stage when using this routine in a control transaction.
1089 * \note This routine should only be used on CONTROL type endpoints.
1091 * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
1092 * together; i.e. the entire stream data must be read or written at the one time.
1094 * \ingroup Group_EndpointStreamRW
1096 * \param[out] Buffer Pointer to the destination data buffer to write to.
1097 * \param[in] Length Number of bytes to send via the currently selected endpoint.
1099 * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
1101 uint8_t Endpoint_Read_Control_Stream_LE(void* Buffer
, uint16_t Length
) ATTR_NON_NULL_PTR_ARG(1);
1103 /** EEPROM buffer source version of \ref Endpoint_Read_Control_Stream_LE().
1105 * \note This function automatically clears the control transfer's status stage. Do not manually attempt
1106 * to clear the status stage when using this routine in a control transaction.
1108 * \note This routine should only be used on CONTROL type endpoints.
1110 * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
1111 * together; i.e. the entire stream data must be read or written at the one time.
1113 * \ingroup Group_EndpointStreamRW
1115 * \param[out] Buffer Pointer to the destination data buffer to write to.
1116 * \param[in] Length Number of bytes to send via the currently selected endpoint.
1118 * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
1120 uint8_t Endpoint_Read_Control_EStream_LE(void* Buffer
, uint16_t Length
) ATTR_NON_NULL_PTR_ARG(1);
1122 /** Reads the given number of bytes from the CONTROL endpoint from the given buffer in big endian,
1123 * discarding fully read packets from the host as needed. The device IN acknowledgement is not
1124 * automatically sent after success or failure states; the user is responsible for manually sending the
1125 * setup IN to finalize the transfer via the \ref Endpoint_ClearIN() macro.
1127 * \note This function automatically clears the control transfer's status stage. Do not manually attempt
1128 * to clear the status stage when using this routine in a control transaction.
1130 * \note This routine should only be used on CONTROL type endpoints.
1132 * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
1133 * together; i.e. the entire stream data must be read or written at the one time.
1135 * \ingroup Group_EndpointStreamRW
1137 * \param[out] Buffer Pointer to the destination data buffer to write to.
1138 * \param[in] Length Number of bytes to send via the currently selected endpoint.
1140 * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
1142 uint8_t Endpoint_Read_Control_Stream_BE(void* Buffer
, uint16_t Length
) ATTR_NON_NULL_PTR_ARG(1);
1144 /** EEPROM buffer source version of \ref Endpoint_Read_Control_Stream_BE().
1146 * \note This function automatically clears the control transfer's status stage. Do not manually attempt
1147 * to clear the status stage when using this routine in a control transaction.
1149 * \note This routine should only be used on CONTROL type endpoints.
1151 * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
1152 * together; i.e. the entire stream data must be read or written at the one time.
1154 * \ingroup Group_EndpointStreamRW
1156 * \param[out] Buffer Pointer to the destination data buffer to write to.
1157 * \param[in] Length Number of bytes to send via the currently selected endpoint.
1159 * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
1161 uint8_t Endpoint_Read_Control_EStream_BE(void* Buffer
, uint16_t Length
) ATTR_NON_NULL_PTR_ARG(1);
1163 /* Private Interface - For use in library only: */
1164 #if !defined(__DOXYGEN__)
1166 #define Endpoint_AllocateMemory() MACROS{ UECFG1X |= (1 << ALLOC); }MACROE
1167 #define Endpoint_DeallocateMemory() MACROS{ UECFG1X &= ~(1 << ALLOC); }MACROE
1169 #define _ENDPOINT_GET_MAXSIZE(n) _ENDPOINT_GET_MAXSIZE2(ENDPOINT_DETAILS_EP ## n)
1170 #define _ENDPOINT_GET_MAXSIZE2(details) _ENDPOINT_GET_MAXSIZE3(details)
1171 #define _ENDPOINT_GET_MAXSIZE3(maxsize, db) maxsize
1173 #define _ENDPOINT_GET_DOUBLEBANK(n) _ENDPOINT_GET_DOUBLEBANK2(ENDPOINT_DETAILS_EP ## n)
1174 #define _ENDPOINT_GET_DOUBLEBANK2(details) _ENDPOINT_GET_DOUBLEBANK3(details)
1175 #define _ENDPOINT_GET_DOUBLEBANK3(maxsize, db) db
1177 #if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)
1178 #define ENDPOINT_DETAILS_EP0 64, true
1179 #define ENDPOINT_DETAILS_EP1 256, true
1180 #define ENDPOINT_DETAILS_EP2 64, true
1181 #define ENDPOINT_DETAILS_EP3 64, true
1182 #define ENDPOINT_DETAILS_EP4 64, true
1183 #define ENDPOINT_DETAILS_EP5 64, true
1184 #define ENDPOINT_DETAILS_EP6 64, true
1186 #define ENDPOINT_DETAILS_EP0 64, true
1187 #define ENDPOINT_DETAILS_EP1 64, false
1188 #define ENDPOINT_DETAILS_EP2 64, false
1189 #define ENDPOINT_DETAILS_EP3 64, true
1190 #define ENDPOINT_DETAILS_EP4 64, true
1193 #define Endpoint_ConfigureEndpoint(Number, Type, Direction, Size, Banks) \
1194 Endpoint_ConfigureEndpoint_Prv((Number), \
1195 (((Type) << EPTYPE0) | (Direction)), \
1196 ((1 << ALLOC) | (Banks) | \
1197 (__builtin_constant_p(Size) ? \
1198 Endpoint_BytesToEPSizeMask(Size) : \
1199 Endpoint_BytesToEPSizeMaskDynamic(Size))))
1201 /* Function Prototypes: */
1202 void Endpoint_ClearEndpoints(void);
1203 uint8_t Endpoint_BytesToEPSizeMaskDynamic(const uint16_t Size
);
1204 bool Endpoint_ConfigureEndpoint_Prv(const uint8_t Number
, const uint8_t UECFG0XData
, const uint8_t UECFG1XData
);
1206 /* Inline Functions: */
1207 static inline uint8_t Endpoint_BytesToEPSizeMask(const uint16_t Bytes
) ATTR_WARN_UNUSED_RESULT ATTR_CONST ATTR_ALWAYS_INLINE
;
1208 static inline uint8_t Endpoint_BytesToEPSizeMask(const uint16_t Bytes
)
1210 uint8_t MaskVal
= 0;
1211 uint16_t CheckBytes
= 8;
1213 while (CheckBytes
< Bytes
)
1219 return (MaskVal
<< EPSIZE0
);
1224 /* Disable C linkage for C++ Compilers: */
1225 #if defined(__cplusplus)