📄 endpoint.h
字号:
* interrupt duration has elapsed. Which endpoints have interrupted can be determined by
* masking the return value against (1 << {Endpoint Number}).
*
* \return Mask whose bits indicate which endpoints have interrupted
*/
static inline uint8_t Endpoint_GetEndpointInterrupts(void);
/** Clears the endpoint interrupt flag. This clears the specified endpoint number's interrupt
* mask in the endpoint interrupt flag register.
*
* \param EndpointNumber Index of the endpoint whose interrupt flag should be cleared
*/
static inline void Endpoint_ClearEndpointInterrupt(uint8_t EndpointNumber);
/** Determines if the specified endpoint number has interrupted (valid only for INTERRUPT type
* endpoints).
*
* \param EndpointNumber Index of the endpoint whose interrupt flag should be tested
*
* \return Boolean true if the specified endpoint has interrupted, false otherwise
*/
static inline bool Endpoint_HasEndpointInterrupted(uint8_t EndpointNumber);
/** Determines if the selected IN endpoint is ready for a new packet.
*
* \ingroup Group_EndpointPacketManagement
*
* \return Boolean true if the current endpoint is ready for an IN packet, false otherwise.
*/
static inline bool Endpoint_IsINReady(void);
/** Determines if the selected OUT endpoint has received new packet.
*
* \ingroup Group_EndpointPacketManagement
*
* \return Boolean true if current endpoint is has received an OUT packet, false otherwise.
*/
static inline bool Endpoint_IsOUTReceived(void);
/** Determines if the current CONTROL type endpoint has received a SETUP packet.
*
* \ingroup Group_EndpointPacketManagement
*
* \return Boolean true if the selected endpoint has received a SETUP packet, false otherwise.
*/
static inline bool Endpoint_IsSETUPReceived(void);
/** Clears a received SETUP packet on the currently selected CONTROL type endpoint, freeing up the
* endpoint for the next packet.
*
* \ingroup Group_EndpointPacketManagement
*
* \note This is not applicable for non CONTROL type endpoints.
*/
static inline void Endpoint_ClearSETUP(void);
/** Sends an IN packet to the host on the currently selected endpoint, freeing up the endpoint for the
* next packet and switching to the alternative endpoint bank if double banked.
*
* \ingroup Group_EndpointPacketManagement
*/
static inline void Endpoint_ClearIN(void);
/** Acknowledges an OUT packet to the host on the currently selected endpoint, freeing up the endpoint
* for the next packet and switching to the alternative endpoint bank if double banked.
*
* \ingroup Group_EndpointPacketManagement
*/
static inline void Endpoint_ClearOUT(void);
/** Stalls the current endpoint, indicating to the host that a logical problem occurred with the
* indicated endpoint and that the current transfer sequence should be aborted. This provides a
* way for devices to indicate invalid commands to the host so that the current transfer can be
* aborted and the host can begin its own recovery sequence.
*
* The currently selected endpoint remains stalled until either the \ref Endpoint_ClearStall() macro
* is called, or the host issues a CLEAR FEATURE request to the device for the currently selected
* endpoint.
*
* \ingroup Group_EndpointPacketManagement
*/
static inline void Endpoint_StallTransaction(void);
/** Clears the STALL condition on the currently selected endpoint.
*
* \ingroup Group_EndpointPacketManagement
*/
static inline void Endpoint_ClearStall(void);
/** Determines if the currently selected endpoint is stalled, false otherwise.
*
* \ingroup Group_EndpointPacketManagement
*
* \return Boolean true if the currently selected endpoint is stalled, false otherwise
*/
static inline bool Endpoint_IsStalled(void);
/** Resets the data toggle of the currently selected endpoint. */
static inline void Endpoint_ResetDataToggle(void);
/** Determines the currently selected endpoint's direction.
*
* \return The currently selected endpoint's direction, as a ENDPOINT_DIR_* mask.
*/
static inline uint8_t Endpoint_GetEndpointDirection(void);
#else
#if defined(USB_FULL_CONTROLLER) || defined(USB_MODIFIED_FULL_CONTROLLER) || defined(__DOXYGEN__)
#define Endpoint_BytesInEndpoint() UEBCX
#else
#define Endpoint_BytesInEndpoint() UEBCLX
#endif
#if !defined(CONTROL_ONLY_DEVICE)
#define Endpoint_GetCurrentEndpoint() (UENUM & ENDPOINT_EPNUM_MASK)
#else
#define Endpoint_GetCurrentEndpoint() ENDPOINT_CONTROLEP
#endif
#if !defined(CONTROL_ONLY_DEVICE)
#define Endpoint_SelectEndpoint(epnum) MACROS{ UENUM = epnum; }MACROE
#else
#define Endpoint_SelectEndpoint(epnum) (void)epnum
#endif
#define Endpoint_ResetFIFO(epnum) MACROS{ UERST = (1 << epnum); UERST = 0; }MACROE
#define Endpoint_EnableEndpoint() MACROS{ UECONX |= (1 << EPEN); }MACROE
#define Endpoint_DisableEndpoint() MACROS{ UECONX &= ~(1 << EPEN); }MACROE
#define Endpoint_IsEnabled() ((UECONX & (1 << EPEN)) ? true : false)
#if !defined(CONTROL_ONLY_DEVICE)
#define Endpoint_IsReadWriteAllowed() ((UEINTX & (1 << RWAL)) ? true : false)
#endif
#define Endpoint_IsConfigured() ((UESTA0X & (1 << CFGOK)) ? true : false)
#define Endpoint_GetEndpointInterrupts() UEINT
#define Endpoint_ClearEndpointInterrupt(n) MACROS{ UEINT &= ~(1 << n); }MACROE
#define Endpoint_HasEndpointInterrupted(n) ((UEINT & (1 << n)) ? true : false)
#define Endpoint_IsINReady() ((UEINTX & (1 << TXINI)) ? true : false)
#define Endpoint_IsOUTReceived() ((UEINTX & (1 << RXOUTI)) ? true : false)
#define Endpoint_IsSETUPReceived() ((UEINTX & (1 << RXSTPI)) ? true : false)
#define Endpoint_ClearSETUP() MACROS{ UEINTX &= ~(1 << RXSTPI); }MACROE
#if !defined(CONTROL_ONLY_DEVICE)
#define Endpoint_ClearIN() MACROS{ uint8_t Temp = UEINTX; UEINTX = (Temp & ~(1 << TXINI)); \
UEINTX = (Temp & ~(1 << FIFOCON)); }MACROE
#else
#define Endpoint_ClearIN() MACROS{ UEINTX &= ~(1 << TXINI); }MACROE
#endif
#if !defined(CONTROL_ONLY_DEVICE)
#define Endpoint_ClearOUT() MACROS{ uint8_t Temp = UEINTX; UEINTX = (Temp & ~(1 << RXOUTI)); \
UEINTX = (Temp & ~(1 << FIFOCON)); }MACROE
#else
#define Endpoint_ClearOUT() MACROS{ UEINTX &= ~(1 << RXOUTI); }MACROE
#endif
#define Endpoint_StallTransaction() MACROS{ UECONX |= (1 << STALLRQ); }MACROE
#define Endpoint_ClearStall() MACROS{ UECONX |= (1 << STALLRQC); }MACROE
#define Endpoint_IsStalled() ((UECONX & (1 << STALLRQ)) ? true : false)
#define Endpoint_ResetDataToggle() MACROS{ UECONX |= (1 << RSTDT); }MACROE
#define Endpoint_GetEndpointDirection() (UECFG0X & ENDPOINT_DIR_IN)
#endif
/* Enums: */
/** Enum for the possible error return codes of the \ref Endpoint_WaitUntilReady() function.
*
* \ingroup Group_EndpointRW
*/
enum Endpoint_WaitUntilReady_ErrorCodes_t
{
ENDPOINT_READYWAIT_NoError = 0, /**< Endpoint is ready for next packet, no error. */
ENDPOINT_READYWAIT_EndpointStalled = 1, /**< The endpoint was stalled during the stream
* transfer by the host or device.
*/
ENDPOINT_READYWAIT_DeviceDisconnected = 2, /**< Device was disconnected from the host while
* waiting for the endpoint to become ready.
*/
ENDPOINT_READYWAIT_Timeout = 3, /**< The host failed to accept or send the next packet
* within the software timeout period set by the
* \ref USB_STREAM_TIMEOUT_MS macro.
*/
};
/** Enum for the possible error return codes of the Endpoint_*_Stream_* functions.
*
* \ingroup Group_EndpointRW
*/
enum Endpoint_Stream_RW_ErrorCodes_t
{
ENDPOINT_RWSTREAM_NoError = 0, /**< Command completed successfully, no error. */
ENDPOINT_RWSTREAM_EndpointStalled = 1, /**< The endpoint was stalled during the stream
* transfer by the host or device.
*/
ENDPOINT_RWSTREAM_DeviceDisconnected = 1, /**< Device was disconnected from the host during
* the transfer.
*/
ENDPOINT_RWSTREAM_Timeout = 2, /**< The host failed to accept or send the next packet
* within the software timeout period set by the
* \ref USB_STREAM_TIMEOUT_MS macro.
*/
ENDPOINT_RWSTREAM_CallbackAborted = 3, /**< Indicates that the stream's callback function
* aborted the transfer early.
*/
};
/** Enum for the possible error return codes of the Endpoint_*_Control_Stream_* functions..
*
* \ingroup Group_EndpointRW
*/
enum Endpoint_ControlStream_RW_ErrorCodes_t
{
ENDPOINT_RWCSTREAM_NoError = 0, /**< Command completed successfully, no error. */
ENDPOINT_RWCSTREAM_HostAborted = 1, /**< The aborted the transfer prematurely. */
};
/* Inline Functions: */
/** Reads one byte from the currently selected endpoint's bank, for OUT direction endpoints.
*
* \ingroup Group_EndpointRW
*
* \return Next byte in the currently selected endpoint's FIFO buffer
*/
static inline uint8_t Endpoint_Read_Byte(void) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline uint8_t Endpoint_Read_Byte(void)
{
return UEDATX;
}
/** Writes one byte from the currently selected endpoint's bank, for IN direction endpoints.
*
* \ingroup Group_EndpointRW
*
* \param Byte Next byte to write into the the currently selected endpoint's FIFO buffer
*/
static inline void Endpoint_Write_Byte(const uint8_t Byte) ATTR_ALWAYS_INLINE;
static inline void Endpoint_Write_Byte(const uint8_t Byte)
{
UEDATX = Byte;
}
/** Discards one byte from the currently selected endpoint's bank, for OUT direction endpoints.
*
* \ingroup Group_EndpointRW
*/
static inline void Endpoint_Discard_Byte(void) ATTR_ALWAYS_INLINE;
static inline void Endpoint_Discard_Byte(void)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -