mirror of
https://github.com/esphome/esphome.git
synced 2024-11-25 16:38:16 +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:
parent
2a7d6addde
commit
d0ca69bc27
2 changed files with 19 additions and 2 deletions
|
@ -86,10 +86,26 @@ void ESP32ArduinoUARTComponent::setup() {
|
||||||
is_default_tx = tx_pin_ == nullptr || tx_pin_->get_pin() == 1;
|
is_default_tx = tx_pin_ == nullptr || tx_pin_->get_pin() == 1;
|
||||||
is_default_rx = rx_pin_ == nullptr || rx_pin_->get_pin() == 3;
|
is_default_rx = rx_pin_ == nullptr || rx_pin_->get_pin() == 3;
|
||||||
#endif
|
#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;
|
this->hw_serial_ = &Serial;
|
||||||
|
next_uart_num++;
|
||||||
} else {
|
} 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->number_ = next_uart_num;
|
||||||
this->hw_serial_ = new HardwareSerial(next_uart_num++); // NOLINT(cppcoreguidelines-owning-memory)
|
this->hw_serial_ = new HardwareSerial(next_uart_num++); // NOLINT(cppcoreguidelines-owning-memory)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#ifdef USE_ESP32_FRAMEWORK_ARDUINO
|
#ifdef USE_ESP32_FRAMEWORK_ARDUINO
|
||||||
|
|
||||||
|
#include <driver/uart.h>
|
||||||
#include <HardwareSerial.h>
|
#include <HardwareSerial.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "esphome/core/component.h"
|
#include "esphome/core/component.h"
|
||||||
|
|
Loading…
Reference in a new issue