RBControl
Library for the RB3201-RBControl board with the ESP32 by RoboticsBrno.
half_duplex_uart.h
Go to the documentation of this file.
1 // clang-format off
2 
3 // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #ifndef _RB_HALF_DUPLEX_UART_H_
18 #define _RB_HALF_DUPLEX_UART_H_
19 
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 #include "soc/uart_reg.h"
26 #include "soc/uart_struct.h"
27 #include "esp_err.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"
39 
40 #ifdef __cplusplus
41 }
42 #endif
43 
44 namespace rb {
45 namespace half_duplex {
46 
57 esp_err_t uart_set_word_length(uart_port_t uart_num, uart_word_length_t data_bit);
58 
69 esp_err_t uart_get_word_length(uart_port_t uart_num, uart_word_length_t* data_bit);
70 
81 esp_err_t uart_set_stop_bits(uart_port_t uart_num, uart_stop_bits_t stop_bits);
82 
93 esp_err_t uart_get_stop_bits(uart_port_t uart_num, uart_stop_bits_t* stop_bits);
94 
105 esp_err_t uart_set_parity(uart_port_t uart_num, uart_parity_t parity_mode);
106 
118 esp_err_t uart_get_parity(uart_port_t uart_num, uart_parity_t* parity_mode);
119 
130 esp_err_t uart_set_baudrate(uart_port_t uart_num, uint32_t baudrate);
131 
143 esp_err_t uart_get_baudrate(uart_port_t uart_num, uint32_t* baudrate);
144 
158 esp_err_t uart_set_line_inverse(uart_port_t uart_num, uint32_t inverse_mask);
159 
172 esp_err_t uart_set_hw_flow_ctrl(uart_port_t uart_num, uart_hw_flowcontrol_t flow_ctrl, uint8_t rx_thresh);
173 
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);
187 
198 esp_err_t uart_get_hw_flow_ctrl(uart_port_t uart_num, uart_hw_flowcontrol_t* flow_ctrl);
199 
211 esp_err_t uart_clear_intr_status(uart_port_t uart_num, uint32_t clr_mask);
212 
224 esp_err_t uart_enable_intr_mask(uart_port_t uart_num, uint32_t enable_mask);
225 
237 esp_err_t uart_disable_intr_mask(uart_port_t uart_num, uint32_t disable_mask);
238 
248 esp_err_t uart_enable_rx_intr(uart_port_t uart_num);
249 
259 esp_err_t uart_disable_rx_intr(uart_port_t uart_num);
260 
270 esp_err_t uart_disable_tx_intr(uart_port_t uart_num);
271 
283 esp_err_t uart_enable_tx_intr(uart_port_t uart_num, int enable, int thresh);
284 
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);
303 
314 esp_err_t uart_isr_free(uart_port_t uart_num);
315 
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);
336 
348 esp_err_t uart_set_rts(uart_port_t uart_num, int level);
349 
360 esp_err_t uart_set_dtr(uart_port_t uart_num, int level);
361 
373 esp_err_t uart_set_tx_idle_num(uart_port_t uart_num, uint16_t idle_num);
374 
385 esp_err_t uart_param_config(uart_port_t uart_num, const uart_config_t *uart_config);
386 
397 esp_err_t uart_intr_config(uart_port_t uart_num, const uart_intr_config_t *intr_conf);
398 
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);
422 
432 esp_err_t uart_driver_delete(uart_port_t uart_num);
433 
445 esp_err_t uart_wait_tx_done(uart_port_t uart_num, TickType_t ticks_to_wait);
446 
461 int uart_tx_chars(uart_port_t uart_num, const char* buffer, uint32_t len);
462 
480 int uart_write_bytes(uart_port_t uart_num, const char* src, size_t size);
481 
502 int uart_write_bytes_with_break(uart_port_t uart_num, const char* src, size_t size, int brk_len);
503 
516 int uart_read_bytes(uart_port_t uart_num, uint8_t* buf, uint32_t length, TickType_t ticks_to_wait);
517 
529 esp_err_t uart_flush(uart_port_t uart_num);
530 
540 esp_err_t uart_flush_input(uart_port_t uart_num);
541 
552 esp_err_t uart_get_buffered_data_len(uart_port_t uart_num, size_t* size);
553 
565 esp_err_t uart_disable_pattern_det_intr(uart_port_t uart_num);
566 
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);
587 
605 int uart_pattern_pop_pos(uart_port_t uart_num);
606 
624 int uart_pattern_get_pos(uart_port_t uart_num);
625 
638 esp_err_t uart_pattern_queue_reset(uart_port_t uart_num, int queue_length);
639 
650 esp_err_t uart_set_mode(uart_port_t uart_num, uart_mode_t mode);
651 
666 esp_err_t uart_set_rx_timeout(uart_port_t uart_num, const uint8_t tout_thresh);
667 
681 esp_err_t uart_get_collision_flag(uart_port_t uart_num, bool* collision_flag);
682 
716 esp_err_t uart_set_wakeup_threshold(uart_port_t uart_num, int wakeup_threshold);
717 
731 esp_err_t uart_get_wakeup_threshold(uart_port_t uart_num, int* out_wakeup_threshold);
732 
733 void uart_set_half_duplex_pin(uart_port_t uart_num, gpio_num_t pin);
734 
735 }; // namespace half_duplex
736 }; // namespace rb
737 
738 #endif /*_RB_HALF_DUPLEX_UART_H_*/
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