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;
80 bool is_default_tx, is_default_rx;
81#ifdef CONFIG_IDF_TARGET_ESP32C3
88 static uint8_t next_uart_num = 0;
89 if (is_default_tx && is_default_rx && next_uart_num == 0) {
90#if ARDUINO_USB_CDC_ON_BOOT
98 bool logger_uses_hardware_uart =
true;
100#ifdef USE_LOGGER_USB_CDC
103 logger_uses_hardware_uart =
false;
107#ifdef USE_LOGGER_USB_SERIAL_JTAG
110 logger_uses_hardware_uart =
false;
120 if (next_uart_num >= SOC_UART_NUM) {
121 ESP_LOGW(TAG,
"Maximum number of UART components created already.");
127 this->
hw_serial_ =
new HardwareSerial(next_uart_num++);
144 ESP_LOGCONFIG(TAG,
"UART %u was reloaded.", this->
number_);
150 ESP_LOGCONFIG(TAG,
"UART Bus %d:", this->
number_);
153 if (this->
rx_pin_ !=
nullptr) {
157 " Baud Rate: %u baud\n"
167#ifdef USE_UART_DEBUGGER
168 for (
size_t i = 0; i <
len; i++) {
185#ifdef USE_UART_DEBUGGER
186 for (
size_t i = 0; i <
len; i++) {
195 ESP_LOGVV(TAG,
" Flushing");
206 ESP_LOGW(TAG,
" You're using the same serial port for logging and the UART component. Please "
207 "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.