17 #ifndef _RB_HALF_DUPLEX_UART_H_
18 #define _RB_HALF_DUPLEX_UART_H_
25 #include "soc/uart_reg.h"
26 #include "soc/uart_struct.h"
28 #include "esp_intr_alloc.h"
29 #include "driver/periph_ctrl.h"
30 #include "freertos/FreeRTOS.h"
31 #include "freertos/semphr.h"
32 #include "freertos/xtensa_api.h"
33 #include "freertos/task.h"
34 #include "freertos/queue.h"
35 #include "freertos/ringbuf.h"
36 #include <esp_types.h>
37 #include "soc/uart_channel.h"
38 #include "driver/uart.h"
45 namespace half_duplex {
105 esp_err_t
uart_set_parity(uart_port_t uart_num, uart_parity_t parity_mode);
118 esp_err_t
uart_get_parity(uart_port_t uart_num, uart_parity_t* parity_mode);
172 esp_err_t
uart_set_hw_flow_ctrl(uart_port_t uart_num, uart_hw_flowcontrol_t flow_ctrl, uint8_t rx_thresh);
186 esp_err_t
uart_set_sw_flow_ctrl(uart_port_t uart_num,
bool enable, uint8_t rx_thresh_xon, uint8_t rx_thresh_xoff);
302 esp_err_t
uart_isr_register(uart_port_t uart_num,
void (*fn)(
void*),
void * arg,
int intr_alloc_flags, uart_isr_handle_t *handle);
335 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);
348 esp_err_t
uart_set_rts(uart_port_t uart_num,
int level);
360 esp_err_t
uart_set_dtr(uart_port_t uart_num,
int level);
385 esp_err_t
uart_param_config(uart_port_t uart_num,
const uart_config_t *uart_config);
397 esp_err_t
uart_intr_config(uart_port_t uart_num,
const uart_intr_config_t *intr_conf);
421 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);
461 int uart_tx_chars(uart_port_t uart_num,
const char* buffer, uint32_t len);
516 int uart_read_bytes(uart_port_t uart_num, uint8_t* buf, uint32_t length, TickType_t ticks_to_wait);
586 esp_err_t
uart_enable_pattern_det_intr(uart_port_t uart_num,
char pattern_chr, uint8_t chr_num,
int chr_tout,
int post_idle,
int pre_idle);
650 esp_err_t
uart_set_mode(uart_port_t uart_num, uart_mode_t mode);
esp_err_t uart_set_tx_idle_num(uart_port_t uart_num, uint16_t idle_num)
Set UART idle interval after tx FIFO is empty.
Definition: half_duplex_uart.cpp:667
esp_err_t uart_set_rx_timeout(uart_port_t uart_num, const uint8_t tout_thresh)
UART set threshold timeout for TOUT feature.
Definition: half_duplex_uart.cpp:1601
esp_err_t uart_get_hw_flow_ctrl(uart_port_t uart_num, uart_hw_flowcontrol_t *flow_ctrl)
Get hardware flow control mode.
Definition: half_duplex_uart.cpp:308
esp_err_t uart_set_stop_bits(uart_port_t uart_num, uart_stop_bits_t stop_bit)
Set UART stop bits.
Definition: half_duplex_uart.cpp:163
esp_err_t uart_set_dtr(uart_port_t uart_num, int level)
Manually set the UART DTR pin level.
Definition: half_duplex_uart.cpp:658
esp_err_t uart_disable_pattern_det_intr(uart_port_t uart_num)
UART disable pattern detect function. Designed for applications like 'AT commands'....
Definition: half_duplex_uart.cpp:518
int uart_pattern_pop_pos(uart_port_t uart_num)
Return the nearest detected pattern position in buffer. The positions of the detected pattern are sav...
Definition: half_duplex_uart.cpp:457
esp_err_t uart_isr_register(uart_port_t uart_num, void(*fn)(void *), void *arg, int intr_alloc_flags, uart_isr_handle_t *handle)
Register UART interrupt handler (ISR).
Definition: half_duplex_uart.cpp:550
esp_err_t uart_set_word_length(uart_port_t uart_num, uart_word_length_t data_bit)
Set UART data bits.
Definition: half_duplex_uart.cpp:146
esp_err_t uart_disable_tx_intr(uart_port_t uart_num)
Disable UART TX interrupt (TX_FULL & TX_TIMEOUT INTERRUPT)
Definition: half_duplex_uart.cpp:533
int uart_tx_chars(uart_port_t uart_num, const char *buffer, uint32_t len)
Send data to the UART port from a given buffer and length.
Definition: half_duplex_uart.cpp:1149
int uart_write_bytes_with_break(uart_port_t uart_num, const char *src, size_t size, int brk_len)
Send data to the UART port from a given buffer and length,.
int uart_pattern_get_pos(uart_port_t uart_num)
Return the nearest detected pattern position in buffer. The positions of the detected pattern are sav...
Definition: half_duplex_uart.cpp:471
esp_err_t uart_wait_tx_done(uart_port_t uart_num, TickType_t ticks_to_wait)
Wait until UART TX FIFO is empty.
esp_err_t uart_set_baudrate(uart_port_t uart_num, uint32_t baud_rate)
Set UART baud rate.
Definition: half_duplex_uart.cpp:219
esp_err_t uart_set_mode(uart_port_t uart_num, uart_mode_t mode)
UART set communication mode.
Definition: half_duplex_uart.cpp:1542
esp_err_t uart_enable_intr_mask(uart_port_t uart_num, uint32_t enable_mask)
Set UART interrupt enable.
Definition: half_duplex_uart.cpp:343
esp_err_t uart_set_hw_flow_ctrl(uart_port_t uart_num, uart_hw_flowcontrol_t flow_ctrl, uint8_t rx_thresh)
Set hardware flow control.
Definition: half_duplex_uart.cpp:287
esp_err_t uart_get_collision_flag(uart_port_t uart_num, bool *collision_flag)
Returns collision detection flag for RS485 mode Function returns the collision detection flag into va...
Definition: half_duplex_uart.cpp:1618
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)
Install UART driver.
Definition: half_duplex_uart.cpp:1382
void uart_set_half_duplex_pin(uart_port_t uart_num, gpio_num_t pin)
Definition: half_duplex_uart.cpp:1649
esp_err_t uart_enable_tx_intr(uart_port_t uart_num, int enable, int thresh)
Enable UART TX interrupt (TX_FULL & TX_TIMEOUT INTERRUPT)
Definition: half_duplex_uart.cpp:538
esp_err_t uart_get_baudrate(uart_port_t uart_num, uint32_t *baudrate)
Get UART baud rate.
Definition: half_duplex_uart.cpp:245
esp_err_t uart_disable_intr_mask(uart_port_t uart_num, uint32_t disable_mask)
Clear UART interrupt enable bits.
Definition: half_duplex_uart.cpp:353
esp_err_t uart_enable_rx_intr(uart_port_t uart_num)
Enable UART RX interrupt (RX_FULL & RX_TIMEOUT INTERRUPT)
Definition: half_duplex_uart.cpp:523
esp_err_t uart_get_stop_bits(uart_port_t uart_num, uart_stop_bits_t *stop_bit)
Get UART stop bits.
Definition: half_duplex_uart.cpp:181
int uart_write_bytes(uart_port_t uart_num, const char *src, size_t size)
Send data to the UART port from a given buffer and length,.
esp_err_t uart_enable_pattern_det_intr(uart_port_t uart_num, char pattern_chr, uint8_t chr_num, int chr_tout, int post_idle, int pre_idle)
UART enable pattern detect function. Designed for applications like 'AT commands'....
Definition: half_duplex_uart.cpp:504
esp_err_t uart_set_line_inverse(uart_port_t uart_num, uint32_t inverse_mask)
Set UART line inverse mode.
Definition: half_duplex_uart.cpp:259
esp_err_t uart_get_parity(uart_port_t uart_num, uart_parity_t *parity_mode)
Get UART parity mode.
Definition: half_duplex_uart.cpp:203
esp_err_t uart_disable_rx_intr(uart_port_t uart_num)
Disable UART RX interrupt (RX_FULL & RX_TIMEOUT INTERRUPT)
Definition: half_duplex_uart.cpp:528
esp_err_t uart_param_config(uart_port_t uart_num, const uart_config_t *uart_config)
Set UART configuration parameters.
Definition: half_duplex_uart.cpp:678
esp_err_t uart_get_buffered_data_len(uart_port_t uart_num, size_t *size)
UART get RX ring buffer cached data length.
Definition: half_duplex_uart.cpp:1311
esp_err_t uart_get_word_length(uart_port_t uart_num, uart_word_length_t *data_bit)
Get UART data bits.
Definition: half_duplex_uart.cpp:156
esp_err_t uart_set_wakeup_threshold(uart_port_t uart_num, int wakeup_threshold)
Set the number of RX pin signal edges for light sleep wakeup.
Definition: half_duplex_uart.cpp:1629
esp_err_t uart_pattern_queue_reset(uart_port_t uart_num, int queue_length)
Allocate a new memory with the given length to save record the detected pattern position in rx buffer...
Definition: half_duplex_uart.cpp:484
esp_err_t uart_set_rts(uart_port_t uart_num, int level)
Manually set the UART RTS pin level.
Definition: half_duplex_uart.cpp:648
esp_err_t uart_set_sw_flow_ctrl(uart_port_t uart_num, bool enable, uint8_t rx_thresh_xon, uint8_t rx_thresh_xoff)
Set software flow control.
Definition: half_duplex_uart.cpp:270
esp_err_t uart_flush(uart_port_t uart_num)
Alias of uart_flush_input. UART ring buffer flush. This will discard all data in the UART RX buffer.
Definition: half_duplex_uart.cpp:1377
esp_err_t uart_set_parity(uart_port_t uart_num, uart_parity_t parity_mode)
Set UART parity mode.
Definition: half_duplex_uart.cpp:193
int uart_read_bytes(uart_port_t uart_num, uint8_t *buf, uint32_t length, TickType_t ticks_to_wait)
UART read bytes from UART buffer.
Definition: half_duplex_uart.cpp:1252
esp_err_t uart_flush_input(uart_port_t uart_num)
Clear input buffer, discard all the data is in the ring-buffer.
Definition: half_duplex_uart.cpp:1319
esp_err_t IRAM_ATTR uart_clear_intr_status(uart_port_t uart_num, uint32_t clr_mask)
Clear UART interrupt status.
Definition: half_duplex_uart.cpp:335
esp_err_t uart_intr_config(uart_port_t uart_num, const uart_intr_config_t *intr_conf)
Configure UART interrupts.
Definition: half_duplex_uart.cpp:710
esp_err_t uart_get_wakeup_threshold(uart_port_t uart_num, int *out_wakeup_threshold)
Get the number of RX pin signal edges for light sleep wakeup.
Definition: half_duplex_uart.cpp:1640
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)
Set UART pin number.
Definition: half_duplex_uart.cpp:586
esp_err_t uart_driver_delete(uart_port_t uart_num)
Uninstall UART driver.
Definition: half_duplex_uart.cpp:1470
esp_err_t uart_isr_free(uart_port_t uart_num)
Free UART interrupt handler registered by uart_isr_register. Must be called on the same core as uart_...
Definition: half_duplex_uart.cpp:572
The base namespace. Contains some logging functions, too.
Definition: half_duplex_uart.cpp:53