*/
esp_err_t uart_set_hw_flow_ctrl(uart_port_t uart_num, uart_hw_flowcontrol_t flow_ctrl, uint8_t rx_thresh);
+/**
+ * @brief Set software flow control.
+ *
+ * @param uart_num UART_NUM_0, UART_NUM_1 or UART_NUM_2
+ * @param enable switch on or off
+ * @param rx_thresh_xon low water mark
+ * @param rx_thresh_xoff high water mark
+ *
+ * @return
+ * - ESP_OK Success
+ * - ESP_FAIL Parameter error
+ */
+ 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);
+
/**
* @brief Get hardware flow control mode
*
#include "driver/uart.h"
#include "driver/gpio.h"
+#define XOFF (char)0x13
+#define XON (char)0x11
+
static const char* UART_TAG = "uart";
#define UART_CHECK(a, str, ret_val) \
if (!(a)) { \
return ESP_OK;
}
+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)
+{
+ UART_CHECK((uart_num < UART_NUM_MAX), "uart_num error", ESP_FAIL);
+ UART_CHECK((rx_thresh_xon < UART_FIFO_LEN), "rx flow xon thresh error", ESP_FAIL);
+ UART_CHECK((rx_thresh_xoff < UART_FIFO_LEN), "rx flow xon thresh error", ESP_FAIL);
+ UART_ENTER_CRITICAL(&uart_spinlock[uart_num]);
+ UART[uart_num]->flow_conf.sw_flow_con_en = enable? 1:0;
+ UART[uart_num]->flow_conf.xonoff_del = enable?1:0;
+ UART[uart_num]->swfc_conf.xon_threshold = rx_thresh_xon;
+ UART[uart_num]->swfc_conf.xoff_threshold = rx_thresh_xoff;
+ UART[uart_num]->swfc_conf.xon_char = XON;
+ UART[uart_num]->swfc_conf.xoff_char = XOFF;
+ UART_EXIT_CRITICAL(&uart_spinlock[uart_num]);
+ return ESP_OK;
+}
+
//only when UART_HW_FLOWCTRL_RTS is set , will the rx_thresh value be set.
esp_err_t uart_set_hw_flow_ctrl(uart_port_t uart_num, uart_hw_flowcontrol_t flow_ctrl, uint8_t rx_thresh)
{