1
0
mirror of https://github.com/esphome/esphome.git synced 2024-10-06 02:40:56 +01:00

Start UART assignment at UART0 if the logger is not enabled or is not configured for hardware logging on ESP32 (#4762)

This commit is contained in:
Justin Gerace 2023-05-15 16:00:05 -07:00 committed by GitHub
parent 2a7d6addde
commit d0ca69bc27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 2 deletions

View File

@ -86,10 +86,26 @@ void ESP32ArduinoUARTComponent::setup() {
is_default_tx = tx_pin_ == nullptr || tx_pin_->get_pin() == 1;
is_default_rx = rx_pin_ == nullptr || rx_pin_->get_pin() == 3;
#endif
if (is_default_tx && is_default_rx) {
static uint8_t next_uart_num = 0;
if (is_default_tx && is_default_rx && next_uart_num == 0) {
this->hw_serial_ = &Serial;
next_uart_num++;
} else {
static uint8_t next_uart_num = 1;
#ifdef USE_LOGGER
// The logger doesn't use this UART component, instead it targets the UARTs
// directly (i.e. Serial/Serial0, Serial1, and Serial2). If the logger is
// enabled, skip the UART that it is configured to use.
if (logger::global_logger->get_baud_rate() > 0 && logger::global_logger->get_uart() == next_uart_num) {
next_uart_num++;
}
#endif // USE_LOGGER
if (next_uart_num >= UART_NUM_MAX) {
ESP_LOGW(TAG, "Maximum number of UART components created already.");
this->mark_failed();
return;
}
this->number_ = next_uart_num;
this->hw_serial_ = new HardwareSerial(next_uart_num++); // NOLINT(cppcoreguidelines-owning-memory)
}

View File

@ -2,6 +2,7 @@
#ifdef USE_ESP32_FRAMEWORK_ARDUINO
#include <driver/uart.h>
#include <HardwareSerial.h>
#include <vector>
#include "esphome/core/component.h"