1 #ifdef USE_ESP32_FRAMEWORK_ARDUINO 14 static const char *
const TAG =
"uart.arduino_esp32";
16 static const uint32_t UART_PARITY_EVEN = 0 << 0;
17 static const uint32_t UART_PARITY_ODD = 1 << 0;
18 static const uint32_t UART_PARITY_ENABLE = 1 << 1;
19 static const uint32_t UART_NB_BIT_5 = 0 << 2;
20 static const uint32_t UART_NB_BIT_6 = 1 << 2;
21 static const uint32_t UART_NB_BIT_7 = 2 << 2;
22 static const uint32_t UART_NB_BIT_8 = 3 << 2;
23 static const uint32_t UART_NB_STOP_BIT_1 = 1 << 4;
24 static const uint32_t UART_NB_STOP_BIT_2 = 3 << 4;
25 static 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;
106 #endif // USE_LOGGER_USB_CDC 108 #ifdef USE_LOGGER_USB_SERIAL_JTAG 111 logger_uses_hardware_uart =
false;
113 #endif // USE_LOGGER_USB_SERIAL_JTAG 121 if (next_uart_num >= UART_NUM_MAX) {
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.");
213 #endif // USE_ESP32_FRAMEWORK_ARDUINO HardwareSerial * hw_serial_
uint32_t get_baud_rate() const
HardwareSerial * get_hw_serial()
bool peek_byte(uint8_t *data) override
InternalGPIOPin * tx_pin_
UARTParityOptions parity_
bool read_array(uint8_t *data, size_t len) override
virtual uint8_t get_pin() const =0
InternalGPIOPin * rx_pin_
void check_logger_conflict() override
void write_array(const uint8_t *data, size_t len) override
virtual void mark_failed()
Mark this component as failed.
Implementation of SPI Controller mode.
bool check_read_timeout_(size_t len=1)
CallbackManager< void(UARTDirection, uint8_t)> debug_callback_
void dump_config() override
void load_settings() override
const LogString * parity_to_str(UARTParityOptions parity)
virtual bool is_inverted() const =0