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
84LIBXR_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 };
118LIBXR_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:
140 const char* control_interface_string = DEFAULT_CONTROL_INTERFACE_STRING,
141 const char* data_interface_string = DEFAULT_DATA_INTERFACE_STRING)
142 : data_in_ep_num_(data_in_ep_num),
143 data_out_ep_num_(data_out_ep_num),
144 comm_ep_num_(comm_ep_num),
145 control_interface_string_(control_interface_string),
146 data_interface_string_(data_interface_string)
147 {
148 }
149
150 const char* GetInterfaceString(size_t local_interface_index) const override
151 {
152 switch (local_interface_index)
153 {
154 case 0:
156 case 1:
158 default:
159 return nullptr;
160 }
161 }
162
170 bool IsDtrSet() const { return (control_line_state_ & CDC_CONTROL_LINE_DTR) != 0; }
171
179 bool IsRtsSet() const { return (control_line_state_ & CDC_CONTROL_LINE_RTS) != 0; }
180
189 {
191 {
192 return ErrorCode::BUSY;
193 }
194 auto buffer = ep_comm_in_->GetBuffer();
195 ASSERT(buffer.size_ >= sizeof(SerialStateNotification));
196 SerialStateNotification* notification =
197 reinterpret_cast<SerialStateNotification*>(buffer.addr_);
198 notification->wIndex = itf_comm_in_num_;
199
200 // 设置串行状态位。
201 // Fill the serial-state bitmap.
202 if (IsDtrSet())
203 {
204 // DTR 有效时报告载波检测(DCD)和数据集就绪(DSR)。
205 // When DTR is asserted, report DCD and DSR as active.
206 notification->serialState = 0x03; // DCD / DSR
207 }
208 else
209 {
210 notification->serialState = 0x00; // 无状态
211 }
212
213 // 填充固定字段。
214 // Fill the fixed notification header fields.
215 notification->bmRequestType = 0xA1; // 设备到主机,类,接口
216 notification->bNotification = static_cast<uint8_t>(CDCNotification::SERIAL_STATE);
217 notification->wValue = 0;
218 notification->wLength = 2;
219
221
222 return ErrorCode::OK;
223 }
224
234
244
245 protected:
257 virtual void BindEndpoints(EndpointPool& endpoint_pool, uint8_t start_itf_num,
258 bool) override
259 {
261 // 获取并配置数据IN端点
262 auto ans = endpoint_pool.Get(ep_data_in_, Endpoint::Direction::IN, data_in_ep_num_);
263 ASSERT(ans == ErrorCode::OK);
264
265 // 获取并配置数据OUT端点
267 ASSERT(ans == ErrorCode::OK);
268
269 // 获取并配置通信端点。
270 // Acquire and configure the communication endpoint.
272 ASSERT(ans == ErrorCode::OK);
273
274 // 配置端点参数。
275 // Configure endpoint parameters.
277 {Endpoint::Direction::IN, Endpoint::Type::BULK, UINT16_MAX, true});
281
282 // === 填充CDC描述符块 ===
283 static constexpr uint8_t COMM_INTERFACE = 0; // 通信接口号
284 static constexpr uint8_t DATA_INTERFACE = 1; // 数据接口号
285
286 // IAD 描述符(关联两组 CDC 接口)。
287 // IAD descriptor that groups the two CDC interfaces.
288 desc_block_.iad = {8,
289 static_cast<uint8_t>(DescriptorType::IAD),
290 static_cast<uint8_t>(COMM_INTERFACE + start_itf_num),
291 2,
292 static_cast<uint8_t>(Class::COMM),
293 static_cast<uint8_t>(Subclass::ABSTRACT_CONTROL_MODEL),
294 static_cast<uint8_t>(Protocol::NONE),
295 0};
296
297 // 通信接口描述符。
298 // Communication interface descriptor.
299 desc_block_.comm_intf = {9,
300 static_cast<uint8_t>(DescriptorType::INTERFACE),
301 static_cast<uint8_t>(COMM_INTERFACE + start_itf_num),
302 0,
303 1,
304 static_cast<uint8_t>(Class::COMM),
305 static_cast<uint8_t>(Subclass::ABSTRACT_CONTROL_MODEL),
306 static_cast<uint8_t>(Protocol::NONE),
307 GetInterfaceStringIndex(COMM_INTERFACE)};
308
309 // CDC 头功能描述符。
310 // CDC header functional descriptor.
311 desc_block_.cdc_header = {5, DescriptorType::CS_INTERFACE, DescriptorSubtype::HEADER,
312 0x0110}; // CDC规范版本1.10
313
314 // 呼叫管理功能描述符。
315 // Call-management functional descriptor.
316 desc_block_.cdc_callmgmt = {
317 5, DescriptorType::CS_INTERFACE, DescriptorSubtype::CALL_MANAGEMENT,
318 0x00, // 无呼叫管理能力
319 static_cast<uint8_t>(DATA_INTERFACE + start_itf_num)}; // 数据接口号
320
321 // ACM 功能描述符。
322 // ACM functional descriptor.
323 desc_block_.cdc_acm = {4, DescriptorType::CS_INTERFACE, DescriptorSubtype::ACM,
324 0x02}; // 支持SetLineCoding/GetLineCoding/SetControlLineState
325
326 // 联合功能描述符。
327 // Union functional descriptor.
328 desc_block_.cdc_union = {5, DescriptorType::CS_INTERFACE, DescriptorSubtype::UNION,
329 static_cast<uint8_t>(COMM_INTERFACE + start_itf_num),
330 static_cast<uint8_t>(DATA_INTERFACE + start_itf_num)};
331
332 // 数据接口描述符。
333 // Data interface descriptor.
334 desc_block_.data_intf = {9,
335 static_cast<uint8_t>(DescriptorType::INTERFACE),
336 static_cast<uint8_t>(DATA_INTERFACE + start_itf_num),
337 0,
338 2,
339 static_cast<uint8_t>(Class::DATA),
340 0x00, // 无子类
341 0x00, // 无协议
342 GetInterfaceStringIndex(DATA_INTERFACE)};
343
344 // 数据OUT端点描述符
345 desc_block_.data_ep_out = {7,
346 static_cast<uint8_t>(DescriptorType::ENDPOINT),
348 static_cast<uint8_t>(Endpoint::Type::BULK),
350 0}; // 轮询间隔0(BULK忽略)
351
352 // 数据IN端点描述符
353 desc_block_.data_ep_in = {7,
354 static_cast<uint8_t>(DescriptorType::ENDPOINT),
355 static_cast<uint8_t>(ep_data_in_->GetAddress()),
356 static_cast<uint8_t>(Endpoint::Type::BULK),
358 0}; // 轮询间隔0(BULK忽略)
359
360 // 通信端点描述符。
361 // Communication endpoint descriptor.
362 desc_block_.comm_ep = {
363 7,
364 static_cast<uint8_t>(DescriptorType::ENDPOINT),
365 static_cast<uint8_t>(ep_comm_in_->GetAddress()), // IN端点地址
366 static_cast<uint8_t>(Endpoint::Type::INTERRUPT),
367 16, // 16字节最大包大小
368 0x04 // 轮询间隔FS-4ms HS-1ms
369 };
370
371 itf_comm_in_num_ = start_itf_num;
372
373 // 设置描述符原始数据。
374 // Publish the raw descriptor block.
375 SetData(RawData{reinterpret_cast<uint8_t*>(&desc_block_), sizeof(desc_block_)});
376
377 // 设置端点传输完成回调。
378 // Install endpoint transfer-complete callbacks.
379 ep_data_out_->SetOnTransferCompleteCallback(on_data_out_complete_cb_);
380 ep_data_in_->SetOnTransferCompleteCallback(on_data_in_complete_cb_);
381
382 inited_ = true;
383
384 // 启动OUT端点传输
386 }
387
395 virtual void UnbindEndpoints(EndpointPool& endpoint_pool, bool) override
396 {
397 inited_ = false;
405 endpoint_pool.Release(ep_data_in_);
406 endpoint_pool.Release(ep_data_out_);
407 endpoint_pool.Release(ep_comm_in_);
408 ep_data_in_ = nullptr;
409 ep_data_out_ = nullptr;
410 ep_comm_in_ = nullptr;
411 }
412
417 static void OnDataOutCompleteStatic(bool in_isr, CDCBase* self, ConstRawData& data)
418 {
419 if (!self->inited_)
420 {
421 return;
422 }
423 self->OnDataOutComplete(in_isr, data);
424 }
425
430 static void OnDataInCompleteStatic(bool in_isr, CDCBase* self, ConstRawData& data)
431 {
432 if (!self->inited_)
433 {
434 return;
435 }
436 self->OnDataInComplete(in_isr, data);
437 }
438
446 virtual void OnDataOutComplete(bool in_isr, ConstRawData& data) = 0;
447
455 virtual void OnDataInComplete(bool in_isr, ConstRawData& data) = 0;
456
463 size_t GetInterfaceCount() override { return 2; }
464
472 bool HasIAD() override { return true; }
473
474 bool OwnsEndpoint(uint8_t ep_addr) const override
475 {
476 if (!inited_)
477 {
478 return false;
479 }
480
481 return ep_data_in_->GetAddress() == ep_addr ||
482 ep_data_out_->GetAddress() == ep_addr || ep_comm_in_->GetAddress() == ep_addr;
483 }
484
491 size_t GetMaxConfigSize() override { return sizeof(desc_block_); }
492
500 ErrorCode OnClassRequest(bool in_isr, uint8_t bRequest, uint16_t wValue,
501 uint16_t wLength, uint16_t wIndex,
502 DeviceClass::ControlTransferResult& result) override
503 {
504 UNUSED(in_isr);
505 UNUSED(wIndex);
506
507 switch (static_cast<ClassRequest>(bRequest))
508 {
510 // 主机将在数据阶段发送7字节参数
511 if (wLength != sizeof(line_coding_))
512 {
513 return ErrorCode::ARG_ERR;
514 }
515 result.read_data =
516 RawData{reinterpret_cast<uint8_t*>(&line_coding_), sizeof(line_coding_)};
517 return ErrorCode::OK;
518
520 // 返回当前线路编码设置。
521 // Return the current line-coding settings.
522 if (wLength != sizeof(line_coding_))
523 {
524 return ErrorCode::ARG_ERR;
525 }
526
527 result.write_data = ConstRawData{reinterpret_cast<const uint8_t*>(&line_coding_),
528 sizeof(line_coding_)};
529 return ErrorCode::OK;
530
532 // 设置 DTR / RTS 状态。
533 // Update the DTR / RTS control-line state.
534 control_line_state_ = wValue;
535 result.write_zlp = true;
538 {
540 }
541 return ErrorCode::OK;
542
544 // BREAK 信号通常忽略。
545 // BREAK is typically ignored on this path.
546 result.write_zlp = true;
547 return ErrorCode::OK;
548
549 default:
551 }
552 }
553
558 ErrorCode OnClassData(bool in_isr, uint8_t bRequest, LibXR::ConstRawData& data) override
559 {
560 UNUSED(in_isr);
561 UNUSED(data);
562
563 switch (static_cast<ClassRequest>(bRequest))
564 {
566 {
567 // 将 CDC 线路编码转换为 UART 配置。
568 // Convert CDC line coding into a UART configuration.
572 {
573 case 0:
574 cfg.stop_bits = 1;
575 break;
576 // TODO: 1.5
577 case 2:
578 cfg.stop_bits = 2;
579 break;
580 default:
581 cfg.stop_bits = 1;
582 }
584 {
585 case 1:
587 break;
588 case 2:
590 break;
591 default:
593 }
596 {
597 on_set_line_coding_cb_.Run(in_isr, cfg);
598 }
599 }
600 return ErrorCode::OK;
601 default:
603 }
604 }
605
606LIBXR_PACKED_BEGIN
615 {
619
620 // CDC类特定描述符
621 struct
622 {
623 uint8_t bFunctionLength = 5;
624 DescriptorType bDescriptorType = DescriptorType::CS_INTERFACE;
625 DescriptorSubtype bDescriptorSubtype = DescriptorSubtype::HEADER;
626 uint16_t bcdCDC = 0x0110;
627 } cdc_header;
628
629 struct
630 {
631 uint8_t bFunctionLength = 5;
632 DescriptorType bDescriptorType = DescriptorType::CS_INTERFACE;
634 uint8_t bmCapabilities = 0x00;
636 } cdc_callmgmt;
637
638 struct
639 {
640 uint8_t bFunctionLength = 4;
641 DescriptorType bDescriptorType = DescriptorType::CS_INTERFACE;
642 DescriptorSubtype bDescriptorSubtype = DescriptorSubtype::ACM;
643 uint8_t bmCapabilities = 0x02;
644 } cdc_acm;
645
646 struct
647 {
648 uint8_t bFunctionLength = 5;
649 DescriptorType bDescriptorType = DescriptorType::CS_INTERFACE;
650 DescriptorSubtype bDescriptorSubtype = DescriptorSubtype::UNION;
653 } cdc_union;
654
656
658
661 } desc_block_;
662LIBXR_PACKED_END
663
664 protected:
665 CDCLineCoding& GetLineCoding() { return line_coding_; }
666
667 bool Inited() { return inited_; }
668
669 Endpoint* GetDataInEndpoint() { return ep_data_in_; }
670
671 Endpoint* GetDataOutEndpoint() { return ep_data_out_; }
672
673 Endpoint* GetCommInEndpoint() { return ep_comm_in_; }
674
675 private:
676 // 端点号。
677 // Endpoint numbers.
682 nullptr;
684 nullptr;
685
686 // 端点指针。
687 // Endpoint pointers.
691
692 // 端点回调。
693 // Endpoint callbacks.
694 LibXR::Callback<LibXR::ConstRawData&> on_data_out_complete_cb_ =
696
697 LibXR::Callback<LibXR::ConstRawData&> on_data_in_complete_cb_ =
699
700 // 用户回调。
701 // User callbacks.
707
708 // 状态标志。
709 // State flags.
710 bool inited_ = false;
712 bool has_line_coding_cb_ = false;
713
714 // 接口信息。
715 // Interface metadata.
717
718 // CDC 参数。
719 // CDC parameters.
720 CDCLineCoding line_coding_ = {115200, 0, 0, 8};
721 uint16_t control_line_state_ = 0;
722};
723
724} // namespace LibXR::USB
通用回调包装,支持动态参数传递 / Generic callback wrapper supporting dynamic argument passing
Definition libxr_cb.hpp:144
static Callback Create(CallableType fun, BoundArgType arg)
创建回调对象并绑定回调函数与参数 / Create a callback instance with bound function and argument
Definition libxr_cb.hpp:167
bool Empty() const
检查回调是否为空 / Check whether the callback is empty
Definition libxr_cb.hpp:248
只读原始数据视图 / 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:229
virtual void BindEndpoints(EndpointPool &endpoint_pool, uint8_t start_itf_num, bool) override
初始化CDC设备 Initialize CDC device
Definition cdc_base.hpp:257
LibXR::Callback< bool, bool > on_set_control_line_state_cb_
Definition cdc_base.hpp:703
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:491
Endpoint::EPNumber data_in_ep_num_
数据IN端点号 / Data IN endpoint number
Definition cdc_base.hpp:678
uint8_t itf_comm_in_num_
通信接口号 / Communication interface number
Definition cdc_base.hpp:716
bool has_line_coding_cb_
Line-coding callback registered.
Definition cdc_base.hpp:712
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:239
Endpoint::EPNumber comm_ep_num_
通信端点号 / Communication endpoint number
Definition cdc_base.hpp:680
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
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, 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
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:690
bool inited_
初始化标志 / Initialization flag
Definition cdc_base.hpp:710
Endpoint * ep_data_in_
数据IN端点 / Data IN endpoint
Definition cdc_base.hpp:688
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:150
static void OnDataOutCompleteStatic(bool in_isr, CDCBase *self, ConstRawData &data)
数据OUT端点传输完成静态回调 Static callback for data OUT endpoint transfer completion
Definition cdc_base.hpp:417
bool OwnsEndpoint(uint8_t ep_addr) const override
可选:端点归属判定 / Optional: endpoint ownership
Definition cdc_base.hpp:474
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:706
bool IsRtsSet() const
检查RTS状态 Check RTS state
Definition cdc_base.hpp:179
Endpoint::EPNumber data_out_ep_num_
数据OUT端点号 / Data OUT endpoint number
Definition cdc_base.hpp:679
uint16_t control_line_state_
控制线路状态 / Control line state
Definition cdc_base.hpp:721
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:500
bool has_control_line_state_cb_
Control-line callback registered.
Definition cdc_base.hpp:711
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:472
static void OnDataInCompleteStatic(bool in_isr, CDCBase *self, ConstRawData &data)
数据IN端点传输完成静态回调 Static callback for data IN endpoint transfer completion
Definition cdc_base.hpp:430
CDCLineCoding line_coding_
当前线路编码 / Current line coding
Definition cdc_base.hpp:720
ErrorCode OnClassData(bool in_isr, uint8_t bRequest, LibXR::ConstRawData &data) override
处理类请求数据阶段 Handle class request data stage
Definition cdc_base.hpp:558
Endpoint * ep_data_out_
数据OUT端点 / Data OUT endpoint
Definition cdc_base.hpp:689
const char * control_interface_string_
控制接口字符串 / Control interface string
Definition cdc_base.hpp:681
ErrorCode SendSerialState()
发送串行状态通知 Send serial state notification
Definition cdc_base.hpp:188
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:395
size_t GetInterfaceCount() override
获取接口数量 Get number of interfaces
Definition cdc_base.hpp:463
const char * data_interface_string_
数据接口字符串 / Data interface string
Definition cdc_base.hpp:683
bool IsDtrSet() const
检查DTR状态 Check DTR state
Definition cdc_base.hpp:170
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
@ EP_AUTO
自动分配端点号 / Auto allocate
uint8_t GetAddress() const
获取端点地址(方向 + 号) / Get endpoint address (dir + num)
Definition ep.hpp:195
@ IN
输入方向 / IN direction
@ OUT
输出方向 / OUT direction
void SetActiveLength(uint16_t len)
设置当前活动缓冲区有效长度 / Set active buffer valid length
Definition ep.hpp:271
void SetOnTransferCompleteCallback(Callback< ConstRawData & > cb)
设置传输完成回调 / Set transfer complete callback
Definition ep.hpp:262
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:226
State GetState() const
获取端点状态 / Get endpoint state
Definition ep.hpp:208
virtual ErrorCode Transfer(size_t size)=0
启动一次传输 / Start a transfer
RawData GetBuffer() const
获取当前可用于传输的缓冲区 / Get current transfer buffer
Definition ep.hpp:246
USB端点池类 / USB endpoint pool class.
Definition ep_pool.hpp:23
ErrorCode Get(Endpoint *&ep_info, Endpoint::Direction direction, Endpoint::EPNumber ep_num=Endpoint::EPNumber::EP_AUTO)
分配端点 / Allocate endpoint
Definition ep_pool.cpp:11
ErrorCode Release(Endpoint *ep_info)
回收端点 / Release endpoint
Definition ep_pool.cpp:37
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:615
InterfaceDescriptor data_intf
数据接口描述符 / Data interface descriptor
Definition cdc_base.hpp:657
uint8_t bSlaveInterface0
从接口号 / Slave interface number
Definition cdc_base.hpp:652
EndpointDescriptor data_ep_out
数据OUT端点描述符 / Data OUT endpoint descriptor
Definition cdc_base.hpp:659
uint16_t bcdCDC
CDC规范版本 / CDC specification version.
Definition cdc_base.hpp:626
uint8_t bmCapabilities
呼叫管理能力 / Call management capabilities
Definition cdc_base.hpp:634
InterfaceDescriptor comm_intf
通信接口描述符 / Communication interface descriptor
Definition cdc_base.hpp:618
uint8_t bDataInterface
数据接口号 / Data interface number
Definition cdc_base.hpp:635
EndpointDescriptor comm_ep
通信端点描述符 / Communication endpoint descriptor
Definition cdc_base.hpp:655
uint8_t bMasterInterface
主接口号 / Master interface number
Definition cdc_base.hpp:651
EndpointDescriptor data_ep_in
数据IN端点描述符 / Data IN endpoint descriptor
Definition cdc_base.hpp:660
IADDescriptor iad
接口关联描述符 / Interface association descriptor
Definition cdc_base.hpp:616
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)