Skip to content

Commit

Permalink
Disallow using UART2 for logger on ESP-32 variants that lack it (esph…
Browse files Browse the repository at this point in the history
  • Loading branch information
oxan authored Oct 13, 2021
1 parent 867fecd commit 6bbb5e9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
6 changes: 5 additions & 1 deletion esphome/components/esp32/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@
import esphome.config_validation as cv
import esphome.codegen as cg

from .const import (
from .const import ( # noqa
KEY_BOARD,
KEY_ESP32,
KEY_SDKCONFIG_OPTIONS,
KEY_VARIANT,
VARIANT_ESP32,
VARIANT_ESP32S2,
VARIANT_ESP32S3,
VARIANT_ESP32C3,
VARIANT_ESP32H2,
VARIANTS,
)

Expand Down
7 changes: 7 additions & 0 deletions esphome/components/logger/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
CONF_TX_BUFFER_SIZE,
)
from esphome.core import CORE, EsphomeError, Lambda, coroutine_with_priority
from esphome.components.esp32 import get_esp32_variant, VARIANT_ESP32S2, VARIANT_ESP32C3

CODEOWNERS = ["@esphome/core"]
logger_ns = cg.esphome_ns.namespace("logger")
Expand Down Expand Up @@ -52,6 +53,10 @@
"VERY_VERBOSE",
]

ESP32_REDUCED_VARIANTS = [VARIANT_ESP32C3, VARIANT_ESP32S2]

UART_SELECTION_ESP32_REDUCED = ["UART0", "UART1"]

UART_SELECTION_ESP32 = ["UART0", "UART1", "UART2"]

UART_SELECTION_ESP8266 = ["UART0", "UART0_SWAP", "UART1"]
Expand All @@ -75,6 +80,8 @@

def uart_selection(value):
if CORE.is_esp32:
if get_esp32_variant() in ESP32_REDUCED_VARIANTS:
return cv.one_of(*UART_SELECTION_ESP32_REDUCED, upper=True)(value)
return cv.one_of(*UART_SELECTION_ESP32, upper=True)(value)
if CORE.is_esp8266:
return cv.one_of(*UART_SELECTION_ESP8266, upper=True)(value)
Expand Down
8 changes: 3 additions & 5 deletions esphome/components/logger/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,9 @@ void Logger::pre_setup() {
case UART_SELECTION_UART1:
this->hw_serial_ = &Serial1;
break;
#ifdef USE_ESP32
#if defined(USE_ESP32) && !CONFIG_IDF_TARGET_ESP32C3 && !CONFIG_IDF_TARGET_ESP32S2
case UART_SELECTION_UART2:
#if !CONFIG_IDF_TARGET_ESP32S2 && !CONFIG_IDF_TARGET_ESP32C3
// FIXME: Validate in config that UART2 can't be set for ESP32-S2 (only has
// UART0-UART1)
this->hw_serial_ = &Serial2;
#endif
break;
#endif
}
Expand All @@ -173,9 +169,11 @@ void Logger::pre_setup() {
case UART_SELECTION_UART1:
uart_num_ = UART_NUM_1;
break;
#if !CONFIG_IDF_TARGET_ESP32C3 && !CONFIG_IDF_TARGET_ESP32S2
case UART_SELECTION_UART2:
uart_num_ = UART_NUM_2;
break;
#endif
}
uart_config_t uart_config{};
uart_config.baud_rate = (int) baud_rate_;
Expand Down

0 comments on commit 6bbb5e9

Please sign in to comment.