VSF Documented
uart.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright(C)2009-2026 by VSF Team *
3 * *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
7 * *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
9 * *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
15 * *
16 ****************************************************************************/
17
18/*
19 * Clean-room re-implementation of ESP-IDF public API "driver/uart.h".
20 * Authored from ESP-IDF v5.1 public API only; no ESP-IDF source was
21 * copied. The VSF port bridges onto
22 *
23 * hal/driver/common/template/vsf_template_usart.h
24 *
25 * via a cfg-injected pool of vsf_usart_t* instances (same pattern as
26 * driver/gptimer.h). uart_port_t (UART_NUM_0, 1, ...) indexes into
27 * this pool.
28 *
29 * Supported API:
30 * uart_driver_install, uart_driver_delete, uart_is_driver_installed,
31 * uart_param_config,
32 * uart_set_baudrate/get_baudrate,
33 * uart_set_word_length/get_word_length,
34 * uart_set_stop_bits/get_stop_bits,
35 * uart_set_parity/get_parity,
36 * uart_set_hw_flow_ctrl/get_hw_flow_ctrl,
37 * uart_write_bytes, uart_write_bytes_with_break,
38 * uart_read_bytes,
39 * uart_get_buffered_data_len, uart_get_tx_buffer_free_size,
40 * uart_flush, uart_flush_input,
41 * uart_set_mode, uart_set_rx_timeout.
42 *
43 * NOT_SUPPORTED:
44 * uart_set_pin (VSF does not manage external pin routing),
45 * uart_set_rts (hardware-managed when flow-ctrl enabled),
46 * uart_set_dtr,
47 * uart_set_tx_idle_num,
48 * uart_wait_tx_done (use uart_flush instead),
49 * uart_pattern_* (ESP-IDF pattern detect is HW-specific).
50 */
51
52#ifndef __VSF_ESPIDF_DRIVER_UART_H__
53#define __VSF_ESPIDF_DRIVER_UART_H__
54
55#include <stdint.h>
56#include <stdbool.h>
57#include <stddef.h>
58
59#include "esp_err.h"
60
61/* FreeRTOS types used by the driver API (QueueHandle_t, TickType_t). */
62#include "freertos/FreeRTOS.h"
63#include "freertos/queue.h"
64
65#ifdef __cplusplus
66extern "C" {
67#endif
68
69/*============================ MACROS ========================================*/
70
72#define UART_PIN_NO_CHANGE (-1)
73
75#define UART_HW_FIFO_LEN (128)
76
77/*============================ TYPES =========================================*/
78
80typedef int uart_port_t;
81
83#define UART_NUM_0 (0)
84#define UART_NUM_1 (1)
85#define UART_NUM_2 (2)
86#define UART_NUM_MAX (3)
89typedef enum {
96
98typedef enum {
104
106typedef enum {
111
113typedef enum {
120
122typedef enum {
129
131typedef enum {
137
139typedef struct {
148
150typedef enum {
161
163typedef struct {
165 size_t size;
168
169/*============================ DRIVER LIFECYCLE ==============================*/
170
183 int rx_buffer_size,
184 int tx_buffer_size,
185 int queue_size,
186 QueueHandle_t *uart_queue,
187 int intr_alloc_flags);
188
191
193extern bool uart_is_driver_installed(uart_port_t uart_num);
194
195/*============================ CONFIGURATION =================================*/
196
199 const uart_config_t *uart_config);
200
201extern esp_err_t uart_set_baudrate(uart_port_t uart_num, uint32_t baudrate);
202extern esp_err_t uart_get_baudrate(uart_port_t uart_num, uint32_t *baudrate);
203
205 uart_word_length_t data_bit);
207 uart_word_length_t *data_bit);
208
210 uart_stop_bits_t stop_bits);
212 uart_stop_bits_t *stop_bits);
213
215 uart_parity_t parity_mode);
217 uart_parity_t *parity_mode);
218
220 uart_hw_flowcontrol_t flow_ctrl,
221 uint8_t rx_thresh);
223 uart_hw_flowcontrol_t *flow_ctrl);
224
225/*============================ I/O ===========================================*/
226
231extern int uart_write_bytes(uart_port_t uart_num,
232 const void *src, size_t size);
233
238extern int uart_write_bytes_with_break(uart_port_t uart_num,
239 const void *src, size_t size,
240 int brk_len);
241
247extern int uart_read_bytes(uart_port_t uart_num,
248 void *buf, uint32_t length,
249 TickType_t ticks_to_wait);
250
251/*============================ BUFFER STATUS =================================*/
252
255 size_t *size);
256
259 size_t *size);
260
262extern esp_err_t uart_flush(uart_port_t uart_num);
263
265extern esp_err_t uart_flush_input(uart_port_t uart_num);
266
267/*============================ PIN ROUTING ===================================*/
268
275extern esp_err_t uart_set_pin(uart_port_t uart_num,
276 int tx_io_num, int rx_io_num,
277 int rts_io_num, int cts_io_num);
278
279/*============================ MODE / TIMEOUT ================================*/
280
282extern esp_err_t uart_set_mode(uart_port_t uart_num, uart_mode_t mode);
283
285extern esp_err_t uart_set_rx_timeout(uart_port_t uart_num, uint8_t tout);
286
287/*============================ WAIT TX DONE ==================================*/
288
295 TickType_t ticks_to_wait);
296
297#ifdef __cplusplus
298}
299#endif
300
301#endif /* __VSF_ESPIDF_DRIVER_UART_H__ */
Definition queue.h:61
int esp_err_t
Definition esp_err.h:41
uint32_t TickType_t
Definition rtos_al.h:59
esp_err_t uart_flush_input(uart_port_t uart_num)
Definition driver_uart_port.c:808
esp_err_t uart_flush(uart_port_t uart_num)
Definition driver_uart_port.c:825
esp_err_t uart_get_word_length(uart_port_t uart_num, uart_word_length_t *data_bit)
Definition driver_uart_port.c:605
esp_err_t uart_get_tx_buffer_free_size(uart_port_t uart_num, size_t *size)
Definition driver_uart_port.c:795
esp_err_t uart_param_config(uart_port_t uart_num, const uart_config_t *uart_config)
Definition driver_uart_port.c:562
bool uart_is_driver_installed(uart_port_t uart_num)
Definition driver_uart_port.c:552
esp_err_t uart_set_hw_flow_ctrl(uart_port_t uart_num, uart_hw_flowcontrol_t flow_ctrl, uint8_t rx_thresh)
Definition driver_uart_port.c:647
esp_err_t uart_get_baudrate(uart_port_t uart_num, uint32_t *baudrate)
Definition driver_uart_port.c:589
esp_err_t uart_get_buffered_data_len(uart_port_t uart_num, size_t *size)
Definition driver_uart_port.c:785
uart_hw_flowcontrol_t
Definition uart.h:113
@ UART_HW_FLOWCTRL_MAX
Definition uart.h:118
@ UART_HW_FLOWCTRL_CTS_RTS
Definition uart.h:117
@ UART_HW_FLOWCTRL_RTS
Definition uart.h:115
@ UART_HW_FLOWCTRL_CTS
Definition uart.h:116
@ UART_HW_FLOWCTRL_DISABLE
Definition uart.h:114
uart_sclk_t
Definition uart.h:131
@ UART_SCLK_APB
Definition uart.h:133
@ UART_SCLK_XTAL
Definition uart.h:134
@ UART_SCLK_DEFAULT
Definition uart.h:132
@ UART_SCLK_RTC
Definition uart.h:135
esp_err_t uart_set_stop_bits(uart_port_t uart_num, uart_stop_bits_t stop_bits)
Definition driver_uart_port.c:613
int uart_port_t
Definition uart.h:80
uart_parity_t
Definition uart.h:106
@ UART_PARITY_DISABLE
Definition uart.h:107
@ UART_PARITY_EVEN
Definition uart.h:108
@ UART_PARITY_ODD
Definition uart.h:109
uart_stop_bits_t
Definition uart.h:98
@ UART_STOP_BITS_2
Definition uart.h:101
@ UART_STOP_BITS_1
Definition uart.h:99
@ UART_STOP_BITS_MAX
Definition uart.h:102
@ UART_STOP_BITS_1_5
Definition uart.h:100
esp_err_t uart_set_baudrate(uart_port_t uart_num, uint32_t baudrate)
Definition driver_uart_port.c:581
esp_err_t uart_set_word_length(uart_port_t uart_num, uart_word_length_t data_bit)
Definition driver_uart_port.c:596
int uart_write_bytes(uart_port_t uart_num, const void *src, size_t size)
Definition driver_uart_port.c:668
esp_err_t uart_set_parity(uart_port_t uart_num, uart_parity_t parity_mode)
Definition driver_uart_port.c:630
uart_mode_t
Definition uart.h:122
@ UART_MODE_UART
Definition uart.h:123
@ UART_MODE_RS485_HALF_DUPLEX
Definition uart.h:124
@ UART_MODE_RS485_COLLISION_DETECT
Definition uart.h:126
@ UART_MODE_RS485_APP_CTRL
Definition uart.h:127
@ UART_MODE_IRDA
Definition uart.h:125
esp_err_t uart_set_mode(uart_port_t uart_num, uart_mode_t mode)
Definition driver_uart_port.c:867
int uart_read_bytes(uart_port_t uart_num, void *buf, uint32_t length, TickType_t ticks_to_wait)
Definition driver_uart_port.c:735
esp_err_t uart_set_pin(uart_port_t uart_num, int tx_io_num, int rx_io_num, int rts_io_num, int cts_io_num)
Definition driver_uart_port.c:855
uart_event_type_t
Definition uart.h:150
@ UART_BUFFER_FULL
Definition uart.h:153
@ UART_DATA_BREAK
Definition uart.h:157
@ UART_FRAME_ERR
Definition uart.h:155
@ UART_BREAK
Definition uart.h:152
@ UART_EVENT_MAX
Definition uart.h:159
@ UART_PATTERN_DET
Definition uart.h:158
@ UART_PARITY_ERR
Definition uart.h:156
@ UART_DATA
Definition uart.h:151
@ UART_FIFO_OVF
Definition uart.h:154
uart_word_length_t
Definition uart.h:89
@ UART_DATA_6_BITS
Definition uart.h:91
@ UART_DATA_5_BITS
Definition uart.h:90
@ UART_DATA_8_BITS
Definition uart.h:93
@ UART_DATA_BITS_MAX
Definition uart.h:94
@ UART_DATA_7_BITS
Definition uart.h:92
esp_err_t uart_get_hw_flow_ctrl(uart_port_t uart_num, uart_hw_flowcontrol_t *flow_ctrl)
Definition driver_uart_port.c:658
esp_err_t uart_get_parity(uart_port_t uart_num, uart_parity_t *parity_mode)
Definition driver_uart_port.c:639
esp_err_t uart_get_stop_bits(uart_port_t uart_num, uart_stop_bits_t *stop_bits)
Definition driver_uart_port.c:622
esp_err_t uart_wait_tx_done(uart_port_t uart_num, TickType_t ticks_to_wait)
Definition driver_uart_port.c:832
int uart_write_bytes_with_break(uart_port_t uart_num, const void *src, size_t size, int brk_len)
Definition driver_uart_port.c:721
esp_err_t uart_driver_delete(uart_port_t uart_num)
Definition driver_uart_port.c:515
esp_err_t uart_driver_install(uart_port_t uart_num, int rx_buffer_size, int tx_buffer_size, int queue_size, QueueHandle_t *uart_queue, int intr_alloc_flags)
Definition driver_uart_port.c:428
esp_err_t uart_set_rx_timeout(uart_port_t uart_num, uint8_t tout)
Definition driver_uart_port.c:875
unsigned uint32_t
Definition stdint.h:9
unsigned char uint8_t
Definition stdint.h:5
Definition uart.h:139
uint8_t rx_flow_ctrl_thresh
Definition uart.h:145
uart_parity_t parity
Definition uart.h:142
uart_word_length_t data_bits
Definition uart.h:141
uart_sclk_t source_clk
Definition uart.h:146
int baud_rate
Definition uart.h:140
uart_hw_flowcontrol_t flow_ctrl
Definition uart.h:144
uart_stop_bits_t stop_bits
Definition uart.h:143
Definition uart.h:163
uart_event_type_t type
Definition uart.h:164
bool timeout_flag
Definition uart.h:166
size_t size
Definition uart.h:165
uint32_t size
Definition vsf_memfs.h:50
uint_fast8_t length
Definition vsf_pbuf.c:38
Generated from commit: vsfteam/vsf@015f4d1