RBControl
Library for the RB3201-RBControl board with the ESP32 by RoboticsBrno.
Classes | Functions | Variables
rb::half_duplex Namespace Reference

Classes

struct  uart_tx_data_t
 
struct  uart_pat_rb_t
 
struct  uart_obj_t
 

Functions

esp_err_t uart_set_word_length (uart_port_t uart_num, uart_word_length_t data_bit)
 Set UART data bits. More...
 
esp_err_t uart_get_word_length (uart_port_t uart_num, uart_word_length_t *data_bit)
 Get UART data bits. More...
 
esp_err_t uart_set_stop_bits (uart_port_t uart_num, uart_stop_bits_t stop_bits)
 Set UART stop bits. More...
 
esp_err_t uart_get_stop_bits (uart_port_t uart_num, uart_stop_bits_t *stop_bits)
 Get UART stop bits. More...
 
esp_err_t uart_set_parity (uart_port_t uart_num, uart_parity_t parity_mode)
 Set UART parity mode. More...
 
esp_err_t uart_get_parity (uart_port_t uart_num, uart_parity_t *parity_mode)
 Get UART parity mode. More...
 
esp_err_t uart_set_baudrate (uart_port_t uart_num, uint32_t baudrate)
 Set UART baud rate. More...
 
esp_err_t uart_get_baudrate (uart_port_t uart_num, uint32_t *baudrate)
 Get UART baud rate. More...
 
esp_err_t uart_set_line_inverse (uart_port_t uart_num, uint32_t inverse_mask)
 Set UART line inverse mode. More...
 
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. More...
 
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. More...
 
esp_err_t uart_get_hw_flow_ctrl (uart_port_t uart_num, uart_hw_flowcontrol_t *flow_ctrl)
 Get hardware flow control mode. More...
 
static esp_err_t IRAM_ATTR uart_reset_rx_fifo (uart_port_t uart_num)
 
esp_err_t IRAM_ATTR uart_clear_intr_status (uart_port_t uart_num, uint32_t clr_mask)
 Clear UART interrupt status. More...
 
esp_err_t uart_enable_intr_mask (uart_port_t uart_num, uint32_t enable_mask)
 Set UART interrupt enable. More...
 
esp_err_t uart_disable_intr_mask (uart_port_t uart_num, uint32_t disable_mask)
 Clear UART interrupt enable bits. More...
 
static void IRAM_ATTR uart_disable_intr_mask_from_isr (uart_port_t uart_num, uint32_t disable_mask)
 
static void IRAM_ATTR uart_enable_intr_mask_from_isr (uart_port_t uart_num, uint32_t enable_mask)
 
static esp_err_t uart_pattern_link_free (uart_port_t uart_num)
 
static esp_err_t IRAM_ATTR uart_pattern_enqueue (uart_port_t uart_num, int pos)
 
static esp_err_t uart_pattern_dequeue (uart_port_t uart_num)
 
static esp_err_t uart_pattern_queue_update (uart_port_t uart_num, int diff_len)
 
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 saved in a queue, this function will dequeue the first pattern position and move the pointer to next pattern position. More...
 
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 saved in a queue, This function do nothing to the queue. More...
 
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. More...
 
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'. When the hardware detect a series of one same character, the interrupt will be triggered. More...
 
esp_err_t uart_disable_pattern_det_intr (uart_port_t uart_num)
 UART disable pattern detect function. Designed for applications like 'AT commands'. When the hardware detects a series of one same character, the interrupt will be triggered. More...
 
esp_err_t uart_enable_rx_intr (uart_port_t uart_num)
 Enable UART RX interrupt (RX_FULL & RX_TIMEOUT INTERRUPT) More...
 
esp_err_t uart_disable_rx_intr (uart_port_t uart_num)
 Disable UART RX interrupt (RX_FULL & RX_TIMEOUT INTERRUPT) More...
 
esp_err_t uart_disable_tx_intr (uart_port_t uart_num)
 Disable UART TX interrupt (TX_FULL & TX_TIMEOUT INTERRUPT) More...
 
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) More...
 
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). More...
 
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_isr_register was called. More...
 
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. More...
 
esp_err_t uart_set_rts (uart_port_t uart_num, int level)
 Manually set the UART RTS pin level. More...
 
esp_err_t uart_set_dtr (uart_port_t uart_num, int level)
 Manually set the UART DTR pin level. More...
 
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. More...
 
esp_err_t uart_param_config (uart_port_t uart_num, const uart_config_t *uart_config)
 Set UART configuration parameters. More...
 
