libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
ch32_uart.hpp
1#pragma once
2
3#include "libxr.hpp"
4#include DEF2STR(LIBXR_CH32_CONFIG_FILE)
5
6#include "ch32_uart_def.hpp"
7#include "double_buffer.hpp"
8#include "libxr_def.hpp"
9#include "libxr_rw.hpp"
10#include "uart.hpp"
11
12namespace LibXR
13{
14
18class CH32UART : public UART
19{
20 public:
24 CH32UART(ch32_uart_id_t id, RawData dma_rx, RawData dma_tx, GPIO_TypeDef* tx_gpio_port,
25 uint16_t tx_gpio_pin, GPIO_TypeDef* rx_gpio_port, uint16_t rx_gpio_pin,
26 uint32_t pin_remap = 0, uint32_t tx_queue_size = 5,
27 UART::Configuration config = {115200, UART::Parity::NO_PARITY, 8, 1});
28
29 ErrorCode SetConfig(UART::Configuration config);
30
31 static ErrorCode WriteFun(WritePort& port, bool in_isr);
32 static ErrorCode ReadFun(ReadPort& port, bool in_isr);
33
34 void TxDmaIRQHandler();
35 void RxDmaIRQHandler();
36
37 ch32_uart_id_t id_;
38 uint16_t uart_mode_;
39
40 ReadPort _read_port;
41 WritePort _write_port;
42
43 RawData dma_buff_rx_;
44 DoubleBuffer dma_buff_tx_;
45 WriteInfoBlock write_info_active_;
46
47 size_t last_rx_pos_ = 0;
48
49 USART_TypeDef* instance_;
50 DMA_Channel_TypeDef* dma_rx_channel_;
51 DMA_Channel_TypeDef* dma_tx_channel_;
52
53 Flag::Plain in_tx_isr, tx_busy_;
54
55 static CH32UART* map_[CH32_UART_NUMBER];
56};
57
58} // namespace LibXR
CH32 UART 驱动实现 / CH32 UART driver implementation.
Definition ch32_uart.hpp:19
void RxDmaIRQHandler()
DMA中断处理函数
ErrorCode SetConfig(UART::Configuration config)
设置 UART 配置 / Sets the UART configuration
CH32UART(ch32_uart_id_t id, RawData dma_rx, RawData dma_tx, GPIO_TypeDef *tx_gpio_port, uint16_t tx_gpio_pin, GPIO_TypeDef *rx_gpio_port, uint16_t rx_gpio_pin, uint32_t pin_remap=0, uint32_t tx_queue_size=5, UART::Configuration config={115200, UART::Parity::NO_PARITY, 8, 1})
构造 UART 对象 / Construct UART object
Definition ch32_uart.cpp:15
双缓冲区管理类 / Double buffer manager class
普通标志位(非原子)/ Non-atomic flag
Definition flag.hpp:115
原始数据封装类。 A class for encapsulating raw data.
ReadPort class for handling read operations.
Definition libxr_rw.hpp:272
通用异步收发传输(UART)基类 / Abstract base class for Universal Asynchronous Receiver-Transmitter (UART)
Definition uart.hpp:19
@ NO_PARITY
无校验 / No parity
WritePort class for handling write operations.
Definition libxr_rw.hpp:413
LibXR 命名空间
Definition ch32_can.hpp:14
ErrorCode(* ReadFun)(ReadPort &port, bool in_isr)
Function pointer type for read operations.
Definition libxr_rw.hpp:249
ErrorCode(* WriteFun)(WritePort &port, bool in_isr)
Function pointer type for write operations.
Definition libxr_rw.hpp:245
UART 配置结构体 / UART configuration structure.
Definition uart.hpp:44