libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
ch32_uart.hpp
1// ch32_uart.hpp
2#pragma once
3
4#include "libxr.hpp"
5#include DEF2STR(LIBXR_CH32_CONFIG_FILE)
6
7#include "ch32_uart_def.hpp"
8#include "double_buffer.hpp"
9#include "libxr_def.hpp"
10#include "libxr_rw.hpp"
11#include "uart.hpp"
12
13namespace LibXR
14{
15
16class CH32UART : public UART
17{
18 public:
19 CH32UART(ch32_uart_id_t id, RawData dma_rx, RawData dma_tx, GPIO_TypeDef *tx_gpio_port,
20 uint16_t tx_gpio_pin, GPIO_TypeDef *rx_gpio_port, uint16_t rx_gpio_pin,
21 uint32_t pin_remap = 0, uint32_t tx_queue_size = 5,
22 UART::Configuration config = {115200, UART::Parity::NO_PARITY, 8, 1});
23
24 ErrorCode SetConfig(UART::Configuration config);
25
26 static ErrorCode WriteFun(WritePort &port);
27 static ErrorCode ReadFun(ReadPort &port);
28
29 static void DmaIRQHandler(DMA_Channel_TypeDef *channel, ch32_uart_id_t id);
30
31 ch32_uart_id_t id_;
32 uint16_t uart_mode_;
33
34 ReadPort _read_port;
35 WritePort _write_port;
36
37 RawData dma_buff_rx_;
38 DoubleBuffer dma_buff_tx_;
39 WriteInfoBlock write_info_active_;
40
41 size_t last_rx_pos_ = 0;
42
43 USART_TypeDef *instance_;
44 DMA_Channel_TypeDef *dma_rx_channel_;
45 DMA_Channel_TypeDef *dma_tx_channel_;
46
47 static CH32UART *map[CH32_UART_NUMBER];
48};
49
50} // namespace LibXR
ErrorCode SetConfig(UART::Configuration config)
设置 UART 配置 / Sets the UART configuration
双缓冲区管理类 / Double buffer manager class
原始数据封装类。 A class for encapsulating raw data.
ReadPort class for handling read operations.
Definition libxr_rw.hpp:270
通用异步收发传输(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:564
LibXR 命名空间
Definition ch32_gpio.hpp:9
ErrorCode(* ReadFun)(ReadPort &port)
Function pointer type for read operations.
Definition libxr_rw.hpp:247
ErrorCode(* WriteFun)(WritePort &port)
Function pointer type for write operations.
Definition libxr_rw.hpp:243
UART 配置结构体 / UART configuration structure.
Definition uart.hpp:44