|
libxr
1.0
Want to be the best embedded framework
|
USB端点池类 / USB endpoint pool class. More...
#include <ep_pool.hpp>
Public Member Functions | |
| EndpointPool (size_t endpoint_num) | |
| 构造函数 / Constructor | |
| EndpointPool (const EndpointPool &)=delete | |
| EndpointPool & | operator= (const EndpointPool &)=delete |
| ErrorCode | Put (Endpoint *ep) |
| 登记一个端点到池中 / Register an endpoint into the pool | |
| ErrorCode | Get (Endpoint *&ep_info, Endpoint::Direction direction, Endpoint::EPNumber ep_num) |
| 分配端点 / Allocate endpoint | |
| ErrorCode | Release (Endpoint *ep_info) |
| 回收端点 / Release endpoint | |
| ErrorCode | FindEndpoint (uint8_t ep_addr, Endpoint *&ans) |
| 查找端点/ Lookup endpoint | |
| Endpoint * | GetEndpoint0Out () |
| 获取端点0的OUT对象 / Get Endpoint 0's OUT object | |
| Endpoint * | GetEndpoint0In () |
| 获取端点0的IN对象 / Get Endpoint 0's IN object | |
| void | SetEndpoint0 (Endpoint *ep0_in, Endpoint *ep0_out) |
| 设置端点0的IN/OUT对象 / Set Endpoint 0 IN/OUT objects | |
Private Types | |
| enum class | SlotUse : uint8_t { AVAILABLE , IN_USE } |
| 槽占用状态 / Slot usage state More... | |
Static Private Member Functions | |
| static size_t | DirIndex (Endpoint::Direction dir) |
| 方向枚举转索引下标 / Convert direction enum to array index | |
Private Attributes | |
| Endpoint * | slots_ [SLOT_COUNT][DIR_COUNT] = {} |
| [端点号][方向] 端点指针 / [num][dir] | |
| SlotUse | use_ [SLOT_COUNT][DIR_COUNT] = {} |
| 对应槽占用状态 / Per-slot usage | |
| Endpoint * | ep0_in_ = nullptr |
| 端点0 IN对象 / Endpoint 0 IN pointer | |
| Endpoint * | ep0_out_ = nullptr |
| 端点0 OUT对象 / Endpoint 0 OUT pointer | |
Static Private Attributes | |
| static constexpr size_t | DIR_COUNT = 2 |
| 方向数量(OUT=0, IN=1)/ Number of direction slots (OUT=0, IN=1) | |
| static constexpr size_t | SLOT_COUNT |
| 索引数组容量(端点号 0..EP_MAX_NUM-1)/ Index array size (endpoint numbers) | |
USB端点池类 / USB endpoint pool class.
按「端点号 × 方向」二维索引管理固定的 Endpoint 指针。所有 Endpoint 对象由后端在 初始化时通过 Put() 填入,池只负责登记、分配、查找与回收,不负责对象生命周期。 端点 0 的 IN/OUT 不进入索引数组,由 SetEndpoint0/GetEndpoint0* 单独管理。
Manages fixed Endpoint pointers indexed by (endpoint-number, direction). All Endpoint objects are populated by the backend at init time via Put(); the pool only registers, allocates, looks up and recycles them, and does not own their lifetime. Endpoint 0's IN/OUT are kept out of the index array and managed by SetEndpoint0/GetEndpoint0*.
Definition at line 28 of file ep_pool.hpp.
|
strongprivate |
槽占用状态 / Slot usage state
| Enumerator | |
|---|---|
| AVAILABLE | 已登记、空闲可分配 / Registered and free to allocate |
| IN_USE | 已分配、正在使用 / Allocated and in use |
Definition at line 125 of file ep_pool.hpp.
|
explicit |
构造函数 / Constructor
| endpoint_num | 端点总数(包含端点0,必须 >=2)/ Total number of endpoints (including EP0, must >=2) |
Definition at line 5 of file ep_pool.cpp.
|
inlinestaticprivate |
方向枚举转索引下标 / Convert direction enum to array index
| dir | 端点方向(IN/OUT)/ Endpoint direction |
Definition at line 136 of file ep_pool.hpp.
| LibXR::ErrorCode EndpointPool::FindEndpoint | ( | uint8_t | ep_addr, |
| Endpoint *& | ans ) |
查找端点/ Lookup endpoint
端点 0 走 ep0_in_/ep0_out_ 旁路;其余端点仅在「已分配(in-use)」状态下可被查到, 与原实现语义一致(未分配端点收到端点级请求视为异常)。 Endpoint 0 goes through the ep0_in_/ep0_out_ bypass; other endpoints are visible only while allocated (in-use), matching the original semantics (an endpoint-level request for an unallocated endpoint is treated as an error).
| ep_addr | 端点地址,IN端点高位需加0x80 / Endpoint address (0x80 for IN endpoints) | |
| [out] | ans | 查找到的端点对象指针 / Found endpoint pointer |
| ErrorCode | 操作结果(OK/NOT_FOUND)/ Operation result |
Definition at line 119 of file ep_pool.cpp.
| LibXR::ErrorCode EndpointPool::Get | ( | Endpoint *& | ep_info, |
| Endpoint::Direction | direction, | ||
| Endpoint::EPNumber | ep_num ) |
分配端点 / Allocate endpoint
按指定端点号与方向精确匹配一个已登记且空闲的端点。调用方必须显式指定端点号, 不再支持自动分配。 Precisely matches a registered, available endpoint by the given number and direction. The caller must specify the endpoint number explicitly; auto-allocation is no longer supported.
| [out] | ep_info | 分配得到的端点对象指针 / Allocated endpoint pointer |
| direction | 端点方向(IN/OUT)/ Endpoint direction | |
| ep_num | 指定端点号(必填)/ Endpoint number (required) |
| ErrorCode | 操作结果(OK/NOT_FOUND)/ Operation result |
Definition at line 52 of file ep_pool.cpp.
| Endpoint * EndpointPool::GetEndpoint0In | ( | ) |
获取端点0的IN对象 / Get Endpoint 0's IN object
Definition at line 158 of file ep_pool.cpp.
| Endpoint * EndpointPool::GetEndpoint0Out | ( | ) |
获取端点0的OUT对象 / Get Endpoint 0's OUT object
Definition at line 156 of file ep_pool.cpp.
| LibXR::ErrorCode EndpointPool::Put | ( | Endpoint * | ep | ) |
登记一个端点到池中 / Register an endpoint into the pool
按端点自身的号(GetNumber)与可用方向(AvailableDirection)入位。端点 0 不应 通过此接口登记(应使用 SetEndpoint0)。 Registered by the endpoint's own number (GetNumber) and available direction (AvailableDirection). Endpoint 0 must not be registered here (use SetEndpoint0).
| ep | 待登记的端点对象指针 / Endpoint pointer to register |
| ErrorCode | 操作结果(OK/ARG_ERR/FULL)/ Operation result |
Definition at line 7 of file ep_pool.cpp.
| LibXR::ErrorCode EndpointPool::Release | ( | Endpoint * | ep_info | ) |
回收端点 / Release endpoint
| ep_info | 待回收的端点对象指针 / Endpoint pointer to release |
| ErrorCode | 操作结果(OK/NOT_FOUND)/ Operation result |
Definition at line 93 of file ep_pool.cpp.
|
staticconstexprprivate |
方向数量(OUT=0, IN=1)/ Number of direction slots (OUT=0, IN=1)
Definition at line 119 of file ep_pool.hpp.
|
private |
端点0 IN对象 / Endpoint 0 IN pointer
Definition at line 144 of file ep_pool.hpp.
|
private |
端点0 OUT对象 / Endpoint 0 OUT pointer
Definition at line 145 of file ep_pool.hpp.
|
staticconstexprprivate |
索引数组容量(端点号 0..EP_MAX_NUM-1)/ Index array size (endpoint numbers)
Definition at line 121 of file ep_pool.hpp.
|
private |
|
private |