5#include "double_buffer.hpp"
7#include "libxr_def.hpp"
9#include "libxr_type.hpp"
94 return static_cast<uint8_t
>(ep);
107 return static_cast<uint8_t
>(ep) | (dir ==
Direction::IN ? 0x80 : 0x00);
120 return static_cast<EPNumber>(addr & 0x7F);
144 bool double_buffer =
false;
336 void OnTransferCompleteCallback(
bool in_isr,
size_t actual_transfer_size)
349 actual_transfer_size)
提供一个通用的回调包装,支持动态参数传递。 Provides a generic callback wrapper, supporting dynamic argument passing.
void Run(bool in_isr, PassArgs &&...args) const
执行回调函数,并传递参数。 Executes the callback function, passing the arguments.
常量原始数据封装类。 A class for encapsulating constant raw data.
双缓冲区管理类 / Double buffer manager class
void SetActiveLength(size_t length)
设置当前活动缓冲区的数据长度 Sets the size of the active buffer
void SetActiveBlock(bool block)
设置当前活动缓冲区 Sets the active buffer
void EnablePending()
手动启用 pending 状态 Manually sets the pending state to true
size_t Size() const
获取每个缓冲区的大小(单位:字节) Gets the size of each buffer in bytes
uint8_t * ActiveBuffer() const
获取当前正在使用的缓冲区指针 Returns the currently active buffer
size_t GetActiveLength() const
获取当前活动缓冲区中准备好的数据长度 Gets the size of valid data in active buffer
uint8_t * PendingBuffer() const
获取备用缓冲区的指针 Returns the pending (inactive) buffer
void Switch()
切换到备用缓冲区(若其有效) Switches to the pending buffer if it's valid
原始数据封装类。 A class for encapsulating raw data.
USB端点基类 / USB Endpoint base class.
Endpoint(EPNumber number, Direction dir, RawData buffer)
构造函数 Constructor
EPNumber
端点号 / Endpoint number
@ EP_AUTO
自动分配端点号 / Auto allocate
@ EP_MAX_NUM
端点数量上限 / Maximum number of endpoints
@ EP_INVALID
非法端点号 / Invalid endpoint
LibXR::DoubleBuffer double_buffer_
双缓冲区 / Double buffer
Direction AvailableDirection() const
获取允许配置的端点方向 Get allowed endpoint direction
Type GetType() const
获取端点类型 Get endpoint type
uint8_t GetAddress() const
获取端点地址(方向 + 号) Get endpoint address (dir + num)
bool IsStalled() const
是否挂起 / Is endpoint stalled
static constexpr uint8_t EPNumberToInt8(EPNumber ep)
端点号转换为uint8_t / Convert endpoint number to uint8_t
virtual ErrorCode Stall()=0
停止端点传输 Stop endpoint transfer
Direction avail_direction_
可配置方向 / Allowed direction
Direction
端点方向 Endpoint direction
@ BOTH
双向(可配置成IN/OUT) / Both (can be configured as IN/OUT)
@ OUT
输出方向 / OUT direction
static constexpr uint8_t EPNumberToAddr(EPNumber ep, Direction dir)
端点号转换为端点地址 / Convert endpoint number to endpoint address
~Endpoint()=default
析构函数 Destructor
Direction GetDirection() const
获取端点方向 Get endpoint direction
bool UseDoubleBuffer() const
是否使用双缓冲区 / Use double buffer
static constexpr EPNumber AddrToEPNumber(uint8_t addr, Direction &dir)
端点地址转换为端点号 / Convert endpoint address to endpoint number
State state_
当前状态 / Endpoint status
virtual void SwitchBuffer()
切换缓冲区 Switch buffer
Config & GetConfig()
获取当前配置 Get endpoint config
EPNumber number_
当前端点编号 / Endpoint number
virtual ErrorCode ClearStall()=0
清除端点停止状态 Clear endpoint stop status
virtual size_t MaxTransferSize() const
返回最大可传输字节数 Return the maximum transferable size at this time
LibXR::RawData buffer_
端点缓冲区 / Endpoint buffer
void SetOnTransferCompleteCallback(Callback< ConstRawData & > cb)
设置传输完成回调 / Set transfer complete callback
static constexpr EPNumber NextEPNumber(EPNumber ep)
获取下一个端点号 / Get the next endpoint number
LibXR::Callback< LibXR::ConstRawData & > on_transfer_complete_
传输完成回调 / Called when transfer completes
virtual void Configure(const Config &cfg)=0
二次初始化/配置端点协议参数(由Pool/Manager分配后调用) Configure endpoint protocol parameters (call after pool allocation...
@ ISOCHRONOUS
等时端点 / Isochronous
@ INTERRUPT
中断端点 / Interrupt
EPNumber GetNumber() const
获取端点号 Get endpoint number
virtual void Close()=0
关闭端点(软禁用/资源复位) Close (soft disable)
uint16_t MaxPacketSize() const
获取最大包长 Get max packet size
virtual void SetActiveBlock(bool active_block)
设置当前活动缓冲区 Set active buffer
void SetState(State state)
设置端点状态 Set endpoint state
State GetState() const
获取端点状态 Get endpoint state
virtual ErrorCode TransferZLP()
传输空包 Transfer zero length packet
virtual ErrorCode Transfer(size_t size)=0
传输数据 Transfer data
Config config_
当前端点配置 / Current configuration
RawData GetBuffer() const
获取端点缓冲区 Get endpoint buffer
端点配置结构体 Endpoint configuration struct
Type type
端点类型 / Endpoint type
uint8_t mult
多包,高带宽端点用 / Multiplier (high-bandwidth)
uint16_t max_packet_size
最大包长 / Max packet size
Direction direction
端点方向 / Endpoint direction