libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
esp_uart.hpp
1#pragma once
2
3#include "driver/uart.h"
4#include "freertos/queue.h"
5#include "freertos/semphr.h"
6#include "libxr_def.hpp"
7#include "libxr_rw.hpp"
8#include "uart.hpp"
9
10namespace LibXR
11{
12class ESP32UART;
14{
15 public:
16 ESP32UARTReadPort(size_t buffer_size, ESP32UART *uart)
17 : ReadPort(buffer_size), uart_(uart)
18 {
19 }
20
21 size_t EmptySize();
22
23 size_t Size();
24
25 void ProcessPendingReads(bool in_isr = true);
26
27 void Reset() { read_size_ = 0; }
28
29 using ReadPort::operator=;
30
31 private:
32 ESP32UART *uart_;
33};
34
36{
37 public:
38 ESP32UARTWritePort(size_t queue_size, size_t buffer_size,
39 ESP32UART *uart)
40 : WritePort(queue_size, buffer_size), uart_(uart)
41 {
42 }
43
44 size_t EmptySize();
45
46 size_t Size();
47
48 void Reset() { write_size_ = 0; }
49
50 using WritePort::operator=;
51
52 private:
53 ESP32UART *uart_;
54};
55
56class ESP32UART : public UART
57{
58 public:
59 ESP32UART(uart_port_t port, int tx_pin, int rx_pin, uint32_t buffer_size = 256,
60 uint32_t rx_thread_stack_depth = 1024, uint32_t rx_thread_priority = 10);
61
62 static ErrorCode WriteFun(WritePort &port);
63 static ErrorCode ReadFun(ReadPort &port);
64
65 ErrorCode SetConfig(UART::Configuration config) override;
66
67 friend class ESP32UARTReadPort;
68 friend class ESP32UARTWritePort;
69
70 private:
71 static void RxTask(void *param);
72 static void TxTask(void *param);
73 void HandleEvent(const uart_event_t &event);
74
75 uart_port_t port_;
76 QueueHandle_t event_queue_;
77 RawData rx_buff_;
78 RawData tx_buff_;
79
80 ESP32UARTReadPort _read_port;
81 ESP32UARTWritePort _write_port;
82};
83
84} // namespace LibXR
ErrorCode SetConfig(UART::Configuration config) override
设置 UART 配置 / Sets the UART configuration
Definition esp_uart.cpp:173
size_t Size()
获取当前队列的已使用大小。 Gets the currently used size of the queue.
Definition esp_uart.cpp:14
size_t EmptySize()
获取队列的剩余可用空间。 Gets the remaining available space in the queue.
Definition esp_uart.cpp:7
void Reset()
Resets the ReadPort.
Definition esp_uart.hpp:27
void ProcessPendingReads(bool in_isr=true)
Processes pending reads.
Definition esp_uart.cpp:21
void Reset()
Resets the WritePort.
Definition esp_uart.hpp:48
size_t Size()
获取当前数据队列的已使用大小。 Gets the used size of the current data queue.
Definition esp_uart.cpp:49
size_t EmptySize()
获取数据队列的剩余可用空间。 Gets the remaining available space in the data queue.
Definition esp_uart.cpp:42
原始数据封装类。 A class for encapsulating raw data.
ReadPort class for handling read operations.
Definition libxr_rw.hpp:270
ReadPort(size_t buffer_size=128)
Constructs a ReadPort with queue sizes.
Definition libxr_rw.hpp:292
通用异步收发传输(UART)基类 / Abstract base class for Universal Asynchronous Receiver-Transmitter (UART)
Definition uart.hpp:19
WritePort class for handling write operations.
Definition libxr_rw.hpp:564
WritePort(size_t queue_size=3, size_t buffer_size=128)
构造一个新的 WritePort 对象。 Constructs a new WritePort object.
Definition libxr_rw.hpp:585
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