libxr
Embedded C++ framework for bare-metal, RTOS and Linux
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,
34 CALL_MANAGEMENT =
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,
58 DIRECT_LINE_CONTROL_MODEL =
59 0x01,
60 ABSTRACT_CONTROL_MODEL =
61 0x02,
62 };
63
65 enum class ClassRequest : uint8_t
66 {
67 SET_LINE_CODING = 0x20,
68 GET_LINE_CODING = 0x21,
69 SET_CONTROL_LINE_STATE = 0x22,
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
92 struct CDCLineCoding
93 {
94 uint32_t dwDTERate;
95 uint8_t bCharFormat;
96 uint8_t bParityType;
98 uint8_t bDataBits;
99 };
100
108 struct SerialStateNotification
109 {
110 uint8_t bmRequestType;
111 uint8_t bNotification;
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:
139 CDCBase(Endpoint::EPNumber data_in_ep_num, Endpoint::EPNumber data_out_ep_num,
140 Endpoint::EPNumber comm_ep_num,
141 const char* control_interface_string = DEFAULT_CONTROL_INTERFACE_STRING,
142 const char* data_interface_string = DEFAULT_DATA_INTERFACE_STRING)
143 : data_in_ep_num_(data_in_ep_num),
144 data_out_ep_num_(data_out_ep_num),
145 comm_ep_num_(comm_ep_num),
146 control_interface_string_(control_interface_string),
147 data_interface_string_(data_interface_string)
148 {
149 }
150
151 const char* GetInterfaceString(size_t local_interface_index) const override
152 {
153 switch (local_interface_index)
154 {
155 case 0:
156 return control_interface_string_;
157 case 1:
158 return data_interface_string_;
159 default:
160 return nullptr;
161 }
162 }
163
171 bool IsDtrSet() const { return (control_line_state_ & CDC_CONTROL_LINE_DTR) != 0; }
172
180 bool IsRtsSet() const { return (control_line_state_ & CDC_CONTROL_LINE_RTS) != 0; }
181
190 {
191 if (ep_comm_in_->GetState() == Endpoint::State::BUSY)
192 {
193 return ErrorCode::BUSY;
194 }
195 auto buffer = ep_comm_in_->GetBuffer();
196 ASSERT(buffer.size_ >= sizeof(SerialStateNotification));
197 SerialStateNotification* notification =
198 reinterpret_cast<SerialStateNotification*>(buffer.addr_);
199 notification->wIndex = itf_comm_in_num_;
200
201 // 设置串行状态位。
202 // Fill the serial-state bitmap.
203 if (IsDtrSet())
204 {
205 // DTR 有效时报告载波检测(DCD)和数据集就绪(DSR)。
206 // When DTR is asserted, report DCD and DSR as active.
207 notification->serialState = 0x03; // DCD / DSR
208 }
209 else
210 {
211 notification->serialState = 0x00; // 无状态
212 }
213
214 // 填充固定字段。
215 // Fill the fixed notification header fields.
216 notification->bmRequestType = 0xA1; // 设备到主机,类,接口
217 notification->bNotification = static_cast<uint8_t>(CDCNotification::SERIAL_STATE);
218 notification->wValue = 0;
219 notification->wLength = 2;
220
221 ep_comm_in_->Transfer(sizeof(SerialStateNotification));
222
223 return ErrorCode::OK;
224 }
225
231 {
232 has_control_line_state_cb_ = !cb.Empty();
233 on_set_control_line_state_cb_ = cb;
234 }
235
241 {
242 has_line_coding_cb_ = !cb.Empty();
243 on_set_line_coding_cb_ = cb;
244 }
245
246 protected:
258 virtual void BindEndpoints(EndpointPool& endpoint_pool, uint8_t start_itf_num,
259 bool) override
260 {
261 control_line_state_ = 0;
262 // 获取并配置数据IN端点
263 auto ans = endpoint_pool.Get(ep_data_in_, Endpoint::Direction::IN, data_in_ep_num_);
264 ASSERT(ans == ErrorCode::OK);
265
266 // 获取并配置数据OUT端点
267 ans = endpoint_pool.Get(ep_data_out_, Endpoint::Direction::OUT, data_out_ep_num_);
268 ASSERT(ans == ErrorCode::OK);
269
270 // 获取并配置通信端点。
271 // Acquire and configure the communication endpoint.
272 ans = endpoint_pool.Get(ep_comm_in_, Endpoint::Direction::IN, comm_ep_num_);
273 ASSERT(ans == ErrorCode::OK);
274
275 // 配置端点参数。
276 // Configure endpoint parameters.
277 ep_data_in_->Configure(
278 {Endpoint::Direction::IN, Endpoint::Type::BULK, UINT16_MAX, true});
279 ep_data_out_->Configure(
282
283 // === 填充CDC描述符块 ===
284 static constexpr uint8_t COMM_INTERFACE = 0; // 通信接口号
285 static constexpr uint8_t DATA_INTERFACE = 1; // 数据接口号
286
287 // IAD 描述符(关联两组 CDC 接口)。
288 // IAD descriptor that groups the two CDC interfaces.
289 desc_block_.iad = {8,
290 static_cast<uint8_t>(DescriptorType::IAD),
291 static_cast<uint8_t>(COMM_INTERFACE + start_itf_num),
292 2,
293 static_cast<uint8_t>(Class::COMM),
294 static_cast<uint8_t>(Subclass::ABSTRACT_CONTROL_MODEL),
295 static_cast<uint8_t>(Protocol::NONE),
296 0};
297
298 // 通信接口描述符。
299 // Communication interface descriptor.
300 desc_block_.comm_intf = {9,
301 static_cast<uint8_t>(DescriptorType::INTERFACE),
302 static_cast<uint8_t>(COMM_INTERFACE + start_itf_num),
303 0,
304 1,
305 static_cast<uint8_t>(Class::COMM),
306 static_cast<uint8_t>(Subclass::ABSTRACT_CONTROL_MODEL),
307 static_cast<uint8_t>(Protocol::NONE),
308 GetInterfaceStringIndex(COMM_INTERFACE)};
309
310 // CDC 头功能描述符。
311 // CDC header functional descriptor.
312 desc_block_.cdc_header = {5, DescriptorType::CS_INTERFACE, DescriptorSubtype::HEADER,
313 0x0110}; // CDC规范版本1.10
314
315 // 呼叫管理功能描述符。
316 // Call-management functional descriptor.
317 desc_block_.cdc_callmgmt = {
318 5, DescriptorType::CS_INTERFACE, DescriptorSubtype::CALL_MANAGEMENT,
319 0x00, // 无呼叫管理能力
320 static_cast<uint8_t>(DATA_INTERFACE + start_itf_num)}; // 数据接口号
321
322 // ACM 功能描述符。
323 // ACM functional descriptor.
324 desc_block_.cdc_acm = {4, DescriptorType::CS_INTERFACE, DescriptorSubtype::ACM,
325 0x02}; // 支持SetLineCoding/GetLineCoding/SetControlLineState
326
327 // 联合功能描述符。
328 // Union functional descriptor.
329 desc_block_.cdc_union = {5, DescriptorType::CS_INTERFACE, DescriptorSubtype::UNION,
330 static_cast<uint8_t>(COMM_INTERFACE + start_itf_num),
331 static_cast<uint8_t>(DATA_INTERFACE + start_itf_num)};
332
333 // 数据接口描述符。
334 // Data interface descriptor.
335 desc_block_.data_intf = {9,
336 static_cast<uint8_t>(DescriptorType::INTERFACE),
337 static_cast<uint8_t>(DATA_INTERFACE + start_itf_num),
338 0,
339 2,
340 static_cast<uint8_t>(Class::DATA),
341 0x00, // 无子类
342 0x00, // 无协议
343 GetInterfaceStringIndex(DATA_INTERFACE)};
344
345 // 数据OUT端点描述符
346 desc_block_.data_ep_out = {7,
347 static_cast<uint8_t>(DescriptorType::ENDPOINT),
348 ep_data_out_->GetAddress(),
349 static_cast<uint8_t>(Endpoint::Type::BULK),
350 ep_data_out_->MaxPacketSize(),
351 0}; // 轮询间隔0(BULK忽略)
352
353 // 数据IN端点描述符
354 desc_block_.data_ep_in = {7,
355 static_cast<uint8_t>(DescriptorType::ENDPOINT),
356 static_cast<uint8_t>(ep_data_in_->GetAddress()),
357 static_cast<uint8_t>(Endpoint::Type::BULK),
358 ep_data_in_->MaxPacketSize(),
359 0}; // 轮询间隔0(BULK忽略)
360
361 // 通信端点描述符。
362 // Communication endpoint descriptor.
363 desc_block_.comm_ep = {
364 7,
365 static_cast<uint8_t>(DescriptorType::ENDPOINT),
366 static_cast<uint8_t>(ep_comm_in_->GetAddress()), // IN端点地址
367 static_cast<uint8_t>(Endpoint::Type::INTERRUPT),
368 16, // 16字节最大包大小
369 0x04 // 轮询间隔FS-4ms HS-1ms
370 };
371
372 itf_comm_in_num_ = start_itf_num;
373
374 // 设置描述符原始数据。
375 // Publish the raw descriptor block.
376 SetData(RawData{reinterpret_cast<uint8_t*>(&desc_block_), sizeof(desc_block_)});
377
378 // 设置端点传输完成回调。
379 // Install endpoint transfer-complete callbacks.
380 ep_data_out_->SetOnTransferCompleteCallback(on_data_out_complete_cb_);
381 ep_data_in_->SetOnTransferCompleteCallback(on_data_in_complete_cb_);
382
383 inited_ = true;
384
385 // 启动OUT端点传输
386 ep_data_out_->Transfer(ep_data_out_->MaxPacketSize());
387 }
388
396 virtual void UnbindEndpoints(EndpointPool& endpoint_pool, bool) override
397 {
398 inited_ = false;
399 control_line_state_ = 0;
400 ep_data_in_->Close();
401 ep_data_out_->Close();
402 ep_comm_in_->Close();
403 ep_data_in_->SetActiveLength(0);
404 ep_data_out_->SetActiveLength(0);
405 ep_comm_in_->SetActiveLength(0);
406 endpoint_pool.Release(ep_data_in_);
407 endpoint_pool.Release(ep_data_out_);
408 endpoint_pool.Release(ep_comm_in_);
409 ep_data_in_ = nullptr;
410 ep_data_out_ = nullptr;
411 ep_comm_in_ = nullptr;
412 }
413
418 static void OnDataOutCompleteStatic(bool in_isr, CDCBase* self, ConstRawData& data)
419 {
420 if (!self->inited_)
421 {
422 return;
423 }
424 self->OnDataOutComplete(in_isr, data);
425 }
426
431 static void OnDataInCompleteStatic(bool in_isr, CDCBase* self, ConstRawData& data)
432 {
433 if (!self->inited_)
434 {
435 return;
436 }
437 self->OnDataInComplete(in_isr, data);
438 }
439
447 virtual void OnDataOutComplete(bool in_isr, ConstRawData& data) = 0;
448
456 virtual void OnDataInComplete(bool in_isr, ConstRawData& data) = 0;
457
464 size_t GetInterfaceCount() override { return 2; }
465
473 bool HasIAD() override { return true; }
474
475 bool OwnsEndpoint(uint8_t ep_addr) const override
476 {
477 if (!inited_)
478 {
479 return false;
480 }
481
482 return ep_data_in_->GetAddress() == ep_addr ||
483 ep_data_out_->GetAddress() == ep_addr || ep_comm_in_->GetAddress() == ep_addr;
484 }
485
492 size_t GetMaxConfigSize() override { return sizeof(desc_block_); }
493
501 ErrorCode OnClassRequest(bool in_isr, uint8_t bRequest, uint16_t wValue,
502 uint16_t wLength, uint16_t wIndex,
503 DeviceClass::ControlTransferResult& result) override
504 {
505 UNUSED(in_isr);
506 UNUSED(wIndex);
507
508 switch (static_cast<ClassRequest>(bRequest))
509 {
510 case ClassRequest::SET_LINE_CODING:
511 // 主机将在数据阶段发送7字节参数
512 if (wLength != sizeof(line_coding_))
513 {
514 return ErrorCode::ARG_ERR;
515 }
516 result.read_data =
517 RawData{reinterpret_cast<uint8_t*>(&line_coding_), sizeof(line_coding_)};
518 return ErrorCode::OK;
519
520 case ClassRequest::GET_LINE_CODING:
521 // 返回当前线路编码设置。
522 // Return the current line-coding settings.
523 if (wLength != sizeof(line_coding_))
524 {
525 return ErrorCode::ARG_ERR;
526 }
527
528 result.write_data = ConstRawData{reinterpret_cast<const uint8_t*>(&line_coding_),
529 sizeof(line_coding_)};
530 return ErrorCode::OK;
531
532 case ClassRequest::SET_CONTROL_LINE_STATE:
533 // 设置 DTR / RTS 状态。
534 // Update the DTR / RTS control-line state.
535 control_line_state_ = wValue;
536 result.write_zlp = true;
538 if (has_control_line_state_cb_)
539 {
540 on_set_control_line_state_cb_.Run(in_isr, IsDtrSet(), IsRtsSet());
541 }
542 return ErrorCode::OK;
543
544 case ClassRequest::SEND_BREAK:
545 // BREAK 信号通常忽略。
546 // BREAK is typically ignored on this path.
547 result.write_zlp = true;
548 return ErrorCode::OK;
549
550 default:
552 }
553 }
554
559 ErrorCode OnClassData(bool in_isr, uint8_t bRequest, LibXR::ConstRawData& data) override
560 {
561 UNUSED(in_isr);
562 UNUSED(data);
563
564 switch (static_cast<ClassRequest>(bRequest))
565 {
566 case ClassRequest::SET_LINE_CODING:
567 {
568 // 将 CDC 线路编码转换为 UART 配置。
569 // Convert CDC line coding into a UART configuration.
571 cfg.baudrate = line_coding_.dwDTERate;
572 switch (line_coding_.bCharFormat)
573 {
574 case 0:
575 cfg.stop_bits = 1;
576 break;
577 // TODO: 1.5
578 case 2:
579 cfg.stop_bits = 2;
580 break;
581 default:
582 cfg.stop_bits = 1;
583 }
584 switch (line_coding_.bParityType)
585 {
586 case 1:
588 break;
589 case 2:
591 break;
592 default:
594 }
595 cfg.data_bits = line_coding_.bDataBits;
596 if (has_line_coding_cb_)
597 {
598 on_set_line_coding_cb_.Run(in_isr, cfg);
599 }
600 }
601 return ErrorCode::OK;
602 default:
604 }
605 }
606
607 LIBXR_PACKED_BEGIN
616 {
620
621 // CDC类特定描述符
622 struct
623 {
624 uint8_t bFunctionLength = 5;
625 DescriptorType bDescriptorType = DescriptorType::CS_INTERFACE;
626 DescriptorSubtype bDescriptorSubtype = DescriptorSubtype::HEADER;
627 uint16_t bcdCDC = 0x0110;
628 } cdc_header;
629
630 struct
631 {
632 uint8_t bFunctionLength = 5;
633 DescriptorType bDescriptorType = DescriptorType::CS_INTERFACE;
634 DescriptorSubtype bDescriptorSubtype = DescriptorSubtype::CALL_MANAGEMENT;
635 uint8_t bmCapabilities = 0x00;
637 } cdc_callmgmt;
638
639 struct
640 {
641 uint8_t bFunctionLength = 4;
642 DescriptorType bDescriptorType = DescriptorType::CS_INTERFACE;
643 DescriptorSubtype bDescriptorSubtype = DescriptorSubtype::ACM;
644 uint8_t bmCapabilities = 0x02;
645 } cdc_acm;
646
647 struct
648 {
649 uint8_t bFunctionLength = 5;
650 DescriptorType bDescriptorType = DescriptorType::CS_INTERFACE;
651 DescriptorSubtype bDescriptorSubtype = DescriptorSubtype::UNION;
654 } cdc_union;
655
657
659
662 } desc_block_;
663 LIBXR_PACKED_END
664
665 protected:
666 CDCLineCoding& GetLineCoding() { return line_coding_; }
667
668 bool Inited() { return inited_; }
669
670 Endpoint* GetDataInEndpoint() { return ep_data_in_; }
671
672 Endpoint* GetDataOutEndpoint() { return ep_data_out_; }
673
674 Endpoint* GetCommInEndpoint() { return ep_comm_in_; }
675
676 private:
677 // 端点号。
678 // Endpoint numbers.
679 Endpoint::EPNumber data_in_ep_num_;
680 Endpoint::EPNumber data_out_ep_num_;
681 Endpoint::EPNumber comm_ep_num_;
682 const char* control_interface_string_ =
683 nullptr;
684 const char* data_interface_string_ =
685 nullptr;
686
687 // 端点指针。
688 // Endpoint pointers.
689 Endpoint* ep_data_in_ = nullptr;
690 Endpoint* ep_data_out_ = nullptr;
691 Endpoint* ep_comm_in_ = nullptr;
692
693 // 端点回调。
694 // Endpoint callbacks.
695 LibXR::Callback<LibXR::ConstRawData&> on_data_out_complete_cb_ =
697
698 LibXR::Callback<LibXR::ConstRawData&> on_data_in_complete_cb_ =
700
701 // 用户回调。
702 // User callbacks.
704 on_set_control_line_state_cb_;
707 on_set_line_coding_cb_;
708
709 // 状态标志。
710 // State flags.
711 bool inited_ = false;
712 bool has_control_line_state_cb_ = false;
713 bool has_line_coding_cb_ = false;
714
715 // 接口信息。
716 // Interface metadata.
717 uint8_t itf_comm_in_num_;
718
719 // CDC 参数。
720 // CDC parameters.
721 CDCLineCoding line_coding_ = {115200, 0, 0, 8};
722 uint16_t control_line_state_ = 0;
723};
724
725} // 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:230
virtual void BindEndpoints(EndpointPool &endpoint_pool, uint8_t start_itf_num, bool) override
初始化CDC设备 Initialize CDC device
Definition cdc_base.hpp:258
size_t GetMaxConfigSize() override
获取最大配置描述符大小 Get maximum configuration descriptor size
Definition cdc_base.hpp:492
void SetOnSetLineCodingCallback(LibXR::Callback< LibXR::UART::Configuration > cb)
设置线路编码变更回调 Set line coding change callback
Definition cdc_base.hpp:240
virtual void OnDataInComplete(bool in_isr, ConstRawData &data)=0
数据IN端点传输完成处理 Handle data IN endpoint transfer completion
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:151
static void OnDataOutCompleteStatic(bool in_isr, CDCBase *self, ConstRawData &data)
数据OUT端点传输完成静态回调 Static callback for data OUT endpoint transfer completion
Definition cdc_base.hpp:418
bool OwnsEndpoint(uint8_t ep_addr) const override
可选:端点归属判定 / Optional: endpoint ownership
Definition cdc_base.hpp:475
bool IsRtsSet() const
检查RTS状态 Check RTS state
Definition cdc_base.hpp:180
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:501
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:473
static void OnDataInCompleteStatic(bool in_isr, CDCBase *self, ConstRawData &data)
数据IN端点传输完成静态回调 Static callback for data IN endpoint transfer completion
Definition cdc_base.hpp:431
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:139
ErrorCode OnClassData(bool in_isr, uint8_t bRequest, LibXR::ConstRawData &data) override
处理类请求数据阶段 Handle class request data stage
Definition cdc_base.hpp:559
ErrorCode SendSerialState()
发送串行状态通知 Send serial state notification
Definition cdc_base.hpp:189
virtual void UnbindEndpoints(EndpointPool &endpoint_pool, bool) override
反初始化CDC设备 Deinitialize CDC device
Definition cdc_base.hpp:396
size_t GetInterfaceCount() override
获取接口数量 Get number of interfaces
Definition cdc_base.hpp:464
bool IsDtrSet() const
检查DTR状态 Check DTR state
Definition cdc_base.hpp:171
void SetData(RawData data)
设置内部数据缓存 / Set internal data cache
Definition desc_cfg.hpp:207
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.
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
定义错误码枚举 / Defines an enumeration for error codes
@ 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:53
uint32_t baudrate
波特率 / Baud rate
Definition uart.hpp:45
CDC描述符块结构 CDC descriptor block structure.
Definition cdc_base.hpp:616
InterfaceDescriptor data_intf
数据接口描述符 / Data interface descriptor
Definition cdc_base.hpp:658
uint8_t bSlaveInterface0
从接口号 / Slave interface number
Definition cdc_base.hpp:653
EndpointDescriptor data_ep_out
数据OUT端点描述符 / Data OUT endpoint descriptor
Definition cdc_base.hpp:660
uint16_t bcdCDC
CDC规范版本 / CDC specification version.
Definition cdc_base.hpp:627
uint8_t bmCapabilities
呼叫管理能力 / Call management capabilities
Definition cdc_base.hpp:635
InterfaceDescriptor comm_intf
通信接口描述符 / Communication interface descriptor
Definition cdc_base.hpp:619
uint8_t bDataInterface
数据接口号 / Data interface number
Definition cdc_base.hpp:636
EndpointDescriptor comm_ep
通信端点描述符 / Communication endpoint descriptor
Definition cdc_base.hpp:656
uint8_t bMasterInterface
主接口号 / Master interface number
Definition cdc_base.hpp:652
EndpointDescriptor data_ep_in
数据IN端点描述符 / Data IN endpoint descriptor
Definition cdc_base.hpp:661
IADDescriptor iad
接口关联描述符 / Interface association descriptor
Definition cdc_base.hpp:617
端点描述符(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)