esp_err_t uart_intr_config (uart_port_t uart_num, const uart_intr_config_t *intr_conf)
 Configure UART interrupts. More...
 
static int uart_find_pattern_from_last (uint8_t *buf, int length, uint8_t pat_chr, int pat_num)
 
static void IRAM_ATTR uart_rx_intr_handler_default (void *param)
 
static int uart_fill_fifo (uart_port_t uart_num, const char *buffer, uint32_t len)
 
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. More...
 
static bool uart_check_buf_full (uart_port_t uart_num)
 
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. More...
 
esp_err_t uart_get_buffered_data_len (uart_port_t uart_num, size_t *size)
 UART get RX ring buffer cached data length. More...
 
esp_err_t uart_flush_input (uart_port_t uart_num)
 Clear input buffer, discard all the data is in the ring-buffer. More...
 
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. More...
 
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. More...
 
esp_err_t uart_driver_delete (uart_port_t uart_num)
 Uninstall UART driver. More...
 
void uart_set_select_notif_callback (uart_port_t uart_num, uart_select_notif_callback_t uart_select_notif_callback)
 
portMUX_TYPE * uart_get_selectlock ()
 
esp_err_t uart_set_mode (uart_port_t uart_num, uart_mode_t mode)
 UART set communication mode. More...
 
esp_err_t uart_set_rx_timeout (uart_port_t uart_num, const uint8_t tout_thresh)
 UART set threshold timeout for TOUT feature. More...
 
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 variable pointed by collision_flag. *collision_flag = true, if collision detected else it is equal to false. This function should be executed when actual transmission is completed (after uart_write_bytes()). More...
 
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. More...
 
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. More...
 
void uart_set_half_duplex_pin (uart_port_t uart_num, gpio_num_t pin)
 
esp_err_t uart_wait_tx_done (uart_port_t uart_num, TickType_t ticks_to_wait)
 Wait until UART TX FIFO is empty. More...
 
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,. More...
 
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,. More...
 

Variables

static const char * UART_TAG = "uart"
 
static uart_obj_tp_uart_obj [UART_NUM_MAX] = {0}
 
static DRAM_ATTR uart_dev_t *const UART [UART_NUM_MAX] = {&UART0, &UART1, &UART2}
 
static portMUX_TYPE uart_spinlock [UART_NUM_MAX] = {portMUX_INITIALIZER_UNLOCKED, portMUX_INITIALIZER_UNLOCKED, portMUX_INITIALIZER_UNLOCKED}
 
static portMUX_TYPE uart_selectlock = portMUX_INITIALIZER_UNLOCKED
 

Function Documentation

◆ uart_check_buf_full()

static bool rb::half_duplex::uart_check_buf_full ( uart_port_t  uart_num)
static

◆ uart_clear_intr_status()

esp_err_t rb::half_duplex::uart_clear_intr_status ( uart_port_t  uart_num,
uint32_t  clr_mask 
)

Clear UART interrupt status.

Parameters
uart_numUART_NUM_0, UART_NUM_1 or UART_NUM_2
clr_maskBit mask of the interrupt status to be cleared. The bit mask should be composed from the fields of register UART_INT_CLR_REG.
Returns
  • ESP_OK Success
  • ESP_FAIL Parameter error

◆ uart_disable_intr_mask()

esp_err_t rb::half_duplex::uart_disable_intr_mask ( uart_port_t  uart_num,
uint32_t  disable_mask 
)

Clear UART interrupt enable bits.

Parameters
uart_numUART_NUM_0, UART_NUM_1 or UART_NUM_2
disable_maskBit mask of the disable bits. The bit mask should be composed from the fields of register UART_INT_ENA_REG.
Returns
  • ESP_OK Success
  • ESP_FAIL Parameter error

◆ uart_disable_intr_mask_from_isr()

static void IRAM_ATTR rb::half_duplex::uart_disable_intr_mask_from_isr ( uart_port_t  uart_num,
uint32_t  disable_mask 
)
static

◆ uart_disable_pattern_det_intr()

esp_err_t rb::half_duplex::uart_disable_pattern_det_intr ( uart_port_t  uart_num)

UART disable pattern detect function. Designed for applications like 'AT commands'. When the hardware detects a series of one same character, the interrupt will be triggered.

Parameters
uart_numUART port number.
Returns
  • ESP_OK Success
  • ESP_FAIL Parameter error

◆ uart_disable_rx_intr()

