📄 endpoint.h
字号:
, uint8_t (* const Callback)(void) #endif ) ATTR_NON_NULL_PTR_ARG(1); /** Writes the given number of bytes to the endpoint from the given buffer in big 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_BE(const void* Buffer, uint16_t Length #if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__) , uint8_t (* const Callback)(void) #endif ) ATTR_NON_NULL_PTR_ARG(1); /** Reads the given number of bytes from the endpoint from the given buffer in little endian, * 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 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 destination data buffer to write to. * \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_Read_Stream_LE(void* Buffer, uint16_t Length #if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__) , uint8_t (* const Callback)(void) #endif ) ATTR_NON_NULL_PTR_ARG(1); /** Reads the given number of bytes from the endpoint from the given buffer in big endian, * 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 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 destination data buffer to write to. * \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_Read_Stream_BE(void* Buffer, uint16_t Length #if !defined(NO_STREAM_CALLBACKS) || defined(__DOXYGEN__) , uint8_t (* const Callback)(void) #endif ) ATTR_NON_NULL_PTR_ARG(1); /** Writes the given number of bytes to the CONTROL type endpoint from the given buffer in little endian, * sending full packets to the host as needed. The host OUT acknowedgement is not automatically cleared * in both failure and success states; the user is responsible for manually clearing the setup OUT to * finalize the transfer via the Endpoint_ClearSetupOUT() macro. * * \note This routine should only be used on CONTROL type endpoints. * * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained * together; i.e. the entire stream data must be read or written at the one time. * * \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. * * \return A value from the Endpoint_ControlStream_RW_ErrorCodes_t enum. */ uint8_t Endpoint_Write_Control_Stream_LE(const void* Buffer, uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); /** Writes the given number of bytes to the CONTROL type endpoint from the given buffer in big endian, * sending full packets to the host as needed. The host OUT acknowedgement is not automatically cleared * in both failure and success states; the user is responsible for manually clearing the setup OUT to * finalize the transfer via the Endpoint_ClearSetupOUT() macro. * * \note This routine should only be used on CONTROL type endpoints. * * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained * together; i.e. the entire stream data must be read or written at the one time. * * \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. * * \return A value from the Endpoint_ControlStream_RW_ErrorCodes_t enum. */ uint8_t Endpoint_Write_Control_Stream_BE(const void* Buffer, uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); /** Reads the given number of bytes from the CONTROL endpoint from the given buffer in little endian, * discarding fully read packets from the host as needed. The device IN acknowedgement is not * automatically sent after success or failure states; the user is responsible for manually sending the * setup IN to finalize the transfer via the Endpoint_ClearSetupIN() macro. * * \note This routine should only be used on CONTROL type endpoints. * * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained * together; i.e. the entire stream data must be read or written at the one time. * * \param Buffer Pointer to the destination data buffer to write to. * \param Length Number of bytes to send via the currently selected endpoint. * * \return A value from the Endpoint_ControlStream_RW_ErrorCodes_t enum. */ uint8_t Endpoint_Read_Control_Stream_LE(void* Buffer, uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); /** Reads the given number of bytes from the CONTROL endpoint from the given buffer in big endian, * discarding fully read packets from the host as needed. The device IN acknowedgement is not * automatically sent after success or failure states; the user is responsible for manually sending the * setup IN to finalize the transfer via the Endpoint_ClearSetupIN() macro. * * \note This routine should only be used on CONTROL type endpoints. * * \warning Unlike the standard stream read/write commands, the control stream commands cannot be chained * together; i.e. the entire stream data must be read or written at the one time. * * \param Buffer Pointer to the destination data buffer to write to. * \param Length Number of bytes to send via the currently selected endpoint. * * \return A value from the Endpoint_ControlStream_RW_ErrorCodes_t enum. */ uint8_t Endpoint_Read_Control_Stream_BE(void* Buffer, uint16_t Length) ATTR_NON_NULL_PTR_ARG(1); /* Function Aliases: */ /** Alias for Endpoint_Discard_Byte(). */ #define Endpoint_Ignore_Byte() Endpoint_Discard_Byte() /** Alias for Endpoint_Discard_Word(). */ #define Endpoint_Ignore_Word() Endpoint_Discard_Word() /** Alias for Endpoint_Discard_DWord(). */ #define Endpoint_Ignore_DWord() Endpoint_Discard_DWord() /** Alias for Endpoint_Read_Word_LE(). By default USB transfers use little endian format, thus * the command with no endianness specifier indicates little endian mode. */ #define Endpoint_Read_Word() Endpoint_Read_Word_LE() /** Alias for Endpoint_Write_Word_LE(). By default USB transfers use little endian format, thus * the command with no endianness specifier indicates little endian mode. */ #define Endpoint_Write_Word(Word) Endpoint_Write_Word_LE(Word) /** Alias for Endpoint_Read_DWord_LE(). By default USB transfers use little endian format, thus * the command with no endianness specifier indicates little endian mode. */ #define Endpoint_Read_DWord() Endpoint_Read_DWord_LE() /** Alias for Endpoint_Write_DWord_LE(). By default USB transfers use little endian format, thus * the command with no endianness specifier indicates little endian mode. */ #define Endpoint_Write_DWord(DWord) Endpoint_Write_DWord_LE(DWord) /** Alias for Endpoint_Read_Stream_LE(). By default USB transfers use little endian format, thus * the command with no endianness specifier indicates little endian mode. */ #if !defined(NO_STREAM_CALLBACKS) #define Endpoint_Read_Stream(Buffer, Length, Callback) Endpoint_Read_Stream_LE(Buffer, Length, Callback) #else #define Endpoint_Read_Stream(Buffer, Length) Endpoint_Read_Stream_LE(Buffer, Length) #endif /** Alias for Endpoint_Write_Stream_LE(). By default USB transfers use little endian format, thus * the command with no endianness specifier indicates little endian mode. */ #if !defined(NO_STREAM_CALLBACKS) #define Endpoint_Write_Stream(Buffer, Length, Callback) Endpoint_Write_Stream_LE(Buffer, Length, Callback) #else #define Endpoint_Write_Stream(Buffer, Length) Endpoint_Write_Stream_LE(Buffer, Length) #endif /** Alias for Endpoint_Read_Control_Stream_LE(). By default USB transfers use little endian format, thus * the command with no endianness specifier indicates little endian mode. */ #define Endpoint_Read_Control_Stream(Data, Length) Endpoint_Read_Control_Stream_LE(Data, Length) /** Alias for Endpoint_Write_Control_Stream_LE(). By default USB transfers use little endian format, thus * the command with no endianness specifier indicates little endian mode. */ #define Endpoint_Write_Control_Stream(Data, Length) Endpoint_Write_Control_Stream_LE(Data, Length) /* Private Interface - For use in library only: */ #if !defined(__DOXYGEN__) /* Macros: */ #define Endpoint_AllocateMemory() MACROS{ UECFG1X |= (1 << ALLOC); }MACROE #define Endpoint_DeallocateMemory() MACROS{ UECFG1X &= ~(1 << ALLOC); }MACROE #define _ENDPOINT_GET_MAXSIZE(n) _ENDPOINT_GET_MAXSIZE2(ENDPOINT_DETAILS_EP ## n) #define _ENDPOINT_GET_MAXSIZE2(details) _ENDPOINT_GET_MAXSIZE3(details) #define _ENDPOINT_GET_MAXSIZE3(maxsize, db) maxsize #define _ENDPOINT_GET_DOUBLEBANK(n) _ENDPOINT_GET_DOUBLEBANK2(ENDPOINT_DETAILS_EP ## n) #define _ENDPOINT_GET_DOUBLEBANK2(details) _ENDPOINT_GET_DOUBLEBANK3(details) #define _ENDPOINT_GET_DOUBLEBANK3(maxsize, db) db #if defined(USB_FULL_CONTROLLER) || defined(USB_MODIFIED_FULL_CONTROLLER) #define ENDPOINT_DETAILS_EP0 64, true #define ENDPOINT_DETAILS_EP1 256, true #define ENDPOINT_DETAILS_EP2 64, true #define ENDPOINT_DETAILS_EP3 64, true #define ENDPOINT_DETAILS_EP4 64, true #define ENDPOINT_DETAILS_EP5 64, true #define ENDPOINT_DETAILS_EP6 64, true #else #define ENDPOINT_DETAILS_EP0 64, true #define ENDPOINT_DETAILS_EP1 64, false #define ENDPOINT_DETAILS_EP2 64, false #define ENDPOINT_DETAILS_EP3 64, true #define ENDPOINT_DETAILS_EP4 64, true #endif #if defined(STATIC_ENDPOINT_CONFIGURATION) #define Endpoint_ConfigureEndpoint(Number, Type, Direction, Size, Banks) \ Endpoint_ConfigureEndpointStatic(Number, \ ((Type << EPTYPE0) | Direction), \ ((1 << ALLOC) | Banks | Endpoint_BytesToEPSizeMask(Size))); #endif /* Function Prototypes: */ void Endpoint_ClearEndpoints(void); bool Endpoint_ConfigureEndpointStatic(const uint8_t Number, const uint8_t UECFG0XData, const uint8_t UECFG1XData); /* Inline Functions: */ static inline uint8_t Endpoint_BytesToEPSizeMask(const uint16_t Bytes) ATTR_WARN_UNUSED_RESULT ATTR_CONST ATTR_ALWAYSINLINE; static inline uint8_t Endpoint_BytesToEPSizeMask(const uint16_t Bytes) { if (Bytes <= 8) return (0 << EPSIZE0); else if (Bytes <= 16) return (1 << EPSIZE0); else if (Bytes <= 32) return (2 << EPSIZE0); #if defined(USB_LIMITED_CONTROLLER) else return (3 << EPSIZE0); #else else if (Bytes <= 64) return (3 << EPSIZE0); else if (Bytes <= 128) return (4 << EPSIZE0); else return (5 << EPSIZE0); #endif } #endif /* Disable C linkage for C++ Compilers: */ #if defined(__cplusplus) } #endif #endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -