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
32 * \brief USB device endpoint management definitions.
34 * This file contains structures, function prototypes and macros related to the management of the device's
35 * data endpoints when the library is initialized in USB device mode.
37 * \note This file should not be included directly. It is automatically included as needed by the USB driver
38 * dispatch header located in LUFA/Drivers/USB/USB.h.
41 /** \ingroup Group_USB
42 * @defgroup Group_EndpointManagement Endpoint Management
44 * Functions, macros and enums related to endpoint management when in USB Device mode. This
45 * module contains the endpoint management macros, as well as endpoint interrupt and data
46 * send/receive functions for various data types.
51 /** @defgroup Group_EndpointRW Endpoint Data Reading and Writing
53 * Functions, macros, variables, enums and types related to data reading and writing from and to endpoints.
56 /** \ingroup Group_EndpointRW
57 * @defgroup Group_EndpointPrimitiveRW Read/Write of Primitive Data Types
59 * Functions, macros, variables, enums and types related to data reading and writing of primitive data types
60 * from and to endpoints.
63 /** \ingroup Group_EndpointRW
64 * @defgroup Group_EndpointStreamRW Read/Write of Multi-Byte Streams
66 * Functions, macros, variables, enums and types related to data reading and writing of data streams from
70 /** @defgroup Group_EndpointPacketManagement Endpoint Packet Management
72 * Functions, macros, variables, enums and types related to packet management of endpoints.
75 #ifndef __ENDPOINT_H__
76 #define __ENDPOINT_H__
80 #include <avr/pgmspace.h>
81 #include <avr/eeprom.h>
84 #include "../../../Common/Common.h"
85 #include "../HighLevel/USBTask.h"
86 #include "USBInterrupt.h"
88 #if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__)
89 #include "../HighLevel/StreamCallbacks.h"
92 /* Enable C linkage for C++ Compilers: */
93 #if defined(__cplusplus)
97 /* Preprocessor Checks: */
98 #if !defined(__INCLUDE_FROM_USB_DRIVER)
99 #error Do not include this file directly. Include LUFA/Drivers/USB/USB.h instead.
102 #if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__)
103 #define __CALLBACK_PARAM , StreamCallbackPtr_t Callback
105 #define __CALLBACK_PARAM
108 /* Private Interface - For use in library only: */
109 #if !defined(__DOXYGEN__)
111 #define _ENDPOINT_GET_MAXSIZE(EPIndex) _ENDPOINT_GET_MAXSIZE2(ENDPOINT_DETAILS_EP ## EPIndex)
112 #define _ENDPOINT_GET_MAXSIZE2(EPDetails) _ENDPOINT_GET_MAXSIZE3(EPDetails)
113 #define _ENDPOINT_GET_MAXSIZE3(MaxSize, DB) (MaxSize)
115 #define _ENDPOINT_GET_DOUBLEBANK(EPIndex) _ENDPOINT_GET_DOUBLEBANK2(ENDPOINT_DETAILS_EP ## EPIndex)
116 #define _ENDPOINT_GET_DOUBLEBANK2(EPDetails) _ENDPOINT_GET_DOUBLEBANK3(EPDetails)
117 #define _ENDPOINT_GET_DOUBLEBANK3(MaxSize, DB) (DB)
119 #if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)
120 #define ENDPOINT_DETAILS_EP0 64, true
121 #define ENDPOINT_DETAILS_EP1 256, true
122 #define ENDPOINT_DETAILS_EP2 64, true
123 #define ENDPOINT_DETAILS_EP3 64, true
124 #define ENDPOINT_DETAILS_EP4 64, true
125 #define ENDPOINT_DETAILS_EP5 64, true
126 #define ENDPOINT_DETAILS_EP6 64, true
128 #define ENDPOINT_DETAILS_EP0 64, true
129 #define ENDPOINT_DETAILS_EP1 64, false
130 #define ENDPOINT_DETAILS_EP2 64, false
131 #define ENDPOINT_DETAILS_EP3 64, true
132 #define ENDPOINT_DETAILS_EP4 64, true
135 /* Inline Functions: */
136 static inline uint8_t Endpoint_BytesToEPSizeMask(const uint16_t Bytes
) ATTR_WARN_UNUSED_RESULT ATTR_CONST
138 static inline uint8_t Endpoint_BytesToEPSizeMask(const uint16_t Bytes
)
141 uint16_t CheckBytes
= 8;
143 while (CheckBytes
< Bytes
)
149 return (MaskVal
<< EPSIZE0
);
152 /* Function Prototypes: */
153 void Endpoint_ClearEndpoints(void);
154 bool Endpoint_ConfigureEndpoint_Prv(const uint8_t Number
,
155 const uint8_t UECFG0XData
,
156 const uint8_t UECFG1XData
);
160 /* Public Interface - May be used in end-application: */
162 /** Endpoint data direction mask for \ref Endpoint_ConfigureEndpoint(). This indicates that the endpoint
163 * should be initialized in the OUT direction - i.e. data flows from host to device.
165 #define ENDPOINT_DIR_OUT (0 << EPDIR)
167 /** Endpoint data direction mask for \ref Endpoint_ConfigureEndpoint(). This indicates that the endpoint
168 * should be initialized in the IN direction - i.e. data flows from device to host.
170 #define ENDPOINT_DIR_IN (1 << EPDIR)
172 /** Mask for the bank mode selection for the \ref Endpoint_ConfigureEndpoint() macro. This indicates
173 * that the endpoint should have one single bank, which requires less USB FIFO memory but results
174 * in slower transfers as only one USB device (the AVR or the host) can access the endpoint's
175 * bank at the one time.
177 #define ENDPOINT_BANK_SINGLE (0 << EPBK0)
179 /** Mask for the bank mode selection for the \ref Endpoint_ConfigureEndpoint() macro. This indicates
180 * that the endpoint should have two banks, which requires more USB FIFO memory but results
181 * in faster transfers as one USB device (the AVR or the host) can access one bank while the other
182 * accesses the second bank.
184 #define ENDPOINT_BANK_DOUBLE (1 << EPBK0)
186 /** Endpoint address for the default control endpoint, which always resides in address 0. This is
187 * defined for convenience to give more readable code when used with the endpoint macros.
189 #define ENDPOINT_CONTROLEP 0
191 #if (!defined(FIXED_CONTROL_ENDPOINT_SIZE) || defined(__DOXYGEN__))
192 /** Default size of the default control endpoint's bank, until altered by the control endpoint bank size
193 * value in the device descriptor. Not available if the FIXED_CONTROL_ENDPOINT_SIZE token is defined.
195 #define ENDPOINT_CONTROLEP_DEFAULT_SIZE 8
198 /** Endpoint number mask, for masking against endpoint addresses to retrieve the endpoint's
199 * numerical address in the device.
201 #define ENDPOINT_EPNUM_MASK 0x07
203 /** Endpoint direction mask, for masking against endpoint addresses to retrieve the endpoint's
204 * direction for comparing with the ENDPOINT_DESCRIPTOR_DIR_* masks.
206 #define ENDPOINT_EPDIR_MASK 0x80
208 /** Endpoint bank size mask, for masking against endpoint addresses to retrieve the endpoint's
209 * bank size in the device.
211 #define ENDPOINT_EPSIZE_MASK 0x7F
213 /** Maximum size in bytes of a given endpoint.
215 * \param[in] n Endpoint number, a value between 0 and (ENDPOINT_TOTAL_ENDPOINTS - 1)
217 #define ENDPOINT_MAX_SIZE(n) _ENDPOINT_GET_MAXSIZE(n)
219 /** Indicates if the given endpoint supports double banking.
221 * \param[in] n Endpoint number, a value between 0 and (ENDPOINT_TOTAL_ENDPOINTS - 1)
223 #define ENDPOINT_DOUBLEBANK_SUPPORTED(n) _ENDPOINT_GET_DOUBLEBANK(n)
225 #if !defined(CONTROL_ONLY_DEVICE)
226 #if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR) || defined(__DOXYGEN__)
227 /** Total number of endpoints (including the default control endpoint at address 0) which may
228 * be used in the device. Different USB AVR models support different amounts of endpoints,
229 * this value reflects the maximum number of endpoints for the currently selected AVR model.
231 #define ENDPOINT_TOTAL_ENDPOINTS 7
233 #define ENDPOINT_TOTAL_ENDPOINTS 5
236 #define ENDPOINT_TOTAL_ENDPOINTS 1
240 /** Enum for the possible error return codes of the \ref Endpoint_WaitUntilReady() function.
242 * \ingroup Group_EndpointRW
244 enum Endpoint_WaitUntilReady_ErrorCodes_t
246 ENDPOINT_READYWAIT_NoError
= 0, /**< Endpoint is ready for next packet, no error. */
247 ENDPOINT_READYWAIT_EndpointStalled
= 1, /**< The endpoint was stalled during the stream
248 * transfer by the host or device.
250 ENDPOINT_READYWAIT_DeviceDisconnected
= 2, /**< Device was disconnected from the host while
251 * waiting for the endpoint to become ready.
253 ENDPOINT_READYWAIT_BusSuspended
= 3, /**< The USB bus has been suspended by the host and
254 * no USB endpoint traffic can occur until the bus
257 ENDPOINT_READYWAIT_Timeout
= 4, /**< The host failed to accept or send the next packet
258 * within the software timeout period set by the
259 * \ref USB_STREAM_TIMEOUT_MS macro.
263 /** Enum for the possible error return codes of the Endpoint_*_Stream_* functions.
265 * \ingroup Group_EndpointStreamRW
267 enum Endpoint_Stream_RW_ErrorCodes_t
269 ENDPOINT_RWSTREAM_NoError
= 0, /**< Command completed successfully, no error. */
270 ENDPOINT_RWSTREAM_EndpointStalled
= 1, /**< The endpoint was stalled during the stream
271 * transfer by the host or device.
273 ENDPOINT_RWSTREAM_DeviceDisconnected
= 2, /**< Device was disconnected from the host during
276 ENDPOINT_RWSTREAM_BusSuspended
= 3, /**< The USB bus has been suspended by the host and
277 * no USB endpoint traffic can occur until the bus
280 ENDPOINT_RWSTREAM_Timeout
= 4, /**< The host failed to accept or send the next packet
281 * within the software timeout period set by the
282 * \ref USB_STREAM_TIMEOUT_MS macro.
284 ENDPOINT_RWSTREAM_CallbackAborted
= 5, /**< Indicates that the stream's callback function
285 * aborted the transfer early.
289 /** Enum for the possible error return codes of the Endpoint_*_Control_Stream_* functions..
291 * \ingroup Group_EndpointStreamRW
293 enum Endpoint_ControlStream_RW_ErrorCodes_t
295 ENDPOINT_RWCSTREAM_NoError
= 0, /**< Command completed successfully, no error. */
296 ENDPOINT_RWCSTREAM_HostAborted
= 1, /**< The aborted the transfer prematurely. */
297 ENDPOINT_RWCSTREAM_DeviceDisconnected
= 2, /**< Device was disconnected from the host during
300 ENDPOINT_RWCSTREAM_BusSuspended
= 3, /**< The USB bus has been suspended by the host and
301 * no USB endpoint traffic can occur until the bus
306 /* Inline Functions: */
307 /** Configures the specified endpoint number with the given endpoint type, direction, bank size
308 * and banking mode. Endpoints should be allocated in ascending order by their address in the
309 * device (i.e. endpoint 1 should be configured before endpoint 2 and so on) to prevent fragmentation
310 * of the USB FIFO memory.
312 * The endpoint type may be one of the EP_TYPE_* macros listed in LowLevel.h and the direction
313 * may be either \ref ENDPOINT_DIR_OUT or \ref ENDPOINT_DIR_IN.
315 * The bank size must indicate the maximum packet size that the endpoint can handle. Different
316 * endpoint numbers can handle different maximum packet sizes - refer to the chosen USB AVR's
317 * datasheet to determine the maximum bank size for each endpoint.
319 * The banking mode may be either \ref ENDPOINT_BANK_SINGLE or \ref ENDPOINT_BANK_DOUBLE.
321 * \note The default control endpoint should not be manually configured by the user application, as
322 * it is automatically configured by the library internally.
325 * \note This routine will select the specified endpoint, and the endpoint will remain selected
326 * once the routine completes regardless of if the endpoint configuration succeeds.
328 * \return Boolean true if the configuration succeeded, false otherwise.
330 static inline bool Endpoint_ConfigureEndpoint(const uint8_t Number
,
332 const uint8_t Direction
,
334 const uint8_t Banks
) ATTR_ALWAYS_INLINE
;
335 static inline bool Endpoint_ConfigureEndpoint(const uint8_t Number
,
337 const uint8_t Direction
,
341 return Endpoint_ConfigureEndpoint_Prv(Number
, (((Type
) << EPTYPE0
) | (Direction
)),
342 ((1 << ALLOC
) | Banks
| Endpoint_BytesToEPSizeMask(Size
)));
345 /** Indicates the number of bytes currently stored in the current endpoint's selected bank.
347 * \note The return width of this function may differ, depending on the maximum endpoint bank size
348 * of the selected AVR model.
350 * \ingroup Group_EndpointRW
352 * \return Total number of bytes in the currently selected Endpoint's FIFO buffer.
354 static inline uint16_t Endpoint_BytesInEndpoint(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE
;
355 static inline uint16_t Endpoint_BytesInEndpoint(void)
357 #if defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR)
359 #elif defined(USB_SERIES_4_AVR)
360 return (((uint16_t)UEBCHX
<< 8) | UEBCLX
);
361 #elif defined(USB_SERIES_2_AVR)
366 /** Get the endpoint address of the currently selected endpoint. This is typically used to save
367 * the currently selected endpoint number so that it can be restored after another endpoint has
370 * \return Index of the currently selected endpoint.
372 static inline uint8_t Endpoint_GetCurrentEndpoint(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE
;
373 static inline uint8_t Endpoint_GetCurrentEndpoint(void)
375 #if !defined(CONTROL_ONLY_DEVICE)
376 return (UENUM
& ENDPOINT_EPNUM_MASK
);
378 return ENDPOINT_CONTROLEP
;
382 /** Selects the given endpoint number. If the address from the device descriptors is used, the
383 * value should be masked with the \ref ENDPOINT_EPNUM_MASK constant to extract only the endpoint
384 * number (and discarding the endpoint direction bit).
386 * Any endpoint operations which do not require the endpoint number to be indicated will operate on
387 * the currently selected endpoint.
389 * \param[in] EndpointNumber Endpoint number to select.
391 static inline void Endpoint_SelectEndpoint(const uint8_t EndpointNumber
) ATTR_ALWAYS_INLINE
;
392 static inline void Endpoint_SelectEndpoint(const uint8_t EndpointNumber
)
394 #if !defined(CONTROL_ONLY_DEVICE)
395 UENUM
= EndpointNumber
;
399 /** Resets the endpoint bank FIFO. This clears all the endpoint banks and resets the USB controller's
400 * In and Out pointers to the bank's contents.
402 * \param[in] EndpointNumber Endpoint number whose FIFO buffers are to be reset.
404 static inline void Endpoint_ResetFIFO(const uint8_t EndpointNumber
) ATTR_ALWAYS_INLINE
;
405 static inline void Endpoint_ResetFIFO(const uint8_t EndpointNumber
)
407 UERST
= (1 << EndpointNumber
);
411 /** Enables the currently selected endpoint so that data can be sent and received through it to
414 * \note Endpoints must first be configured properly via \ref Endpoint_ConfigureEndpoint().
416 static inline void Endpoint_EnableEndpoint(void) ATTR_ALWAYS_INLINE
;
417 static inline void Endpoint_EnableEndpoint(void)
419 UECONX
|= (1 << EPEN
);
422 /** Disables the currently selected endpoint so that data cannot be sent and received through it
423 * to and from a host.
425 static inline void Endpoint_DisableEndpoint(void) ATTR_ALWAYS_INLINE
;
426 static inline void Endpoint_DisableEndpoint(void)
428 UECONX
&= ~(1 << EPEN
);
431 /** Determines if the currently selected endpoint is enabled, but not necessarily configured.
433 * \return Boolean True if the currently selected endpoint is enabled, false otherwise.
435 static inline bool Endpoint_IsEnabled(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE
;
436 static inline bool Endpoint_IsEnabled(void)
438 return ((UECONX
& (1 << EPEN
)) ?
true : false);
441 /** Determines if the currently selected endpoint may be read from (if data is waiting in the endpoint
442 * bank and the endpoint is an OUT direction, or if the bank is not yet full if the endpoint is an IN
443 * direction). This function will return false if an error has occurred in the endpoint, if the endpoint
444 * is an OUT direction and no packet (or an empty packet) has been received, or if the endpoint is an IN
445 * direction and the endpoint bank is full.
447 * \ingroup Group_EndpointPacketManagement
449 * \return Boolean true if the currently selected endpoint may be read from or written to, depending on its direction.
451 static inline bool Endpoint_IsReadWriteAllowed(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE
;
452 static inline bool Endpoint_IsReadWriteAllowed(void)
454 return ((UEINTX
& (1 << RWAL
)) ?
true : false);
457 /** Determines if the currently selected endpoint is configured.
459 * \return Boolean true if the currently selected endpoint has been configured, false otherwise.
461 static inline bool Endpoint_IsConfigured(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE
;
462 static inline bool Endpoint_IsConfigured(void)
464 return ((UESTA0X
& (1 << CFGOK
)) ?
true : false);
467 /** Returns a mask indicating which INTERRUPT type endpoints have interrupted - i.e. their
468 * interrupt duration has elapsed. Which endpoints have interrupted can be determined by
469 * masking the return value against (1 << {Endpoint Number}).
471 * \return Mask whose bits indicate which endpoints have interrupted.
473 static inline uint8_t Endpoint_GetEndpointInterrupts(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE
;
474 static inline uint8_t Endpoint_GetEndpointInterrupts(void)
479 /** Determines if the specified endpoint number has interrupted (valid only for INTERRUPT type
482 * \param[in] EndpointNumber Index of the endpoint whose interrupt flag should be tested.
484 * \return Boolean true if the specified endpoint has interrupted, false otherwise.
486 static inline bool Endpoint_HasEndpointInterrupted(const uint8_t EndpointNumber
) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE
;
487 static inline bool Endpoint_HasEndpointInterrupted(const uint8_t EndpointNumber
)
489 return ((UEINT
& (1 << EndpointNumber
)) ?
true : false);
492 /** Determines if the selected IN endpoint is ready for a new packet.
494 * \ingroup Group_EndpointPacketManagement
496 * \return Boolean true if the current endpoint is ready for an IN packet, false otherwise.
498 static inline bool Endpoint_IsINReady(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE
;
499 static inline bool Endpoint_IsINReady(void)
501 return ((UEINTX
& (1 << TXINI
)) ?
true : false);
504 /** Determines if the selected OUT endpoint has received new packet.
506 * \ingroup Group_EndpointPacketManagement
508 * \return Boolean true if current endpoint is has received an OUT packet, false otherwise.
510 static inline bool Endpoint_IsOUTReceived(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE
;
511 static inline bool Endpoint_IsOUTReceived(void)
513 return ((UEINTX
& (1 << RXOUTI
)) ?
true : false);
516 /** Determines if the current CONTROL type endpoint has received a SETUP packet.
518 * \ingroup Group_EndpointPacketManagement
520 * \return Boolean true if the selected endpoint has received a SETUP packet, false otherwise.
522 static inline bool Endpoint_IsSETUPReceived(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE
;
523 static inline bool Endpoint_IsSETUPReceived(void)
525 return ((UEINTX
& (1 << RXSTPI
)) ?
true : false);
528 /** Clears a received SETUP packet on the currently selected CONTROL type endpoint, freeing up the
529 * endpoint for the next packet.
531 * \ingroup Group_EndpointPacketManagement
533 * \note This is not applicable for non CONTROL type endpoints.
535 static inline void Endpoint_ClearSETUP(void) ATTR_ALWAYS_INLINE
;
536 static inline void Endpoint_ClearSETUP(void)
538 UEINTX
&= ~(1 << RXSTPI
);
541 /** Sends an IN packet to the host on the currently selected endpoint, freeing up the endpoint for the
542 * next packet and switching to the alternative endpoint bank if double banked.
544 * \ingroup Group_EndpointPacketManagement
546 static inline void Endpoint_ClearIN(void) ATTR_ALWAYS_INLINE
;
547 static inline void Endpoint_ClearIN(void)
549 #if !defined(CONTROL_ONLY_DEVICE)
550 UEINTX
&= ~((1 << TXINI
) | (1 << FIFOCON
));
552 UEINTX
&= ~(1 << TXINI
);
556 /** Acknowledges an OUT packet to the host on the currently selected endpoint, freeing up the endpoint
557 * for the next packet and switching to the alternative endpoint bank if double banked.
559 * \ingroup Group_EndpointPacketManagement
561 static inline void Endpoint_ClearOUT(void) ATTR_ALWAYS_INLINE
;
562 static inline void Endpoint_ClearOUT(void)
564 #if !defined(CONTROL_ONLY_DEVICE)
565 UEINTX
&= ~((1 << RXOUTI
) | (1 << FIFOCON
));
567 UEINTX
&= ~(1 << RXOUTI
);
571 /** Stalls the current endpoint, indicating to the host that a logical problem occurred with the
572 * indicated endpoint and that the current transfer sequence should be aborted. This provides a
573 * way for devices to indicate invalid commands to the host so that the current transfer can be
574 * aborted and the host can begin its own recovery sequence.
576 * The currently selected endpoint remains stalled until either the \ref Endpoint_ClearStall() macro
577 * is called, or the host issues a CLEAR FEATURE request to the device for the currently selected
580 * \ingroup Group_EndpointPacketManagement
582 static inline void Endpoint_StallTransaction(void) ATTR_ALWAYS_INLINE
;
583 static inline void Endpoint_StallTransaction(void)
585 UECONX
|= (1 << STALLRQ
);
588 /** Clears the STALL condition on the currently selected endpoint.
590 * \ingroup Group_EndpointPacketManagement
592 static inline void Endpoint_ClearStall(void) ATTR_ALWAYS_INLINE
;
593 static inline void Endpoint_ClearStall(void)
595 UECONX
|= (1 << STALLRQC
);
598 /** Determines if the currently selected endpoint is stalled, false otherwise.
600 * \ingroup Group_EndpointPacketManagement
602 * \return Boolean true if the currently selected endpoint is stalled, false otherwise.
604 static inline bool Endpoint_IsStalled(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE
;
605 static inline bool Endpoint_IsStalled(void)
607 return ((UECONX
& (1 << STALLRQ
)) ?
true : false);
610 /** Resets the data toggle of the currently selected endpoint. */
611 static inline void Endpoint_ResetDataToggle(void) ATTR_ALWAYS_INLINE
;
612 static inline void Endpoint_ResetDataToggle(void)
614 UECONX
|= (1 << RSTDT
);
617 /** Determines the currently selected endpoint's direction.
619 * \return The currently selected endpoint's direction, as a ENDPOINT_DIR_* mask.
621 static inline uint8_t Endpoint_GetEndpointDirection(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE
;
622 static inline uint8_t Endpoint_GetEndpointDirection(void)
624 return (UECFG0X
& ENDPOINT_DIR_IN
);
627 /** Sets the direction of the currently selected endpoint.
629 * \param[in] DirectionMask New endpoint direction, as a ENDPOINT_DIR_* mask.
631 static inline void Endpoint_SetEndpointDirection(const uint8_t DirectionMask
) ATTR_ALWAYS_INLINE
;
632 static inline void Endpoint_SetEndpointDirection(const uint8_t DirectionMask
)
634 UECFG0X
= ((UECFG0X
& ~ENDPOINT_DIR_IN
) | DirectionMask
);
637 /** Reads one byte from the currently selected endpoint's bank, for OUT direction endpoints.
639 * \ingroup Group_EndpointPrimitiveRW
641 * \return Next byte in the currently selected endpoint's FIFO buffer.
643 static inline uint8_t Endpoint_Read_Byte(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE
;
644 static inline uint8_t Endpoint_Read_Byte(void)
649 /** Writes one byte from the currently selected endpoint's bank, for IN direction endpoints.
651 * \ingroup Group_EndpointPrimitiveRW
653 * \param[in] Byte Next byte to write into the the currently selected endpoint's FIFO buffer.
655 static inline void Endpoint_Write_Byte(const uint8_t Byte
) ATTR_ALWAYS_INLINE
;
656 static inline void Endpoint_Write_Byte(const uint8_t Byte
)
661 /** Discards one byte from the currently selected endpoint's bank, for OUT direction endpoints.
663 * \ingroup Group_EndpointPrimitiveRW
665 static inline void Endpoint_Discard_Byte(void) ATTR_ALWAYS_INLINE
;
666 static inline void Endpoint_Discard_Byte(void)
673 /** Reads two bytes from the currently selected endpoint's bank in little endian format, for OUT
674 * direction endpoints.
676 * \ingroup Group_EndpointPrimitiveRW
678 * \return Next word in the currently selected endpoint's FIFO buffer.
680 static inline uint16_t Endpoint_Read_Word_LE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE
;
681 static inline uint16_t Endpoint_Read_Word_LE(void)
689 Data
.Bytes
[0] = UEDATX
;
690 Data
.Bytes
[1] = UEDATX
;
695 /** Reads two bytes from the currently selected endpoint's bank in big endian format, for OUT
696 * direction endpoints.
698 * \ingroup Group_EndpointPrimitiveRW
700 * \return Next word in the currently selected endpoint's FIFO buffer.
702 static inline uint16_t Endpoint_Read_Word_BE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE
;
703 static inline uint16_t Endpoint_Read_Word_BE(void)
711 Data
.Bytes
[1] = UEDATX
;
712 Data
.Bytes
[0] = UEDATX
;
717 /** Writes two bytes to the currently selected endpoint's bank in little endian format, for IN
718 * direction endpoints.
720 * \ingroup Group_EndpointPrimitiveRW
722 * \param[in] Word Next word to write to the currently selected endpoint's FIFO buffer.
724 static inline void Endpoint_Write_Word_LE(const uint16_t Word
) ATTR_ALWAYS_INLINE
;
725 static inline void Endpoint_Write_Word_LE(const uint16_t Word
)
727 UEDATX
= (Word
& 0xFF);
728 UEDATX
= (Word
>> 8);
731 /** Writes two bytes to the currently selected endpoint's bank in big endian format, for IN
732 * direction endpoints.
734 * \ingroup Group_EndpointPrimitiveRW
736 * \param[in] Word Next word to write to the currently selected endpoint's FIFO buffer.
738 static inline void Endpoint_Write_Word_BE(const uint16_t Word
) ATTR_ALWAYS_INLINE
;
739 static inline void Endpoint_Write_Word_BE(const uint16_t Word
)
741 UEDATX
= (Word
>> 8);
742 UEDATX
= (Word
& 0xFF);
745 /** Discards two bytes from the currently selected endpoint's bank, for OUT direction endpoints.
747 * \ingroup Group_EndpointPrimitiveRW
749 static inline void Endpoint_Discard_Word(void) ATTR_ALWAYS_INLINE
;
750 static inline void Endpoint_Discard_Word(void)
758 /** Reads four bytes from the currently selected endpoint's bank in little endian format, for OUT
759 * direction endpoints.
761 * \ingroup Group_EndpointPrimitiveRW
763 * \return Next double word in the currently selected endpoint's FIFO buffer.
765 static inline uint32_t Endpoint_Read_DWord_LE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE
;
766 static inline uint32_t Endpoint_Read_DWord_LE(void)
774 Data
.Bytes
[0] = UEDATX
;
775 Data
.Bytes
[1] = UEDATX
;
776 Data
.Bytes
[2] = UEDATX
;
777 Data
.Bytes
[3] = UEDATX
;
782 /** Reads four bytes from the currently selected endpoint's bank in big endian format, for OUT
783 * direction endpoints.
785 * \ingroup Group_EndpointPrimitiveRW
787 * \return Next double word in the currently selected endpoint's FIFO buffer.
789 static inline uint32_t Endpoint_Read_DWord_BE(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE
;
790 static inline uint32_t Endpoint_Read_DWord_BE(void)
798 Data
.Bytes
[3] = UEDATX
;
799 Data
.Bytes
[2] = UEDATX
;
800 Data
.Bytes
[1] = UEDATX
;
801 Data
.Bytes
[0] = UEDATX
;
806 /** Writes four bytes to the currently selected endpoint's bank in little endian format, for IN
807 * direction endpoints.
809 * \ingroup Group_EndpointPrimitiveRW
811 * \param[in] DWord Next double word to write to the currently selected endpoint's FIFO buffer.
813 static inline void Endpoint_Write_DWord_LE(const uint32_t DWord
) ATTR_ALWAYS_INLINE
;
814 static inline void Endpoint_Write_DWord_LE(const uint32_t DWord
)
816 UEDATX
= (DWord
& 0xFF);
817 UEDATX
= (DWord
>> 8);
818 UEDATX
= (DWord
>> 16);
819 UEDATX
= (DWord
>> 24);
822 /** Writes four bytes to the currently selected endpoint's bank in big endian format, for IN
823 * direction endpoints.
825 * \ingroup Group_EndpointPrimitiveRW
827 * \param[in] DWord Next double word to write to the currently selected endpoint's FIFO buffer.
829 static inline void Endpoint_Write_DWord_BE(const uint32_t DWord
) ATTR_ALWAYS_INLINE
;
830 static inline void Endpoint_Write_DWord_BE(const uint32_t DWord
)
832 UEDATX
= (DWord
>> 24);
833 UEDATX
= (DWord
>> 16);
834 UEDATX
= (DWord
>> 8);
835 UEDATX
= (DWord
& 0xFF);
838 /** Discards four bytes from the currently selected endpoint's bank, for OUT direction endpoints.
840 * \ingroup Group_EndpointPrimitiveRW
842 static inline void Endpoint_Discard_DWord(void) ATTR_ALWAYS_INLINE
;
843 static inline void Endpoint_Discard_DWord(void)
853 /* External Variables: */
854 /** Global indicating the maximum packet size of the default control endpoint located at address
855 * 0 in the device. This value is set to the value indicated in the device descriptor in the user
856 * project once the USB interface is initialized into device mode.
858 * If space is an issue, it is possible to fix this to a static value by defining the control
859 * endpoint size in the FIXED_CONTROL_ENDPOINT_SIZE token passed to the compiler in the makefile
860 * via the -D switch. When a fixed control endpoint size is used, the size is no longer dynamically
861 * read from the descriptors at runtime and instead fixed to the given value. When used, it is
862 * important that the descriptor control endpoint size value matches the size given as the
863 * FIXED_CONTROL_ENDPOINT_SIZE token - it is recommended that the FIXED_CONTROL_ENDPOINT_SIZE token
864 * be used in the descriptors to ensure this.
866 * \note This variable should be treated as read-only in the user application, and never manually
869 #if (!defined(FIXED_CONTROL_ENDPOINT_SIZE) || defined(__DOXYGEN__))
870 extern uint8_t USB_ControlEndpointSize
;
872 #define USB_ControlEndpointSize FIXED_CONTROL_ENDPOINT_SIZE
875 /* Function Prototypes: */
876 /** Spin-loops until the currently selected non-control endpoint is ready for the next packet of data
877 * to be read or written to it.
879 * \note This routine should not be called on CONTROL type endpoints.
881 * \ingroup Group_EndpointRW
883 * \return A value from the \ref Endpoint_WaitUntilReady_ErrorCodes_t enum.
885 uint8_t Endpoint_WaitUntilReady(void);
887 /** Completes the status stage of a control transfer on a CONTROL type endpoint automatically,
888 * with respect to the data direction. This is a convenience function which can be used to
889 * simplify user control request handling.
891 void Endpoint_ClearStatusStage(void);
893 /** Reads and discards the given number of bytes from the endpoint from the given buffer,
894 * discarding fully read packets from the host as needed. The last packet is not automatically
895 * discarded once the remaining bytes has been read; the user is responsible for manually
896 * discarding the last packet from the host via the \ref Endpoint_ClearOUT() macro. Between
897 * each USB packet, the given stream callback function is executed repeatedly until the next
898 * packet is ready, allowing for early aborts of stream transfers.
900 * The callback routine should be created according to the information in \ref Group_StreamCallbacks.
901 * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are
902 * disabled and this function has the Callback parameter omitted.
904 * \note This routine should not be used on CONTROL type endpoints.
906 * \ingroup Group_EndpointStreamRW
908 * \param[in] Length Number of bytes to send via the currently selected endpoint.
909 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback.
911 * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
913 uint8_t Endpoint_Discard_Stream(uint16_t Length
916 /** Writes the given number of bytes to the endpoint from the given buffer in little endian,
917 * sending full packets to the host as needed. The last packet filled is not automatically sent;
918 * the user is responsible for manually sending the last written packet to the host via the
919 * \ref Endpoint_ClearIN() macro. Between each USB packet, the given stream callback function
920 * is executed repeatedly until the endpoint is ready to accept the next packet, allowing for early
921 * aborts of stream transfers.
923 * The callback routine should be created according to the information in \ref Group_StreamCallbacks.
924 * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are
925 * disabled and this function has the Callback parameter omitted.
927 * \note This routine should not be used on CONTROL type endpoints.
929 * \ingroup Group_EndpointStreamRW
931 * \param[in] Buffer Pointer to the source data buffer to read from.
932 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
933 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback.
935 * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
937 uint8_t Endpoint_Write_Stream_LE(const void* Buffer
,
939 __CALLBACK_PARAM
) ATTR_NON_NULL_PTR_ARG(1);
941 /** EEPROM buffer source version of \ref Endpoint_Write_Stream_LE().
943 * \ingroup Group_EndpointStreamRW
945 * \param[in] Buffer Pointer to the source data buffer to read from.
946 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
947 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback.
949 * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
951 uint8_t Endpoint_Write_EStream_LE(const void* Buffer
,
953 __CALLBACK_PARAM
) ATTR_NON_NULL_PTR_ARG(1);
955 /** FLASH buffer source version of \ref Endpoint_Write_Stream_LE().
957 * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.
959 * \ingroup Group_EndpointStreamRW
961 * \param[in] Buffer Pointer to the source data buffer to read from.
962 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
963 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback.
965 * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
967 uint8_t Endpoint_Write_PStream_LE(const void* Buffer
,
969 __CALLBACK_PARAM
) ATTR_NON_NULL_PTR_ARG(1);
971 /** Writes the given number of bytes to the endpoint from the given buffer in big endian,
972 * sending full packets to the host as needed. The last packet filled is not automatically sent;
973 * the user is responsible for manually sending the last written packet to the host via the
974 * \ref Endpoint_ClearIN() macro. Between each USB packet, the given stream callback function
975 * is executed repeatedly until the endpoint is ready to accept the next packet, allowing for early
976 * aborts of stream transfers.
978 * The callback routine should be created according to the information in \ref Group_StreamCallbacks.
979 * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are
980 * disabled and this function has the Callback parameter omitted.
982 * \note This routine should not be used on CONTROL type endpoints.
984 * \ingroup Group_EndpointStreamRW
986 * \param[in] Buffer Pointer to the source data buffer to read from.
987 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
988 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback.
990 * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
992 uint8_t Endpoint_Write_Stream_BE(const void* Buffer
,
994 __CALLBACK_PARAM
) ATTR_NON_NULL_PTR_ARG(1);
996 /** EEPROM buffer source version of \ref Endpoint_Write_Stream_BE().
998 * \ingroup Group_EndpointStreamRW
1000 * \param[in] Buffer Pointer to the source data buffer to read from.
1001 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
1002 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback.
1004 * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
1006 uint8_t Endpoint_Write_EStream_BE(const void* Buffer
,
1008 __CALLBACK_PARAM
) ATTR_NON_NULL_PTR_ARG(1);
1010 /** FLASH buffer source version of \ref Endpoint_Write_Stream_BE().
1012 * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.
1014 * \ingroup Group_EndpointStreamRW
1016 * \param[in] Buffer Pointer to the source data buffer to read from.
1017 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
1018 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback.
1020 * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
1022 uint8_t Endpoint_Write_PStream_BE(const void* Buffer
,
1024 __CALLBACK_PARAM
) ATTR_NON_NULL_PTR_ARG(1);
1026 /** Reads the given number of bytes from the endpoint from the given buffer in little endian,
1027 * discarding fully read packets from the host as needed. The last packet is not automatically
1028 * discarded once the remaining bytes has been read; the user is responsible for manually
1029 * discarding the last packet from the host via the \ref Endpoint_ClearOUT() macro. Between
1030 * each USB packet, the given stream callback function is executed repeatedly until the endpoint
1031 * is ready to accept the next packet, allowing for early aborts of stream transfers.
1033 * The callback routine should be created according to the information in \ref Group_StreamCallbacks.
1034 * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are
1035 * disabled and this function has the Callback parameter omitted.
1037 * \note This routine should not be used on CONTROL type endpoints.
1039 * \ingroup Group_EndpointStreamRW
1041 * \param[out] Buffer Pointer to the destination data buffer to write to.
1042 * \param[in] Length Number of bytes to send via the currently selected endpoint.
1043 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback.
1045 * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
1047 uint8_t Endpoint_Read_Stream_LE(void* Buffer
,
1049 __CALLBACK_PARAM
) ATTR_NON_NULL_PTR_ARG(1);
1051 /** EEPROM buffer source version of \ref Endpoint_Read_Stream_LE().
1053 * \ingroup Group_EndpointStreamRW
1055 * \param[out] Buffer Pointer to the destination data buffer to write to, located in EEPROM memory space.
1056 * \param[in] Length Number of bytes to send via the currently selected endpoint.
1057 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback.
1059 * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
1061 uint8_t Endpoint_Read_EStream_LE(void* Buffer
,
1063 __CALLBACK_PARAM
) ATTR_NON_NULL_PTR_ARG(1);
1065 /** Reads the given number of bytes from the endpoint from the given buffer in big endian,
1066 * discarding fully read packets from the host as needed. The last packet is not automatically
1067 * discarded once the remaining bytes has been read; the user is responsible for manually
1068 * discarding the last packet from the host via the \ref Endpoint_ClearOUT() macro. Between
1069 * each USB packet, the given stream callback function is executed repeatedly until the endpoint
1070 * is ready to accept the next packet, allowing for early aborts of stream transfers.
1072 * The callback routine should be created according to the information in \ref Group_StreamCallbacks.
1073 * If the token NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are
1074 * disabled and this function has the Callback parameter omitted.
1076 * \note This routine should not be used on CONTROL type endpoints.
1078 * \ingroup Group_EndpointStreamRW
1080 * \param[out] Buffer Pointer to the destination data buffer to write to.
1081 * \param[in] Length Number of bytes to send via the currently selected endpoint.
1082 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback.
1084 * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
1086 uint8_t Endpoint_Read_Stream_BE(void* Buffer
,
1088 __CALLBACK_PARAM
) ATTR_NON_NULL_PTR_ARG(1);
1090 /** EEPROM buffer source version of \ref Endpoint_Read_Stream_BE().
1092 * \ingroup Group_EndpointStreamRW
1094 * \param[out] Buffer Pointer to the destination data buffer to write to, located in EEPROM memory space.
1095 * \param[in] Length Number of bytes to send via the currently selected endpoint.
1096 * \param[in] Callback Name of a callback routine to call between successive USB packet transfers, NULL if no callback.
1098 * \return A value from the \ref Endpoint_Stream_RW_ErrorCodes_t enum.
1100 uint8_t Endpoint_Read_EStream_BE(void* Buffer
,
1102 __CALLBACK_PARAM
) ATTR_NON_NULL_PTR_ARG(1);
1104 /** Writes the given number of bytes to the CONTROL type endpoint from the given buffer in little endian,
1105 * sending full packets to the host as needed. The host OUT acknowledgement is not automatically cleared
1106 * in both failure and success states; the user is responsible for manually clearing the setup OUT to
1107 * finalize the transfer via the \ref Endpoint_ClearOUT() macro.
1109 * \note This function automatically clears the control transfer's status stage. Do not manually attempt
1110 * to clear the status stage when using this routine in a control transaction.
1113 * \note This routine should only be used on CONTROL type endpoints.
1115 * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
1116 * together; i.e. the entire stream data must be read or written at the one time.
1118 * \ingroup Group_EndpointStreamRW
1120 * \param[in] Buffer Pointer to the source data buffer to read from.
1121 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
1123 * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
1125 uint8_t Endpoint_Write_Control_Stream_LE(const void* Buffer
,
1126 uint16_t Length
) ATTR_NON_NULL_PTR_ARG(1);
1128 /** EEPROM buffer source version of Endpoint_Write_Control_Stream_LE.
1130 * \note This function automatically clears the control transfer's status stage. Do not manually attempt
1131 * to clear the status stage when using this routine in a control transaction.
1134 * \note This routine should only be used on CONTROL type endpoints.
1136 * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
1137 * together; i.e. the entire stream data must be read or written at the one time.
1139 * \ingroup Group_EndpointStreamRW
1141 * \param[in] Buffer Pointer to the source data buffer to read from.
1142 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
1144 * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
1146 uint8_t Endpoint_Write_Control_EStream_LE(const void* Buffer
,
1147 uint16_t Length
) ATTR_NON_NULL_PTR_ARG(1);
1149 /** FLASH buffer source version of \ref Endpoint_Write_Control_Stream_LE().
1151 * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.
1153 * \note This function automatically clears the control transfer's status stage. Do not manually attempt
1154 * to clear the status stage when using this routine in a control transaction.
1157 * \note This routine should only be used on CONTROL type endpoints.
1159 * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
1160 * together; i.e. the entire stream data must be read or written at the one time.
1162 * \ingroup Group_EndpointStreamRW
1164 * \param[in] Buffer Pointer to the source data buffer to read from.
1165 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
1167 * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
1169 uint8_t Endpoint_Write_Control_PStream_LE(const void* Buffer
,
1170 uint16_t Length
) ATTR_NON_NULL_PTR_ARG(1);
1172 /** Writes the given number of bytes to the CONTROL type endpoint from the given buffer in big endian,
1173 * sending full packets to the host as needed. The host OUT acknowledgement is not automatically cleared
1174 * in both failure and success states; the user is responsible for manually clearing the setup OUT to
1175 * finalize the transfer via the \ref Endpoint_ClearOUT() macro.
1177 * \note This function automatically clears the control transfer's status stage. Do not manually attempt
1178 * to clear the status stage when using this routine in a control transaction.
1181 * \note This routine should only be used on CONTROL type endpoints.
1183 * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
1184 * together; i.e. the entire stream data must be read or written at the one time.
1186 * \ingroup Group_EndpointStreamRW
1188 * \param[in] Buffer Pointer to the source data buffer to read from.
1189 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
1191 * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
1193 uint8_t Endpoint_Write_Control_Stream_BE(const void* Buffer
,
1194 uint16_t Length
) ATTR_NON_NULL_PTR_ARG(1);
1196 /** EEPROM buffer source version of \ref Endpoint_Write_Control_Stream_BE().
1198 * \note This function automatically clears the control transfer's status stage. Do not manually attempt
1199 * to clear the status stage when using this routine in a control transaction.
1202 * \note This routine should only be used on CONTROL type endpoints.
1204 * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
1205 * together; i.e. the entire stream data must be read or written at the one time.
1207 * \ingroup Group_EndpointStreamRW
1209 * \param[in] Buffer Pointer to the source data buffer to read from.
1210 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
1212 * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
1214 uint8_t Endpoint_Write_Control_EStream_BE(const void* Buffer
,
1215 uint16_t Length
) ATTR_NON_NULL_PTR_ARG(1);
1217 /** FLASH buffer source version of \ref Endpoint_Write_Control_Stream_BE().
1219 * \pre The FLASH data must be located in the first 64KB of FLASH for this function to work correctly.
1221 * \note This function automatically clears the control transfer's status stage. Do not manually attempt
1222 * to clear the status stage when using this routine in a control transaction.
1225 * \note This routine should only be used on CONTROL type endpoints.
1227 * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
1228 * together; i.e. the entire stream data must be read or written at the one time.
1230 * \ingroup Group_EndpointStreamRW
1232 * \param[in] Buffer Pointer to the source data buffer to read from.
1233 * \param[in] Length Number of bytes to read for the currently selected endpoint into the buffer.
1235 * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
1237 uint8_t Endpoint_Write_Control_PStream_BE(const void* Buffer
,
1238 uint16_t Length
) ATTR_NON_NULL_PTR_ARG(1);
1240 /** Reads the given number of bytes from the CONTROL endpoint from the given buffer in little endian,
1241 * discarding fully read packets from the host as needed. The device IN acknowledgement is not
1242 * automatically sent after success or failure states; the user is responsible for manually sending the
1243 * setup IN to finalize the transfer via the \ref Endpoint_ClearIN() macro.
1245 * \note This function automatically clears the control transfer's status stage. Do not manually attempt
1246 * to clear the status stage when using this routine in a control transaction.
1249 * \note This routine should only be used on CONTROL type endpoints.
1251 * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
1252 * together; i.e. the entire stream data must be read or written at the one time.
1254 * \ingroup Group_EndpointStreamRW
1256 * \param[out] Buffer Pointer to the destination data buffer to write to.
1257 * \param[in] Length Number of bytes to send via the currently selected endpoint.
1259 * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
1261 uint8_t Endpoint_Read_Control_Stream_LE(void* Buffer
,
1262 uint16_t Length
) ATTR_NON_NULL_PTR_ARG(1);
1264 /** EEPROM buffer source version of \ref Endpoint_Read_Control_Stream_LE().
1266 * \note This function automatically clears the control transfer's status stage. Do not manually attempt
1267 * to clear the status stage when using this routine in a control transaction.
1270 * \note This routine should only be used on CONTROL type endpoints.
1272 * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
1273 * together; i.e. the entire stream data must be read or written at the one time.
1275 * \ingroup Group_EndpointStreamRW
1277 * \param[out] Buffer Pointer to the destination data buffer to write to.
1278 * \param[in] Length Number of bytes to send via the currently selected endpoint.
1280 * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
1282 uint8_t Endpoint_Read_Control_EStream_LE(void* Buffer
,
1283 uint16_t Length
) ATTR_NON_NULL_PTR_ARG(1);
1285 /** Reads the given number of bytes from the CONTROL endpoint from the given buffer in big endian,
1286 * discarding fully read packets from the host as needed. The device IN acknowledgement is not
1287 * automatically sent after success or failure states; the user is responsible for manually sending the
1288 * setup IN to finalize the transfer via the \ref Endpoint_ClearIN() macro.
1290 * \note This function automatically clears the control transfer's status stage. Do not manually attempt
1291 * to clear the status stage when using this routine in a control transaction.
1294 * \note This routine should only be used on CONTROL type endpoints.
1296 * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
1297 * together; i.e. the entire stream data must be read or written at the one time.
1299 * \ingroup Group_EndpointStreamRW
1301 * \param[out] Buffer Pointer to the destination data buffer to write to.
1302 * \param[in] Length Number of bytes to send via the currently selected endpoint.
1304 * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
1306 uint8_t Endpoint_Read_Control_Stream_BE(void* Buffer
,
1307 uint16_t Length
) ATTR_NON_NULL_PTR_ARG(1);
1309 /** EEPROM buffer source version of \ref Endpoint_Read_Control_Stream_BE().
1311 * \note This function automatically clears the control transfer's status stage. Do not manually attempt
1312 * to clear the status stage when using this routine in a control transaction.
1315 * \note This routine should only be used on CONTROL type endpoints.
1317 * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained
1318 * together; i.e. the entire stream data must be read or written at the one time.
1320 * \ingroup Group_EndpointStreamRW
1322 * \param[out] Buffer Pointer to the destination data buffer to write to.
1323 * \param[in] Length Number of bytes to send via the currently selected endpoint.
1325 * \return A value from the \ref Endpoint_ControlStream_RW_ErrorCodes_t enum.
1327 uint8_t Endpoint_Read_Control_EStream_BE(void* Buffer
,
1328 uint16_t Length
) ATTR_NON_NULL_PTR_ARG(1);
1330 /* Disable C linkage for C++ Compilers: */
1331 #if defined(__cplusplus)