libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
stm32_uart.hpp
1#pragma once
2
3#include "main.h"
4
5#ifdef HAL_UART_MODULE_ENABLED
6
7#ifdef UART
8#undef UART
9#endif
10
11#include "double_buffer.hpp"
12#include "libxr_def.hpp"
13#include "libxr_rw.hpp"
14#include "uart.hpp"
15
16typedef enum
17{
18#ifdef USART1
19 STM32_USART1,
20#endif
21#ifdef USART2
22 STM32_USART2,
23#endif
24#ifdef USART3
25 STM32_USART3,
26#endif
27#ifdef USART4
28 STM32_USART4,
29#endif
30#ifdef USART5
31 STM32_USART5,
32#endif
33#ifdef USART6
34 STM32_USART6,
35#endif
36#ifdef USART7
37 STM32_USART7,
38#endif
39#ifdef USART8
40 STM32_USART8,
41#endif
42#ifdef USART9
43 STM32_USART9,
44#endif
45#ifdef USART10
46 STM32_USART10,
47#endif
48#ifdef USART11
49 STM32_USART11,
50#endif
51#ifdef USART12
52 STM32_USART12,
53#endif
54#ifdef USART13
55 STM32_USART13,
56#endif
57#ifdef UART1
58 STM32_UART1,
59#endif
60#ifdef UART2
61 STM32_UART2,
62#endif
63#ifdef UART3
64 STM32_UART3,
65#endif
66#ifdef UART4
67 STM32_UART4,
68#endif
69#ifdef UART5
70 STM32_UART5,
71#endif
72#ifdef UART6
73 STM32_UART6,
74#endif
75#ifdef UART7
76 STM32_UART7,
77#endif
78#ifdef UART8
79 STM32_UART8,
80#endif
81#ifdef UART9
82 STM32_UART9,
83#endif
84#ifdef UART10
85 STM32_UART10,
86#endif
87#ifdef UART11
88 STM32_UART11,
89#endif
90#ifdef UART12
91 STM32_UART12,
92#endif
93#ifdef UART13
94 STM32_UART13,
95#endif
96#ifdef LPUART1
97 STM32_LPUART1,
98#endif
99#ifdef LPUART2
100 STM32_LPUART2,
101#endif
102#ifdef LPUART3
103 STM32_LPUART3,
104#endif
105 STM32_UART_NUMBER,
106 STM32_UART_ID_ERROR
107} stm32_uart_id_t;
108
109stm32_uart_id_t STM32_UART_GetID(USART_TypeDef *addr);
110
111namespace LibXR
112{
113class STM32UART : public UART
114{
115 public:
116 static ErrorCode WriteFun(WritePort &port);
117
118 static ErrorCode ReadFun(ReadPort &port);
119
120 STM32UART(UART_HandleTypeDef *uart_handle, RawData dma_buff_rx, RawData dma_buff_tx,
121 uint32_t tx_queue_size = 5);
122
123 ErrorCode SetConfig(UART::Configuration config);
124
125 ReadPort _read_port;
126 WritePort _write_port;
127
128 RawData dma_buff_rx_;
129 DoubleBuffer dma_buff_tx_;
130 WriteInfoBlock write_info_active_;
131
132 size_t last_rx_pos_ = 0;
133
134 UART_HandleTypeDef *uart_handle_;
135
136 stm32_uart_id_t id_ = STM32_UART_ID_ERROR;
137
138 static STM32UART *map[STM32_UART_NUMBER]; // NOLINT
139};
140
141} // namespace LibXR
142
143#endif
双缓冲区管理类 / Double buffer manager class
原始数据封装类。 A class for encapsulating raw data.
ReadPort class for handling read operations.
Definition libxr_rw.hpp:268
ErrorCode SetConfig(UART::Configuration config)
设置 UART 配置 / Sets the UART configuration
通用异步收发传输(UART)基类 / Abstract base class for Universal Asynchronous Receiver-Transmitter (UART)
Definition uart.hpp:19
WritePort class for handling write operations.
Definition libxr_rw.hpp:402
LibXR 命名空间
Definition ch32_gpio.hpp:9
ErrorCode(* ReadFun)(ReadPort &port)
Function pointer type for read operations.
Definition libxr_rw.hpp:245
ErrorCode(* WriteFun)(WritePort &port)
Function pointer type for write operations.
Definition libxr_rw.hpp:241
UART 配置结构体 / UART configuration structure.
Definition uart.hpp:44