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#pragma pack(push, 1)
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#pragma pack(pop)
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
233
242
243 protected:
255 virtual void BindEndpoints(EndpointPool& endpoint_pool, uint8_t start_itf_num,
256 bool) override
257 {
259 // 获取并配置数据IN端点
260 auto ans = endpoint_pool.Get(ep_data_in_, Endpoint::Direction::IN, data_in_ep_num_);
261 ASSERT(ans == ErrorCode::OK);
262
263 // 获取并配置数据OUT端点
265 ASSERT(ans == ErrorCode::OK);
266
267 // 获取并配置通信端点。
268 // Acquire and configure the communication endpoint.
270 ASSERT(ans == ErrorCode::OK);
271
272 // 配置端点参数。
273 // Configure endpoint parameters.
275 {Endpoint::Direction::IN, Endpoint::Type::BULK, UINT16_MAX, true});
279
280 // === 填充CDC描述符块 ===
281 static constexpr uint8_t COMM_INTERFACE = 0; // 通信接口号
282 static constexpr uint8_t DATA_INTERFACE = 1; // 数据接口号
283
284 // IAD 描述符(关联两组 CDC 接口)。
285 // IAD descriptor that groups the two CDC interfaces.
286 desc_block_.iad = {8,
287 static_cast<uint8_t>(DescriptorType::IAD),
288 static_cast<uint8_t>(COMM_INTERFACE + start_itf_num),
289 2,
290 static_cast<uint8_t>(Class::COMM),
291 static_cast<uint8_t>(Subclass::ABSTRACT_CONTROL_MODEL),
292 static_cast<uint8_t>(Protocol::NONE),
293 0};
294
295 // 通信接口描述符。
296 // Communication interface descriptor.
297 desc_block_.comm_intf = {9,
298 static_cast<uint8_t>(DescriptorType::INTERFACE),
299 static_cast<uint8_t>(COMM_INTERFACE + start_itf_num),
300 0,
301 1,
302 static_cast<uint8_t>(Class::COMM),
303 static_cast<uint8_t>(Subclass::ABSTRACT_CONTROL_MODEL),
304 static_cast<uint8_t>(Protocol::NONE),
305 GetInterfaceStringIndex(COMM_INTERFACE)};
306
307 // CDC 头功能描述符。
308 // CDC header functional descriptor.
309 desc_block_.cdc_header = {5, DescriptorType::CS_INTERFACE, DescriptorSubtype::HEADER,
310 0x0110}; // CDC规范版本1.10
311
312 // 呼叫管理功能描述符。
313 // Call-management functional descriptor.
314 desc_block_.cdc_callmgmt = {
315 5, DescriptorType::CS_INTERFACE, DescriptorSubtype::CALL_MANAGEMENT,
316 0x00, // 无呼叫管理能力
317 static_cast<uint8_t>(DATA_INTERFACE + start_itf_num)}; // 数据接口号
318
319 // ACM 功能描述符。
320 // ACM functional descriptor.
321 desc_block_.cdc_acm = {4, DescriptorType::CS_INTERFACE, DescriptorSubtype::ACM,
322 0x02}; // 支持SetLineCoding/GetLineCoding/SetControlLineState
323
324 // 联合功能描述符。
325 // Union functional descriptor.
326 desc_block_.cdc_union = {5, DescriptorType::CS_INTERFACE, DescriptorSubtype::UNION,
327 static_cast<uint8_t>(COMM_INTERFACE + start_itf_num),
328 static_cast<uint8_t>(DATA_INTERFACE + start_itf_num)};
329
330 // 数据接口描述符。
331 // Data interface descriptor.
332 desc_block_.data_intf = {9,
333 static_cast<uint8_t>(DescriptorType::INTERFACE),
334 static_cast<uint8_t>(DATA_INTERFACE + start_itf_num),
335 0,
336 2,
337 static_cast<uint8_t>(Class::DATA),
338 0x00, // 无子类
339 0x00, // 无协议
340 GetInterfaceStringIndex(DATA_INTERFACE)};
341
342 // 数据OUT端点描述符
343 desc_block_.data_ep_out = {7,
344 static_cast<uint8_t>(DescriptorType::ENDPOINT),
346 static_cast<uint8_t>(Endpoint::Type::BULK),
348 0}; // 轮询间隔0(BULK忽略)
349
350 // 数据IN端点描述符
351 desc_block_.data_ep_in = {7,
352 static_cast<uint8_t>(DescriptorType::ENDPOINT),
353 static_cast<uint8_t>(ep_data_in_->GetAddress()),
354 static_cast<uint8_t>(Endpoint::Type::BULK),
356 0}; // 轮询间隔0(BULK忽略)
357
358 // 通信端点描述符。
359 // Communication endpoint descriptor.
360 desc_block_.comm_ep = {
361 7,
362 static_cast<uint8_t>(DescriptorType::ENDPOINT),
363 static_cast<uint8_t>(ep_comm_in_->GetAddress()), // IN端点地址
364 static_cast<uint8_t>(Endpoint::Type::INTERRUPT),
365 16, // 16字节最大包大小
366 0x04 // 轮询间隔FS-4ms HS-1ms
367 };
368
369 itf_comm_in_num_ = start_itf_num;
370
371 // 设置描述符原始数据。
372 // Publish the raw descriptor block.
373 SetData(RawData{reinterpret_cast<uint8_t*>(&desc_block_), sizeof(desc_block_)});
374
375 // 设置端点传输完成回调。
376 // Install endpoint transfer-complete callbacks.
377 ep_data_out_->SetOnTransferCompleteCallback(on_data_out_complete_cb_);
378 ep_data_in_->SetOnTransferCompleteCallback(on_data_in_complete_cb_);
379
380 inited_ = true;
381
382 // 启动OUT端点传输
384 }
385
393 virtual void UnbindEndpoints(EndpointPool& endpoint_pool, bool) override
394 {
395 inited_ = false;
403 endpoint_pool.Release(ep_data_in_);
404 endpoint_pool.Release(ep_data_out_);
405 endpoint_pool.Release(ep_comm_in_);
406 ep_data_in_ = nullptr;
407 ep_data_out_ = nullptr;
408 ep_comm_in_ = nullptr;
409 }
410
415 static void OnDataOutCompleteStatic(bool in_isr, CDCBase* self, ConstRawData& data)
416 {
417 if (!self->inited_)
418 {
419 return;
420 }
421 self->OnDataOutComplete(in_isr, data);
422 }
423
428 static void OnDataInCompleteStatic(bool in_isr, CDCBase* self, ConstRawData& data)
429 {
430 if (!self->inited_)
431 {
432 return;
433 }
434 self->OnDataInComplete(in_isr, data);
435 }
436
444 virtual void OnDataOutComplete(bool in_isr, ConstRawData& data) = 0;
445
453 virtual void OnDataInComplete(bool in_isr, ConstRawData& data) = 0;
454
461 size_t GetInterfaceCount() override { return 2; }
462
470 bool HasIAD() override { return true; }
471
472 bool OwnsEndpoint(uint8_t ep_addr) const override
473 {
474 if (!inited_)
475 {
476 return false;
477 }
478
479 return ep_data_in_->GetAddress() == ep_addr ||
480 ep_data_out_->GetAddress() == ep_addr || ep_comm_in_->GetAddress() == ep_addr;
481 }
482
489 size_t GetMaxConfigSize() override { return sizeof(desc_block_); }
490
498 ErrorCode OnClassRequest(bool in_isr, uint8_t bRequest, uint16_t wValue,
499 uint16_t wLength, uint16_t wIndex,
500 DeviceClass::ControlTransferResult& result) override
501 {
502 UNUSED(in_isr);
503 UNUSED(wIndex);
504
505 switch (static_cast<ClassRequest>(bRequest))
506 {
508 // 主机将在数据阶段发送7字节参数
509 if (wLength != sizeof(line_coding_))
510 {
511 return ErrorCode::ARG_ERR;
512 }
513 result.read_data =
514 RawData{reinterpret_cast<uint8_t*>(&line_coding_), sizeof(line_coding_)};
515 return ErrorCode::OK;
516
518 // 返回当前线路编码设置。
519 // Return the current line-coding settings.
520 if (wLength != sizeof(line_coding_))
521 {
522 return ErrorCode::ARG_ERR;
523 }
524
525 result.write_data = ConstRawData{reinterpret_cast<const uint8_t*>(&line_coding_),
526 sizeof(line_coding_)};
527 return ErrorCode::OK;
528
530 // 设置 DTR / RTS 状态。
531 // Update the DTR / RTS control-line state.
532 control_line_state_ = wValue;
533 result.write_zlp = true;
536 return ErrorCode::OK;
537
539 // BREAK 信号通常忽略。
540 // BREAK is typically ignored on this path.
541 result.write_zlp = true;
542 return ErrorCode::OK;
543
544 default:
546 }
547 }
548
553 ErrorCode OnClassData(bool in_isr, uint8_t bRequest, LibXR::ConstRawData& data) override
554 {
555 UNUSED(in_isr);
556 UNUSED(data);
557
558 switch (static_cast<ClassRequest>(bRequest))
559 {
561 {
562 // 将 CDC 线路编码转换为 UART 配置。
563 // Convert CDC line coding into a UART configuration.
567 {
568 case 0:
569 cfg.stop_bits = 1;
570 break;
571 // TODO: 1.5
572 case 2:
573 cfg.stop_bits = 2;
574 break;
575 default:
576 cfg.stop_bits = 1;
577 }
579 {
580 case 1:
582 break;
583 case 2:
585 break;
586 default:
588 }
590 on_set_line_coding_cb_.Run(in_isr, cfg);
591 }
592 return ErrorCode::OK;
593 default:
595 }
596 }
597
598#pragma pack(push, 1)
607 {
611
612 // CDC类特定描述符
613 struct
614 {
615 uint8_t bFunctionLength = 5;
616 DescriptorType bDescriptorType = DescriptorType::CS_INTERFACE;
617 DescriptorSubtype bDescriptorSubtype = DescriptorSubtype::HEADER;
618 uint16_t bcdCDC = 0x0110;
619 } cdc_header;
620
621 struct
622 {
623 uint8_t bFunctionLength = 5;
624 DescriptorType bDescriptorType = DescriptorType::CS_INTERFACE;
626 uint8_t bmCapabilities = 0x00;
628 } cdc_callmgmt;
629
630 struct
631 {
632 uint8_t bFunctionLength = 4;
633 DescriptorType bDescriptorType = DescriptorType::CS_INTERFACE;
634 DescriptorSubtype bDescriptorSubtype = DescriptorSubtype::ACM;
635 uint8_t bmCapabilities = 0x02;
636 } cdc_acm;
637
638 struct
639 {
640 uint8_t bFunctionLength = 5;
641 DescriptorType bDescriptorType = DescriptorType::CS_INTERFACE;
642 DescriptorSubtype bDescriptorSubtype = DescriptorSubtype::UNION;
645 } cdc_union;
646
648
650
653 } desc_block_;
654#pragma pack(pop)
655
656 protected:
657 CDCLineCoding& GetLineCoding() { return line_coding_; }
658
659 bool Inited() { return inited_; }
660
661 Endpoint* GetDataInEndpoint() { return ep_data_in_; }
662
663 Endpoint* GetDataOutEndpoint() { return ep_data_out_; }
664
665 Endpoint* GetCommInEndpoint() { return ep_comm_in_; }
666
667 private:
668 // 端点号。
669 // Endpoint numbers.
674 nullptr;
676 nullptr;
677
678 // 端点指针。
679 // Endpoint pointers.
683
684 // 端点回调。
685 // Endpoint callbacks.
686 LibXR::Callback<LibXR::ConstRawData&> on_data_out_complete_cb_ =
688
689 LibXR::Callback<LibXR::ConstRawData&> on_data_in_complete_cb_ =
691
692 // 用户回调。
693 // User callbacks.
699
700 // 状态标志。
701 // State flags.
702 bool inited_ = false;
703
704 // 接口信息。
705 // Interface metadata.
707
708 // CDC 参数。
709 // CDC parameters.
710 CDCLineCoding line_coding_ = {115200, 0, 0, 8};
711 uint16_t control_line_state_ = 0;
712};
713
714} // namespace LibXR::USB
通用回调包装,支持动态参数传递 / Generic callback wrapper supporting dynamic argument passing
Definition libxr_cb.hpp:142
static Callback Create(CallableType fun, BoundArgType arg)
创建回调对象并绑定回调函数与参数 / Create a callback instance with bound function and argument
Definition libxr_cb.hpp:159
常量原始数据封装类。 A class for encapsulating constant raw data.
原始数据封装类。 A class for encapsulating raw data.
@ 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:255
LibXR::Callback< bool, bool > on_set_control_line_state_cb_
Definition cdc_base.hpp:695
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:489
Endpoint::EPNumber data_in_ep_num_
数据IN端点号 / Data IN endpoint number
Definition cdc_base.hpp:670
uint8_t itf_comm_in_num_
通信接口号 / Communication interface number
Definition cdc_base.hpp:706
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:672
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:682
bool inited_
初始化标志 / Initialization flag
Definition cdc_base.hpp:702
Endpoint * ep_data_in_
数据IN端点 / Data IN endpoint
Definition cdc_base.hpp:680
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:415
bool OwnsEndpoint(uint8_t ep_addr) const override
可选:端点归属判定 / Optional: endpoint ownership
Definition cdc_base.hpp:472
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:698
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:671
uint16_t control_line_state_
控制线路状态 / Control line state
Definition cdc_base.hpp:711
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:498
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:470
static void OnDataInCompleteStatic(bool in_isr, CDCBase *self, ConstRawData &data)
数据IN端点传输完成静态回调 Static callback for data IN endpoint transfer completion
Definition cdc_base.hpp:428
CDCLineCoding line_coding_
当前线路编码 / Current line coding
Definition cdc_base.hpp:710
ErrorCode OnClassData(bool in_isr, uint8_t bRequest, LibXR::ConstRawData &data) override
处理类请求数据阶段 Handle class request data stage
Definition cdc_base.hpp:553
Endpoint * ep_data_out_
数据OUT端点 / Data OUT endpoint
Definition cdc_base.hpp:681
const char * control_interface_string_
控制接口字符串 / Control interface string
Definition cdc_base.hpp:673
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:393
size_t GetInterfaceCount() override
获取接口数量 Get number of interfaces
Definition cdc_base.hpp:461
const char * data_interface_string_
数据接口字符串 / Data interface string
Definition cdc_base.hpp:675
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:607
InterfaceDescriptor data_intf
数据接口描述符 / Data interface descriptor
Definition cdc_base.hpp:649
uint8_t bSlaveInterface0
从接口号 / Slave interface number
Definition cdc_base.hpp:644
EndpointDescriptor data_ep_out
数据OUT端点描述符 / Data OUT endpoint descriptor
Definition cdc_base.hpp:651
uint16_t bcdCDC
CDC规范版本 / CDC specification version.
Definition cdc_base.hpp:618
uint8_t bmCapabilities
呼叫管理能力 / Call management capabilities
Definition cdc_base.hpp:626
InterfaceDescriptor comm_intf
通信接口描述符 / Communication interface descriptor
Definition cdc_base.hpp:610
uint8_t bDataInterface
数据接口号 / Data interface number
Definition cdc_base.hpp:627
EndpointDescriptor comm_ep
通信端点描述符 / Communication endpoint descriptor
Definition cdc_base.hpp:647
uint8_t bMasterInterface
主接口号 / Master interface number
Definition cdc_base.hpp:643
EndpointDescriptor data_ep_in
数据IN端点描述符 / Data IN endpoint descriptor
Definition cdc_base.hpp:652
IADDescriptor iad
接口关联描述符 / Interface association descriptor
Definition cdc_base.hpp:608
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)