libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
LibXR::UART Class Referenceabstract

通用异步收发传输(UART)基类 / Abstract base class for Universal Asynchronous Receiver-Transmitter (UART) More...

#include <uart.hpp>

Inheritance diagram for LibXR::UART:
[legend]
Collaboration diagram for LibXR::UART:
[legend]

Data Structures

struct  Configuration
 UART 配置结构体 / UART configuration structure. More...
 

Public Types

enum class  Parity : uint8_t { NO_PARITY = 0 , EVEN = 1 , ODD = 2 }
 奇偶校验模式 / Parity mode More...
 

Public Member Functions

template<typename ReadPortType = ReadPort, typename WritePortType = WritePort>
 UART (ReadPortType *read_port, WritePortType *write_port)
 UART 构造函数 / UART constructor.
 
virtual ErrorCode SetConfig (Configuration config)=0
 设置 UART 配置 / Sets the UART configuration
 
template<typename OperationType , typename = std::enable_if_t<std::is_base_of_v< WriteOperation, std::decay_t<OperationType>>>>
ErrorCode Write (ConstRawData data, OperationType &&op)
 
template<typename OperationType , typename = std::enable_if_t<std::is_base_of_v< ReadOperation, std::decay_t<OperationType>>>>
ErrorCode Read (RawData data, OperationType &&op)
 

Data Fields

ReadPortread_port_
 读取端口 / Read port
 
WritePortwrite_port_
 写入端口 / Write port
 

Detailed Description

通用异步收发传输(UART)基类 / Abstract base class for Universal Asynchronous Receiver-Transmitter (UART)

该类定义了 UART 设备的基本接口,包括配置和数据传输端口。 This class defines the basic interface for a UART device, including configuration and data transmission ports.

Definition at line 18 of file uart.hpp.

Member Enumeration Documentation

◆ Parity

enum class LibXR::UART::Parity : uint8_t
strong

奇偶校验模式 / Parity mode

指定 UART 传输时的奇偶校验模式。 Specifies the parity mode used in UART transmission.

Enumerator
NO_PARITY 

无校验 / No parity

EVEN 

偶校验 / Even parity

ODD 

奇校验 / Odd parity

Definition at line 28 of file uart.hpp.

29 {
30 NO_PARITY = 0,
31 EVEN = 1,
32 ODD = 2
33 };
@ NO_PARITY
无校验 / No parity
@ ODD
奇校验 / Odd parity
@ EVEN
偶校验 / Even parity

Constructor & Destructor Documentation

◆ UART()

template<typename ReadPortType = ReadPort, typename WritePortType = WritePort>
LibXR::UART::UART ( ReadPortType * read_port,
WritePortType * write_port )
inline

UART 构造函数 / UART constructor.

Parameters
rx_buffer_size接收缓冲区大小 / Receive buffer size
tx_queue_size发送队列大小 / Transmit queue size
tx_buffer_size发送缓冲区大小 / Transmit buffer size

该构造函数初始化 UART 的读取和写入端口。 This constructor initializes the read and write ports of the UART.

Definition at line 64 of file uart.hpp.

65 : read_port_(read_port), write_port_(write_port)
66 {
67 }
ReadPort * read_port_
读取端口 / Read port
Definition uart.hpp:51
WritePort * write_port_
写入端口 / Write port
Definition uart.hpp:52

Member Function Documentation

◆ Read()

template<typename OperationType , typename = std::enable_if_t<std::is_base_of_v< ReadOperation, std::decay_t<OperationType>>>>
ErrorCode LibXR::UART::Read ( RawData data,
OperationType && op )
inline

Definition at line 90 of file uart.hpp.

91 {
92 return (*read_port_)(data, std::forward<OperationType>(op));
93 }

◆ SetConfig()

virtual ErrorCode LibXR::UART::SetConfig ( Configuration config)
pure virtual

设置 UART 配置 / Sets the UART configuration

Parameters
configUART 配置信息 / UART configuration settings
Returns
返回操作状态,成功时返回 ErrorCode::OK,否则返回相应错误码 / Returns the operation status, ErrorCode::OK if successful, otherwise an error code

该方法为纯虚函数,子类必须实现具体的 UART 配置逻辑。 This is a pure virtual function. Subclasses must implement the specific UART configuration logic.

Implemented in LibXR::CH32UART, LibXR::ESP32UART, LibXR::ESP32VirtualUART< BUFFER_SIZE >, LibXR::LinuxUART, LibXR::STM32UART, LibXR::STM32VirtualUART, and LibXR::TinyUSBVirtualUART.

◆ Write()

template<typename OperationType , typename = std::enable_if_t<std::is_base_of_v< WriteOperation, std::decay_t<OperationType>>>>
ErrorCode LibXR::UART::Write ( ConstRawData data,
OperationType && op )
inline

Definition at line 83 of file uart.hpp.

84 {
85 return (*write_port_)(data, std::forward<OperationType>(op));
86 }

Field Documentation

◆ read_port_

ReadPort* LibXR::UART::read_port_

读取端口 / Read port

Definition at line 51 of file uart.hpp.

◆ write_port_

WritePort* LibXR::UART::write_port_

写入端口 / Write port

Definition at line 52 of file uart.hpp.


The documentation for this class was generated from the following file: