5#include "libxr_def.hpp"
7#include "serialized_service.hpp"
49 using LibXR::UART::Read;
51 using LibXR::UART::Write;
68 size_t tx_buffer_size = 128,
size_t tx_queue_size = 5,
69 const char* control_interface_string = CDCBase::DEFAULT_CONTROL_INTERFACE_STRING,
70 const char* data_interface_string = CDCBase::DEFAULT_DATA_INTERFACE_STRING)
71 :
CDCBase(data_in_ep_num, data_out_ep_num, comm_ep_num, control_interface_string,
72 data_interface_string),
73 LibXR::
UART(&read_port_cdc_, &write_port_cdc_),
74 read_port_cdc_(rx_buffer_size, *this),
75 write_port_cdc_(tx_queue_size, tx_buffer_size)
90 auto& line_coding = GetLineCoding();
95 line_coding.bCharFormat = 0;
98 line_coding.bCharFormat = 2;
107 line_coding.bParityType = 0;
110 line_coding.bParityType = 1;
113 line_coding.bParityType = 2;
126 line_coding.bDataBits =
static_cast<uint8_t
>(cfg.
data_bits);
132 line_coding.dwDTERate = cfg.
baudrate;
144 auto* ep = GetDataOutEndpoint();
145 if (ep ==
nullptr || ep->MaxPacketSize() == 0U || !read_port_cdc_.
Readable())
159 [[maybe_unused]]
const auto ans =
172 [[maybe_unused]]
const auto ans = ep->Transfer(ep->MaxPacketSize());
197 bool in_isr)
override;
207 need_write_zlp_ =
false;
226 if (data.
size_ != 0U)
229 if (queue.EmptySize() < data.
size_)
237 [[maybe_unused]]
const auto ans =
263 void RequestTx(
bool in_isr);
270 void ServiceTx(
bool in_isr);
277 void StartTxBuffer(
Endpoint& ep, [[maybe_unused]]
bool in_isr);
286 void FillTxBuffer(
Endpoint& ep,
bool in_isr);
293 void ProgressTx(
bool in_isr);
299 bool need_write_zlp_ =
false;
只读原始数据视图 / Immutable raw data view
size_t size_
数据字节数 / Data size in bytes
const void * addr_
数据起始地址 / Data start address
ErrorCode PushBatch(const uint8_t *data, size_t size)
批量复制字节到接收队列 / Copy a batch of bytes into the RX queue.
基于 SPSC 字节队列的读端口 / Read endpoint backed by an SPSC byte queue.
bool Readable() const
检查端口是否支持读取 / Check whether the port supports reads.
ReadQueue GetReadQueue(bool in_isr=false)
获取后端接收入队接口 / Obtain the backend RX producer interface.
事件合并与回调串行化服务 / Event-coalescing serialized-callback service.
通用异步收发传输(UART)基类 / Abstract base class for Universal Asynchronous Receiver-Transmitter (UART)
ReadPort * read_port_
读取端口 / Read port
@ NO_PARITY
无校验 / No parity
WritePort * write_port_
写入端口 / Write port
USB CDC ACM (Abstract Control Model) 设备类实现 USB CDC ACM (Abstract Control Model) device class implemen...
ErrorCode SendSerialState()
发送串行状态通知 Send serial state notification
virtual void UnbindEndpoints(EndpointPool &endpoint_pool, bool) override
反初始化CDC设备 Deinitialize CDC device
USB CDC-ACM UART 适配器 / USB CDC-ACM UART adapter.
bool TryRearmOut(bool in_isr)
回填暂存数据并重新启动 OUT 接收 / Enqueue saved data and restart OUT reception
void UnbindEndpoints(EndpointPool &endpoint_pool, bool in_isr) override
解绑端点并清理接收暂存状态 / Unbind endpoints and clear saved receive state
CDCUart(Endpoint::EPNumber data_in_ep_num, Endpoint::EPNumber data_out_ep_num, Endpoint::EPNumber comm_ep_num, size_t rx_buffer_size=128, size_t tx_buffer_size=128, size_t tx_queue_size=5, const char *control_interface_string=CDCBase::DEFAULT_CONTROL_INTERFACE_STRING, const char *data_interface_string=CDCBase::DEFAULT_DATA_INTERFACE_STRING)
构造 CDC UART / Construct the CDC UART
void BindEndpoints(EndpointPool &endpoint_pool, uint8_t start_itf_num, bool in_isr) override
绑定端点并恢复配置前已排队的发送 / Bind endpoints and resume queued writes
void OnDataInComplete(bool in_isr, ConstRawData &data) override
在 IN 完成后请求推进发送 / Request TX progress after IN completion
void OnDataOutComplete(bool in_isr, ConstRawData &data) override
将 OUT 数据放入接收队列 / Enqueue completed OUT data
ErrorCode SetConfig(UART::Configuration cfg, bool in_isr=false) override
设置 CDC 线路编码 / Set CDC line coding
USB CDC 接收端口 / USB CDC receive port.
CDCUartReadPort(uint32_t size, CDCUart &owner)
构造接收端口 / Construct the receive port
ConstRawData pending_data_
待入队的端点数据 / Endpoint data awaiting enqueue
CDCUart & owner_
所属 CDC UART / Owning CDC UART
void OnReadQueueSpaceAvailable(bool in_isr) override
在接收队列腾出空间后恢复接收 / Resume reception when queue space is available
bool recv_pause_
接收暂停标志 / Receive pause flag
USB 端点基类 / USB Endpoint base class.
EPNumber
端点号 Endpoint number
USB端点池类 / USB endpoint pool class.
基于 SPSC 字节队列的写端口 / Write endpoint backed by an SPSC byte queue.
LibXR 命名空间 / LibXR namespace.
ErrorCode
定义错误码枚举 / Defines an enumeration for error codes
@ OK
操作成功 / Operation successful
@ ARG_ERR
参数错误 / Argument error
void(* WriteFun)(WritePort &port, bool in_isr)
写入进度通知函数类型 / Write progress notification function type.
UART 配置结构体 / UART configuration structure.
uint8_t stop_bits
停止位长度 / Number of stop bits
uint32_t baudrate
波特率 / Baud rate