libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
ep_pool.hpp
1#pragma once
2
3#include <cstddef>
4#include <cstdint>
5
6#include "ep.hpp"
7
8namespace LibXR::USB
9{
10
29{
30 public:
40 explicit EndpointPool(size_t endpoint_num);
41
42 EndpointPool(const EndpointPool&) = delete;
43 EndpointPool& operator=(const EndpointPool&) = delete;
44
57
72 ErrorCode Get(Endpoint*& ep_info, Endpoint::Direction direction,
73 Endpoint::EPNumber ep_num);
74
80 ErrorCode Release(Endpoint* ep_info);
81
96 ErrorCode FindEndpoint(uint8_t ep_addr, Endpoint*& ans);
97
103
109
115 void SetEndpoint0(Endpoint* ep0_in, Endpoint* ep0_out);
116
117 private:
119 static constexpr size_t DIR_COUNT = 2;
121 static constexpr size_t SLOT_COUNT =
122 static_cast<size_t>(Endpoint::EPNumber::EP_MAX_NUM);
123
125 enum class SlotUse : uint8_t
126 {
127 AVAILABLE,
128 IN_USE
129 };
130
136 static size_t DirIndex(Endpoint::Direction dir)
137 {
138 return (dir == Endpoint::Direction::IN) ? 1U : 0U;
139 }
140
143
144 Endpoint* ep0_in_ = nullptr;
145 Endpoint* ep0_out_ = nullptr;
146};
147
148} // namespace LibXR::USB
USB 端点基类 / USB Endpoint base class.
Definition ep.hpp:24
EPNumber
端点号 Endpoint number
Definition ep.hpp:42
@ EP_MAX_NUM
端点数量上限 / Maximum number of endpoints
Direction
端点方向 Endpoint direction
Definition ep.hpp:31
@ IN
输入方向 / IN direction
USB端点池类 / USB endpoint pool class.
Definition ep_pool.hpp:29
SlotUse use_[SLOT_COUNT][DIR_COUNT]
对应槽占用状态 / Per-slot usage
Definition ep_pool.hpp:142
EndpointPool(size_t endpoint_num)
构造函数 / Constructor
Definition ep_pool.cpp:5
static constexpr size_t DIR_COUNT
方向数量(OUT=0, IN=1)/ Number of direction slots (OUT=0, IN=1)
Definition ep_pool.hpp:119
ErrorCode Put(Endpoint *ep)
登记一个端点到池中 / Register an endpoint into the pool
Definition ep_pool.cpp:7
Endpoint * GetEndpoint0In()
获取端点0的IN对象 / Get Endpoint 0's IN object
Definition ep_pool.cpp:158
void SetEndpoint0(Endpoint *ep0_in, Endpoint *ep0_out)
设置端点0的IN/OUT对象 / Set Endpoint 0 IN/OUT objects
Definition ep_pool.cpp:160
ErrorCode Release(Endpoint *ep_info)
回收端点 / Release endpoint
Definition ep_pool.cpp:93
SlotUse
槽占用状态 / Slot usage state
Definition ep_pool.hpp:126
@ AVAILABLE
已登记、空闲可分配 / Registered and free to allocate
@ IN_USE
已分配、正在使用 / Allocated and in use
Endpoint * slots_[SLOT_COUNT][DIR_COUNT]
[端点号][方向] 端点指针 / [num][dir]
Definition ep_pool.hpp:141
Endpoint * ep0_in_
端点0 IN对象 / Endpoint 0 IN pointer
Definition ep_pool.hpp:144
ErrorCode FindEndpoint(uint8_t ep_addr, Endpoint *&ans)
查找端点/ Lookup endpoint
Definition ep_pool.cpp:119
static constexpr size_t SLOT_COUNT
索引数组容量(端点号 0..EP_MAX_NUM-1)/ Index array size (endpoint numbers)
Definition ep_pool.hpp:121
Endpoint * ep0_out_
端点0 OUT对象 / Endpoint 0 OUT pointer
Definition ep_pool.hpp:145
Endpoint * GetEndpoint0Out()
获取端点0的OUT对象 / Get Endpoint 0's OUT object
Definition ep_pool.cpp:156
static size_t DirIndex(Endpoint::Direction dir)
方向枚举转索引下标 / Convert direction enum to array index
Definition ep_pool.hpp:136
ErrorCode Get(Endpoint *&ep_info, Endpoint::Direction direction, Endpoint::EPNumber ep_num)
分配端点 / Allocate endpoint
Definition ep_pool.cpp:52
ErrorCode
定义错误码枚举