16 int TXD_PIN = UART_PIN_NO_CHANGE,
17 int RXD_PIN = UART_PIN_NO_CHANGE,
18 int RTS_PIN = UART_PIN_NO_CHANGE,
19 int CTS_PIN = UART_PIN_NO_CHANGE,
20 uart_config_t UART_CONFIG = (uart_config_t) {
22 .data_bits = UART_DATA_8_BITS,
23 .parity = UART_PARITY_DISABLE,
24 .stop_bits = UART_STOP_BITS_1,
25 .flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
26 .rx_flow_ctrl_thresh = 122,
29 uart_mode_t UART_MODE = UART_MODE_UART,
30 unsigned int TX_BUF_SIZE = 256,
31 unsigned int RX_BUF_SIZE = 512) : UART_NUM(UART_NUM) {
37 ESP_ERROR_CHECK(uart_param_config(
UART_NUM, &UART_CONFIG));
39 ESP_ERROR_CHECK(uart_set_pin(
UART_NUM, TXD_PIN, RXD_PIN, RTS_PIN, CTS_PIN));
41 ESP_ERROR_CHECK(uart_driver_install(
UART_NUM, RX_BUF_SIZE, TX_BUF_SIZE, 20, &
uart_queue, 0));
43 ESP_ERROR_CHECK(uart_set_mode(
UART_NUM, UART_MODE));
47 return uart_write_bytes(
UART_NUM, (
const char *) data, dataSize);
60 ESP_ERROR_CHECK(uart_flush_input(
UART_NUM));
66 ESP_ERROR_CHECK(uart_driver_delete(
UART_NUM));
70 return uart_read_bytes(this->
UART_NUM, buffer, length, 4);
74 ESP_ERROR_CHECK(uart_set_baudrate(
UART_NUM, new_baudrate));
81 switch (new_flowcontrol) {
83 hw = uart_set_hw_flow_ctrl(
UART_NUM, UART_HW_FLOWCTRL_CTS_RTS, 0);
88 hw = uart_set_hw_flow_ctrl(
UART_NUM, UART_HW_FLOWCTRL_DISABLE, 0);
93 hw = uart_set_hw_flow_ctrl(
UART_NUM, UART_HW_FLOWCTRL_CTS_RTS, 0);
100 hw = uart_set_hw_flow_ctrl(
UART_NUM, UART_HW_FLOWCTRL_DISABLE, 0);
111 uart_parity_t esp_parity;
112 switch (parity_bit) {
114 esp_parity = UART_PARITY_EVEN;
117 esp_parity = UART_PARITY_ODD;
121 esp_parity = UART_PARITY_DISABLE;
124 if (uart_set_parity(
UART_NUM, esp_parity))
133 uart_stop_bits_t esp_stop;
136 esp_stop = UART_STOP_BITS_1_5;
139 esp_stop = UART_STOP_BITS_2;
143 esp_stop = UART_STOP_BITS_1;
147 if (uart_set_stop_bits(
UART_NUM, esp_stop))
155 ESP_ERROR_CHECK(uart_get_buffered_data_len(
UART_NUM, &len));
160 uart_hw_flowcontrol_t esp_hw;
162 ESP_ERROR_CHECK(uart_get_hw_flow_ctrl(
UART_NUM, &esp_hw));
164 case UART_HW_FLOWCTRL_DISABLE:
167 case UART_HW_FLOWCTRL_RTS:
168 case UART_HW_FLOWCTRL_CTS:
169 case UART_HW_FLOWCTRL_CTS_RTS:
172 case UART_HW_FLOWCTRL_MAX:
186 uart_parity_t esp_parity;
188 ESP_ERROR_CHECK(uart_get_parity(
UART_NUM, &esp_parity));
189 switch (esp_parity) {
190 case UART_PARITY_EVEN:
193 case UART_PARITY_ODD:
196 case UART_PARITY_DISABLE:
205 uart_stop_bits_t esp_stop;
207 ESP_ERROR_CHECK(uart_get_stop_bits(
UART_NUM, &esp_stop));
209 case UART_STOP_BITS_1:
212 case UART_STOP_BITS_1_5:
215 case UART_STOP_BITS_2:
218 case UART_STOP_BITS_MAX:
228 uart_word_length_t esp_word;
230 ESP_ERROR_CHECK(uart_get_word_length(
UART_NUM, &esp_word));
232 case UART_DATA_5_BITS:
235 case UART_DATA_6_BITS:
238 case UART_DATA_7_BITS:
241 case UART_DATA_8_BITS:
244 case UART_DATA_BITS_MAX:
253 uart_word_length_t esp_word;
254 switch (word_length) {
256 esp_word = UART_DATA_5_BITS;
259 esp_word = UART_DATA_6_BITS;
262 esp_word = UART_DATA_7_BITS;
266 esp_word = UART_DATA_8_BITS;
269 esp_err_t esp_err = uart_set_word_length(
UART_NUM, esp_word);
word_length_t get_word_length() override
Set UART data bits length.
stop_bit_t get_stop_bit() override
get stop bit
uint32_t get_baudrate() override
Get baudrate of UART.
ESP32_UART(uart_port_t UART_NUM, int TXD_PIN, int RXD_PIN, int RTS_PIN, int CTS_PIN, uart_config_t UART_CONFIG, uart_mode_t UART_MODE, unsigned int TX_BUF_SIZE, unsigned int RX_BUF_SIZE)
Create a uart driver with custom settings.
err_t _set_stop_bit(stop_bit_t stop_bit) override
set stop bit
bool software_flowcontrol
err_t _set_flowcontrol(flowcontrol_t new_flowcontrol) override
Set software or hardware flowcontrol.
const uart_port_t UART_NUM
uint32_t get_read_buffer_length() override
Get amount of bytes in the read buffer.
uint32_t _set_baudrate(uint32_t new_baudrate) override
Set baudrate of the UART.
parity_t get_parity() override
Get parity of UART.
Link * driver
stores the driver.
flowcontrol_t get_flowcontrol() override
get flowcontrol of UART
err_t _set_parity(parity_t parity_bit) override
Set parity bit.
size_t _write(uint8_t *data, size_t dataSize) override
write data to the link/bus.
size_t _read(uint8_t *buffer, size_t length) override
Read bytes and out them in the buffer.
err_t _set_word_length(word_length_t word_length) override
Set UART data bits length.
static const uint8_t XOFF