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__
69 #if defined(__AVR32__)
73 #elif defined(__AVR__)
75 #include <avr/pgmspace.h>
76 #include <avr/eeprom.h>
80 #include "../../../Common/Common.h"
81 #include "../HighLevel/USBTask.h"
83 #if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__)
84 #include "../HighLevel/StreamCallbacks.h"
87 /* Enable C linkage for C++ Compilers: */
88 #if defined(__cplusplus)
92 /* Preprocessor Checks: */
93 #if !defined(__INCLUDE_FROM_USB_DRIVER)
94 #error Do not include this file directly. Include LUFA/Drivers/USB.h instead.
97 /* Public Interface - May be used in end-application: */
99 /** Endpoint data direction mask for \ref Endpoint_ConfigureEndpoint(). This indicates that the endpoint
100 * should be initialized in the OUT direction - i.e. data flows from host to device.
102 #define ENDPOINT_DIR_OUT (0 << EPDIR)
104 /** Endpoint data direction mask for \ref Endpoint_ConfigureEndpoint(). This indicates that the endpoint
105 * should be initialized in the IN direction - i.e. data flows from device to host.
107 #define ENDPOINT_DIR_IN (1 << EPDIR)
109 /** Mask for the bank mode selection for the \ref Endpoint_ConfigureEndpoint() macro. This indicates
110 * that the endpoint should have one single bank, which requires less USB FIFO memory but results
111 * in slower transfers as only one USB device (the AVR or the host) can access the endpoint's
112 * bank at the one time.
114 #define ENDPOINT_BANK_SINGLE (0 << EPBK0)
116 /** Mask for the bank mode selection for the \ref Endpoint_ConfigureEndpoint() macro. This indicates
117 * that the endpoint should have two banks, which requires more USB FIFO memory but results
118 * in faster transfers as one USB device (the AVR or the host) can access one bank while the other
119 * accesses the second bank.
121 #define ENDPOINT_BANK_DOUBLE (1 << EPBK0)
123 /** Endpoint address for the default control endpoint, which always resides in address 0. This is
124 * defined for convenience to give more readable code when used with the endpoint macros.
126 #define ENDPOINT_CONTROLEP 0
128 #if (!defined(FIXED_CONTROL_ENDPOINT_SIZE) || defined(__DOXYGEN__))
129 /** Default size of the default control endpoint's bank, until altered by the Endpoint0Size value
130 * in the device descriptor. Not available if the FIXED_CONTROL_ENDPOINT_SIZE token is defined.
132 #define ENDPOINT_CONTROLEP_DEFAULT_SIZE 8
135 /** Endpoint number mask, for masking against endpoint addresses to retrieve the endpoint's
136 * numerical address in the device.
138 #define ENDPOINT_EPNUM_MASK 0x07
140 /** Endpoint direction mask, for masking against endpoint addresses to retrieve the endpoint's
141 * direction for comparing with the ENDPOINT_DESCRIPTOR_DIR_* masks.
143 #define ENDPOINT_EPDIR_MASK 0x80
145 /** Endpoint bank size mask, for masking against endpoint addresses to retrieve the endpoint's
146 * bank size in the device.
148 #define ENDPOINT_EPSIZE_MASK 0x7FF
150 /** Maximum size in bytes of a given endpoint.
152 * \param[in] n Endpoint number, a value between 0 and (ENDPOINT_TOTAL_ENDPOINTS - 1)
154 #define ENDPOINT_MAX_SIZE(n) _ENDPOINT_GET_MAXSIZE(n)
156 /** Indicates if the given endpoint supports double banking.
158 * \param[in] n Endpoint number, a value between 0 and (ENDPOINT_TOTAL_ENDPOINTS - 1)
160 #define ENDPOINT_DOUBLEBANK_SUPPORTED(n) _ENDPOINT_GET_DOUBLEBANK(n)
162 #if !defined(CONTROL_ONLY_DEVICE)
163 #if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR) || defined(__DOXYGEN__)
164 /** Total number of endpoints (including the default control endpoint at address 0) which may
165 * be used in the device. Different USB AVR models support different amounts of endpoints,
166 * this value reflects the maximum number of endpoints for the currently selected AVR model.
168 #define ENDPOINT_TOTAL_ENDPOINTS 7
170 #define ENDPOINT_TOTAL_ENDPOINTS 5
173 #define ENDPOINT_TOTAL_ENDPOINTS 1
176 /* Pseudo-Function Macros: */
177 #if defined(__DOXYGEN__)
178 /** Indicates the number of bytes currently stored in the current endpoint's selected bank.
180 * \note The return width of this function may differ, depending on the maximum endpoint bank size
181 * of the selected AVR model.
183 * \ingroup Group_EndpointRW
185 * \return Total number of bytes in the currently selected Endpoint's FIFO buffer
187 static inline uint16_t Endpoint_BytesInEndpoint(void);
189 /** Get the endpoint address of the currently selected endpoint. This is typically used to save
190 * the currently selected endpoint number so that it can be restored after another endpoint has
193 * \return Index of the currently selected endpoint
195 static inline uint8_t Endpoint_GetCurrentEndpoint(void);
197 /** Selects the given endpoint number. If the address from the device descriptors is used, the
198 * value should be masked with the \ref ENDPOINT_EPNUM_MASK constant to extract only the endpoint
199 * number (and discarding the endpoint direction bit).
201 * Any endpoint operations which do not require the endpoint number to be indicated will operate on
202 * the currently selected endpoint.
204 * \param[in] EndpointNumber Endpoint number to select
206 static inline void Endpoint_SelectEndpoint(uint8_t EndpointNumber
);
208 /** Resets the endpoint bank FIFO. This clears all the endpoint banks and resets the USB controller's
209 * In and Out pointers to the bank's contents.
211 * \param[in] EndpointNumber Endpoint number whose FIFO buffers are to be reset
213 static inline void Endpoint_ResetFIFO(uint8_t EndpointNumber
);
215 /** Enables the currently selected endpoint so that data can be sent and received through it to
218 * \note Endpoints must first be configured properly via \ref Endpoint_ConfigureEndpoint().
220 static inline void Endpoint_EnableEndpoint(void);
222 /** Disables the currently selected endpoint so that data cannot be sent and received through it
223 * to and from a host.
225 static inline void Endpoint_DisableEndpoint(void);
227 /** Determines if the currently selected endpoint is enabled, but not necessarily configured.
229 * \return Boolean True if the currently selected endpoint is enabled, false otherwise
231 static inline bool Endpoint_IsEnabled(void);
233 /** Determines if the currently selected endpoint may be read from (if data is waiting in the endpoint
234 * bank and the endpoint is an OUT direction, or if the bank is not yet full if the endpoint is an IN
235 * direction). This function will return false if an error has occurred in the endpoint, if the endpoint
236 * is an OUT direction and no packet (or an empty packet) has been received, or if the endpoint is an IN
237 * direction and the endpoint bank is full.
239 * \ingroup Group_EndpointPacketManagement
241 * \return Boolean true if the currently selected endpoint may be read from or written to, depending on its direction
243 static inline bool Endpoint_IsReadWriteAllowed(void);
245 /** Determines if the currently selected endpoint is configured.
247 * \return Boolean true if the currently selected endpoint has been configured, false otherwise
249 static inline bool Endpoint_IsConfigured(void);
251 /** Returns a mask indicating which INTERRUPT type endpoints have interrupted - i.e. their
252 * interrupt duration has elapsed. Which endpoints have interrupted can be determined by
253 * masking the return value against (1 << {Endpoint Number}).
255 * \return Mask whose bits indicate which endpoints have interrupted
257 static inline uint8_t Endpoint_GetEndpointInterrupts(void);
259 /** Determines if the specified endpoint number has interrupted (valid only for INTERRUPT type
262 * \param[in] EndpointNumber Index of the endpoint whose interrupt flag should be tested
264 * \return Boolean true if the specified endpoint has interrupted, false otherwise
266 static inline bool Endpoint_HasEndpointInterrupted(uint8_t EndpointNumber
);
268 /** Determines if the selected IN endpoint is ready for a new packet.
270 * \ingroup Group_EndpointPacketManagement
272 * \return Boolean true if the current endpoint is ready for an IN packet, false otherwise.
274 static inline bool Endpoint_IsINReady(void);
276 /** Determines if the selected OUT endpoint has received new packet.
278 * \ingroup Group_EndpointPacketManagement
280 * \return Boolean true if current endpoint is has received an OUT packet, false otherwise.
282 static inline bool Endpoint_IsOUTReceived(void);
284 /** Determines if the current CONTROL type endpoint has received a SETUP packet.
286 * \ingroup Group_EndpointPacketManagement
288 * \return Boolean true if the selected endpoint has received a SETUP packet, false otherwise.
290 static inline bool Endpoint_IsSETUPReceived(void);
292 /** Clears a received SETUP packet on the currently selected CONTROL type endpoint, freeing up the
293 * endpoint for the next packet.
295 * \ingroup Group_EndpointPacketManagement
297 * \note This is not applicable for non CONTROL type endpoints.
299 static inline void Endpoint_ClearSETUP(void);
301 /** Sends an IN packet to the host on the currently selected endpoint, freeing up the endpoint for the
302 * next packet and switching to the alternative endpoint bank if double banked.
304 * \ingroup Group_EndpointPacketManagement
306 static inline void Endpoint_ClearIN(void);
308 /** Acknowledges an OUT packet to the host on the currently selected endpoint, freeing up the endpoint
309 * for the next packet and switching to the alternative endpoint bank if double banked.
311 * \ingroup Group_EndpointPacketManagement
313 static inline void Endpoint_ClearOUT(void);
315 /** Stalls the current endpoint, indicating to the host that a logical problem occurred with the
316 * indicated endpoint and that the current transfer sequence should be aborted. This provides a
317 * way for devices to indicate invalid commands to the host so that the current transfer can be
318 * aborted and the host can begin its own recovery sequence.
320 * The currently selected endpoint remains stalled until either the \ref Endpoint_ClearStall() macro
321 * is called, or the host issues a CLEAR FEATURE request to the device for the currently selected
324 * \ingroup Group_EndpointPacketManagement
326 static inline void Endpoint_StallTransaction(void);
328 /** Clears the STALL condition on the currently selected endpoint.
330 * \ingroup Group_EndpointPacketManagement
332 static inline void Endpoint_ClearStall(void);
334 /** Determines if the currently selected endpoint is stalled, false otherwise.
336 * \ingroup Group_EndpointPacketManagement
338 * \return Boolean true if the currently selected endpoint is stalled, false otherwise
340 static inline bool Endpoint_IsStalled(void);
342 /** Resets the data toggle of the currently selected endpoint. */
343 static inline void Endpoint_ResetDataToggle(void);
345 /** Determines the currently selected endpoint's direction.
347 * \return The currently selected endpoint's direction, as a ENDPOINT_DIR_* mask.
349 static inline uint8_t Endpoint_GetEndpointDirection(void);
351 /** Sets the direction of the currently selected endpoint.
353 * \param[in] DirectionMask New endpoint direction, as a ENDPOINT_DIR_* mask.
355 static inline void Endpoint_SetEndpointDirection(uint8_t DirectionMask
);
357 #if defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)
358 #define Endpoint_BytesInEndpoint() UEBCX
359 #elif defined(USB_SERIES_4_AVR)
360 #define Endpoint_BytesInEndpoint() (((uint16_t)UEBCHX << 8) | UEBCLX)
361 #elif defined(USB_SERIES_2_AVR)
362 #define Endpoint_BytesInEndpoint() UEBCLX
365 #if !defined(CONTROL_ONLY_DEVICE)
366 #define Endpoint_GetCurrentEndpoint() (UENUM & ENDPOINT_EPNUM_MASK)
368 #define Endpoint_GetCurrentEndpoint() ENDPOINT_CONTROLEP
371 #if !defined(CONTROL_ONLY_DEVICE)
372 #define Endpoint_SelectEndpoint(epnum) MACROS{ UENUM = (epnum); }MACROE
374 #define Endpoint_SelectEndpoint(epnum) (void)(epnum)
377 #define Endpoint_ResetFIFO(epnum) MACROS{ UERST = (1 << (epnum)); UERST = 0; }MACROE
379 #define Endpoint_EnableEndpoint() MACROS{ UECONX |= (1 << EPEN); }MACROE
381 #define Endpoint_DisableEndpoint() MACROS{ UECONX &= ~(1 << EPEN); }MACROE
383 #define Endpoint_IsEnabled() ((UECONX & (1 << EPEN)) ? true : false)
385 #if !defined(CONTROL_ONLY_DEVICE)
386 #define Endpoint_IsReadWriteAllowed() ((UEINTX & (1 << RWAL)) ? true : false)
389 #define Endpoint_IsConfigured() ((UESTA0X & (1 << CFGOK)) ? true : false)
391 #define Endpoint_GetEndpointInterrupts() UEINT
393 #define Endpoint_HasEndpointInterrupted(n) ((UEINT & (1 << (n))) ? true : false)
395 #define Endpoint_IsINReady() ((UEINTX & (1 << TXINI)) ? true : false)
397 #define Endpoint_IsOUTReceived() ((UEINTX & (1 << RXOUTI)) ? true : false)
399 #define Endpoint_IsSETUPReceived() ((UEINTX & (1 << RXSTPI)) ? true : false)
401 #define Endpoint_ClearSETUP() MACROS{ UEINTX &= ~(1 << RXSTPI); }MACROE
403 #if !defined(CONTROL_ONLY_DEVICE)
404 #define Endpoint_ClearIN() MACROS{ uint8_t Temp = UEINTX; UEINTX = (Temp & ~(1 << TXINI)); \
405 UEINTX = (Temp & ~(1 << FIFOCON)); }MACROE
407 #define Endpoint_ClearIN() MACROS{ UEINTX &= ~(1 << TXINI); }MACROE
410 #if !defined(CONTROL_ONLY_DEVICE)
411 #define Endpoint_ClearOUT() MACROS{ uint8_t Temp = UEINTX; UEINTX = (Temp & ~(1 << RXOUTI)); \
412 UEINTX = (Temp & ~(1 << FIFOCON)); }MACROE
414 #define Endpoint_ClearOUT() MACROS{ UEINTX &= ~(1 << RXOUTI); }MACROE
417 #define Endpoint_StallTransaction() MACROS{ UECONX |= (1 << STALLRQ); }MACROE
419 #define Endpoint_ClearStall() MACROS{ UECONX |= (1 << STALLRQC); }MACROE
421 #define Endpoint_IsStalled() ((UECONX & (1 << STALLRQ)) ? true : false)
423 #define Endpoint_ResetDataToggle() MACROS{ UECONX |= (1 << RSTDT); }MACROE
425 #define Endpoint_GetEndpointDirection() (UECFG0X & ENDPOINT_DIR_IN)
427 #define Endpoint_SetEndpointDirection(dir) MACROS{ UECFG0X = ((UECFG0X & ~ENDPOINT_DIR_IN) | (dir)); }MACROE
431 /** Enum for the possible error return codes of the \ref Endpoint_WaitUntilReady() function.
433 * \ingroup Group_EndpointRW
435 enum Endpoint_WaitUntilReady_ErrorCodes_t
437 ENDPOINT_READYWAIT_NoError
= 0, /**< Endpoint is ready for next packet, no error. */
438 ENDPOINT_READYWAIT_EndpointStalled
= 1, /**< The endpoint was stalled during the stream
439 * transfer by the host or device.
441 ENDPOINT_READYWAIT_DeviceDisconnected
= 2, /**< Device was disconnected from the host while
442 * waiting for the endpoint to become ready.
444 ENDPOINT_READYWAIT_Timeout
= 3, /**< The host failed to accept or send the next packet
445 * within the software timeout period set by the
446 * \ref USB_STREAM_TIMEOUT_MS macro.
450 /** Enum for the possible error return codes of the Endpoint_*_Stream_* functions.
452 * \ingroup Group_EndpointStreamRW
454 enum Endpoint_Stream_RW_ErrorCodes_t
456 ENDPOINT_RWSTREAM_NoError
= 0, /**< Command completed successfully, no error. */
457 ENDPOINT_RWSTREAM_EndpointStalled
= 1, /**< The endpoint was stalled during the stream
458 * transfer by the host or device.
460 ENDPOINT_RWSTREAM_DeviceDisconnected
= 2, /**< Device was disconnected from the host during
463 ENDPOINT_RWSTREAM_Timeout
= 3, /**< The host failed to accept or send the next packet
464 * within the software timeout period set by the
465 * \ref USB_STREAM_TIMEOUT_MS macro.
467 ENDPOINT_RWSTREAM_CallbackAborted
= 4, /**< Indicates that the stream's callback function
468 * aborted the transfer early.
472 /** Enum for the possible error return codes of the Endpoint_*_Control_Stream_* functions..
474 * \ingroup Group_EndpointStreamRW
476 enum Endpoint_ControlStream_RW_ErrorCodes_t
478 ENDPOINT_RWCSTREAM_NoError
= 0, /**< Command completed successfully, no error. */
479 ENDPOINT_RWCSTREAM_HostAborted
= 1, /**< The aborted the transfer prematurely. */
480 ENDPOINT_RWCSTREAM_DeviceDisconnected
= 2, /**< Device was disconnected from the host during
485 /* Inline Functions: */
486 /** Reads one byte from the currently selected endpoint's bank, for OUT direction endpoints.
488 * \ingroup Group_EndpointPrimitiveRW
490 * \return Next byte in the currently selected endpoint's FIFO buffer
492 static inline uint8_t Endpoint_Read_Byte(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE
;
493 static inline uint8_t Endpoint_Read_Byte(void)
495 #if defined(__AVR32__)
497 #elif defined(__AVR__)
502 /** Writes one byte from the currently selected endpoint's bank, for IN direction endpoints.
504 * \ingroup Group_EndpointPrimitiveRW
506 * \param[in] Byte Next byte to write into the the currently selected endpoint's FIFO buffer
508 static inline void Endpoint_Write_Byte(const uint8_t Byte
) ATTR_ALWAYS_INLINE
;
509 static inline void Endpoint_Write_Byte(const uint8_t Byte
)
511 #if defined(__AVR32__)
513 #elif defined(__AVR__)
518 /** Discards one byte from the currently selected endpoint's bank, for OUT direction endpoints.
520 * \ingroup Group_EndpointPrimitiveRW
522 static inline void Endpoint_Discard_Byte(void) ATTR_ALWAYS_INLINE
;
523 static inline void Endpoint_Discard_Byte(void)
527 #if defined(__AVR32__)
529 #elif defined(__AVR__)
534 /** Reads two bytes from the currently selected endpoint's bank in little endian format, for OUT
535 * direction endpoints.
537 * \ingroup Group_EndpointPrimitiveRW
539 * \return Next word in the currently selected endpoint's FIFO buffer
541 static inline uint16_t Endpoint_Read_Word_LE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE
;
542 static inline uint16_t Endpoint_Read_Word_LE(void)
550 #if defined(__AVR32__)
552 #elif defined(__AVR__)
553 Data
.Bytes
[0] = UEDATX
;
554 Data
.Bytes
[1] = UEDATX
;
560 /** Reads two bytes from the currently selected endpoint's bank in big endian format, for OUT
561 * direction endpoints.
563 * \ingroup Group_EndpointPrimitiveRW
565 * \return Next word in the currently selected endpoint's FIFO buffer
567 static inline uint16_t Endpoint_Read_Word_BE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE
;
568 static inline uint16_t Endpoint_Read_Word_BE(void)
576 #if defined(__AVR32__)
578 #elif defined(__AVR__)
579 Data
.Bytes
[1] = UEDATX
;
580 Data
.Bytes
[0] = UEDATX
;
586 /** Writes two bytes to the currently selected endpoint's bank in little endian format, for IN
587 * direction endpoints.
589 * \ingroup Group_EndpointPrimitiveRW
591 * \param[in] Word Next word to write to the currently selected endpoint's FIFO buffer
593 static inline void Endpoint_Write_Word_LE(const uint16_t Word
) ATTR_ALWAYS_INLINE
;
594 static inline void Endpoint_Write_Word_LE(const uint16_t Word
)
596 #if defined(__AVR32__)
598 #elif defined(__AVR__)
599 UEDATX
= (Word
& 0xFF);
600 UEDATX
= (Word
>> 8);
604 /** Writes two bytes to the currently selected endpoint's bank in big endian format, for IN
605 * direction endpoints.
607 * \ingroup Group_EndpointPrimitiveRW
609 * \param[in] Word Next word to write to the currently selected endpoint's FIFO buffer
611 static inline void Endpoint_Write_Word_BE(const uint16_t Word
) ATTR_ALWAYS_INLINE
;
612 static inline void Endpoint_Write_Word_BE(const uint16_t Word
)
614 #if defined(__AVR32__)
616 #elif defined(__AVR__)
617 UEDATX
= (Word
>> 8);
618 UEDATX
= (Word
& 0xFF);
622 /** Discards two bytes from the currently selected endpoint's bank, for OUT direction endpoints.
624 * \ingroup Group_EndpointPrimitiveRW
626 static inline void Endpoint_Discard_Word(void) ATTR_ALWAYS_INLINE
;
627 static inline void Endpoint_Discard_Word(void)
631 #if defined(__AVR32__)
633 #elif defined(__AVR__)
639 /** Reads four bytes from the currently selected endpoint's bank in little endian format, for OUT
640 * direction endpoints.
642 * \ingroup Group_EndpointPrimitiveRW
644 * \return Next double word in the currently selected endpoint's FIFO buffer
646 static inline uint32_t Endpoint_Read_DWord_LE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE
;
647 static inline uint32_t Endpoint_Read_DWord_LE(void)
655 #if defined(__AVR32__)
657 #elif defined(__AVR__)
658 Data
.Bytes
[0] = UEDATX
;
659 Data
.Bytes
[1] = UEDATX
;
660 Data
.Bytes
[2] = UEDATX
;
661 Data
.Bytes
[3] = UEDATX
;
667 /** Reads four bytes from the currently selected endpoint's bank in big endian format, for OUT
668 * direction endpoints.
670 * \ingroup Group_EndpointPrimitiveRW
672 * \return Next double word in the currently selected endpoint's FIFO buffer
674 static inline uint32_t Endpoint_Read_DWord_BE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE
;
675 static inline uint32_t Endpoint_Read_DWord_BE(void)
683 #if defined(__AVR32__)
685 #elif defined(__AVR__)
686 Data
.Bytes
[3] = UEDATX
;
687 Data
.Bytes
[2] = UEDATX
;
688 Data
.Bytes
[1] = UEDATX
;
689 Data
.Bytes
[0] = UEDATX
;
695 /** Writes four bytes to the currently selected endpoint's bank in little endian format, for IN
696 * direction endpoints.
698 * \ingroup Group_EndpointPrimitiveRW
700 * \param[in] DWord Next double word to write to the currently selected endpoint's FIFO buffer
702 static inline void Endpoint_Write_DWord_LE(const uint32_t DWord
) ATTR_ALWAYS_INLINE
;
703 static inline void Endpoint_Write_DWord_LE(const uint32_t DWord
)
705 #if defined(__AVR32__)
707 #elif defined(__AVR__)
708 UEDATX
= (DWord
& 0xFF);
709 UEDATX
= (DWord
>> 8);
710 UEDATX
= (DWord
>> 16);
711 UEDATX
= (DWord
>> 24);
715 /** Writes four bytes to the currently selected endpoint's bank in big endian format, for IN
716 * direction endpoints.
718 * \ingroup Group_EndpointPrimitiveRW
720 * \param[in] DWord Next double word to write to the currently selected endpoint's FIFO buffer
722 static inline void Endpoint_Write_DWord_BE(const uint32_t DWord
) ATTR_ALWAYS_INLINE
;
723 static inline void Endpoint_Write_DWord_BE(const uint32_t DWord
)
725 #if defined(__AVR32__)
727 #elif defined(__AVR__)
728 UEDATX
= (DWord
>> 24);
729 UEDATX
= (DWord
>> 16);
730 UEDATX
= (DWord
>> 8);
731 UEDATX
= (DWord
& 0xFF);
735 /** Discards four bytes from the currently selected endpoint's bank, for OUT direction endpoints.
737 * \ingroup Group_EndpointPrimitiveRW
739 static inline void Endpoint_Discard_DWord(void) ATTR_ALWAYS_INLINE
;
740 static inline void Endpoint_Discard_DWord(void)
744 #if defined(__AVR32__)
746 #elif defined(__AVR__)
754 /* External Variables: */
755 /** Global indicating the maximum packet size of the default control endpoint located at address
756 * 0 in the device. This value is set to the value indicated in the device descriptor in the user
757 * project once the USB interface is initialized into device mode.
759 * If space is an issue, it is possible to fix this to a static value by defining the control
760 * endpoint size in the FIXED_CONTROL_ENDPOINT_SIZE token passed to the compiler in the makefile
761 * via the -D switch. When a fixed control endpoint size is used, the size is no longer dynamically
762 * read from the descriptors at runtime and instead fixed to the given value. When used, it is
763 * important that the descriptor control endpoint size value matches the size given as the
764 * FIXED_CONTROL_ENDPOINT_SIZE token - it is recommended that the FIXED_CONTROL_ENDPOINT_SIZE token
765 * be used in the descriptors to ensure this.
767 * \note This variable should be treated as read-only in the user application, and never manually
770 #if (!defined(FIXED_CONTROL_ENDPOINT_SIZE) || defined(__DOXYGEN__))
771 extern uint8_t USB_ControlEndpointSize
;
773 #define USB_ControlEndpointSize FIXED_CONTROL_ENDPOINT_SIZE
776 /* Function Prototypes: */
777 #if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__)
778 #define __CALLBACK_PARAM , StreamCallbackPtr_t Callback
780 #define __CALLBACK_PARAM
783 /** Configures the specified endpoint number with the given endpoint type, direction, bank size
784 * and banking mode. Endpoints should be allocated in ascending order by their address in the
785 * device (i.e. endpoint 1 should be configured before endpoint 2 and so on) to prevent fragmentation
786 * of the USB FIFO memory.
788 * The endpoint type may be one of the EP_TYPE_* macros listed in LowLevel.h and the direction
789 * may be either \ref ENDPOINT_DIR_OUT or \ref ENDPOINT_DIR_IN.
791 * The bank size must indicate the maximum packet size that the endpoint can handle. Different
792 * endpoint numbers can handle different maximum packet sizes - refer to the chosen USB AVR's
793 * datasheet to determine the maximum bank size for each endpoint.
795 * The banking mode may be either \ref ENDPOINT_BANK_SINGLE or \ref ENDPOINT_BANK_DOUBLE.
797 * \note The default control endpoint does not have to be manually configured, as it is automatically
798 * configured by the library internally.
800 * \note This routine will select the specified endpoint, and the endpoint will remain selected
801 * once the routine completes regardless of if the endpoint configuration succeeds.
803 * \return Boolean true if the configuration succeeded, false otherwise
805 bool Endpoint_ConfigureEndpoint(const uint8_t Number
, const uint8_t Type
, const uint8_t Direction
,
806 const uint16_t Size
, const uint8_t Banks
);
808 /** Spin-loops until the currently selected non-control endpoint is ready for the next packet of data
809 * to be read or written to it.
811 * \note This routine should not be called on CONTROL type endpoints.
813 * \ingroup Group_EndpointRW
815 * \return A value from the \ref Endpoint_WaitUntilReady_ErrorCodes_t enum.
817 uint8_t Endpoint_WaitUntilReady(void);
819 /** Completes the status stage of a control transfer on a CONTROL type endpoint automatically,
820 * with respect to the data direction. This is a convenience function which can be used to
821 * simplify user control request handling.
823 void Endpoint_ClearStatusStage(void);
825 /** Reads and discards the given number of bytes from the endpoint from the given buffer,
826 * discarding fully read packets from the host as needed. The last packet is not automatically
827 * discarded once the remaining bytes has been read; the user is responsible for manually
828 * discarding the last packet from the host via the \ref Endpoint_ClearOUT() macro. Between
829 * each USB packet, the given stream callback function is executed repeatedly until the next
830 * packet is ready, allowing for early aborts of stream transfers.
832 * The callback routine should be created according to the information in \ref Group_StreamCallbacks.
833 * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are
834 * disabled and this function has the Callback parameter omitted.
836 * \note This routine should not be used on CONTROL type endpoints.
838 * \ingroup Group_EndpointStreamRW
840 * \param[in] Length Number of bytes to send via the currently selected endpoint.
841 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
843 * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
845 uint8_t Endpoint_Discard_Stream(uint16_t Length __CALLBACK_PARAM
);
847 /** Writes the given number of bytes to the endpoint from the given buffer in little endian,
848 * sending full packets to the host as needed. The last packet filled is not automatically sent;
849 * the user is responsible for manually sending the last written packet to the host via the
850 * \ref Endpoint_ClearIN() macro. Between each USB packet, the given stream callback function
851 * is executed repeatedly until the endpoint is ready to accept the next packet, allowing for early
852 * aborts of stream transfers.
854 * The callback routine should be created according to the information in \ref Group_StreamCallbacks.
855 * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are
856 * disabled and this function has the Callback parameter omitted.
858 * \note This routine should not be used on CONTROL type endpoints.
860 * \ingroup Group_EndpointStreamRW
862 * \param[in] Buffer Pointer to the source data buffer to read from.
863 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
864 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
866 * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
868 uint8_t Endpoint_Write_Stream_LE(const void* Buffer
, uint16_t Length __CALLBACK_PARAM
) ATTR_NON_NULL_PTR_ARG(1);
870 /** EEPROM buffer source version of \ref Endpoint_Write_Stream_LE().
872 * \ingroup Group_EndpointStreamRW
874 * \param[in] Buffer Pointer to the source data buffer to read from.
875 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
876 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
878 * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
880 uint8_t Endpoint_Write_EStream_LE(const void* Buffer
, uint16_t Length __CALLBACK_PARAM
) ATTR_NON_NULL_PTR_ARG(1);
882 /** FLASH buffer source version of \ref Endpoint_Write_Stream_LE().
884 * \note The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.
886 * \ingroup Group_EndpointStreamRW
888 * \param[in] Buffer Pointer to the source data buffer to read from.
889 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
890 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
892 * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
894 uint8_t Endpoint_Write_PStream_LE(const void* Buffer
, uint16_t Length __CALLBACK_PARAM
) ATTR_NON_NULL_PTR_ARG(1);
896 /** Writes the given number of bytes to the endpoint from the given buffer in big endian,
897 * sending full packets to the host as needed. The last packet filled is not automatically sent;
898 * the user is responsible for manually sending the last written packet to the host via the
899 * \ref Endpoint_ClearIN() macro. Between each USB packet, the given stream callback function
900 * is executed repeatedly until the endpoint is ready to accept the next packet, allowing for early
901 * aborts of stream transfers.
903 * The callback routine should be created according to the information in \ref Group_StreamCallbacks.
904 * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are
905 * disabled and this function has the Callback parameter omitted.
907 * \note This routine should not be used on CONTROL type endpoints.
909 * \ingroup Group_EndpointStreamRW
911 * \param[in] Buffer Pointer to the source data buffer to read from.
912 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
913 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
915 * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
917 uint8_t Endpoint_Write_Stream_BE(const void* Buffer
, uint16_t Length __CALLBACK_PARAM
) ATTR_NON_NULL_PTR_ARG(1);
919 /** EEPROM buffer source version of \ref Endpoint_Write_Stream_BE().
921 * \ingroup Group_EndpointStreamRW
923 * \param[in] Buffer Pointer to the source data buffer to read from.
924 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
925 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
927 * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
929 uint8_t Endpoint_Write_EStream_BE(const void* Buffer
, uint16_t Length __CALLBACK_PARAM
) ATTR_NON_NULL_PTR_ARG(1);
931 /** FLASH buffer source version of \ref Endpoint_Write_Stream_BE().
933 * \note The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.
935 * \ingroup Group_EndpointStreamRW
937 * \param[in] Buffer Pointer to the source data buffer to read from.
938 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
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_Write_PStream_BE(const void* Buffer
, uint16_t Length __CALLBACK_PARAM
) ATTR_NON_NULL_PTR_ARG(1);
945 /** Reads the given number of bytes from the endpoint from the given buffer in little endian,
946 * discarding fully read packets from the host as needed. The last packet is not automatically
947 * discarded once the remaining bytes has been read; the user is responsible for manually
948 * discarding the last packet from the host via the \ref Endpoint_ClearOUT() macro. Between
949 * each USB packet, the given stream callback function is executed repeatedly until the endpoint
950 * is ready to accept the next packet, allowing for early aborts of stream transfers.
952 * The callback routine should be created according to the information in \ref Group_StreamCallbacks.
953 * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are
954 * disabled and this function has the Callback parameter omitted.
956 * \note This routine should not be used on CONTROL type endpoints.
958 * \ingroup Group_EndpointStreamRW
960 * \param[out] Buffer Pointer to the destination data buffer to write to.
961 * \param[in] Length Number of bytes to send via the currently selected endpoint.
962 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
964 * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
966 uint8_t Endpoint_Read_Stream_LE(void* Buffer
, uint16_t Length __CALLBACK_PARAM
) ATTR_NON_NULL_PTR_ARG(1);
968 /** EEPROM buffer source version of \ref Endpoint_Read_Stream_LE().
970 * \ingroup Group_EndpointStreamRW
972 * \param[out] Buffer Pointer to the destination data buffer to write to, located in EEPROM memory space.
973 * \param[in] Length Number of bytes to send via the currently selected endpoint.
974 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
976 * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
978 uint8_t Endpoint_Read_EStream_LE(void* Buffer
, uint16_t Length __CALLBACK_PARAM
) ATTR_NON_NULL_PTR_ARG(1);
980 /** Reads the given number of bytes from the endpoint from the given buffer in big endian,
981 * discarding fully read packets from the host as needed. The last packet is not automatically
982 * discarded once the remaining bytes has been read; the user is responsible for manually
983 * discarding the last packet from the host via the \ref Endpoint_ClearOUT() macro. Between
984 * each USB packet, the given stream callback function is executed repeatedly until the endpoint
985 * is ready to accept the next packet, allowing for early aborts of stream transfers.
987 * The callback routine should be created according to the information in \ref Group_StreamCallbacks.
988 * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are
989 * disabled and this function has the Callback parameter omitted.
991 * \note This routine should not be used on CONTROL type endpoints.
993 * \ingroup Group_EndpointStreamRW
995 * \param[out] Buffer Pointer to the destination data buffer to write to.
996 * \param[in] Length Number of bytes to send via the currently selected endpoint.
997 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
999 * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
1001 uint8_t Endpoint_Read_Stream_BE(void* Buffer
, uint16_t Length __CALLBACK_PARAM
) ATTR_NON_NULL_PTR_ARG(1);
1003 /** EEPROM buffer source version of \ref Endpoint_Read_Stream_BE().
1005 * \ingroup Group_EndpointStreamRW
1007 * \param[out] Buffer Pointer to the destination data buffer to write to, located in EEPROM memory space.
1008 * \param[in] Length Number of bytes to send via the currently selected endpoint.
1009 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback
1011 * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
1013 uint8_t Endpoint_Read_EStream_BE(void* Buffer
, uint16_t Length __CALLBACK_PARAM
) ATTR_NON_NULL_PTR_ARG(1);
1015 /** Writes the given number of bytes to the CONTROL type endpoint from the given buffer in little endian,
1016 * sending full packets to the host as needed. The host OUT acknowledgement is not automatically cleared
1017 * in both failure and success states; the user is responsible for manually clearing the setup OUT to
1018 * finalize the transfer via the \ref Endpoint_ClearOUT() macro.
1020 * \note This function automatically clears the control transfer's status stage. Do not manually attempt
1021 * to clear the status stage when using this routine in a control transaction.
1023 * \note This routine should only be used on CONTROL type endpoints.
1025 * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
1026 * together; i.e. the entire stream data must be read or written at the one time.
1028 * \ingroup Group_EndpointStreamRW
1030 * \param[in] Buffer Pointer to the source data buffer to read from.
1031 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
1033 * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
1035 uint8_t Endpoint_Write_Control_Stream_LE(const void* Buffer
, uint16_t Length
) ATTR_NON_NULL_PTR_ARG(1);
1037 /** EEPROM buffer source version of Endpoint_Write_Control_Stream_LE.
1039 * \note This function automatically clears the control transfer's status stage. Do not manually attempt
1040 * to clear the status stage when using this routine in a control transaction.
1042 * \note This routine should only be used on CONTROL type endpoints.
1044 * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
1045 * together; i.e. the entire stream data must be read or written at the one time.
1047 * \ingroup Group_EndpointStreamRW
1049 * \param[in] Buffer Pointer to the source data buffer to read from.
1050 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
1052 * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
1054 uint8_t Endpoint_Write_Control_EStream_LE(const void* Buffer
, uint16_t Length
) ATTR_NON_NULL_PTR_ARG(1);
1056 /** FLASH buffer source version of \ref Endpoint_Write_Control_Stream_LE().
1058 * \note This function automatically clears the control transfer's status stage. Do not manually attempt
1059 * to clear the status stage when using this routine in a control transaction.
1061 * \note The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.
1063 * \note This routine should only be used on CONTROL type endpoints.
1065 * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
1066 * together; i.e. the entire stream data must be read or written at the one time.
1068 * \ingroup Group_EndpointStreamRW
1070 * \param[in] Buffer Pointer to the source data buffer to read from.
1071 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
1073 * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
1075 uint8_t Endpoint_Write_Control_PStream_LE(const void* Buffer
, uint16_t Length
) ATTR_NON_NULL_PTR_ARG(1);
1077 /** Writes the given number of bytes to the CONTROL type endpoint from the given buffer in big endian,
1078 * sending full packets to the host as needed. The host OUT acknowledgement is not automatically cleared
1079 * in both failure and success states; the user is responsible for manually clearing the setup OUT to
1080 * finalize the transfer via the \ref Endpoint_ClearOUT() macro.
1082 * \note This function automatically clears the control transfer's status stage. Do not manually attempt
1083 * to clear the status stage when using this routine in a control transaction.
1085 * \note This routine should only be used on CONTROL type endpoints.
1087 * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
1088 * together; i.e. the entire stream data must be read or written at the one time.
1090 * \ingroup Group_EndpointStreamRW
1092 * \param[in] Buffer Pointer to the source data buffer to read from.
1093 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
1095 * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
1097 uint8_t Endpoint_Write_Control_Stream_BE(const void* Buffer
, uint16_t Length
) ATTR_NON_NULL_PTR_ARG(1);
1099 /** EEPROM buffer source version of \ref Endpoint_Write_Control_Stream_BE().
1101 * \note This function automatically clears the control transfer's status stage. Do not manually attempt
1102 * to clear the status stage when using this routine in a control transaction.
1104 * \note This routine should only be used on CONTROL type endpoints.
1106 * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
1107 * together; i.e. the entire stream data must be read or written at the one time.
1109 * \ingroup Group_EndpointStreamRW
1111 * \param[in] Buffer Pointer to the source data buffer to read from.
1112 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
1114 * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
1116 uint8_t Endpoint_Write_Control_EStream_BE(const void* Buffer
, uint16_t Length
) ATTR_NON_NULL_PTR_ARG(1);
1118 /** FLASH buffer source version of \ref Endpoint_Write_Control_Stream_BE().
1120 * \note This function automatically clears the control transfer's status stage. Do not manually attempt
1121 * to clear the status stage when using this routine in a control transaction.
1123 * \note The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.
1125 * \note This routine should only be used on CONTROL type endpoints.
1127 * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
1128 * together; i.e. the entire stream data must be read or written at the one time.
1130 * \ingroup Group_EndpointStreamRW
1132 * \param[in] Buffer Pointer to the source data buffer to read from.
1133 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
1135 * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
1137 uint8_t Endpoint_Write_Control_PStream_BE(const void* Buffer
, uint16_t Length
) ATTR_NON_NULL_PTR_ARG(1);
1139 /** Reads the given number of bytes from the CONTROL endpoint from the given buffer in little endian,
1140 * discarding fully read packets from the host as needed. The device IN acknowledgement is not
1141 * automatically sent after success or failure states; the user is responsible for manually sending the
1142 * setup IN to finalize the transfer via the \ref Endpoint_ClearIN() macro.
1144 * \note This function automatically clears the control transfer's status stage. Do not manually attempt
1145 * to clear the status stage when using this routine in a control transaction.
1147 * \note This routine should only be used on CONTROL type endpoints.
1149 * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
1150 * together; i.e. the entire stream data must be read or written at the one time.
1152 * \ingroup Group_EndpointStreamRW
1154 * \param[out] Buffer Pointer to the destination data buffer to write to.
1155 * \param[in] Length Number of bytes to send via the currently selected endpoint.
1157 * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
1159 uint8_t Endpoint_Read_Control_Stream_LE(void* Buffer
, uint16_t Length
) ATTR_NON_NULL_PTR_ARG(1);
1161 /** EEPROM buffer source version of \ref Endpoint_Read_Control_Stream_LE().
1163 * \note This function automatically clears the control transfer's status stage. Do not manually attempt
1164 * to clear the status stage when using this routine in a control transaction.
1166 * \note This routine should only be used on CONTROL type endpoints.
1168 * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
1169 * together; i.e. the entire stream data must be read or written at the one time.
1171 * \ingroup Group_EndpointStreamRW
1173 * \param[out] Buffer Pointer to the destination data buffer to write to.
1174 * \param[in] Length Number of bytes to send via the currently selected endpoint.
1176 * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
1178 uint8_t Endpoint_Read_Control_EStream_LE(void* Buffer
, uint16_t Length
) ATTR_NON_NULL_PTR_ARG(1);
1180 /** Reads the given number of bytes from the CONTROL endpoint from the given buffer in big endian,
1181 * discarding fully read packets from the host as needed. The device IN acknowledgement is not
1182 * automatically sent after success or failure states; the user is responsible for manually sending the
1183 * setup IN to finalize the transfer via the \ref Endpoint_ClearIN() macro.
1185 * \note This function automatically clears the control transfer's status stage. Do not manually attempt
1186 * to clear the status stage when using this routine in a control transaction.
1188 * \note This routine should only be used on CONTROL type endpoints.
1190 * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
1191 * together; i.e. the entire stream data must be read or written at the one time.
1193 * \ingroup Group_EndpointStreamRW
1195 * \param[out] Buffer Pointer to the destination data buffer to write to.
1196 * \param[in] Length Number of bytes to send via the currently selected endpoint.
1198 * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
1200 uint8_t Endpoint_Read_Control_Stream_BE(void* Buffer
, uint16_t Length
) ATTR_NON_NULL_PTR_ARG(1);
1202 /** EEPROM buffer source version of \ref Endpoint_Read_Control_Stream_BE().
1204 * \note This function automatically clears the control transfer's status stage. Do not manually attempt
1205 * to clear the status stage when using this routine in a control transaction.
1207 * \note This routine should only be used on CONTROL type endpoints.
1209 * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
1210 * together; i.e. the entire stream data must be read or written at the one time.
1212 * \ingroup Group_EndpointStreamRW
1214 * \param[out] Buffer Pointer to the destination data buffer to write to.
1215 * \param[in] Length Number of bytes to send via the currently selected endpoint.
1217 * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
1219 uint8_t Endpoint_Read_Control_EStream_BE(void* Buffer
, uint16_t Length
) ATTR_NON_NULL_PTR_ARG(1);
1221 /* Private Interface - For use in library only: */
1222 #if !defined(__DOXYGEN__)
1224 #define Endpoint_AllocateMemory() MACROS{ UECFG1X |= (1 << ALLOC); }MACROE
1225 #define Endpoint_DeallocateMemory() MACROS{ UECFG1X &= ~(1 << ALLOC); }MACROE
1227 #define _ENDPOINT_GET_MAXSIZE(n) _ENDPOINT_GET_MAXSIZE2(ENDPOINT_DETAILS_EP ## n)
1228 #define _ENDPOINT_GET_MAXSIZE2(details) _ENDPOINT_GET_MAXSIZE3(details)
1229 #define _ENDPOINT_GET_MAXSIZE3(maxsize, db) maxsize
1231 #define _ENDPOINT_GET_DOUBLEBANK(n) _ENDPOINT_GET_DOUBLEBANK2(ENDPOINT_DETAILS_EP ## n)
1232 #define _ENDPOINT_GET_DOUBLEBANK2(details) _ENDPOINT_GET_DOUBLEBANK3(details)
1233 #define _ENDPOINT_GET_DOUBLEBANK3(maxsize, db) db
1235 #if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)
1236 #define ENDPOINT_DETAILS_EP0 64, true
1237 #define ENDPOINT_DETAILS_EP1 256, true
1238 #define ENDPOINT_DETAILS_EP2 64, true
1239 #define ENDPOINT_DETAILS_EP3 64, true
1240 #define ENDPOINT_DETAILS_EP4 64, true
1241 #define ENDPOINT_DETAILS_EP5 64, true
1242 #define ENDPOINT_DETAILS_EP6 64, true
1244 #define ENDPOINT_DETAILS_EP0 64, true
1245 #define ENDPOINT_DETAILS_EP1 64, false
1246 #define ENDPOINT_DETAILS_EP2 64, false
1247 #define ENDPOINT_DETAILS_EP3 64, true
1248 #define ENDPOINT_DETAILS_EP4 64, true
1251 #define Endpoint_ConfigureEndpoint(Number, Type, Direction, Size, Banks) \
1252 Endpoint_ConfigureEndpoint_Prv((Number), \
1253 (((Type) << EPTYPE0) | (Direction)), \
1254 ((1 << ALLOC) | (Banks) | \
1255 (__builtin_constant_p(Size) ? \
1256 Endpoint_BytesToEPSizeMask(Size) : \
1257 Endpoint_BytesToEPSizeMaskDynamic(Size))))
1259 /* Function Prototypes: */
1260 void Endpoint_ClearEndpoints(void);
1261 uint8_t Endpoint_BytesToEPSizeMaskDynamic(const uint16_t Size
);
1262 bool Endpoint_ConfigureEndpoint_Prv(const uint8_t Number
, const uint8_t UECFG0XData
, const uint8_t UECFG1XData
);
1264 /* Inline Functions: */
1265 static inline uint8_t Endpoint_BytesToEPSizeMask(const uint16_t Bytes
) ATTR_WARN_UNUSED_RESULT ATTR_CONST ATTR_ALWAYS_INLINE
;
1266 static inline uint8_t Endpoint_BytesToEPSizeMask(const uint16_t Bytes
)
1268 uint8_t MaskVal
= 0;
1269 uint16_t CheckBytes
= 8;
1271 while (CheckBytes
< Bytes
)
1277 return (MaskVal
<< EPSIZE0
);
1282 /* Disable C linkage for C++ Compilers: */
1283 #if defined(__cplusplus)