19 uart_parity_t parity = UART_PARITY_DISABLE;
21 parity = UART_PARITY_EVEN;
23 parity = UART_PARITY_ODD;
26 uart_word_length_t data_bits;
29 data_bits = UART_DATA_5_BITS;
32 data_bits = UART_DATA_6_BITS;
35 data_bits = UART_DATA_7_BITS;
38 data_bits = UART_DATA_8_BITS;
41 data_bits = UART_DATA_BITS_MAX;
45 uart_config_t uart_config;
47 uart_config.data_bits = data_bits;
48 uart_config.parity = parity;
49 uart_config.stop_bits = this->
stop_bits_ == 1 ? UART_STOP_BITS_1 : UART_STOP_BITS_2;
50 uart_config.flow_ctrl = UART_HW_FLOWCTRL_DISABLE;
51#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
52 uart_config.source_clk = UART_SCLK_DEFAULT;
54 uart_config.source_clk = UART_SCLK_APB;
56 uart_config.rx_flow_ctrl_thresh = 122;
62 static uint8_t next_uart_num = 0;
65 bool logger_uses_hardware_uart =
true;
67#ifdef USE_LOGGER_USB_CDC
70 logger_uses_hardware_uart =
false;
74#ifdef USE_LOGGER_USB_SERIAL_JTAG
77 logger_uses_hardware_uart =
false;
87 if (next_uart_num >= SOC_UART_NUM) {
88 ESP_LOGW(TAG,
"Maximum number of UART components created already.");
92 this->
uart_num_ =
static_cast<uart_port_t
>(next_uart_num++);
93 ESP_LOGCONFIG(TAG,
"Setting up UART %u...", this->
uart_num_);
95 this->
lock_ = xSemaphoreCreateMutex();
97 xSemaphoreTake(this->
lock_, portMAX_DELAY);
100 esp_err_t err = uart_param_config(this->
uart_num_, &uart_config);
102 ESP_LOGW(TAG,
"uart_param_config failed: %s", esp_err_to_name(err));
112 invert |= UART_SIGNAL_TXD_INV;
114 invert |= UART_SIGNAL_RXD_INV;
116 err = uart_set_line_inverse(this->
uart_num_, invert);
118 ESP_LOGW(TAG,
"uart_set_line_inverse failed: %s", esp_err_to_name(err));
123 err = uart_set_pin(this->
uart_num_, tx, rx, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
125 ESP_LOGW(TAG,
"uart_set_pin failed: %s", esp_err_to_name(err));
137 ESP_LOGW(TAG,
"uart_driver_install failed: %s", esp_err_to_name(err));
142 xSemaphoreGive(this->
lock_);