libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
cdc_base.hpp
1#pragma once
2#include <cstring>
3
4#include "dev_core.hpp"
5#include "libxr_def.hpp"
6#include "uart.hpp"
7#include "usb/core/desc_cfg.hpp"
8
9namespace LibXR::USB
10{
11
23class CDCBase : public DeviceClass
24{
25 public:
26 static constexpr const char* DEFAULT_CONTROL_INTERFACE_STRING = "XRUSB CDC Control";
27 static constexpr const char* DEFAULT_DATA_INTERFACE_STRING = "XRUSB CDC Data";
28
29 private:
31 enum class DescriptorSubtype : uint8_t
32 {
33 HEADER = 0x00,
35 0x01,
36 ACM = 0x02,
37 UNION = 0x06,
38 };
39
41 enum class Class : uint8_t
42 {
43 COMM = 0x02,
44 DATA = 0x0A
45 };
46
48 enum class Protocol : uint8_t
49 {
50 NONE = 0x00,
51 AT_COMMAND = 0x01,
52 };
53
55 enum class Subclass : uint8_t
56 {
57 NONE = 0x00,
59 0x01,
61 0x02,
62 };
63
65 enum class ClassRequest : uint8_t
66 {
67 SET_LINE_CODING = 0x20,
68 GET_LINE_CODING = 0x21,
70 SEND_BREAK = 0x23
71 };
72
74 enum class CDCNotification : uint8_t
75 {
76 NETWORK_CONNECTION = 0x00,
77 RESPONSE_AVAILABLE = 0x01,
78 AUX_JACK_HOOK_STATE = 0x08,
79 RING_DETECT = 0x09,
80 SERIAL_STATE = 0x20,
82 };
83
84 LIBXR_PACKED_BEGIN
93 {
94 uint32_t dwDTERate;
95 uint8_t bCharFormat;
96 uint8_t bParityType;
98 uint8_t bDataBits;
99 };
100
109 {
113 uint16_t wValue;
114 uint16_t wIndex;
115 uint16_t wLength;
116 uint16_t serialState;
117 };
118 LIBXR_PACKED_END
119
120 // 确保 CDCLineCoding 结构体大小为 7 字节。
121 // Ensure CDCLineCoding is exactly 7 bytes.
122 static_assert(sizeof(CDCLineCoding) == 7, "LineCoding结构必须7字节");
123
124 // 控制线路状态位定义
125 static constexpr uint16_t CDC_CONTROL_LINE_DTR = 0x01;
126 static constexpr uint16_t CDC_CONTROL_LINE_RTS = 0x02;
127
128 public:
137 CDCBase(Endpoint::EPNumber data_in_ep_num, Endpoint::EPNumber data_out_ep_num,
138 Endpoint::EPNumber comm_ep_num,
139 const char* control_interface_string = DEFAULT_CONTROL_INTERFACE_STRING,
140 const char* data_interface_string = DEFAULT_DATA_INTERFACE_STRING)
141 : data_in_ep_num_(data_in_ep_num),
142 data_out_ep_num_(data_out_ep_num),
143 comm_ep_num_(comm_ep_num),
144 control_interface_string_(control_interface_string),
145 data_interface_string_(data_interface_string)
146 {
147 }
148
149 const char* GetInterfaceString(size_t local_interface_index) const override
150 {
151 switch (local_interface_index)
152 {
153 case 0:
155 case 1:
157 default:
158 return nullptr;
159 }
160 }
161
169 bool IsDtrSet() const { return (control_line_state_ & CDC_CONTROL_LINE_DTR) != 0; }
170
178 bool IsRtsSet() const { return (control_line_state_ & CDC_CONTROL_LINE_RTS) != 0; }
179
188 {
190 {
191 return ErrorCode::BUSY;
192 }
193 auto buffer = ep_comm_in_->GetBuffer();
194 ASSERT(buffer.size_ >= sizeof(SerialStateNotification));
195 SerialStateNotification* notification =
196 reinterpret_cast<SerialStateNotification*>(buffer.addr_);
197 notification->wIndex = itf_comm_in_num_;
198
199 // 设置串行状态位。
200 // Fill the serial-state bitmap.
201 if (IsDtrSet())
202 {
203 // DTR 有效时报告载波检测(DCD)和数据集就绪(DSR)。
204 // When DTR is asserted, report DCD and DSR as active.
205 notification->serialState = 0x03; // DCD / DSR
206 }
207 else
208 {
209 notification->serialState = 0x00; // 无状态
210 }
211
212 // 填充固定字段。
213 // Fill the fixed notification header fields.
214 notification->bmRequestType = 0xA1; // 设备到主机,类,接口
215 notification->bNotification = static_cast<uint8_t>(CDCNotification::SERIAL_STATE);
216 notification->wValue = 0;
217 notification->wLength = 2;
218
220
221 return ErrorCode::OK;
222 }
223
233
243
244 protected:
256 virtual void BindEndpoints(EndpointPool& endpoint_pool, uint8_t start_itf_num,
257 bool) override
258 {
260 // 获取并配置数据IN端点
261 auto ans = endpoint_pool.Get(ep_data_in_, Endpoint::Direction::IN, data_in_ep_num_);
262 ASSERT(ans == ErrorCode::OK);
263
264 // 获取并配置数据OUT端点
266 ASSERT(ans == ErrorCode::OK);
267
268 // 获取并配置通信端点。
269 // Acquire and configure the communication endpoint.
271 ASSERT(ans == ErrorCode::OK);
272
273 // 配置端点参数。
274 // Configure endpoint parameters.
276 {Endpoint::Direction::IN, Endpoint::Type::BULK, UINT16_MAX, true});
280
281 // === 填充CDC描述符块 ===
282 static constexpr uint8_t COMM_INTERFACE = 0; // 通信接口号
283 static constexpr uint8_t DATA_INTERFACE = 1; // 数据接口号
284
285 // IAD 描述符(关联两组 CDC 接口)。
286 // IAD descriptor that groups the two CDC interfaces.
287 desc_block_.iad = {8,
288 static_cast<uint8_t>(DescriptorType::IAD),
289 static_cast<uint8_t>(COMM_INTERFACE + start_itf_num),
290 2,
291 static_cast<uint8_t>(Class::COMM),
292 static_cast<uint8_t>(Subclass::ABSTRACT_CONTROL_MODEL),
293 static_cast<uint8_t>(Protocol::NONE),
294 0};
295
296 // 通信接口描述符。
297 // Communication interface descriptor.
298 desc_block_.comm_intf = {9,
299 static_cast<uint8_t>(DescriptorType::INTERFACE),
300 static_cast<uint8_t>(COMM_INTERFACE + start_itf_num),
301 0,
302 1,
303 static_cast<uint8_t>(Class::COMM),
304 static_cast<uint8_t>(Subclass::ABSTRACT_CONTROL_MODEL),
305 static_cast<uint8_t>(Protocol::NONE),
306 GetInterfaceStringIndex(COMM_INTERFACE)};
307
308 // CDC 头功能描述符。
309 // CDC header functional descriptor.
310 desc_block_.cdc_header = {5, DescriptorType::CS_INTERFACE, DescriptorSubtype::HEADER,
311 0x0110}; // CDC规范版本1.10
312
313 // 呼叫管理功能描述符。
314 // Call-management functional descriptor.
315 desc_block_.cdc_callmgmt = {
316 5, DescriptorType::CS_INTERFACE, DescriptorSubtype::CALL_MANAGEMENT,
317 0x00, // 无呼叫管理能力
318 static_cast<uint8_t>(DATA_INTERFACE + start_itf_num)}; // 数据接口号
319
320 // ACM 功能描述符。
321 // ACM functional descriptor.
322 desc_block_.cdc_acm = {4, DescriptorType::CS_INTERFACE, DescriptorSubtype::ACM,
323 0x02}; // 支持SetLineCoding/GetLineCoding/SetControlLineState
324
325 // 联合功能描述符。
326 // Union functional descriptor.
327 desc_block_.cdc_union = {5, DescriptorType::CS_INTERFACE, DescriptorSubtype::UNION,
328 static_cast<uint8_t>(COMM_INTERFACE + start_itf_num),
329 static_cast<uint8_t>(DATA_INTERFACE + start_itf_num)};
330
331 // 数据接口描述符。
332 // Data interface descriptor.
333 desc_block_.data_intf = {9,
334 static_cast<uint8_t>(DescriptorType::INTERFACE),
335 static_cast<uint8_t>(DATA_INTERFACE + start_itf_num),
336 0,
337 2,
338 static_cast<uint8_t>(Class::DATA),
339 0x00, // 无子类
340 0x00, // 无协议
341 GetInterfaceStringIndex(DATA_INTERFACE)};
342
343 // 数据OUT端点描述符
344 desc_block_.data_ep_out = {7,
345 static_cast<uint8_t>(DescriptorType::ENDPOINT),
347 static_cast<uint8_t>(Endpoint::Type::BULK),
349 0}; // 轮询间隔0(BULK忽略)
350
351 // 数据IN端点描述符
352 desc_block_.data_ep_in = {7,
353 static_cast<uint8_t>(DescriptorType::ENDPOINT),
354 static_cast<uint8_t>(ep_data_in_->GetAddress()),
355 static_cast<uint8_t>(Endpoint::Type::BULK),
357 0}; // 轮询间隔0(BULK忽略)
358
359 // 通信端点描述符。
360 // Communication endpoint descriptor.
361 desc_block_.comm_ep = {
362 7,
363 static_cast<uint8_t>(DescriptorType::ENDPOINT),
364 static_cast<uint8_t>(ep_comm_in_->GetAddress()), // IN端点地址
365 static_cast<uint8_t>(Endpoint::Type::INTERRUPT),
366 16, // 16字节最大包大小
367 0x04 // 轮询间隔FS-4ms HS-1ms
368 };
369
370 itf_comm_in_num_ = start_itf_num;
371
372 // 设置描述符原始数据。
373 // Publish the raw descriptor block.
374 SetData(RawData{reinterpret_cast<uint8_t*>(&desc_block_), sizeof(desc_block_)});
375
376 // 设置端点传输完成回调。
377 // Install endpoint transfer-complete callbacks.
378 ep_data_out_->SetOnTransferCompleteCallback(on_data_out_complete_cb_);
379 ep_data_in_->SetOnTransferCompleteCallback(on_data_in_complete_cb_);
380
381 inited_ = true;
382
383 // 启动OUT端点传输
385 }
386
394 virtual void UnbindEndpoints(EndpointPool& endpoint_pool, bool) override
395 {
396 inited_ = false;
404 endpoint_pool.Release(ep_data_in_);
405 endpoint_pool.Release(ep_data_out_);
406 endpoint_pool.Release(ep_comm_in_);
407 ep_data_in_ = nullptr;
408 ep_data_out_ = nullptr;
409 ep_comm_in_ = nullptr;
410 }
411
416 static void OnDataOutCompleteStatic(bool in_isr, CDCBase* self, ConstRawData& data)
417 {
418 if (!self->inited_)
419 {
420 return;
421 }
422 self->OnDataOutComplete(in_isr, data);
423 }
424
429 static void OnDataInCompleteStatic(bool in_isr, CDCBase* self, ConstRawData& data)
430 {
431 if (!self->inited_)
432 {
433 return;
434 }
435 self->OnDataInComplete(in_isr, data);
436 }
437
445 virtual void OnDataOutComplete(bool in_isr, ConstRawData& data) = 0;
446
454 virtual void OnDataInComplete(bool in_isr, ConstRawData& data) = 0;
455
462 size_t GetInterfaceCount() override { return 2; }
463
471 bool HasIAD() override { return true; }
472
473 bool OwnsEndpoint(uint8_t ep_addr) const override
474 {
475 if (!inited_)
476 {
477 return false;
478 }
479
480 return ep_data_in_->GetAddress() == ep_addr ||
481 ep_data_out_->GetAddress() == ep_addr || ep_comm_in_->GetAddress() == ep_addr;
482 }
483
490 size_t GetMaxConfigSize() override { return sizeof(desc_block_); }
491
499 ErrorCode OnClassRequest(bool in_isr, uint8_t bRequest, uint16_t wValue,
500 uint16_t wLength, uint16_t wIndex,
501 DeviceClass::ControlTransferResult& result) override
502 {
503 UNUSED(in_isr);
504 UNUSED(wIndex);
505
506 switch (static_cast<ClassRequest>(bRequest))
507 {
509 // 主机将在数据阶段发送7字节参数
510 if (wLength != sizeof(line_coding_))
511 {
512 return ErrorCode::ARG_ERR;
513 }
514 result.read_data =
515 RawData{reinterpret_cast<uint8_t*>(&line_coding_), sizeof(line_coding_)};
516 return ErrorCode::OK;
517
519 // 返回当前线路编码设置。
520 // Return the current line-coding settings.
521 if (wLength != sizeof(line_coding_))
522 {
523 return ErrorCode::ARG_ERR;
524 }
525
526 result.write_data = ConstRawData{reinterpret_cast<const uint8_t*>(&line_coding_),
527 sizeof(line_coding_)};
528 return ErrorCode::OK;
529
531 // 设置 DTR / RTS 状态。
532 // Update the DTR / RTS control-line state.
533 control_line_state_ = wValue;
534 result.write_zlp = true;
537 {
539 }
540 return ErrorCode::OK;
541
543 // BREAK 信号通常忽略。
544 // BREAK is typically ignored on this path.
545 result.write_zlp = true;
546 return ErrorCode::OK;
547
548 default:
550 }
551 }
552
557 ErrorCode OnClassData(bool in_isr, uint8_t bRequest, LibXR::ConstRawData& data) override
558 {
559 UNUSED(in_isr);
560 UNUSED(data);
561
562 switch (static_cast<ClassRequest>(bRequest))
563 {
565 {
566 // 将 CDC 线路编码转换为 UART 配置。
567 // Convert CDC line coding into a UART configuration.
571 {
572 case 0:
573 cfg.stop_bits = 1;
574 break;
575 // TODO: 1.5
576 case 2:
577 cfg.stop_bits = 2;
578 break;
579 default:
580 cfg.stop_bits = 1;
581 }
583 {
584 case 1:
586 break;
587 case 2:
589 break;
590 default:
592 }
595 {
596 on_set_line_coding_cb_.Run(in_isr, cfg);
597 }
598 }
599 return ErrorCode::OK;
600 default:
602 }
603 }
604
605 LIBXR_PACKED_BEGIN
614 {
618
619 // CDC类特定描述符
620 struct
621 {
622 uint8_t bFunctionLength = 5;
623 DescriptorType bDescriptorType = DescriptorType::CS_INTERFACE;
624 DescriptorSubtype bDescriptorSubtype = DescriptorSubtype::HEADER;
625 uint16_t bcdCDC = 0x0110;
626 } cdc_header;
627
628 struct
629 {
630 uint8_t bFunctionLength = 5;
631 DescriptorType bDescriptorType = DescriptorType::CS_INTERFACE;
633 uint8_t bmCapabilities = 0x00;
635 } cdc_callmgmt;
636
637 struct
638 {
639 uint8_t bFunctionLength = 4;
640 DescriptorType bDescriptorType = DescriptorType::CS_INTERFACE;
641 DescriptorSubtype bDescriptorSubtype = DescriptorSubtype::ACM;
642 uint8_t bmCapabilities = 0x02;
643 } cdc_acm;
644
645 struct
646 {
647 uint8_t bFunctionLength = 5;
648 DescriptorType bDescriptorType = DescriptorType::CS_INTERFACE;
649 DescriptorSubtype bDescriptorSubtype = DescriptorSubtype::UNION;
652 } cdc_union;
653
655
657
660 } desc_block_;
661 LIBXR_PACKED_END
662
663 protected:
664 CDCLineCoding& GetLineCoding() { return line_coding_; }
665
666 bool Inited() { return inited_; }
667
668 Endpoint* GetDataInEndpoint() { return ep_data_in_; }
669
670 Endpoint* GetDataOutEndpoint() { return ep_data_out_; }
671
672 Endpoint* GetCommInEndpoint() { return ep_comm_in_; }
673
674 private:
675 // 端点号。
676 // Endpoint numbers.
681 nullptr;
683 nullptr;
684
685 // 端点指针。
686 // Endpoint pointers.
690
691 // 端点回调。
692 // Endpoint callbacks.
693 LibXR::Callback<LibXR::ConstRawData&> on_data_out_complete_cb_ =
695
696 LibXR::Callback<LibXR::ConstRawData&> on_data_in_complete_cb_ =
698
699 // 用户回调。
700 // User callbacks.
706
707 // 状态标志。
708 // State flags.
709 bool inited_ = false;
711 bool has_line_coding_cb_ = false;
712
713 // 接口信息。
714 // Interface metadata.
716
717 // CDC 参数。
718 // CDC parameters.
719 CDCLineCoding line_coding_ = {115200, 0, 0, 8};
720 uint16_t control_line_state_ = 0;
721};
722
723} // namespace LibXR::USB
通用回调包装,支持动态参数传递 / Generic callback wrapper supporting dynamic argument passing
Definition libxr_cb.hpp:143
static Callback Create(CallableType fun, BoundArgType arg)
创建回调对象并绑定回调函数与参数 / Create a callback instance with bound function and argument
Definition libxr_cb.hpp:166
bool Empty() const
检查回调是否为空 / Check whether the callback is empty
Definition libxr_cb.hpp:245
只读原始数据视图 / Immutable raw data view
可写原始数据视图 / Mutable raw data view
@ NO_PARITY
无校验 / No parity
@ ODD
奇校验 / Odd parity
@ EVEN
偶校验 / Even parity
USB CDC ACM (Abstract Control Model) 设备类实现 USB CDC ACM (Abstract Control Model) device class implemen...
Definition cdc_base.hpp:24
void SetOnSetControlLineStateCallback(LibXR::Callback< bool, bool > cb)
设置控制线路状态变更回调 Set control line state change callback
Definition cdc_base.hpp:228
virtual void BindEndpoints(EndpointPool &endpoint_pool, uint8_t start_itf_num, bool) override
初始化CDC设备 Initialize CDC device
Definition cdc_base.hpp:256
LibXR::Callback< bool, bool > on_set_control_line_state_cb_
Definition cdc_base.hpp:702
Protocol
CDC协议代码 / CDC protocol codes.
Definition cdc_base.hpp:49
@ AT_COMMAND
AT命令协议 / AT Command protocol.
@ NONE
无协议 / No protocol
size_t GetMaxConfigSize() override
获取最大配置描述符大小 Get maximum configuration descriptor size
Definition cdc_base.hpp:490
Endpoint::EPNumber data_in_ep_num_
数据IN端点号 / Data IN endpoint number
Definition cdc_base.hpp:677
uint8_t itf_comm_in_num_
通信接口号 / Communication interface number
Definition cdc_base.hpp:715
bool has_line_coding_cb_
Line-coding callback registered.
Definition cdc_base.hpp:711
CDCNotification
CDC通知类型 / CDC notification types.
Definition cdc_base.hpp:75
@ RESPONSE_AVAILABLE
响应可用通知 / Response available
@ NETWORK_CONNECTION
网络连接通知 / Network connection
@ AUX_JACK_HOOK_STATE
辅助插槽状态通知 / Aux jack hook state
@ RING_DETECT
响铃检测通知 / Ring detect
void SetOnSetLineCodingCallback(LibXR::Callback< LibXR::UART::Configuration > cb)
设置线路编码变更回调 Set line coding change callback
Definition cdc_base.hpp:238
Endpoint::EPNumber comm_ep_num_
通信端点号 / Communication endpoint number
Definition cdc_base.hpp:679
Class
USB设备类代码 / USB device class codes.
Definition cdc_base.hpp:42
@ 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.
Definition cdc_base.hpp:56
@ 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
Definition cdc_base.hpp:689
bool inited_
初始化标志 / Initialization flag
Definition cdc_base.hpp:709
Endpoint * ep_data_in_
数据IN端点 / Data IN endpoint
Definition cdc_base.hpp:687
const char * GetInterfaceString(size_t local_interface_index) const override
返回本类暴露的第 N 个接口字符串 Return the string for the Nth local interface exposed by this class.
Definition cdc_base.hpp:149
static void OnDataOutCompleteStatic(bool in_isr, CDCBase *self, ConstRawData &data)
数据OUT端点传输完成静态回调 Static callback for data OUT endpoint transfer completion
Definition cdc_base.hpp:416
bool OwnsEndpoint(uint8_t ep_addr) const override
可选:端点归属判定 / Optional: endpoint ownership
Definition cdc_base.hpp:473
static constexpr uint16_t CDC_CONTROL_LINE_DTR
DTR控制位 / DTR control bit.
Definition cdc_base.hpp:125
ClassRequest
CDC类特定请求 / CDC class-specific requests.
Definition cdc_base.hpp:66
@ 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
DescriptorSubtype
CDC功能描述符子类型定义 / CDC functional descriptor subtypes.
Definition cdc_base.hpp:32
@ 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
Definition cdc_base.hpp:705
bool IsRtsSet() const
检查RTS状态 Check RTS state
Definition cdc_base.hpp:178
Endpoint::EPNumber data_out_ep_num_
数据OUT端点号 / Data OUT endpoint number
Definition cdc_base.hpp:678
uint16_t control_line_state_
控制线路状态 / Control line state
Definition cdc_base.hpp:720
ErrorCode OnClassRequest(bool in_isr, uint8_t bRequest, uint16_t wValue, uint16_t wLength, uint16_t wIndex, DeviceClass::ControlTransferResult &result) override
处理类特定请求 Handle class-specific requests
Definition cdc_base.hpp:499
bool has_control_line_state_cb_
Control-line callback registered.
Definition cdc_base.hpp:710
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
Definition cdc_base.hpp:471
static void OnDataInCompleteStatic(bool in_isr, CDCBase *self, ConstRawData &data)
数据IN端点传输完成静态回调 Static callback for data IN endpoint transfer completion
Definition cdc_base.hpp:429
CDCLineCoding line_coding_
当前线路编码 / Current line coding
Definition cdc_base.hpp:719
CDCBase(Endpoint::EPNumber data_in_ep_num, Endpoint::EPNumber data_out_ep_num, Endpoint::EPNumber comm_ep_num, const char *control_interface_string=DEFAULT_CONTROL_INTERFACE_STRING, const char *data_interface_string=DEFAULT_DATA_INTERFACE_STRING)
CDC构造函数 CDC constructor.
Definition cdc_base.hpp:137
ErrorCode OnClassData(bool in_isr, uint8_t bRequest, LibXR::ConstRawData &data) override
处理类请求数据阶段 Handle class request data stage
Definition cdc_base.hpp:557
Endpoint * ep_data_out_
数据OUT端点 / Data OUT endpoint
Definition cdc_base.hpp:688
const char * control_interface_string_
控制接口字符串 / Control interface string
Definition cdc_base.hpp:680
ErrorCode SendSerialState()
发送串行状态通知 Send serial state notification
Definition cdc_base.hpp:187
static constexpr uint16_t CDC_CONTROL_LINE_RTS
RTS控制位 / RTS control bit.
Definition cdc_base.hpp:126
virtual void UnbindEndpoints(EndpointPool &endpoint_pool, bool) override
反初始化CDC设备 Deinitialize CDC device
Definition cdc_base.hpp:394
size_t GetInterfaceCount() override
获取接口数量 Get number of interfaces
Definition cdc_base.hpp:462
const char * data_interface_string_
数据接口字符串 / Data interface string
Definition cdc_base.hpp:682
bool IsDtrSet() const
检查DTR状态 Check DTR state
Definition cdc_base.hpp:169
void SetData(RawData data)
设置内部数据缓存 / Set internal data cache
Definition desc_cfg.hpp:193
USB 设备类接口基类 / USB device class interface base.
uint8_t GetInterfaceStringIndex(size_t local_interface_index) const
返回已分配的接口字符串索引 Return the assigned USB string index for a local interface.
USB 端点基类 / USB Endpoint base class.
Definition ep.hpp:24
EPNumber
端点号 Endpoint number
Definition ep.hpp:42
uint8_t GetAddress() const
获取端点地址(方向 + 号) / Get endpoint address (dir + num)
Definition ep.hpp:194
@ IN
输入方向 / IN direction
@ OUT
输出方向 / OUT direction
void SetActiveLength(uint16_t len)
设置当前活动缓冲区有效长度 / Set active buffer valid length
Definition ep.hpp:270
void SetOnTransferCompleteCallback(Callback< ConstRawData & > cb)
设置传输完成回调 / Set transfer complete callback
Definition ep.hpp:261
virtual void Configure(const Config &cfg)=0
配置端点协议参数 / Configure endpoint protocol parameters
@ BULK
批量端点 / Bulk
@ INTERRUPT
中断端点 / Interrupt
virtual void Close()=0
关闭端点 / Close endpoint
uint16_t MaxPacketSize() const
获取最大包长 / Get max packet size
Definition ep.hpp:225
State GetState() const
获取端点状态 / Get endpoint state
Definition ep.hpp:207
virtual ErrorCode Transfer(size_t size)=0
启动一次传输 / Start a transfer
RawData GetBuffer() const
获取当前可用于传输的缓冲区 / Get current transfer buffer
Definition ep.hpp:245
USB端点池类 / USB endpoint pool class.
Definition ep_pool.hpp:29
ErrorCode Release(Endpoint *ep_info)
回收端点 / Release endpoint
Definition ep_pool.cpp:93
ErrorCode Get(Endpoint *&ep_info, Endpoint::Direction direction, Endpoint::EPNumber ep_num)
分配端点 / Allocate endpoint
Definition ep_pool.cpp:52
ErrorCode
定义错误码枚举
@ BUSY
忙碌 | Busy
@ NOT_SUPPORT
不支持 | Not supported
@ OK
操作成功 | Operation successful
@ ARG_ERR
参数错误 | Argument error
UART 配置结构体 / UART configuration structure.
Definition uart.hpp:44
uint8_t stop_bits
停止位长度 / Number of stop bits
Definition uart.hpp:50
Parity parity
校验模式 / Parity mode
Definition uart.hpp:47
uint8_t data_bits
数据位长度 / Number of data bits
Definition uart.hpp:48
uint32_t baudrate
波特率 / Baud rate
Definition uart.hpp:45
CDC描述符块结构 CDC descriptor block structure.
Definition cdc_base.hpp:614
InterfaceDescriptor data_intf
数据接口描述符 / Data interface descriptor
Definition cdc_base.hpp:656
uint8_t bSlaveInterface0
从接口号 / Slave interface number
Definition cdc_base.hpp:651
EndpointDescriptor data_ep_out
数据OUT端点描述符 / Data OUT endpoint descriptor
Definition cdc_base.hpp:658
uint16_t bcdCDC
CDC规范版本 / CDC specification version.
Definition cdc_base.hpp:625
uint8_t bmCapabilities
呼叫管理能力 / Call management capabilities
Definition cdc_base.hpp:633
InterfaceDescriptor comm_intf
通信接口描述符 / Communication interface descriptor
Definition cdc_base.hpp:617
uint8_t bDataInterface
数据接口号 / Data interface number
Definition cdc_base.hpp:634
EndpointDescriptor comm_ep
通信端点描述符 / Communication endpoint descriptor
Definition cdc_base.hpp:654
uint8_t bMasterInterface
主接口号 / Master interface number
Definition cdc_base.hpp:650
EndpointDescriptor data_ep_in
数据IN端点描述符 / Data IN endpoint descriptor
Definition cdc_base.hpp:659
IADDescriptor iad
接口关联描述符 / Interface association descriptor
Definition cdc_base.hpp:615
CDC线路编码参数结构体 CDC line coding parameters structure.
Definition cdc_base.hpp:93
uint32_t dwDTERate
波特率(小端格式) / Baud rate (little-endian)
Definition cdc_base.hpp:94
uint8_t bCharFormat
停止位:0=1位,1=1.5位,2=2位 / Stop bits: 0=1, 1=1.5, 2=2
Definition cdc_base.hpp:95
uint8_t bDataBits
数据位:5,6,7,8或16 / Data bits: 5,6,7,8 or 16
Definition cdc_base.hpp:98
串行状态通知结构体 Serial state notification structure
Definition cdc_base.hpp:109
uint16_t wLength
数据长度(固定为2)| Data length (fixed to 2)
Definition cdc_base.hpp:115
uint16_t wIndex
接口号 / Interface number
Definition cdc_base.hpp:114
uint16_t serialState
串行状态位图 / Serial state bitmap
Definition cdc_base.hpp:116
uint8_t bmRequestType
请求类型(固定为 0xA1) / Request type (fixed to 0xA1)
Definition cdc_base.hpp:110
uint16_t wValue
值(固定为 0) / Value (fixed to 0)
Definition cdc_base.hpp:113
端点描述符(7 字节)/ Endpoint descriptor (7 bytes)
Definition desc_cfg.hpp:91
IAD(8 字节)/ Interface Association Descriptor (8 bytes)
Definition desc_cfg.hpp:60
接口描述符(9 字节)/ Interface descriptor (9 bytes)
Definition desc_cfg.hpp:75
控制请求(Class/Vendor)处理结果 / Control request (Class/Vendor) handling result
bool write_zlp
发送 STATUS IN(发送 ZLP)/ Send STATUS IN (send ZLP)