6#include "usb/core/desc_cfg.hpp"
115 static_assert(
sizeof(
CDCLineCoding) == 7,
"LineCoding结构必须7字节");
168 return ErrorCode::BUSY;
195 return ErrorCode::OK;
232 ASSERT(ans == ErrorCode::OK);
236 ASSERT(ans == ErrorCode::OK);
240 ASSERT(ans == ErrorCode::OK);
250 static constexpr uint8_t COMM_INTERFACE = 0;
251 static constexpr uint8_t DATA_INTERFACE = 1;
254 desc_block_.
iad = {8,
255 static_cast<uint8_t
>(DescriptorType::IAD),
256 static_cast<uint8_t
>(COMM_INTERFACE + start_itf_num),
265 static_cast<uint8_t
>(DescriptorType::INTERFACE),
266 static_cast<uint8_t
>(COMM_INTERFACE + start_itf_num),
279 desc_block_.cdc_callmgmt = {
282 static_cast<uint8_t
>(DATA_INTERFACE + start_itf_num)};
290 static_cast<uint8_t
>(COMM_INTERFACE + start_itf_num),
291 static_cast<uint8_t
>(DATA_INTERFACE + start_itf_num)};
295 static_cast<uint8_t
>(DescriptorType::INTERFACE),
296 static_cast<uint8_t
>(DATA_INTERFACE + start_itf_num),
306 static_cast<uint8_t
>(DescriptorType::ENDPOINT),
314 static_cast<uint8_t
>(DescriptorType::ENDPOINT),
323 static_cast<uint8_t
>(DescriptorType::ENDPOINT),
333 SetData(
RawData{
reinterpret_cast<uint8_t*
>(&desc_block_),
sizeof(desc_block_)});
456 return ErrorCode::ARG_ERR;
460 return ErrorCode::OK;
466 return ErrorCode::ARG_ERR;
471 return ErrorCode::OK;
479 return ErrorCode::OK;
483 return ErrorCode::OK;
486 return ErrorCode::NOT_SUPPORT;
532 return ErrorCode::OK;
534 return ErrorCode::NOT_SUPPORT;
555 uint8_t bFunctionLength = 5;
556 DescriptorType bDescriptorType = DescriptorType::CS_INTERFACE;
563 uint8_t bFunctionLength = 5;
564 DescriptorType bDescriptorType = DescriptorType::CS_INTERFACE;
572 uint8_t bFunctionLength = 4;
573 DescriptorType bDescriptorType = DescriptorType::CS_INTERFACE;
580 uint8_t bFunctionLength = 5;
581 DescriptorType bDescriptorType = DescriptorType::CS_INTERFACE;
599 bool Inited() {
return inited_; }
601 Endpoint* GetDataInEndpoint() {
return ep_data_in_; }
605 Endpoint* GetCommInEndpoint() {
return ep_comm_in_; }
提供一个通用的回调包装,支持动态参数传递。 Provides a generic callback wrapper, supporting dynamic argument passing.
void Run(bool in_isr, PassArgs &&...args) const
执行回调函数,并传递参数。 Executes the callback function, passing the arguments.
static Callback Create(FunType fun, ArgType arg)
创建一个新的回调对象,并绑定回调函数和参数。 Creates a new callback instance, binding a function and an argument.
常量原始数据封装类。 A class for encapsulating constant raw data.
原始数据封装类。 A class for encapsulating raw data.
@ NO_PARITY
无校验 / No parity
USB CDC ACM (Abstract Control Model) 设备类实现 USB CDC ACM (Abstract Control Model) device class implemen...
void SetOnSetControlLineStateCallback(LibXR::Callback< bool, bool > cb)
设置控制线路状态变更回调 Set control line state change callback
LibXR::Callback< bool, bool > on_set_control_line_state_cb_
Protocol
CDC协议代码 / CDC protocol codes.
@ AT_COMMAND
AT命令协议 / AT Command protocol.
size_t GetMaxConfigSize() override
获取最大配置描述符大小 Get maximum configuration descriptor size
size_t GetInterfaceNum() override
获取接口数量 Get number of interfaces
Endpoint::EPNumber data_in_ep_num_
数据IN端点号 / Data IN endpoint number
uint8_t itf_comm_in_num_
通信接口号 / Communication interface number
CDCNotification
CDC通知类型 / CDC notification types.
@ RESPONSE_AVAILABLE
响应可用通知 / Response available
@ NETWORK_CONNECTION
网络连接通知 / Network connection
@ AUX_JACK_HOOK_STATE
辅助插槽状态通知 / Aux jack hook state
@ RING_DETECT
响铃检测通知 / Ring detect
ErrorCode OnClassRequest(bool in_isr, uint8_t bRequest, uint16_t wValue, uint16_t wLength, DeviceClass::RequestResult &result) override
处理类特定请求 Handle class-specific requests
void SetOnSetLineCodingCallback(LibXR::Callback< LibXR::UART::Configuration > cb)
设置线路编码变更回调 Set line coding change callback
Endpoint::EPNumber comm_ep_num_
通信端点号 / Communication endpoint number
Class
USB设备类代码 / USB device class codes.
@ COMM
通信设备类 / Communications device class
@ DATA
数据接口类 / Data interface class
virtual void OnDataInComplete(bool in_isr, ConstRawData &data)=0
数据IN端点传输完成处理 Handle data IN endpoint transfer completion
Subclass
CDC子类代码 / CDC subclass codes.
@ DIRECT_LINE_CONTROL_MODEL
直接控制模型(CDC-DCM)| Direct Control Model (CDC-DCM)
@ ABSTRACT_CONTROL_MODEL
抽象控制模型(CDC-ACM)| Abstract Control Model (CDC-ACM)
Endpoint * ep_comm_in_
通信IN端点 / Communication IN endpoint
bool inited_
初始化标志 / Initialization flag
Endpoint * ep_data_in_
数据IN端点 / Data IN endpoint
static void OnDataOutCompleteStatic(bool in_isr, CDCBase *self, ConstRawData &data)
数据OUT端点传输完成静态回调 Static callback for data OUT endpoint transfer completion
static constexpr uint16_t CDC_CONTROL_LINE_DTR
DTR控制位 / DTR control bit.
ClassRequest
CDC类特定请求 / CDC class-specific requests.
@ SEND_BREAK
发送BREAK信号 / Send BREAK signal
@ GET_LINE_CODING
获取当前线路编码 / Get current line coding
@ SET_CONTROL_LINE_STATE
设置控制线路状态 / Set control line state
@ SET_LINE_CODING
设置串行线路编码 / Set line coding parameters
virtual void Deinit(EndpointPool &endpoint_pool) override
反初始化CDC设备 Deinitialize CDC device
DescriptorSubtype
CDC功能描述符子类型定义 / CDC functional descriptor subtypes.
@ ACM
抽象控制模型描述符 / Abstract control model descriptor
@ CALL_MANAGEMENT
呼叫管理功能描述符 / Call management functional descriptor
@ HEADER
头功能描述符 / Header functional descriptor
@ UNION
联合功能描述符 / Union functional descriptor
LibXR::Callback< LibXR::UART::Configuration > on_set_line_coding_cb_
线路编码变更回调 / Line coding change callback
bool IsRtsSet() const
检查RTS状态 Check RTS state
CDCBase(Endpoint::EPNumber data_in_ep_num=Endpoint::EPNumber::EP_AUTO, Endpoint::EPNumber data_out_ep_num=Endpoint::EPNumber::EP_AUTO, Endpoint::EPNumber comm_ep_num=Endpoint::EPNumber::EP_AUTO)
CDC构造函数 CDC constructor.
Endpoint::EPNumber data_out_ep_num_
数据OUT端点号 / Data OUT endpoint number
uint16_t control_line_state_
控制线路状态 / Control line state
virtual void OnDataOutComplete(bool in_isr, ConstRawData &data)=0
数据OUT端点传输完成处理 Handle data OUT endpoint transfer completion
bool HasIAD() override
检查是否包含IAD Check if IAD is present
static void OnDataInCompleteStatic(bool in_isr, CDCBase *self, ConstRawData &data)
数据IN端点传输完成静态回调 Static callback for data IN endpoint transfer completion
CDCLineCoding line_coding_
当前线路编码 / Current line coding
virtual void Init(EndpointPool &endpoint_pool, uint8_t start_itf_num) override
初始化CDC设备 Initialize CDC device
ErrorCode OnClassData(bool in_isr, uint8_t bRequest, LibXR::ConstRawData &data) override
处理类请求数据阶段 Handle class request data stage
Endpoint * ep_data_out_
数据OUT端点 / Data OUT endpoint
ErrorCode SendSerialState()
发送串行状态通知 Send serial state notification
static constexpr uint16_t CDC_CONTROL_LINE_RTS
RTS控制位 / RTS control bit.
bool IsDtrSet() const
检查DTR状态 Check DTR state
void SetData(RawData data)
设置配置项数据 Set configuration item data
USB 设备类接口基类,所有自定义 USB 类(如 HID、CDC、MSC)都需派生自本类。 USB device class base interface, all custom device cla...
USB端点基类 / USB Endpoint base class.
EPNumber
端点号 / Endpoint number
@ EP_AUTO
自动分配端点号 / Auto allocate
uint8_t GetAddress() const
获取端点地址(方向 + 号) Get endpoint address (dir + num)
@ OUT
输出方向 / OUT direction
virtual size_t MaxTransferSize() const
返回最大可传输字节数 Return the maximum transferable size at this time
void SetOnTransferCompleteCallback(Callback< ConstRawData & > cb)
设置传输完成回调 / Set transfer complete callback
virtual void Configure(const Config &cfg)=0
二次初始化/配置端点协议参数(由Pool/Manager分配后调用) Configure endpoint protocol parameters (call after pool allocation...
@ INTERRUPT
中断端点 / Interrupt
virtual void Close()=0
关闭端点(软禁用/资源复位) Close (soft disable)
uint16_t MaxPacketSize() const
获取最大包长 Get max packet size
State GetState() const
获取端点状态 Get endpoint state
virtual ErrorCode Transfer(size_t size)=0
传输数据 Transfer data
RawData GetBuffer() const
获取端点缓冲区 Get endpoint buffer
USB端点池类 / USB endpoint pool class.
ErrorCode Get(Endpoint *&ep_info, Endpoint::Direction direction, Endpoint::EPNumber ep_num=Endpoint::EPNumber::EP_AUTO)
分配端点 / Allocate endpoint
ErrorCode Release(Endpoint *ep_info)
回收端点 / Release endpoint
UART 配置结构体 / UART configuration structure.
uint8_t stop_bits
停止位长度 / Number of stop bits
Parity parity
校验模式 / Parity mode
uint8_t data_bits
数据位长度 / Number of data bits
uint32_t baudrate
波特率 / Baud rate
CDC描述符块结构 CDC descriptor block structure.
InterfaceDescriptor data_intf
数据接口描述符 / Data interface descriptor
uint8_t bSlaveInterface0
从接口号 / Slave interface number
EndpointDescriptor data_ep_out
数据OUT端点描述符 / Data OUT endpoint descriptor
uint16_t bcdCDC
CDC规范版本 / CDC specification version.
uint8_t bmCapabilities
呼叫管理能力 / Call management capabilities
InterfaceDescriptor comm_intf
通信接口描述符 / Communication interface descriptor
uint8_t bDataInterface
数据接口号 / Data interface number
EndpointDescriptor comm_ep
通信端点描述符 / Communication endpoint descriptor
uint8_t bMasterInterface
主接口号 / Master interface number
EndpointDescriptor data_ep_in
数据IN端点描述符 / Data IN endpoint descriptor
IADDescriptor iad
接口关联描述符 / Interface association descriptor
CDC线路编码参数结构体 CDC line coding parameters structure.
uint32_t dwDTERate
波特率(小端格式)| Baud rate (little-endian)
uint8_t bCharFormat
停止位:0=1位,1=1.5位,2=2位 / Stop bits: 0=1, 1=1.5, 2=2
uint8_t bDataBits
数据位:5,6,7,8或16 / Data bits: 5,6,7,8 or 16
串行状态通知结构体 Serial state notification structure
uint16_t wLength
数据长度(固定为2)| Data length (fixed to 2)
uint16_t wIndex
接口号 / Interface number
uint16_t serialState
串行状态位图 / Serial state bitmap
uint8_t bmRequestType
请求类型(固定为0xA1)| Request type (fixed to 0xA1)
uint16_t wValue
值(固定为0)| Value (fixed to 0)
端点描述符结构体 Endpoint descriptor structure (USB 2.0 Spec 9.6.6)
接口关联描述符(IAD,Interface Association Descriptor) IAD descriptor structure (用于复合设备多接口归组 / used for groupi...
接口描述符结构体 Interface descriptor structure (USB 2.0 Spec 9.6.5)
控制请求结果结构体 / Structure for control transfer results
RawData read_data
设备返回给主机的数据 / Data to read (to host)
bool write_zlp
写操作是否需要发送 0 长度包 / Send ZLP after write
ConstRawData write_data
主机写入设备的数据 / Data to write (from host)