📄 pipe.h
字号:
* accepted by the pipe before it is automatically frozen. */ #define Pipe_SetFiniteINRequests(n) MACROS{ UPCONX &= ~(1 << INMODE); UPINRQX = n; }MACROE /** Returns true if the currently selected pipe is configured, false otherwise. */ #define Pipe_IsConfigured() ((UPSTAX & (1 << CFGOK)) ? true : false) /** Sets the period between interrupts for an INTERRUPT type pipe to a specified number of milliseconds. */ #define Pipe_SetInterruptPeriod(ms) MACROS{ UPCFG2X = ms; }MACROE /** Returns a mask indicating which pipe's interrupt periods have elapsed, indicating that the pipe should * be serviced. */ #define Pipe_GetPipeInterrupts() UPINT /** Clears the interrupt flag for the specified pipe number. */ #define Pipe_ClearPipeInterrupt(n) MACROS{ UPINT &= ~(1 << n); }MACROE /** Returns true if the specified pipe's interrupt period has elapsed, false otherwise. */ #define Pipe_HasPipeInterrupted(n) ((UPINT & (1 << n)) ? true : false) /** Clears the pipe bank, and switches to the alternate bank if the currently selected pipe is * dual-banked. When cleared, this either frees the bank up for the next packet from the host * (if the endpoint is of the OUT direction) or sends the packet contents to the host (if the * pipe is of the IN direction). */ #define Pipe_ClearCurrentBank() MACROS{ UPINTX &= ~(1 << FIFOCON); }MACROE /** Unfreezes the pipe, allowing it to communicate with an attached device. */ #define Pipe_Unfreeze() MACROS{ UPCONX &= ~(1 << PFREEZE); }MACROE /** Freezes the pipe, preventing it from communicating with an attached device. */ #define Pipe_Freeze() MACROS{ UPCONX |= (1 << PFREEZE); }MACROE /** Clears the master pipe error flag. */ #define Pipe_ClearError() MACROS{ UPINTX &= ~(1 << PERRI); }MACROE /** Returns true if the master pipe error flag is set for the currently selected pipe, indicating that * some sort of hardware error has occurred on the pipe. * * \see Pipe_GetErrorFlags() macro for information on retreiving the exact error flag. */ #define Pipe_IsError() ((UPINTX & (1 << PERRI)) ? true : false) /** Clears all the currently selected pipe's hardware error flags, but does not clear the master error * flag for the pipe. */ #define Pipe_ClearErrorFlags() MACROS{ UPERRX = 0; }MACROE /** Returns a mask of the hardware error flags which have occured on the currently selected pipe. This * value can then be masked against the PIPE_ERRORFLAG_* masks to determine what error has occurred. */ #define Pipe_GetErrorFlags() UPERRX /** Returns true if the currently selected pipe may be read from (if data is waiting in the pipe * bank and the pipe is an IN direction, or if the bank is not yet full if the pipe is an OUT * direction). This function will return false if an error has occured in the pipe, or if the pipe * is an IN direction and no packet has been received, or if the pipe is an OUT direction and the * pipe bank is full. */ #define Pipe_ReadWriteAllowed() ((UPINTX & (1 << RWAL)) ? true : false) /** Clears the flag indicating that a SETUP request has been sent to the attached device from the * currently selected CONTROL type pipe. */ #define Pipe_ClearSetupSent() MACROS{ UPINTX &= ~(1 << TXSTPI); }MACROE /** Returns true if no SETUP request is currently being sent to the attached device, false otherwise. */ #define Pipe_IsSetupSent() ((UPINTX & (1 << TXSTPI)) ? true : false) /** Returns true if the currently selected pipe has been stalled by the attached device, false otherwise. */ #define Pipe_IsStalled() ((UPINTX & (1 << RXSTALLI)) ? true : false) /** Clears the stall condition on the currently selected pipe. */ #define Pipe_ClearStall() MACROS{ UPINTX &= ~(1 << RXSTALLI); }MACROE /** Returns true if an IN request has been received on the currently selected CONTROL type pipe, false * otherwise. */ #define Pipe_IsSetupINReceived() ((UPINTX & (1 << RXINI)) ? true : false) /** Returns true if the currently selected CONTROL type pipe is ready to send an OUT request, false * otherwise. */ #define Pipe_IsSetupOUTReady() ((UPINTX & (1 << TXOUTI)) ? true : false) /** Acknowedges the reception of a setup IN request from the attached device on the currently selected * CONTROL type endpoint, allowing for the transmission of a setup OUT packet, or the reception of * another setup IN packet. */ #define Pipe_ClearSetupIN() MACROS{ UPINTX &= ~(1 << RXINI); UPINTX &= ~(1 << FIFOCON); }MACROE /** Sends the currently selected CONTROL type pipe's contents to the device as a setup OUT packet. */ #define Pipe_ClearSetupOUT() MACROS{ UPINTX &= ~(1 << TXOUTI); UPINTX &= ~(1 << FIFOCON); }MACROE /** Returns true if the device sent a NAK (Negative Acknowedge) in response to the last sent packet on * the currently selected pipe. This ocurrs when the host sends a packet to the device, but the device * is not currently ready to handle the packet (i.e. its endpoint banks are full). Once a NAK has been * received, it must be cleard using Pipe_ClearNAKReceived() before the previous (or any other) packet * can be re-sent. */ #define Pipe_IsNAKReceived() ((UPINTX & (1 << NAKEDI)) ? true : false) /** Clears the NAK condition on the currently selected pipe. * * \see Pipe_IsNAKReceived() for more details. */ #define Pipe_ClearNAKReceived() MACROS{ UPINTX &= ~(1 << NAKEDI); }MACROE /* Enums: */ /** Enum for the possible error return codes of the Pipe_WaitUntilReady function */ enum Pipe_WaitUntilReady_ErrorCodes_t { PIPE_READYWAIT_NoError = 0, /**< Pipe ready for next packet, no error */ PIPE_READYWAIT_PipeStalled = 1, /**< The device stalled the pipe while waiting. */ PIPE_READYWAIT_DeviceDisconnected = 2, /**< Device was disconnected from the host while waiting. */ PIPE_READYWAIT_Timeout = 3, /**< The device failed to accept or send the next packet * within the software timeout period set by the * USB_STREAM_TIMEOUT_MS macro. */ }; /** Enum for the possible error return codes of the Pipe_*_Stream_* functions. */ enum Pipe_Stream_RW_ErrorCodes_t { PIPE_RWSTREAM_ERROR_NoError = 0, /**< Command completed successfully, no error. */ PIPE_RWSTREAM_ERROR_PipeStalled = 1, /**< The device stalled the pipe during the transfer. */ PIPE_RWSTREAM_ERROR_DeviceDisconnected = 2, /**< Device was disconnected from the host during * the transfer. */ PIPE_RWSTREAM_ERROR_Timeout = 3, /**< The device failed to accept or send the next packet * within the software timeout period set by the * USB_STREAM_TIMEOUT_MS macro. */ PIPE_RWSTREAM_ERROR_CallbackAborted = 4, /**< Indicates that the stream's callback function aborted * the transfer early. */ }; /* Inline Functions: */ /** Reads one byte from the currently selected pipe's bank, for OUT direction pipes. */ static inline uint8_t Pipe_Read_Byte(void) ATTR_WARN_UNUSED_RESULT; static inline uint8_t Pipe_Read_Byte(void) { return UPDATX; } /** Writes one byte from the currently selected pipe's bank, for IN direction pipes. */ static inline void Pipe_Write_Byte(const uint8_t Byte) { UPDATX = Byte; } /** Discards one byte from the currently selected pipe's bank, for OUT direction pipes. */ static inline void Pipe_Discard_Byte(void) { uint8_t Dummy; Dummy = UPDATX; } /** Reads two bytes from the currently selected pipe's bank in little endian format, for OUT * direction pipes. */ static inline uint16_t Pipe_Read_Word_LE(void) ATTR_WARN_UNUSED_RESULT; static inline uint16_t Pipe_Read_Word_LE(void) { uint16_t Data; Data = UPDATX; Data |= (((uint16_t)UPDATX) << 8); return Data; } /** Reads two bytes from the currently selected pipe's bank in big endian format, for OUT * direction pipes. */ static inline uint16_t Pipe_Read_Word_BE(void) ATTR_WARN_UNUSED_RESULT; static inline uint16_t Pipe_Read_Word_BE(void) { uint16_t Data; Data = (((uint16_t)UPDATX) << 8); Data |= UPDATX; return Data; } /** Writes two bytes to the currently selected pipe's bank in little endian format, for IN * direction pipes. */ static inline void Pipe_Write_Word_LE(const uint16_t Word) { UPDATX = (Word & 0xFF); UPDATX = (Word >> 8); } /** Writes two bytes to the currently selected pipe's bank in big endian format, for IN * direction pipes. */ static inline void Pipe_Write_Word_BE(const uint16_t Word) { UPDATX = (Word >> 8); UPDATX = (Word & 0xFF); } /** Discards two bytes from the currently selected pipe's bank, for OUT direction pipes. */ static inline void Pipe_Ignore_Word(void) { uint8_t Dummy; Dummy = UPDATX; Dummy = UPDATX; } /** Reads four bytes from the currently selected pipe's bank in little endian format, for OUT * direction pipes. */ static inline uint32_t Pipe_Read_DWord_LE(void) ATTR_WARN_UNUSED_RESULT; static inline uint32_t Pipe_Read_DWord_LE(void) { union { uint32_t DWord; uint8_t Bytes[4]; } Data; Data.Bytes[0] = UPDATX; Data.Bytes[1] = UPDATX; Data.Bytes[2] = UPDATX; Data.Bytes[3] = UPDATX; return Data.DWord; } /** Reads four bytes from the currently selected pipe's bank in big endian format, for OUT * direction pipes. */ static inline uint32_t Pipe_Read_DWord_BE(void) ATTR_WARN_UNUSED_RESULT; static inline uint32_t Pipe_Read_DWord_BE(void) { union { uint32_t DWord; uint8_t Bytes[4]; } Data; Data.Bytes[3] = UPDATX; Data.Bytes[2] = UPDATX; Data.Bytes[1] = UPDATX; Data.Bytes[0] = UPDATX; return Data.DWord; } /** Writes four bytes to the currently selected pipe's bank in little endian format, for IN * direction pipes. */ static inline void Pipe_Write_DWord_LE(const uint32_t DWord) { Pipe_Write_Word_LE(DWord); Pipe_Write_Word_LE(DWord >> 16); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -