ESP32-P4 OBC Firmware
ESP-IDF firmware for Plant-B CubeSat OBC
 
Loading...
Searching...
No Matches
uart_device.h
Go to the documentation of this file.
1
24
25#ifndef __UART_DEVICE_H__
26#define __UART_DEVICE_H__
27
28#include "driver/uart.h"
29#include "pal_err.h"
30#include "pal_log.h"
31#include "freertos/task.h"
32
40
46#define DEFAULT_TX (23)
47#define DEFAULT_RX (22)
48#define DEFAULT_CTS (20)
49#define DEFAULT_RTS (21)
50#define DEFAULT_BAUDRATE (115200)
51#define DEFAULT_BUF_SIZE (2028)
52#define DEFAULT_CTRL_TRESH (122)
53#define DEFAULT_EVT_QUEUE_SIZE (10)
55
56#ifdef __cplusplus
57extern "C" {
58#endif
59
65typedef struct {
66 const char *const TAG;
67 uart_port_t port;
68 uint32_t baudrate;
69
70 uint8_t tx_pin;
71 uint8_t rx_pin;
72 uint8_t rts_pin;
73 uint8_t cts_pin;
74
75 bool flow_ctrl;
76
78 size_t rx_buf_size;
79 size_t tx_buf_size;
81
85typedef struct uartd uartd_t;
86
93
113
135
144
159 const uartd_handle_t dev,
160 uart_event_t *event,
161 TickType_t timeout
162);
163
183 const uartd_handle_t restrict dev,
184 void *restrict buf,
185 size_t sz,
186 size_t len,
187 TickType_t timeout,
188 size_t *out_bytes
189);
190
209 const uartd_handle_t restrict dev,
210 const void *const restrict buf,
211 size_t sz,
212 size_t len,
213 size_t *out_bytes
214);
215
236 const uartd_handle_t restrict dev,
237 char *restrict line,
238 size_t max_len,
239 TickType_t timeout,
240 size_t *out_len
241);
242
261 const uartd_handle_t restrict dev,
262 const char *const restrict line,
263 size_t *out_len
264);
265
266#ifdef __cplusplus
267}
268#endif
269 // end of uart_device group
271
272#endif // __UART_DEVICE_H__
273
uint32_t baudrate
UART baud rate.
Definition uart_device.h:68
bool flow_ctrl
Enable hardware flow control.
Definition uart_device.h:75
size_t tx_buf_size
TX buffer size.
Definition uart_device.h:79
uint8_t cts_pin
CTS GPIO pin.
Definition uart_device.h:73
uint8_t rts_pin
RTS GPIO pin.
Definition uart_device.h:72
uart_port_t port
UART port number.
Definition uart_device.h:67
uint8_t tx_pin
TX GPIO pin.
Definition uart_device.h:70
size_t evt_queue_size
UART event queue size.
Definition uart_device.h:77
size_t rx_buf_size
RX buffer size.
Definition uart_device.h:78
uint8_t rx_pin
RX GPIO pin.
Definition uart_device.h:71
const char *const TAG
Logging tag.
Definition uart_device.h:66
pal_err_t uartd_read(const uartd_handle_t restrict dev, void *restrict buf, size_t sz, size_t len, TickType_t timeout, size_t *out_bytes)
Read raw data from UART.
Definition uart_device.c:169
uartd_config_t uartd_default_config(void)
Get a default UART configuration to drive the UART1 controller.
Definition uart_device.c:34
struct uartd uartd_t
UART device.
Definition uart_device.h:85
uartd_handle_t uartd_init(uartd_config_t *restrict cfg)
Initialize an UART controller.
Definition uart_device.c:55
pal_err_t uartd_deinit(uartd_handle_t restrict dev)
Deinitialize a UART device.
Definition uart_device.c:131
pal_err_t uartd_write(const uartd_handle_t restrict dev, const void *const restrict buf, size_t sz, size_t len, size_t *out_bytes)
Write raw data to UART.
Definition uart_device.c:197
pal_err_t uartd_wait_event(const uartd_handle_t dev, uart_event_t *event, TickType_t timeout)
Wait for an UART event.
Definition uart_device.c:156
pal_err_t uartd_writeline(const uartd_handle_t restrict dev, const char *const restrict line, size_t *out_len)
Write a null-terminated line to UART.
Definition uart_device.c:266
pal_err_t uartd_readline(const uartd_handle_t restrict dev, char *restrict line, size_t max_len, TickType_t timeout, size_t *out_len)
Read up to a newline-terminated string from UART.
Definition uart_device.c:223
uartd_t * uartd_handle_t
UART device handle.
Definition uart_device.h:92
UART device configuration structure.
Definition uart_device.h:65
int pal_err_t
Definition pal_err.h:9
uartd_config_t * cfg
Definition uart_device.c:30
Definition uart_device.c:29