⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 endpoint.h

📁 userial is an Free project building an USB to I2C/SPI/GPIO bridge, using the Atmel AT90USB647 chip.
💻 H
📖 第 1 页 / 共 3 页
字号:
				                                                 *   USB_STREAM_TIMEOUT_MS macro.				                                                 */			};					/** Enum for the possible error return codes of the Endpoint_*_Stream_* functions. */			enum Endpoint_Stream_RW_ErrorCodes_t			{				ENDPOINT_RWSTREAM_ERROR_NoError            = 0, /**< Command completed successfully, no error. */				ENDPOINT_RWSTREAM_ERROR_EndpointStalled    = 1, /**< The endpoint was stalled during the stream				                                                 *   transfer by the host or device.				                                                 */				ENDPOINT_RWSTREAM_ERROR_DeviceDisconnected = 1, /**< Device was disconnected from the host during				                                                 *   the transfer.				                                                 */				ENDPOINT_RWSTREAM_ERROR_Timeout            = 2, /**< The host failed to accept or send the next packet				                                                 *   within the software timeout period set by the				                                                 *   USB_STREAM_TIMEOUT_MS macro.				                                                 */				ENDPOINT_RWSTREAM_ERROR_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. */			enum Endpoint_ControlStream_RW_ErrorCodes_t			{				ENDPOINT_RWCSTREAM_ERROR_NoError            = 0, /**< Command completed successfully, no error. */				ENDPOINT_RWCSTREAM_ERROR_HostAborted        = 1, /**< The aborted the transfer prematurely. */			};		/* Inline Functions: */			/** Reads one byte from the currently selected endpoint's bank, for OUT direction endpoints. */			static inline uint8_t Endpoint_Read_Byte(void) ATTR_WARN_UNUSED_RESULT;			static inline uint8_t Endpoint_Read_Byte(void)			{				return UEDATX;			}			/** Writes one byte from the currently selected endpoint's bank, for IN direction endpoints. */			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. */			static inline void Endpoint_Discard_Byte(void)			{				uint8_t Dummy;								Dummy = UEDATX;			}						/** Reads two bytes from the currently selected endpoint's bank in little endian format, for OUT			 *  direction endpoints.			 */			static inline uint16_t Endpoint_Read_Word_LE(void) ATTR_WARN_UNUSED_RESULT;			static inline uint16_t Endpoint_Read_Word_LE(void)			{				uint16_t Data;								Data  = UEDATX;				Data |= (((uint16_t)UEDATX) << 8);							return Data;			}			/** Reads two bytes from the currently selected endpoint's bank in big endian format, for OUT			 *  direction endpoints.			 */			static inline uint16_t Endpoint_Read_Word_BE(void) ATTR_WARN_UNUSED_RESULT;			static inline uint16_t Endpoint_Read_Word_BE(void)			{				uint16_t Data;								Data  = (((uint16_t)UEDATX) << 8);				Data |= UEDATX;							return Data;			}			/** Writes two bytes to the currently selected endpoint's bank in little endian format, for IN			 *  direction endpoints.			 */			static inline void Endpoint_Write_Word_LE(const uint16_t Word)			{				UEDATX = (Word & 0xFF);				UEDATX = (Word >> 8);			}						/** Writes two bytes to the currently selected endpoint's bank in big endian format, for IN			 *  direction endpoints.			 */			static inline void Endpoint_Write_Word_BE(const uint16_t Word)			{				UEDATX = (Word >> 8);				UEDATX = (Word & 0xFF);			}			/** Discards two bytes from the currently selected endpoint's bank, for OUT direction endpoints. */			static inline void Endpoint_Discard_Word(void)			{				uint8_t Dummy;								Dummy = UEDATX;				Dummy = UEDATX;			}			/** Reads four bytes from the currently selected endpoint's bank in little endian format, for OUT			 *  direction endpoints.			 */			static inline uint32_t Endpoint_Read_DWord_LE(void) ATTR_WARN_UNUSED_RESULT;			static inline uint32_t Endpoint_Read_DWord_LE(void)			{				union				{					uint32_t DWord;					uint8_t  Bytes[4];				} Data;								Data.Bytes[0] = UEDATX;				Data.Bytes[1] = UEDATX;				Data.Bytes[2] = UEDATX;				Data.Bytes[3] = UEDATX;							return Data.DWord;			}			/** Reads four bytes from the currently selected endpoint's bank in big endian format, for OUT			 *  direction endpoints.			 */			static inline uint32_t Endpoint_Read_DWord_BE(void) ATTR_WARN_UNUSED_RESULT;			static inline uint32_t Endpoint_Read_DWord_BE(void)			{				union				{					uint32_t DWord;					uint8_t  Bytes[4];				} Data;								Data.Bytes[3] = UEDATX;				Data.Bytes[2] = UEDATX;				Data.Bytes[1] = UEDATX;				Data.Bytes[0] = UEDATX;							return Data.DWord;			}			/** Writes four bytes to the currently selected endpoint's bank in little endian format, for IN			 *  direction endpoints.			 */			static inline void Endpoint_Write_DWord_LE(const uint32_t DWord)			{				Endpoint_Write_Word_LE(DWord);				Endpoint_Write_Word_LE(DWord >> 16);			}						/** Writes four bytes to the currently selected endpoint's bank in big endian format, for IN			 *  direction endpoints.			 */			static inline void Endpoint_Write_DWord_BE(const uint32_t DWord)			{				Endpoint_Write_Word_BE(DWord >> 16);				Endpoint_Write_Word_BE(DWord);			}			/** Discards four bytes from the currently selected endpoint's bank, for OUT direction endpoints. */			static inline void Endpoint_Discard_DWord(void)			{				uint8_t Dummy;								Dummy = UEDATX;				Dummy = UEDATX;				Dummy = UEDATX;				Dummy = UEDATX;			}		/* External Variables: */			/** Global indicating the maximum packet size of the default control endpoint located at address			 *  0 in the device. This value is set to the value indicated in the device descriptor in the user			 *  project once the USB interface is initialized into device mode.			 *			 *  If space is an issue, it is possible to fix this to a static value by defining the control			 *  endpoint size in the FIXED_CONTROL_ENDPOINT_SIZE token passed to the compiler in the makefile			 *  via the -D switch. When a fixed control endpoint size is used, the size is no longer dynamically			 *  read from the descriptors at runtime and instead fixed to the given value. When used, it is			 *  important that the descriptor control endpoint size value matches the size given as the			 *  FIXED_CONTROL_ENDPOINT_SIZE token - it is recommended that the FIXED_CONTROL_ENDPOINT_SIZE token			 *  be used in the descriptors to ensure this.			 *			 *  \note This variable should be treated as read-only in the user application, and never manually			 *        changed in value.			 */			#if (!defined(FIXED_CONTROL_ENDPOINT_SIZE) || defined(__DOXYGEN__))				extern uint8_t USB_ControlEndpointSize;			#else				#define USB_ControlEndpointSize FIXED_CONTROL_ENDPOINT_SIZE			#endif		/* Function Prototypes: */			/** Configures the specified endpoint number with the given endpoint type, direction, bank size			 *  and banking mode. Endpoints should be allocated in ascending order by their address in the			 *  device (i.e. endpoint 1 should be configured before endpoint 2 and so on).			 *			 *  The endpoint type may be one of the EP_TYPE_* macros listed in LowLevel.h and the direction			 *  may be either ENDPOINT_DIR_OUT or ENDPOINT_DIR_IN.			 *			 *  The bank size must indicate the maximum packet size that the endpoint can handle. Different			 *  endpoint numbers can handle different maximum packet sizes - refer to the chosen USB AVR's			 *  datasheet to determine the maximum bank size for each endpoint.			 *			 *  The banking mode may be either ENDPOINT_BANK_SINGLE or ENDPOINT_BANK_DOUBLE.			 *			 *  The success of this routine can be determined via the Endpoint_IsConfigured() macro.			 *			 *  By default, the routine is entirely dynamic, and will accept both constant and variable inputs.			 *  If dynamic configuration is unused, a small space savings can be made by defining the			 *  STATIC_ENDPOINT_CONFIGURATION macro via the -D switch to the compiler, to optimize for constant			 *  input values.			 *			 *  \note This routine will select the specified endpoint, and the endpoint will remain selected			 *        once the routine completes regardless of if the endpoint configuration succeeds.			 *			 *  \return Boolean true if the configuration succeeded, false otherwise			 */			bool Endpoint_ConfigureEndpoint(const uint8_t  Number, const uint8_t Type, const uint8_t Direction,			                                const uint16_t Size, const uint8_t Banks);			/** Spinloops until the currently selected non-control endpoint is ready for the next packet of data			 *  to be read or written to it.			 *			 *  \note This routine should not be called on CONTROL type endpoints.			 *			 *  \return A value from the Endpoint_WaitUntilReady_ErrorCodes_t enum.			 */			uint8_t Endpoint_WaitUntilReady(void);			/** Reads and discards the given number of bytes from the endpoint from the given buffer,			 *  discarding fully read packets from the host as needed. The last packet is not automatically			 *  discarded once the remaining bytes has been read; the user is responsible for manually			 *  discarding the last packet from the host via the Endpoint_ClearCurrentBank() macro. Between			 *  each USB packet, the given stream callback function is executed repeatedly until the next			 *  packet is ready, allowing for early aborts of stream transfers.			 *			 *	The callback routine should be created using the STREAM_CALLBACK() macro. If the token			 *  NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are disabled			 *  and this function has the Callback parameter ommitted.			 *			 *  \note This routine should not be used on CONTROL type endpoints.			 *			 *  \param Length    Number of bytes to send via the currently selected endpoint.			 *  \param Callback  Name of a callback routine to call between sucessive USB packet transfers, NULL if no callback			 *			 *  \return A value from the Endpoint_Stream_RW_ErrorCodes_t enum.			 */			uint8_t Endpoint_Discard_Stream(uint16_t Length			#if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__)			                                , uint8_t (* const Callback)(void)			#endif			                                );			/** Writes the given number of bytes to the endpoint from the given buffer in little endian,			 *  sending full packets to the host as needed. The last packet filled is not automatically sent;			 *  the user is responsible for manually sending the last written packet to the host via the			 *  Endpoint_ClearCurrentBank() macro. Between each USB packet, the given stream callback function			 *  is executed repeatedly until the endpoint is ready to accept the next packet, allowing for early			 *  aborts of stream transfers.			 *			 *	The callback routine should be created using the STREAM_CALLBACK() macro. If the token			 *  NO_STREAM_CALLBACKS is passed via the -D option to the compiler, stream callbacks are disabled			 *  and this function has the Callback parameter ommitted.			 *			 *  \note This routine should not be used on CONTROL type endpoints.			 *			 *  \param Buffer    Pointer to the source data buffer to read from.			 *  \param Length    Number of bytes to read for the currently selected endpoint into the buffer.			 *  \param Callback  Name of a callback routine to call between sucessive USB packet transfers, NULL if no callback			 *			 *  \return A value from the Endpoint_Stream_RW_ErrorCodes_t enum.			 */			uint8_t Endpoint_Write_Stream_LE(const void* Buffer, uint16_t Length			#if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -