2019-06-14 03:01:30 +00:00
|
|
|
// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD
|
2016-12-15 01:45:40 +00:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
2019-06-14 03:01:30 +00:00
|
|
|
//
|
2016-12-15 01:45:40 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2019-06-14 03:01:30 +00:00
|
|
|
#pragma once
|
2016-12-15 01:45:40 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "esp_err.h"
|
2016-12-19 04:52:10 +00:00
|
|
|
#include "esp_intr_alloc.h"
|
2016-12-15 01:45:40 +00:00
|
|
|
#include "freertos/FreeRTOS.h"
|
|
|
|
#include "freertos/semphr.h"
|
|
|
|
#include "freertos/xtensa_api.h"
|
|
|
|
#include "freertos/task.h"
|
|
|
|
#include "freertos/queue.h"
|
|
|
|
#include "freertos/ringbuf.h"
|
2019-04-17 12:19:44 +00:00
|
|
|
#include "hal/uart_types.h"
|
|
|
|
#include "soc/uart_caps.h"
|
2016-12-15 01:45:40 +00:00
|
|
|
|
2019-04-17 12:19:44 +00:00
|
|
|
// Valid UART port number
|
|
|
|
#define UART_NUM_0 (0) /*!< UART port 0 */
|
|
|
|
#define UART_NUM_1 (1) /*!< UART port 1 */
|
2019-06-14 03:01:30 +00:00
|
|
|
#if SOC_UART_NUM > 2
|
2019-04-17 12:19:44 +00:00
|
|
|
#define UART_NUM_2 (2) /*!< UART port 2 */
|
2019-06-14 03:01:30 +00:00
|
|
|
#endif
|
2019-04-17 12:19:44 +00:00
|
|
|
#define UART_NUM_MAX (SOC_UART_NUM) /*!< UART port max */
|
2016-12-15 01:45:40 +00:00
|
|
|
|
2019-04-17 12:19:44 +00:00
|
|
|
#define UART_PIN_NO_CHANGE (-1) /*!< Constant for uart_set_pin function which indicates that UART pin should not be changed */
|
2016-12-15 01:45:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief UART interrupt configuration parameters for uart_intr_config function
|
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
uint32_t intr_enable_mask; /*!< UART interrupt enable mask, choose from UART_XXXX_INT_ENA_M under UART_INT_ENA_REG(i), connect with bit-or operator*/
|
2017-09-27 20:03:22 +00:00
|
|
|
uint8_t rx_timeout_thresh; /*!< UART timeout interrupt threshold (unit: time of sending one byte)*/
|
2016-12-15 01:45:40 +00:00
|
|
|
uint8_t txfifo_empty_intr_thresh; /*!< UART TX empty interrupt threshold.*/
|
|
|
|
uint8_t rxfifo_full_thresh; /*!< UART RX full interrupt threshold.*/
|
|
|
|
} uart_intr_config_t;
|
|
|
|
|
|
|
|
/**
|
2017-09-27 20:03:22 +00:00
|
|
|
* @brief UART event types used in the ring buffer
|
2016-12-15 01:45:40 +00:00
|
|
|
*/
|
|
|
|
typedef enum {
|
|
|
|
UART_DATA, /*!< UART data event*/
|
|
|
|
UART_BREAK, /*!< UART break event*/
|
|
|
|
UART_BUFFER_FULL, /*!< UART RX buffer full event*/
|
|
|
|
UART_FIFO_OVF, /*!< UART FIFO overflow event*/
|
|
|
|
UART_FRAME_ERR, /*!< UART RX frame error event*/
|
|
|
|
UART_PARITY_ERR, /*!< UART RX parity event*/
|
|
|
|
UART_DATA_BREAK, /*!< UART TX data and break event*/
|
2017-05-11 13:59:50 +00:00
|
|
|
UART_PATTERN_DET, /*!< UART pattern detected */
|
2016-12-15 01:45:40 +00:00
|
|
|
UART_EVENT_MAX, /*!< UART event max index*/
|
|
|
|
} uart_event_type_t;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Event structure used in UART event queue
|
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
uart_event_type_t type; /*!< UART event type */
|
|
|
|
size_t size; /*!< UART data size for UART_DATA event*/
|
|
|
|
} uart_event_t;
|
|
|
|
|
2016-12-19 04:52:10 +00:00
|
|
|
typedef intr_handle_t uart_isr_handle_t;
|
|
|
|
|
2019-04-17 12:19:44 +00:00
|
|
|
/**
|
|
|
|
* @brief Install UART driver and set the UART to the default configuration.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
|
|
|
* @param rx_buffer_size UART RX ring buffer size.
|
|
|
|
* @param tx_buffer_size UART 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.
|
|
|
|
* @param queue_size UART event queue size/depth.
|
|
|
|
* @param uart_queue UART 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.
|
|
|
|
* @param intr_alloc_flags Flags 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)
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_FAIL Parameter error
|
|
|
|
*/
|
|
|
|
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);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Uninstall UART driver.
|
|
|
|
*
|
|
|
|
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_FAIL Parameter error
|
|
|
|
*/
|
|
|
|
esp_err_t uart_driver_delete(uart_port_t uart_num);
|
|
|
|
|
2016-12-15 01:45:40 +00:00
|
|
|
/**
|
|
|
|
* @brief Set UART data bits.
|
|
|
|
*
|
2019-04-17 12:19:44 +00:00
|
|
|
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
2016-12-15 01:45:40 +00:00
|
|
|
* @param data_bit UART data bits
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_FAIL Parameter error
|
|
|
|
*/
|
|
|
|
esp_err_t uart_set_word_length(uart_port_t uart_num, uart_word_length_t data_bit);
|
|
|
|
|
|
|
|
/**
|
2019-04-17 12:19:44 +00:00
|
|
|
* @brief Get the UART data bit configuration.
|
2016-12-15 01:45:40 +00:00
|
|
|
*
|
2019-04-17 12:19:44 +00:00
|
|
|
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
2016-12-15 01:45:40 +00:00
|
|
|
* @param data_bit Pointer to accept value of UART data bits.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_FAIL Parameter error
|
|
|
|
* - ESP_OK Success, result will be put in (*data_bit)
|
|
|
|
*/
|
|
|
|
esp_err_t uart_get_word_length(uart_port_t uart_num, uart_word_length_t* data_bit);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Set UART stop bits.
|
|
|
|
*
|
2019-04-17 12:19:44 +00:00
|
|
|
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
2016-12-15 01:45:40 +00:00
|
|
|
* @param stop_bits UART stop bits
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_FAIL Fail
|
|
|
|
*/
|
|
|
|
esp_err_t uart_set_stop_bits(uart_port_t uart_num, uart_stop_bits_t stop_bits);
|
|
|
|
|
|
|
|
/**
|
2019-04-17 12:19:44 +00:00
|
|
|
* @brief Get the UART stop bit configuration.
|
2016-12-15 01:45:40 +00:00
|
|
|
*
|
2019-04-17 12:19:44 +00:00
|
|
|
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
2016-12-15 01:45:40 +00:00
|
|
|
* @param stop_bits Pointer to accept value of UART stop bits.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_FAIL Parameter error
|
|
|
|
* - ESP_OK Success, result will be put in (*stop_bit)
|
|
|
|
*/
|
|
|
|
esp_err_t uart_get_stop_bits(uart_port_t uart_num, uart_stop_bits_t* stop_bits);
|
|
|
|
|
|
|
|
/**
|
2017-09-27 20:03:22 +00:00
|
|
|
* @brief Set UART parity mode.
|
2016-12-15 01:45:40 +00:00
|
|
|
*
|
2019-04-17 12:19:44 +00:00
|
|
|
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
2016-12-15 01:45:40 +00:00
|
|
|
* @param parity_mode the enum of uart parity configuration
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_FAIL Parameter error
|
|
|
|
* - ESP_OK Success
|
|
|
|
*/
|
|
|
|
esp_err_t uart_set_parity(uart_port_t uart_num, uart_parity_t parity_mode);
|
|
|
|
|
|
|
|
/**
|
2019-04-17 12:19:44 +00:00
|
|
|
* @brief Get the UART parity mode configuration.
|
2016-12-15 01:45:40 +00:00
|
|
|
*
|
2019-04-17 12:19:44 +00:00
|
|
|
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
2016-12-15 01:45:40 +00:00
|
|
|
* @param parity_mode Pointer to accept value of UART parity mode.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_FAIL Parameter error
|
|
|
|
* - ESP_OK Success, result will be put in (*parity_mode)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
esp_err_t uart_get_parity(uart_port_t uart_num, uart_parity_t* parity_mode);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Set UART baud rate.
|
|
|
|
*
|
2019-04-17 12:19:44 +00:00
|
|
|
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
2016-12-15 01:45:40 +00:00
|
|
|
* @param baudrate UART baud rate.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_FAIL Parameter error
|
|
|
|
* - ESP_OK Success
|
|
|
|
*/
|
|
|
|
esp_err_t uart_set_baudrate(uart_port_t uart_num, uint32_t baudrate);
|
|
|
|
|
|
|
|
/**
|
2019-04-17 12:19:44 +00:00
|
|
|
* @brief Get the UART baud rate configuration.
|
2016-12-15 01:45:40 +00:00
|
|
|
*
|
2019-04-17 12:19:44 +00:00
|
|
|
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
2016-12-15 01:45:40 +00:00
|
|
|
* @param baudrate Pointer to accept value of UART baud rate
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_FAIL Parameter error
|
|
|
|
* - ESP_OK Success, result will be put in (*baudrate)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
esp_err_t uart_get_baudrate(uart_port_t uart_num, uint32_t* baudrate);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Set UART line inverse mode
|
|
|
|
*
|
2019-04-17 12:19:44 +00:00
|
|
|
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
|
|
|
* @param inverse_mask Choose the wires that need to be inverted. Using the ORred mask of `uart_signal_inv_t`
|
2016-12-15 01:45:40 +00:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_FAIL Parameter error
|
|
|
|
*/
|
|
|
|
esp_err_t uart_set_line_inverse(uart_port_t uart_num, uint32_t inverse_mask);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Set hardware flow control.
|
|
|
|
*
|
2019-04-17 12:19:44 +00:00
|
|
|
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
2016-12-15 01:45:40 +00:00
|
|
|
* @param flow_ctrl Hardware flow control mode
|
2017-09-27 20:03:22 +00:00
|
|
|
* @param rx_thresh Threshold of Hardware RX flow control (0 ~ UART_FIFO_LEN).
|
|
|
|
* Only when UART_HW_FLOWCTRL_RTS is set, will the rx_thresh value be set.
|
2016-12-15 01:45:40 +00:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_FAIL Parameter error
|
|
|
|
*/
|
|
|
|
esp_err_t uart_set_hw_flow_ctrl(uart_port_t uart_num, uart_hw_flowcontrol_t flow_ctrl, uint8_t rx_thresh);
|
|
|
|
|
2017-08-01 15:02:44 +00:00
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
*/
|
2019-04-17 12:19:44 +00:00
|
|
|
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);
|
2017-08-01 15:02:44 +00:00
|
|
|
|
2016-12-15 01:45:40 +00:00
|
|
|
/**
|
2019-04-17 12:19:44 +00:00
|
|
|
* @brief Get the UART hardware flow control configuration.
|
2016-12-15 01:45:40 +00:00
|
|
|
*
|
2019-04-17 12:19:44 +00:00
|
|
|
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
2016-12-15 01:45:40 +00:00
|
|
|
* @param flow_ctrl Option for different flow control mode.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_FAIL Parameter error
|
|
|
|
* - ESP_OK Success, result will be put in (*flow_ctrl)
|
|
|
|
*/
|
|
|
|
esp_err_t uart_get_hw_flow_ctrl(uart_port_t uart_num, uart_hw_flowcontrol_t* flow_ctrl);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Clear UART interrupt status
|
|
|
|
*
|
2019-04-17 12:19:44 +00:00
|
|
|
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
2017-09-27 20:03:22 +00:00
|
|
|
* @param clr_mask Bit mask of the interrupt status to be cleared.
|
2016-12-15 01:45:40 +00:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_FAIL Parameter error
|
|
|
|
*/
|
|
|
|
esp_err_t uart_clear_intr_status(uart_port_t uart_num, uint32_t clr_mask);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Set UART interrupt enable
|
|
|
|
*
|
2019-04-17 12:19:44 +00:00
|
|
|
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
2016-12-15 01:45:40 +00:00
|
|
|
* @param enable_mask Bit mask of the enable bits.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_FAIL Parameter error
|
|
|
|
*/
|
|
|
|
esp_err_t uart_enable_intr_mask(uart_port_t uart_num, uint32_t enable_mask);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Clear UART interrupt enable bits
|
|
|
|
*
|
2019-04-17 12:19:44 +00:00
|
|
|
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
2016-12-15 01:45:40 +00:00
|
|
|
* @param disable_mask Bit mask of the disable bits.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_FAIL Parameter error
|
|
|
|
*/
|
|
|
|
esp_err_t uart_disable_intr_mask(uart_port_t uart_num, uint32_t disable_mask);
|
|
|
|
|
|
|
|
/**
|
2017-09-27 20:03:22 +00:00
|
|
|
* @brief Enable UART RX interrupt (RX_FULL & RX_TIMEOUT INTERRUPT)
|
2016-12-15 01:45:40 +00:00
|
|
|
*
|
2019-04-17 12:19:44 +00:00
|
|
|
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
2016-12-15 01:45:40 +00:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_FAIL Parameter error
|
|
|
|
*/
|
|
|
|
esp_err_t uart_enable_rx_intr(uart_port_t uart_num);
|
|
|
|
|
|
|
|
/**
|
2017-09-27 20:03:22 +00:00
|
|
|
* @brief Disable UART RX interrupt (RX_FULL & RX_TIMEOUT INTERRUPT)
|
2016-12-15 01:45:40 +00:00
|
|
|
*
|
2019-04-17 12:19:44 +00:00
|
|
|
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
2016-12-15 01:45:40 +00:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_FAIL Parameter error
|
|
|
|
*/
|
|
|
|
esp_err_t uart_disable_rx_intr(uart_port_t uart_num);
|
|
|
|
|
|
|
|
/**
|
2017-09-27 20:03:22 +00:00
|
|
|
* @brief Disable UART TX interrupt (TX_FULL & TX_TIMEOUT INTERRUPT)
|
2016-12-15 01:45:40 +00:00
|
|
|
*
|
2019-04-17 12:19:44 +00:00
|
|
|
* @param uart_num UART port number
|
2016-12-15 01:45:40 +00:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_FAIL Parameter error
|
|
|
|
*/
|
|
|
|
esp_err_t uart_disable_tx_intr(uart_port_t uart_num);
|
|
|
|
|
|
|
|
/**
|
2017-09-27 20:03:22 +00:00
|
|
|
* @brief Enable UART TX interrupt (TX_FULL & TX_TIMEOUT INTERRUPT)
|
2016-12-15 01:45:40 +00:00
|
|
|
*
|
2019-04-17 12:19:44 +00:00
|
|
|
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
2016-12-15 01:45:40 +00:00
|
|
|
* @param enable 1: enable; 0: disable
|
|
|
|
* @param thresh Threshold of TX interrupt, 0 ~ UART_FIFO_LEN
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_FAIL Parameter error
|
|
|
|
*/
|
|
|
|
esp_err_t uart_enable_tx_intr(uart_port_t uart_num, int enable, int thresh);
|
|
|
|
|
|
|
|
/**
|
2017-09-27 20:03:22 +00:00
|
|
|
* @brief Register UART interrupt handler (ISR).
|
2016-12-15 01:45:40 +00:00
|
|
|
*
|
|
|
|
* @note UART ISR handler will be attached to the same CPU core that this function is running on.
|
|
|
|
*
|
2019-04-17 12:19:44 +00:00
|
|
|
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
2016-12-15 01:45:40 +00:00
|
|
|
* @param fn Interrupt handler function.
|
|
|
|
* @param arg parameter for handler function
|
2017-09-27 20:03:22 +00:00
|
|
|
* @param intr_alloc_flags Flags used to allocate the interrupt. One or multiple (ORred)
|
2019-06-14 03:01:30 +00:00
|
|
|
* ESP_INTR_FLAG_* values. See esp_intr_alloc.h for more info.
|
2016-12-19 04:52:10 +00:00
|
|
|
* @param handle Pointer to return handle. If non-NULL, a handle for the interrupt will
|
|
|
|
* be returned here.
|
2016-12-15 01:45:40 +00:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_FAIL Parameter error
|
|
|
|
*/
|
2016-12-19 04:52:10 +00:00
|
|
|
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);
|
2016-12-15 01:45:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Free UART interrupt handler registered by uart_isr_register. Must be called on the same core as
|
|
|
|
* uart_isr_register was called.
|
|
|
|
*
|
2019-04-17 12:19:44 +00:00
|
|
|
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
2016-12-15 01:45:40 +00:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_FAIL Parameter error
|
|
|
|
*/
|
2016-12-08 04:38:22 +00:00
|
|
|
esp_err_t uart_isr_free(uart_port_t uart_num);
|
2016-12-15 01:45:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Set UART pin number
|
|
|
|
*
|
|
|
|
* @note Internal signal can be output to multiple GPIO pads.
|
2017-09-27 20:03:22 +00:00
|
|
|
* Only one GPIO pad can connect with input signal.
|
2016-12-15 01:45:40 +00:00
|
|
|
*
|
2019-06-14 03:01:30 +00:00
|
|
|
* @note Instead of GPIO number a macro 'UART_PIN_NO_CHANGE' may be provided
|
2017-09-27 20:03:22 +00:00
|
|
|
to keep the currently allocated pin.
|
|
|
|
*
|
2019-04-17 12:19:44 +00:00
|
|
|
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
2017-09-27 20:03:22 +00:00
|
|
|
* @param tx_io_num UART TX pin GPIO number.
|
|
|
|
* @param rx_io_num UART RX pin GPIO number.
|
|
|
|
* @param rts_io_num UART RTS pin GPIO number.
|
|
|
|
* @param cts_io_num UART CTS pin GPIO number.
|
2016-12-15 01:45:40 +00:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_FAIL Parameter error
|
|
|
|
*/
|
|
|
|
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);
|
|
|
|
|
|
|
|
/**
|
2017-09-27 20:03:22 +00:00
|
|
|
* @brief Manually set the UART RTS pin level.
|
|
|
|
* @note UART must be configured with hardware flow control disabled.
|
2016-12-15 01:45:40 +00:00
|
|
|
*
|
2019-04-17 12:19:44 +00:00
|
|
|
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
2017-09-27 20:03:22 +00:00
|
|
|
* @param level 1: RTS output low (active); 0: RTS output high (block)
|
2016-12-15 01:45:40 +00:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_FAIL Parameter error
|
|
|
|
*/
|
|
|
|
esp_err_t uart_set_rts(uart_port_t uart_num, int level);
|
|
|
|
|
|
|
|
/**
|
2017-09-27 20:03:22 +00:00
|
|
|
* @brief Manually set the UART DTR pin level.
|
2016-12-15 01:45:40 +00:00
|
|
|
*
|
2019-04-17 12:19:44 +00:00
|
|
|
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
2016-12-15 01:45:40 +00:00
|
|
|
* @param level 1: DTR output low; 0: DTR output high
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_FAIL Parameter error
|
|
|
|
*/
|
|
|
|
esp_err_t uart_set_dtr(uart_port_t uart_num, int level);
|
|
|
|
|
2017-10-18 04:04:59 +00:00
|
|
|
/**
|
|
|
|
* @brief Set UART idle interval after tx FIFO is empty
|
|
|
|
*
|
2019-04-17 12:19:44 +00:00
|
|
|
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
2017-10-18 04:04:59 +00:00
|
|
|
* @param idle_num idle interval after tx FIFO is empty(unit: the time it takes to send one bit
|
|
|
|
* under current baudrate)
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_FAIL Parameter error
|
|
|
|
*/
|
|
|
|
esp_err_t uart_set_tx_idle_num(uart_port_t uart_num, uint16_t idle_num);
|
|
|
|
|
2016-12-15 01:45:40 +00:00
|
|
|
/**
|
2018-04-11 06:56:00 +00:00
|
|
|
* @brief Set UART configuration parameters.
|
2016-12-15 01:45:40 +00:00
|
|
|
*
|
2019-04-17 12:19:44 +00:00
|
|
|
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
2016-12-15 01:45:40 +00:00
|
|
|
* @param uart_config UART parameter settings
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_FAIL Parameter error
|
|
|
|
*/
|
|
|
|
esp_err_t uart_param_config(uart_port_t uart_num, const uart_config_t *uart_config);
|
|
|
|
|
|
|
|
/**
|
2018-04-11 06:56:00 +00:00
|
|
|
* @brief Configure UART interrupts.
|
2016-12-15 01:45:40 +00:00
|
|
|
*
|
2019-04-17 12:19:44 +00:00
|
|
|
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
2016-12-15 01:45:40 +00:00
|
|
|
* @param intr_conf UART interrupt settings
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_FAIL Parameter error
|
|
|
|
*/
|
|
|
|
esp_err_t uart_intr_config(uart_port_t uart_num, const uart_intr_config_t *intr_conf);
|
|
|
|
|
|
|
|
/**
|
2017-09-27 20:03:22 +00:00
|
|
|
* @brief Wait until UART TX FIFO is empty.
|
2016-12-15 01:45:40 +00:00
|
|
|
*
|
2019-04-17 12:19:44 +00:00
|
|
|
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
2016-12-15 01:45:40 +00:00
|
|
|
* @param ticks_to_wait Timeout, count in RTOS ticks
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_FAIL Parameter error
|
|
|
|
* - ESP_ERR_TIMEOUT Timeout
|
|
|
|
*/
|
|
|
|
esp_err_t uart_wait_tx_done(uart_port_t uart_num, TickType_t ticks_to_wait);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Send data to the UART port from a given buffer and length.
|
2019-06-14 03:01:30 +00:00
|
|
|
*
|
2017-09-27 20:03:22 +00:00
|
|
|
* 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.
|
2016-12-15 01:45:40 +00:00
|
|
|
* @note This function should only be used when UART TX buffer is not enabled.
|
|
|
|
*
|
2019-04-17 12:19:44 +00:00
|
|
|
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
2018-04-11 06:56:00 +00:00
|
|
|
* @param buffer data buffer address
|
|
|
|
* @param len data length to send
|
2016-12-15 01:45:40 +00:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - (-1) Parameter error
|
2017-09-27 20:03:22 +00:00
|
|
|
* - OTHERS (>=0) The number of bytes pushed to the TX FIFO
|
2016-12-15 01:45:40 +00:00
|
|
|
*/
|
|
|
|
int uart_tx_chars(uart_port_t uart_num, const char* buffer, uint32_t len);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Send data to the UART port from a given buffer and length,
|
|
|
|
*
|
2017-09-27 20:03:22 +00:00
|
|
|
* If the UART driver's parameter 'tx_buffer_size' is set to zero:
|
2016-12-15 01:45:40 +00:00
|
|
|
* This function will not return until all the data have been sent out, or at least pushed into TX FIFO.
|
|
|
|
*
|
2017-09-27 20:03:22 +00:00
|
|
|
* 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.
|
2016-12-15 01:45:40 +00:00
|
|
|
*
|
2019-04-17 12:19:44 +00:00
|
|
|
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
2018-04-11 06:56:00 +00:00
|
|
|
* @param src data buffer address
|
|
|
|
* @param size data length to send
|
2016-12-15 01:45:40 +00:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - (-1) Parameter error
|
2017-09-27 20:03:22 +00:00
|
|
|
* - OTHERS (>=0) The number of bytes pushed to the TX FIFO
|
2016-12-15 01:45:40 +00:00
|
|
|
*/
|
|
|
|
int uart_write_bytes(uart_port_t uart_num, const char* src, size_t size);
|
|
|
|
|
|
|
|
/**
|
2018-04-11 06:56:00 +00:00
|
|
|
* @brief Send data to the UART port from a given buffer and length,
|
2016-12-15 01:45:40 +00:00
|
|
|
*
|
2018-07-02 07:53:21 +00:00
|
|
|
* If the UART driver's parameter 'tx_buffer_size' is set to zero:
|
2016-12-15 01:45:40 +00:00
|
|
|
* This function will not return until all the data and the break signal have been sent out.
|
2017-09-27 20:03:22 +00:00
|
|
|
* After all data is sent out, send a break signal.
|
2016-12-15 01:45:40 +00:00
|
|
|
*
|
2017-09-27 20:03:22 +00:00
|
|
|
* 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.
|
2016-12-15 01:45:40 +00:00
|
|
|
*
|
2019-04-17 12:19:44 +00:00
|
|
|
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
2016-12-15 01:45:40 +00:00
|
|
|
* @param src data buffer address
|
|
|
|
* @param size data length to send
|
2018-05-14 11:47:16 +00:00
|
|
|
* @param brk_len break signal duration(unit: the time it takes to send one bit at current baudrate)
|
2016-12-15 01:45:40 +00:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - (-1) Parameter error
|
2017-09-27 20:03:22 +00:00
|
|
|
* - OTHERS (>=0) The number of bytes pushed to the TX FIFO
|
2016-12-15 01:45:40 +00:00
|
|
|
*/
|
|
|
|
int uart_write_bytes_with_break(uart_port_t uart_num, const char* src, size_t size, int brk_len);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief UART read bytes from UART buffer
|
|
|
|
*
|
2019-04-17 12:19:44 +00:00
|
|
|
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
2016-12-15 01:45:40 +00:00
|
|
|
* @param buf pointer to the buffer.
|
|
|
|
* @param length data length
|
|
|
|
* @param ticks_to_wait sTimeout, count in RTOS ticks
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - (-1) Error
|
2017-09-27 20:03:22 +00:00
|
|
|
* - OTHERS (>=0) The number of bytes read from UART FIFO
|
2016-12-15 01:45:40 +00:00
|
|
|
*/
|
|
|
|
int uart_read_bytes(uart_port_t uart_num, uint8_t* buf, uint32_t length, TickType_t ticks_to_wait);
|
|
|
|
|
|
|
|
/**
|
2017-08-25 13:04:13 +00:00
|
|
|
* @brief 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.
|
2019-04-17 12:19:44 +00:00
|
|
|
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
2016-12-15 01:45:40 +00:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_FAIL Parameter error
|
|
|
|
*/
|
|
|
|
esp_err_t uart_flush(uart_port_t uart_num);
|
|
|
|
|
2016-12-19 04:52:10 +00:00
|
|
|
/**
|
2017-08-25 13:04:13 +00:00
|
|
|
* @brief 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.
|
2019-04-17 12:19:44 +00:00
|
|
|
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
2016-12-19 04:52:10 +00:00
|
|
|
*
|
2017-08-25 13:04:13 +00:00
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_FAIL Parameter error
|
|
|
|
*/
|
|
|
|
esp_err_t uart_flush_input(uart_port_t uart_num);
|
|
|
|
|
|
|
|
/**
|
2018-04-11 06:56:00 +00:00
|
|
|
* @brief UART get RX ring buffer cached data length
|
|
|
|
*
|
2019-04-17 12:19:44 +00:00
|
|
|
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
2018-04-11 06:56:00 +00:00
|
|
|
* @param size Pointer of size_t to accept cached data length
|
2016-12-19 04:52:10 +00:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_FAIL Parameter error
|
|
|
|
*/
|
|
|
|
esp_err_t uart_get_buffered_data_len(uart_port_t uart_num, size_t* size);
|
|
|
|
|
|
|
|
/**
|
2018-04-11 06:56:00 +00:00
|
|
|
* @brief 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.
|
2016-12-19 04:52:10 +00:00
|
|
|
*
|
2019-04-17 12:19:44 +00:00
|
|
|
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
2016-12-19 04:52:10 +00:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_FAIL Parameter error
|
|
|
|
*/
|
|
|
|
esp_err_t uart_disable_pattern_det_intr(uart_port_t uart_num);
|
|
|
|
|
2019-06-14 03:01:30 +00:00
|
|
|
#if CONFIG_IDF_TARGET_ESP32
|
2016-12-19 04:52:10 +00:00
|
|
|
/**
|
2017-09-27 20:03:22 +00:00
|
|
|
* @brief 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.
|
2019-07-01 10:00:10 +00:00
|
|
|
* @note This function only works for esp32. And this function is deprecated, please use
|
|
|
|
* uart_enable_pattern_det_baud_intr instead.
|
2016-12-19 04:52:10 +00:00
|
|
|
*
|
|
|
|
* @param uart_num UART port number.
|
2019-07-01 10:00:10 +00:00
|
|
|
* @param pattern_chr character of the pattern.
|
2016-12-19 04:52:10 +00:00
|
|
|
* @param chr_num number of the character, 8bit value.
|
2017-09-27 20:03:22 +00:00
|
|
|
* @param chr_tout timeout of the interval between each pattern characters, 24bit value, unit is APB (80Mhz) clock cycle.
|
2019-07-01 10:00:10 +00:00
|
|
|
* When the duration is less than this value, it will not take this data as at_cmd char.
|
2017-09-27 20:03:22 +00:00
|
|
|
* @param post_idle idle time after the last pattern character, 24bit value, unit is APB (80Mhz) clock cycle.
|
2018-04-03 04:34:16 +00:00
|
|
|
* When the duration is less than this value, it will not take the previous data as the last at_cmd char
|
2017-09-27 20:03:22 +00:00
|
|
|
* @param pre_idle idle time before the first pattern character, 24bit value, unit is APB (80Mhz) clock cycle.
|
2019-07-01 10:00:10 +00:00
|
|
|
* When the duration is less than this value, it will not take this data as the first at_cmd char.
|
2016-12-19 04:52:10 +00:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_FAIL Parameter error
|
|
|
|
*/
|
2019-07-01 10:00:10 +00:00
|
|
|
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) __attribute__((deprecated));
|
|
|
|
#endif
|
|
|
|
|
2019-06-14 03:01:30 +00:00
|
|
|
/**
|
|
|
|
* @brief 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.
|
|
|
|
*
|
|
|
|
* @param uart_num UART port number.
|
2019-07-01 10:00:10 +00:00
|
|
|
* @param pattern_chr character of the pattern.
|
2019-06-14 03:01:30 +00:00
|
|
|
* @param chr_num number of the character, 8bit value.
|
2019-07-01 10:00:10 +00:00
|
|
|
* @param chr_tout timeout of the interval between each pattern characters, 16bit value, unit is the baud-rate cycle you configured.
|
|
|
|
* When the duration is more than this value, it will not take this data as at_cmd char.
|
|
|
|
* @param post_idle idle time after the last pattern character, 16bit value, unit is the baud-rate cycle you configured.
|
2019-06-14 03:01:30 +00:00
|
|
|
* When the duration is less than this value, it will not take the previous data as the last at_cmd char
|
2019-07-01 10:00:10 +00:00
|
|
|
* @param pre_idle idle time before the first pattern character, 16bit value, unit is the baud-rate cycle you configured.
|
|
|
|
* When the duration is less than this value, it will not take this data as the first at_cmd char.
|
2019-06-14 03:01:30 +00:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_FAIL Parameter error
|
|
|
|
*/
|
2019-07-01 10:00:10 +00:00
|
|
|
esp_err_t uart_enable_pattern_det_baud_intr(uart_port_t uart_num, char pattern_chr, uint8_t chr_num, int chr_tout, int post_idle, int pre_idle);
|
2016-12-15 01:45:40 +00:00
|
|
|
|
2017-08-25 13:04:13 +00:00
|
|
|
/**
|
|
|
|
* @brief 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.
|
|
|
|
*
|
2019-04-17 12:19:44 +00:00
|
|
|
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
2017-08-25 13:04:13 +00:00
|
|
|
* @return
|
|
|
|
* - (-1) No pattern found for current index or parameter error
|
|
|
|
* - others the pattern position in rx buffer.
|
|
|
|
*/
|
|
|
|
int uart_pattern_pop_pos(uart_port_t uart_num);
|
|
|
|
|
2018-04-03 04:34:16 +00:00
|
|
|
/**
|
|
|
|
* @brief 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.
|
|
|
|
*
|
2019-04-17 12:19:44 +00:00
|
|
|
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
2018-04-03 04:34:16 +00:00
|
|
|
* @return
|
|
|
|
* - (-1) No pattern found for current index or parameter error
|
|
|
|
* - others the pattern position in rx buffer.
|
|
|
|
*/
|
|
|
|
int uart_pattern_get_pos(uart_port_t uart_num);
|
|
|
|
|
2017-08-25 13:04:13 +00:00
|
|
|
/**
|
|
|
|
* @brief Allocate a new memory with the given length to save record the detected pattern position in rx buffer.
|
2019-04-17 12:19:44 +00:00
|
|
|
*
|
|
|
|
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
2017-08-25 13:04:13 +00:00
|
|
|
* @param queue_length Max 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.
|
|
|
|
* @return
|
|
|
|
* - ESP_ERR_NO_MEM No enough memory
|
|
|
|
* - ESP_ERR_INVALID_STATE Driver not installed
|
|
|
|
* - ESP_FAIL Parameter error
|
|
|
|
* - ESP_OK Success
|
|
|
|
*/
|
|
|
|
esp_err_t uart_pattern_queue_reset(uart_port_t uart_num, int queue_length);
|
|
|
|
|
2018-04-11 06:56:00 +00:00
|
|
|
/**
|
2019-06-14 03:01:30 +00:00
|
|
|
* @brief UART set communication mode
|
2019-04-17 12:19:44 +00:00
|
|
|
*
|
2018-04-11 06:56:00 +00:00
|
|
|
* @note This function must be executed after uart_driver_install(), when the driver object is initialized.
|
2019-04-17 12:19:44 +00:00
|
|
|
* @param uart_num Uart number to configure, the max port number is (UART_NUM_MAX -1).
|
2019-06-14 03:01:30 +00:00
|
|
|
* @param mode UART UART mode to set
|
2018-04-11 06:56:00 +00:00
|
|
|
*
|
|
|
|
* @return
|
2018-06-27 14:48:14 +00:00
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_ERR_INVALID_ARG Parameter error
|
2018-04-11 06:56:00 +00:00
|
|
|
*/
|
|
|
|
esp_err_t uart_set_mode(uart_port_t uart_num, uart_mode_t mode);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief UART set threshold timeout for TOUT feature
|
|
|
|
*
|
2019-04-17 12:19:44 +00:00
|
|
|
* @param uart_num Uart number to configure, the max port number is (UART_NUM_MAX -1).
|
2019-06-14 03:01:30 +00:00
|
|
|
* @param tout_thresh This 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.
|
2018-04-11 06:56:00 +00:00
|
|
|
* If the time is expired the UART_RXFIFO_TOUT_INT interrupt is triggered. If tout_thresh == 0,
|
|
|
|
* the TOUT feature is disabled.
|
|
|
|
*
|
|
|
|
* @return
|
2018-06-27 14:48:14 +00:00
|
|
|
* - ESP_OK Success
|
|
|
|
* - ESP_ERR_INVALID_ARG Parameter error
|
|
|
|
* - ESP_ERR_INVALID_STATE Driver is not installed
|
2018-04-11 06:56:00 +00:00
|
|
|
*/
|
|
|
|
esp_err_t uart_set_rx_timeout(uart_port_t uart_num, const uint8_t tout_thresh);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Returns collision detection flag for RS485 mode
|
|
|
|
* Function returns the collision detection flag into variable pointed by collision_flag.
|
2018-05-31 08:33:40 +00:00
|
|
|
* *collision_flag = true, if collision detected else it is equal to false.
|
2018-04-11 06:56:00 +00:00
|
|
|
* This function should be executed when actual transmission is completed (after uart_write_bytes()).
|
|
|
|
*
|
2019-04-17 12:19:44 +00:00
|
|
|
* @param uart_num Uart number to configure the max port number is (UART_NUM_MAX -1).
|
2018-04-11 06:56:00 +00:00
|
|
|
* @param collision_flag Pointer to variable of type bool to return collision flag.
|
|
|
|
*
|
|
|
|
* @return
|
2019-06-14 03:01:30 +00:00
|
|
|
* - ESP_OK Success
|
2018-06-27 14:48:14 +00:00
|
|
|
* - ESP_ERR_INVALID_ARG Parameter error
|
2018-04-11 06:56:00 +00:00
|
|
|
*/
|
|
|
|
esp_err_t uart_get_collision_flag(uart_port_t uart_num, bool* collision_flag);
|
|
|
|
|
2018-08-14 00:40:31 +00:00
|
|
|
/**
|
|
|
|
* @brief 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.
|
2018-10-25 09:28:55 +00:00
|
|
|
* For example, letter 'a' with ASCII code 97 is encoded as 0100001101 on the wire
|
2018-08-14 00:40:31 +00:00
|
|
|
* (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.
|
|
|
|
*
|
2018-10-25 09:28:55 +00:00
|
|
|
* @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.
|
2018-08-14 00:40:31 +00:00
|
|
|
*
|
2019-04-17 12:19:44 +00:00
|
|
|
* @param uart_num UART number, the max port number is (UART_NUM_MAX -1).
|
2018-08-14 00:40:31 +00:00
|
|
|
* @param wakeup_threshold number of RX edges for light sleep wakeup, value is 3 .. 0x3ff.
|
|
|
|
* @return
|
|
|
|
* - ESP_OK on success
|
|
|
|
* - ESP_ERR_INVALID_ARG if uart_num is incorrect or wakeup_threshold is
|
|
|
|
* outside of [3, 0x3ff] range.
|
|
|
|
*/
|
|
|
|
esp_err_t uart_set_wakeup_threshold(uart_port_t uart_num, int wakeup_threshold);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief 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.
|
|
|
|
*
|
2019-04-17 12:19:44 +00:00
|
|
|
* @param uart_num UART number, the max port number is (UART_NUM_MAX -1).
|
2018-08-14 00:40:31 +00:00
|
|
|
* @param[out] out_wakeup_threshold output, set to the current value of wakeup
|
|
|
|
* threshold for the given UART.
|
|
|
|
* @return
|
|
|
|
* - ESP_OK on success
|
|
|
|
* - ESP_ERR_INVALID_ARG if out_wakeup_threshold is NULL
|
|
|
|
*/
|
|
|
|
esp_err_t uart_get_wakeup_threshold(uart_port_t uart_num, int* out_wakeup_threshold);
|
|
|
|
|
2019-05-22 12:21:11 +00:00
|
|
|
/**
|
|
|
|
* @brief Wait until UART tx memory empty and the last char send ok (polling mode).
|
|
|
|
*
|
|
|
|
* @param uart_num UART number
|
|
|
|
*
|
2019-04-17 12:19:44 +00:00
|
|
|
* * @return
|
|
|
|
* - ESP_OK on success
|
|
|
|
* - ESP_ERR_INVALID_ARG Parameter error
|
|
|
|
* - ESP_FAIL Driver not installed
|
|
|
|
*/
|
|
|
|
esp_err_t uart_wait_tx_idle_polling(uart_port_t uart_num);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Configure TX signal loop back to RX module, just for the test usage.
|
|
|
|
*
|
|
|
|
* @param uart_num UART number
|
|
|
|
* @param loop_back_en Set ture to enable the loop back function, else set it false.
|
|
|
|
*
|
|
|
|
* * @return
|
|
|
|
* - ESP_OK on success
|
|
|
|
* - ESP_ERR_INVALID_ARG Parameter error
|
|
|
|
* - ESP_FAIL Driver not installed
|
2019-05-22 12:21:11 +00:00
|
|
|
*/
|
2019-04-17 12:19:44 +00:00
|
|
|
esp_err_t uart_set_loop_back(uart_port_t uart_num, bool loop_back_en);
|
2019-05-22 12:21:11 +00:00
|
|
|
|
2016-12-15 01:45:40 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|