esp_err_t rb::half_duplex::uart_disable_rx_intr ( uart_port_t  uart_num)

Disable UART RX interrupt (RX_FULL & RX_TIMEOUT INTERRUPT)

Parameters
uart_numUART_NUM_0, UART_NUM_1 or UART_NUM_2
Returns
  • ESP_OK Success
  • ESP_FAIL Parameter error

◆ uart_disable_tx_intr()

esp_err_t rb::half_duplex::uart_disable_tx_intr ( uart_port_t  uart_num)

Disable UART TX interrupt (TX_FULL & TX_TIMEOUT INTERRUPT)

Parameters
uart_numUART_NUM_0, UART_NUM_1 or UART_NUM_2
Returns
  • ESP_OK Success
  • ESP_FAIL Parameter error

◆ uart_driver_delete()

esp_err_t rb::half_duplex::uart_driver_delete ( uart_port_t  uart_num)

Uninstall UART driver.

Parameters
uart_numUART_NUM_0, UART_NUM_1 or UART_NUM_2
Returns
  • ESP_OK Success
  • ESP_FAIL Parameter error

◆ uart_driver_install()

esp_err_t rb::half_duplex::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.

UART ISR handler will be attached to the same CPU core that this function is running on.

Note
Rx_buffer_size should be greater than UART_FIFO_LEN. Tx_buffer_size should be either zero or greater than UART_FIFO_LEN.
Parameters
uart_numUART_NUM_0, UART_NUM_1 or UART_NUM_2
rx_buffer_sizeUART RX ring buffer size.
tx_buffer_sizeUART TX ring buffer size. If set to zero, driver will not use TX buffer, TX function will block task until all data have been sent out.
queue_sizeUART event queue size/depth.
uart_queueUART event queue handle (out param). On success, a new queue handle is written here to provide access to UART events. If set to NULL, driver will not use an event queue.
intr_alloc_flagsFlags used to allocate the interrupt. One or multiple (ORred) ESP_INTR_FLAG_* values. See esp_intr_alloc.h for more info. Do not set ESP_INTR_FLAG_IRAM here (the driver's ISR handler is not located in IRAM)
Returns
  • ESP_OK Success
  • ESP_FAIL Parameter error

◆ uart_enable_intr_mask()

esp_err_t rb::half_duplex::uart_enable_intr_mask ( uart_port_t  uart_num,
uint32_t  enable_mask 
)

Set UART interrupt enable.

Parameters
uart_numUART_NUM_0, UART_NUM_1 or UART_NUM_2
enable_maskBit mask of the enable bits. The bit mask should be composed from the fields of register UART_INT_ENA_REG.
Returns
  • ESP_OK Success
  • ESP_FAIL Parameter error

◆ uart_enable_intr_mask_from_isr()

static void IRAM_ATTR rb::half_duplex::uart_enable_intr_mask_from_isr ( uart_port_t  uart_num,
uint32_t  enable_mask 
)
static

◆ uart_enable_pattern_det_intr()

esp_err_t rb::half_duplex::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'. When the hardware detect a series of one same character, the interrupt will be triggered.

Parameters
uart_numUART port number.
pattern_chrcharacter of the pattern
chr_numnumber of the character, 8bit value.
chr_touttimeout of the interval between each pattern characters, 24bit value, unit is APB (80Mhz) clock cycle. When the duration is less than this value, it will not take this data as at_cmd char
post_idleidle time after the last pattern character, 24bit value, unit is APB (80Mhz) clock cycle. When the duration is less than this value, it will not take the previous data as the last at_cmd char
pre_idleidle time before the first pattern character, 24bit value, unit is APB (80Mhz) clock cycle. When the duration is less than this value, it will not take this data as the first at_cmd char
Returns
  • ESP_OK Success
  • ESP_FAIL Parameter error

◆ uart_enable_rx_intr()

esp_err_t rb::half_duplex::uart_enable_rx_intr ( uart_port_t  uart_num)

Enable UART RX interrupt (RX_FULL & RX_TIMEOUT INTERRUPT)

Parameters
uart_numUART_NUM_0, UART_NUM_1 or UART_NUM_2
Returns
  • ESP_OK Success
  • ESP_FAIL Parameter error

◆ uart_enable_tx_intr()

esp_err_t rb::half_duplex::uart_enable_tx_intr ( uart_port_t  uart_num,
int  enable,
int  thresh 
)

Enable UART TX interrupt (TX_FULL & TX_TIMEOUT INTERRUPT)

Parameters
uart_numUART_NUM_0, UART_NUM_1 or UART_NUM_2
enable1: enable; 0: disable
threshThreshold of TX interrupt, 0 ~ UART_FIFO_LEN
Returns
  • ESP_OK Success
  • ESP_FAIL Parameter error

◆ uart_fill_fifo()

static int rb::half_duplex::uart_fill_fifo ( uart_port_t  uart_num,
const char *  buffer,
uint32_t  len 
)
static

◆ uart_find_pattern_from_last()

static int rb::half_duplex::uart_find_pattern_from_last ( uint8_t *  buf,
int  length,
uint8_t  pat_chr,
int  pat_num 
)
static

◆ uart_flush()

esp_err_t rb::half_duplex::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.

Note
Instead of waiting the data sent out, this function will clear UART rx buffer. In order to send all the data in tx FIFO, we can use uart_wait_tx_done function.
Parameters
uart_numUART_NUM_0, UART_NUM_1 or UART_NUM_2
Returns
  • ESP_OK Success
  • ESP_FAIL Parameter error

◆ uart_flush_input()

esp_err_t rb::half_duplex::uart_flush_input ( uart_port_t  uart_num)

Clear input buffer, discard all the data is in the ring-buffer.

Note
In order to send all the data in tx FIFO, we can use uart_wait_tx_done function.
Parameters
uart_numUART_NUM_0, UART_NUM_1 or UART_NUM_2
Returns
  • ESP_OK Success
  • ESP_FAIL Parameter error

◆ uart_get_baudrate()

esp_err_t rb::half_duplex::uart_get_baudrate ( uart_port_t  uart_num,
uint32_t *  baudrate 
)

Get UART baud rate.

Parameters
uart_numUART_NUM_0, UART_NUM_1 or UART_NUM_2
baudratePointer to accept value of UART baud rate
Returns
  • ESP_FAIL Parameter error
  • ESP_OK Success, result will be put in (*baudrate)

◆ uart_get_buffered_data_len()

esp_err_t rb::half_duplex::uart_get_buffered_data_len ( uart_port_t  uart_num,
size_t *  size 
)

UART get RX ring buffer cached data length.

Parameters
uart_numUART port number.
sizePointer of size_t to accept cached data length
Returns
  • ESP_OK Success
  • ESP_FAIL Parameter error

◆ uart_get_collision_flag()

esp_err_t rb::half_duplex::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 variable pointed by collision_flag. *collision_flag = true, if collision detected else it is equal to false. This function should be executed when actual transmission is completed (after uart_write_bytes()).

Parameters
uart_numUart number to configure
collision_flagPointer to variable of type bool to return collision flag.
Returns
  • ESP_OK Success
  • ESP_ERR_INVALID_ARG Parameter error

◆ uart_get_hw_flow_ctrl()

esp_err_t rb::half_duplex::uart_get_hw_flow_ctrl ( uart_port_t  uart_num,
uart_hw_flowcontrol_t *  flow_ctrl 
)

Get hardware flow control mode.

Parameters
uart_numUART_NUM_0, UART_NUM_1 or UART_NUM_2
flow_ctrlOption for different flow control mode.
Returns
  • ESP_FAIL Parameter error
  • ESP_OK Success, result will be put in (*flow_ctrl)

◆ uart_get_parity()

esp_err_t rb::half_duplex::uart_get_parity ( uart_port_t  uart_num,
uart_parity_t *  parity_mode 
)

Get UART parity mode.

Parameters
uart_numUART_NUM_0, UART_NUM_1 or UART_NUM_2
parity_modePointer to accept value of UART parity mode.
Returns
  • ESP_FAIL Parameter error
  • ESP_OK Success, result will be put in (*parity_mode)

◆ uart_get_selectlock()

portMUX_TYPE* rb::half_duplex::uart_get_selectlock ( )

◆ uart_get_stop_bits()

esp_err_t rb::half_duplex::uart_get_stop_bits ( uart_port_t  uart_num,
uart_stop_bits_t *  stop_bits 
)

Get UART stop bits.

Parameters
uart_numUART_NUM_0, UART_NUM_1 or UART_NUM_2
stop_bitsPointer to accept value of UART stop bits.
Returns
  • ESP_FAIL Parameter error
  • ESP_OK Success, result will be put in (*stop_bit)

◆ uart_get_wakeup_threshold()

esp_err_t rb::half_duplex::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.

See description of uart_set_wakeup_threshold for the explanation of UART wakeup feature.

Parameters
uart_numUART number
[out]out_wakeup_thresholdoutput, set to the current value of wakeup threshold for the given UART.
Returns
  • ESP_OK on success
  • ESP_ERR_INVALID_ARG if out_wakeup_threshold is NULL

◆ uart_get_word_length()

esp_err_t rb::half_duplex::uart_get_word_length ( uart_port_t  uart_num,
uart_word_length_t *  data_bit 
)

Get UART data bits.

Parameters
uart_numUART_NUM_0, UART_NUM_1 or UART_NUM_2
data_bitPointer to accept value of UART data bits.
Returns
  • ESP_FAIL Parameter error
  • ESP_OK Success, result will be put in (*data_bit)

◆ uart_intr_config()

esp_err_t rb::half_duplex::uart_intr_config ( uart_port_t  uart_num,
const uart_intr_config_t *  intr_conf 
)

Configure UART interrupts.

Parameters
uart_numUART_NUM_0, UART_NUM_1 or UART_NUM_2
intr_confUART interrupt settings
Returns
  • ESP_OK Success
  • ESP_FAIL Parameter error

◆ uart_isr_free()

esp_err_t rb::half_duplex::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_isr_register was called.

Parameters
uart_numUART_NUM_0, UART_NUM_1 or UART_NUM_2
Returns
  • ESP_OK Success
  • ESP_FAIL Parameter error

◆ uart_isr_register()

esp_err_t rb::half_duplex::uart_isr_register ( uart_port_t  uart_num,
void(*)(void *)  fn,
void *  arg,
int  intr_alloc_flags,
uart_isr_handle_t *  handle 
)

Register UART interrupt handler (ISR).

Note
UART ISR handler will be attached to the same CPU core that this function is running on.
Parameters
uart_numUART_NUM_0, UART_NUM_1 or UART_NUM_2
fnInterrupt handler function.
argparameter for handler function
intr_alloc_flagsFlags used to allocate the interrupt. One or multiple (ORred) ESP_INTR_FLAG_* values. See esp_intr_alloc.h for more info.
handlePointer to return handle. If non-NULL, a handle for the interrupt will be returned here.
Returns
  • ESP_OK Success
  • ESP_FAIL Parameter error

◆ uart_param_config()

esp_err_t rb::half_duplex::uart_param_config ( uart_port_t  uart_num,
const uart_config_t *  uart_config 
)

Set UART configuration parameters.

Parameters
uart_numUART_NUM_0, UART_NUM_1 or UART_NUM_2
uart_configUART parameter settings
Returns
  • ESP_OK Success
  • ESP_FAIL Parameter error

◆ uart_pattern_dequeue()

static esp_err_t rb::half_duplex::uart_pattern_dequeue ( uart_port_t  uart_num)
static

◆ uart_pattern_enqueue()

static esp_err_t IRAM_ATTR rb::half_duplex::uart_pattern_enqueue ( uart_port_t  uart_num,
int  pos 
)
static

◆ uart_pattern_get_pos()

int rb::half_duplex::uart_pattern_get_pos ( uart_port_t  uart_num)

Return the nearest detected pattern position in buffer. The positions of the detected pattern are saved in a queue, This function do nothing to the queue.

Note
If the RX buffer is full and flow control is not enabled, the detected pattern may not be found in the rx buffer due to overflow.

The following APIs will modify the pattern position info: uart_flush_input, uart_read_bytes, uart_driver_delete, uart_pop_pattern_pos It is the application's responsibility to ensure atomic access to the pattern queue and the rx data buffer when using pattern detect feature.

Parameters
uart_numUART port number
Returns
  • (-1) No pattern found for current index or parameter error
  • others the pattern position in rx buffer.

◆ uart_pattern_link_free()

static esp_err_t rb::half_duplex::uart_pattern_link_free ( uart_port_t  uart_num)
static

◆ uart_pattern_pop_pos()

int rb::half_duplex::uart_pattern_pop_pos ( uart_port_t  uart_num)

Return the nearest detected pattern position in buffer. The positions of the detected pattern are saved in a queue, this function will dequeue the first pattern position and move the pointer to next pattern position.

Note
If the RX buffer is full and flow control is not enabled, the detected pattern may not be found in the rx buffer due to overflow.

The following APIs will modify the pattern position info: uart_flush_input, uart_read_bytes, uart_driver_delete, uart_pop_pattern_pos It is the application's responsibility to ensure atomic access to the pattern queue and the rx data buffer when using pattern detect feature.

Parameters
uart_numUART port number
Returns
  • (-1) No pattern found for current index or parameter error
  • others the pattern position in rx buffer.

◆ uart_pattern_queue_reset()

esp_err_t rb::half_duplex::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.

Parameters
uart_numUART port number
queue_lengthMax queue length for the detected pattern. If the queue length is not large enough, some pattern positions might be lost. Set this value to the maximum number of patterns that could be saved in data buffer at the same time.
Returns
  • ESP_ERR_NO_MEM No enough memory
  • ESP_ERR_INVALID_STATE Driver not installed
  • ESP_FAIL Parameter error
  • ESP_OK Success

◆ uart_pattern_queue_update()

static esp_err_t rb::half_duplex::uart_pattern_queue_update ( uart_port_t  uart_num,
int  diff_len 
)
static

◆ uart_read_bytes()

int rb::half_duplex::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.

Parameters
uart_numUART_NUM_0, UART_NUM_1 or UART_NUM_2
bufpointer to the buffer.
lengthdata length
ticks_to_waitsTimeout, count in RTOS ticks
Returns
  • (-1) Error
  • OTHERS (>=0) The number of bytes read from UART FIFO

◆ uart_reset_rx_fifo()

static esp_err_t IRAM_ATTR rb::half_duplex::uart_reset_rx_fifo ( uart_port_t  uart_num)
static

◆ uart_rx_intr_handler_default()

static void IRAM_ATTR rb::half_duplex::uart_rx_intr_handler_default ( void *  param)
static

◆ uart_set_baudrate()

esp_err_t rb::half_duplex::uart_set_baudrate ( uart_port_t  uart_num,
uint32_t  baudrate 
)

Set UART baud rate.

Parameters
uart_numUART_NUM_0, UART_NUM_1 or UART_NUM_2
baudrateUART baud rate.
Returns
  • ESP_FAIL Parameter error
  • ESP_OK Success

◆ uart_set_dtr()

esp_err_t rb::half_duplex::uart_set_dtr ( uart_port_t  uart_num,
int  level 
)

Manually set the UART DTR pin level.

Parameters
uart_numUART_NUM_0, UART_NUM_1 or UART_NUM_2
level1: DTR output low; 0: DTR output high
Returns
  • ESP_OK Success
  • ESP_FAIL Parameter error

◆ uart_set_half_duplex_pin()

void rb::half_duplex::uart_set_half_duplex_pin ( uart_port_t  uart_num,
gpio_num_t  pin 
)

◆ uart_set_hw_flow_ctrl()

esp_err_t rb::half_duplex::uart_set_hw_flow_ctrl ( uart_port_t  uart_num,
uart_hw_flowcontrol_t  flow_ctrl,
uint8_t  rx_thresh 
)

Set hardware flow control.

Parameters
uart_numUART_NUM_0, UART_NUM_1 or UART_NUM_2
flow_ctrlHardware flow control mode
rx_threshThreshold of Hardware RX flow control (0 ~ UART_FIFO_LEN). Only when UART_HW_FLOWCTRL_RTS is set, will the rx_thresh value be set.
Returns
  • ESP_OK Success
  • ESP_FAIL Parameter error

◆ uart_set_line_inverse()

esp_err_t rb::half_duplex::uart_set_line_inverse ( uart_port_t  uart_num,
uint32_t  inverse_mask 
)

Set UART line inverse mode.

Parameters
uart_numUART_NUM_0, UART_NUM_1 or UART_NUM_2
inverse_maskChoose the wires that need to be inverted. Inverse_mask should be chosen from UART_INVERSE_RXD / UART_INVERSE_TXD / UART_INVERSE_RTS / UART_INVERSE_CTS, combined with OR operation.
Returns
  • ESP_OK Success
  • ESP_FAIL Parameter error

◆ uart_set_mode()

esp_err_t rb::half_duplex::uart_set_mode ( uart_port_t  uart_num,
uart_mode_t  mode 
)

UART set communication mode.

Note
This function must be executed after uart_driver_install(), when the driver object is initialized.
Parameters
uart_numUart number to configure
modeUART UART mode to set
Returns
  • ESP_OK Success
  • ESP_ERR_INVALID_ARG Parameter error

◆ uart_set_parity()

esp_err_t rb::half_duplex::uart_set_parity ( uart_port_t  uart_num,
uart_parity_t  parity_mode 
)

Set UART parity mode.

Parameters
uart_numUART_NUM_0, UART_NUM_1 or UART_NUM_2
parity_modethe enum of uart parity configuration
Returns
  • ESP_FAIL Parameter error
  • ESP_OK Success

◆ uart_set_pin()

esp_err_t rb::half_duplex::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.

Note
Internal signal can be output to multiple GPIO pads. Only one GPIO pad can connect with input signal.
Instead of GPIO number a macro 'UART_PIN_NO_CHANGE' may be provided to keep the currently allocated pin.
Parameters
uart_numUART_NUM_0, UART_NUM_1 or UART_NUM_2
tx_io_numUART TX pin GPIO number.
rx_io_numUART RX pin GPIO number.
rts_io_numUART RTS pin GPIO number.
cts_io_numUART CTS pin GPIO number.
Returns
  • ESP_OK Success
  • ESP_FAIL Parameter error

◆ uart_set_rts()

esp_err_t rb::half_duplex::uart_set_rts ( uart_port_t  uart_num,
int  level 
)

Manually set the UART RTS pin level.

Note
UART must be configured with hardware flow control disabled.
Parameters
uart_numUART_NUM_0, UART_NUM_1 or UART_NUM_2
level1: RTS output low (active); 0: RTS output high (block)
Returns
  • ESP_OK Success
  • ESP_FAIL Parameter error

◆ uart_set_rx_timeout()

esp_err_t rb::half_duplex::uart_set_rx_timeout ( uart_port_t  uart_num,
const uint8_t  tout_thresh 
)

UART set threshold timeout for TOUT feature.

Parameters
uart_numUart number to configure
tout_threshThis parameter defines timeout threshold in uart symbol periods. The maximum value of threshold is 126. tout_thresh = 1, defines TOUT interrupt timeout equal to transmission time of one symbol (~11 bit) on current baudrate. If the time is expired the UART_RXFIFO_TOUT_INT interrupt is triggered. If tout_thresh == 0, the TOUT feature is disabled.
Returns
  • ESP_OK Success
  • ESP_ERR_INVALID_ARG Parameter error
  • ESP_ERR_INVALID_STATE Driver is not installed

◆ uart_set_select_notif_callback()

void rb::half_duplex::uart_set_select_notif_callback ( uart_port_t  uart_num,
uart_select_notif_callback_t  uart_select_notif_callback 
)

◆ uart_set_stop_bits()

esp_err_t rb::half_duplex::uart_set_stop_bits ( uart_port_t  uart_num,
uart_stop_bits_t  stop_bits 
)

Set UART stop bits.

Parameters
uart_numUART_NUM_0, UART_NUM_1 or UART_NUM_2
stop_bitsUART stop bits
Returns
  • ESP_OK Success
  • ESP_FAIL Fail

◆ uart_set_sw_flow_ctrl()

esp_err_t rb::half_duplex::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.

Parameters
uart_numUART_NUM_0, UART_NUM_1 or UART_NUM_2
enableswitch on or off
rx_thresh_xonlow water mark
rx_thresh_xoffhigh water mark
Returns
  • ESP_OK Success
  • ESP_FAIL Parameter error

◆ uart_set_tx_idle_num()

esp_err_t rb::half_duplex::uart_set_tx_idle_num ( uart_port_t  uart_num,
uint16_t  idle_num 
)

Set UART idle interval after tx FIFO is empty.

Parameters
uart_numUART_NUM_0, UART_NUM_1 or UART_NUM_2
idle_numidle interval after tx FIFO is empty(unit: the time it takes to send one bit under current baudrate)
Returns
  • ESP_OK Success
  • ESP_FAIL Parameter error

◆ uart_set_wakeup_threshold()

esp_err_t rb::half_duplex::uart_set_wakeup_threshold ( uart_port_t  uart_num,
int  wakeup_threshold 
)

Set the number of RX pin signal edges for light sleep wakeup.

UART can be used to wake up the system from light sleep. This feature works by counting the number of positive edges on RX pin and comparing the count to the threshold. When the count exceeds the threshold, system is woken up from light sleep. This function allows setting the threshold value.

Stop bit and parity bits (if enabled) also contribute to the number of edges. For example, letter 'a' with ASCII code 97 is encoded as 0100001101 on the wire (with 8n1 configuration), start and stop bits included. This sequence has 3 positive edges (transitions from 0 to 1). Therefore, to wake up the system when 'a' is sent, set wakeup_threshold=3.

The character that triggers wakeup is not received by UART (i.e. it can not be obtained from UART FIFO). Depending on the baud rate, a few characters after that will also not be received. Note that when the chip enters and exits light sleep mode, APB frequency will be changing. To make sure that UART has correct baud rate all the time, select REF_TICK as UART clock source, by setting use_ref_tick field in uart_config_t to true.

Note
in ESP32, the wakeup signal can only be input via IO_MUX (i.e. GPIO3 should be configured as function_1 to wake up UART0, GPIO9 should be configured as function_5 to wake up UART1), UART2 does not support light sleep wakeup feature.
Parameters
uart_numUART number
wakeup_thresholdnumber of RX edges for light sleep wakeup, value is 3 .. 0x3ff.
Returns
  • ESP_OK on success
  • ESP_ERR_INVALID_ARG if uart_num is incorrect or wakeup_threshold is outside of [3, 0x3ff] range.

◆ uart_set_word_length()

esp_err_t rb::half_duplex::uart_set_word_length ( uart_port_t  uart_num,
uart_word_length_t  data_bit 
)

Set UART data bits.

Parameters
uart_numUART_NUM_0, UART_NUM_1 or UART_NUM_2
data_bitUART data bits
Returns
  • ESP_OK Success
  • ESP_FAIL Parameter error

◆ uart_tx_chars()

int rb::half_duplex::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.

This function will not wait for enough space in TX FIFO. It will just fill the available TX FIFO and return when the FIFO is full.

Note
This function should only be used when UART TX buffer is not enabled.
Parameters
uart_numUART_NUM_0, UART_NUM_1 or UART_NUM_2
bufferdata buffer address
lendata length to send
Returns
  • (-1) Parameter error
  • OTHERS (>=0) The number of bytes pushed to the TX FIFO

◆ uart_wait_tx_done()

esp_err_t rb::half_duplex::uart_wait_tx_done ( uart_port_t  uart_num,
TickType_t  ticks_to_wait 
)

Wait until UART TX FIFO is empty.

Parameters
uart_numUART_NUM_0, UART_NUM_1 or UART_NUM_2
ticks_to_waitTimeout, count in RTOS ticks
Returns
  • ESP_OK Success
  • ESP_FAIL Parameter error
  • ESP_ERR_TIMEOUT Timeout

◆ uart_write_bytes()

int rb::half_duplex::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,.

If the UART driver's parameter 'tx_buffer_size' is set to zero: This function will not return until all the data have been sent out, or at least pushed into TX FIFO.

Otherwise, if the 'tx_buffer_size' > 0, this function will return after copying all the data to tx ring buffer, UART ISR will then move data from the ring buffer to TX FIFO gradually.

Parameters
uart_numUART_NUM_0, UART_NUM_1 or UART_NUM_2
srcdata buffer address
sizedata length to send
Returns
  • (-1) Parameter error
  • OTHERS (>=0) The number of bytes pushed to the TX FIFO

◆ uart_write_bytes_with_break()

int rb::half_duplex::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,.

If the UART driver's parameter 'tx_buffer_size' is set to zero: This function will not return until all the data and the break signal have been sent out. After all data is sent out, send a break signal.

Otherwise, if the 'tx_buffer_size' > 0, this function will return after copying all the data to tx ring buffer, UART ISR will then move data from the ring buffer to TX FIFO gradually. After all data sent out, send a break signal.

Parameters
uart_numUART_NUM_0, UART_NUM_1 or UART_NUM_2
srcdata buffer address
sizedata length to send
brk_lenbreak signal duration(unit: the time it takes to send one bit at current baudrate)
Returns
  • (-1) Parameter error
  • OTHERS (>=0) The number of bytes pushed to the TX FIFO

Variable Documentation

◆ p_uart_obj

uart_obj_t* rb::half_duplex::p_uart_obj[UART_NUM_MAX] = {0}
static

◆ UART

DRAM_ATTR uart_dev_t* const rb::half_duplex::UART[UART_NUM_MAX] = {&UART0, &UART1, &UART2}
static

◆ uart_selectlock

portMUX_TYPE rb::half_duplex::uart_selectlock = portMUX_INITIALIZER_UNLOCKED
static

◆ uart_spinlock

portMUX_TYPE rb::half_duplex::uart_spinlock[UART_NUM_MAX] = {portMUX_INITIALIZER_UNLOCKED, portMUX_INITIALIZER_UNLOCKED, portMUX_INITIALIZER_UNLOCKED}
static

◆ UART_TAG

const char* rb::half_duplex::UART_TAG = "uart"
static