1#ifdef USE_ESP32_FRAMEWORK_ARDUINO
14static const char *
const TAG =
"uart.arduino_esp32";
16static const uint32_t UART_PARITY_EVEN = 0 << 0;
17static const uint32_t UART_PARITY_ODD = 1 << 0;
18static const uint32_t UART_PARITY_ENABLE = 1 << 1;
19static const uint32_t UART_NB_BIT_5 = 0 << 2;
20static const uint32_t UART_NB_BIT_6 = 1 << 2;
21static const uint32_t UART_NB_BIT_7 = 2 << 2;
22static const uint32_t UART_NB_BIT_8 = 3 << 2;
23static const uint32_t UART_NB_STOP_BIT_1 = 1 << 4;
24static const uint32_t UART_NB_STOP_BIT_2 = 3 << 4;
25static const uint32_t UART_TICK_APB_CLOCK = 1 << 27;
45 config |= UART_PARITY_EVEN | UART_PARITY_ENABLE;
47 config |= UART_PARITY_ODD | UART_PARITY_ENABLE;
52 config |= UART_NB_BIT_5;
55 config |= UART_NB_BIT_6;
58 config |= UART_NB_BIT_7;
61 config |= UART_NB_BIT_8;
66 config |= UART_NB_STOP_BIT_1;
68 config |= UART_NB_STOP_BIT_2;
71 config |= UART_TICK_APB_CLOCK;
77 ESP_LOGCONFIG(TAG,
"Setting up UART...");
81 bool is_default_tx, is_default_rx;
82#ifdef CONFIG_IDF_TARGET_ESP32C3
89 static uint8_t next_uart_num = 0;
90 if (is_default_tx && is_default_rx && next_uart_num == 0) {
91#if ARDUINO_USB_CDC_ON_BOOT
99 bool logger_uses_hardware_uart =
true;
101#ifdef USE_LOGGER_USB_CDC
104 logger_uses_hardware_uart =
false;
108#ifdef USE_LOGGER_USB_SERIAL_JTAG
111 logger_uses_hardware_uart =
false;
121 if (next_uart_num >= SOC_UART_NUM) {
122 ESP_LOGW(TAG,
"Maximum number of UART components created already.");
128 this->
hw_serial_ =
new HardwareSerial(next_uart_num++);
145 ESP_LOGCONFIG(TAG,
"UART %u was reloaded.", this->
number_);
151 ESP_LOGCONFIG(TAG,
"UART Bus %d:", this->
number_);
154 if (this->
rx_pin_ !=
nullptr) {
157 ESP_LOGCONFIG(TAG,
" Baud Rate: %u baud", this->
baud_rate_);
158 ESP_LOGCONFIG(TAG,
" Data Bits: %u", this->
data_bits_);
160 ESP_LOGCONFIG(TAG,
" Stop bits: %u", this->
stop_bits_);
166#ifdef USE_UART_DEBUGGER
167 for (
size_t i = 0; i <
len; i++) {
184#ifdef USE_UART_DEBUGGER
185 for (
size_t i = 0; i <
len; i++) {
194 ESP_LOGVV(TAG,
" Flushing...");
205 ESP_LOGW(TAG,
" You're using the same serial port for logging and the UART component. Please "
206 "disable logging over the serial port by setting logger->baud_rate to 0.");
virtual void mark_failed()
Mark this component as failed.
virtual uint8_t get_pin() const =0
virtual bool is_inverted() const =0
void load_settings() override
HardwareSerial * get_hw_serial()
bool peek_byte(uint8_t *data) override
void write_array(const uint8_t *data, size_t len) override
void check_logger_conflict() override
HardwareSerial * hw_serial_
bool read_array(uint8_t *data, size_t len) override
void dump_config() override
UARTParityOptions parity_
bool check_read_timeout_(size_t len=1)
InternalGPIOPin * tx_pin_
uint32_t get_baud_rate() const
CallbackManager< void(UARTDirection, uint8_t)> debug_callback_
InternalGPIOPin * rx_pin_
@ UART_SELECTION_USB_SERIAL_JTAG
const LogString * parity_to_str(UARTParityOptions parity)
@ UART_CONFIG_PARITY_EVEN
Providing packet encoding functions for exchanging data with a remote host.