mirror of
https://github.com/esphome/esphome.git
synced 2024-12-22 05:24:53 +01:00
Disallow using UART2 for logger on ESP-32 variants that lack it (#2510)
This commit is contained in:
parent
867fecd157
commit
6bbb5e9b56
3 changed files with 15 additions and 6 deletions
|
@ -21,12 +21,16 @@ from esphome.core import CORE, HexInt
|
||||||
import esphome.config_validation as cv
|
import esphome.config_validation as cv
|
||||||
import esphome.codegen as cg
|
import esphome.codegen as cg
|
||||||
|
|
||||||
from .const import (
|
from .const import ( # noqa
|
||||||
KEY_BOARD,
|
KEY_BOARD,
|
||||||
KEY_ESP32,
|
KEY_ESP32,
|
||||||
KEY_SDKCONFIG_OPTIONS,
|
KEY_SDKCONFIG_OPTIONS,
|
||||||
KEY_VARIANT,
|
KEY_VARIANT,
|
||||||
|
VARIANT_ESP32,
|
||||||
|
VARIANT_ESP32S2,
|
||||||
|
VARIANT_ESP32S3,
|
||||||
VARIANT_ESP32C3,
|
VARIANT_ESP32C3,
|
||||||
|
VARIANT_ESP32H2,
|
||||||
VARIANTS,
|
VARIANTS,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ from esphome.const import (
|
||||||
CONF_TX_BUFFER_SIZE,
|
CONF_TX_BUFFER_SIZE,
|
||||||
)
|
)
|
||||||
from esphome.core import CORE, EsphomeError, Lambda, coroutine_with_priority
|
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"]
|
CODEOWNERS = ["@esphome/core"]
|
||||||
logger_ns = cg.esphome_ns.namespace("logger")
|
logger_ns = cg.esphome_ns.namespace("logger")
|
||||||
|
@ -52,6 +53,10 @@ LOG_LEVEL_SEVERITY = [
|
||||||
"VERY_VERBOSE",
|
"VERY_VERBOSE",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
ESP32_REDUCED_VARIANTS = [VARIANT_ESP32C3, VARIANT_ESP32S2]
|
||||||
|
|
||||||
|
UART_SELECTION_ESP32_REDUCED = ["UART0", "UART1"]
|
||||||
|
|
||||||
UART_SELECTION_ESP32 = ["UART0", "UART1", "UART2"]
|
UART_SELECTION_ESP32 = ["UART0", "UART1", "UART2"]
|
||||||
|
|
||||||
UART_SELECTION_ESP8266 = ["UART0", "UART0_SWAP", "UART1"]
|
UART_SELECTION_ESP8266 = ["UART0", "UART0_SWAP", "UART1"]
|
||||||
|
@ -75,6 +80,8 @@ is_log_level = cv.one_of(*LOG_LEVELS, upper=True)
|
||||||
|
|
||||||
def uart_selection(value):
|
def uart_selection(value):
|
||||||
if CORE.is_esp32:
|
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)
|
return cv.one_of(*UART_SELECTION_ESP32, upper=True)(value)
|
||||||
if CORE.is_esp8266:
|
if CORE.is_esp8266:
|
||||||
return cv.one_of(*UART_SELECTION_ESP8266, upper=True)(value)
|
return cv.one_of(*UART_SELECTION_ESP8266, upper=True)(value)
|
||||||
|
|
|
@ -153,13 +153,9 @@ void Logger::pre_setup() {
|
||||||
case UART_SELECTION_UART1:
|
case UART_SELECTION_UART1:
|
||||||
this->hw_serial_ = &Serial1;
|
this->hw_serial_ = &Serial1;
|
||||||
break;
|
break;
|
||||||
#ifdef USE_ESP32
|
#if defined(USE_ESP32) && !CONFIG_IDF_TARGET_ESP32C3 && !CONFIG_IDF_TARGET_ESP32S2
|
||||||
case UART_SELECTION_UART2:
|
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;
|
this->hw_serial_ = &Serial2;
|
||||||
#endif
|
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -173,9 +169,11 @@ void Logger::pre_setup() {
|
||||||
case UART_SELECTION_UART1:
|
case UART_SELECTION_UART1:
|
||||||
uart_num_ = UART_NUM_1;
|
uart_num_ = UART_NUM_1;
|
||||||
break;
|
break;
|
||||||
|
#if !CONFIG_IDF_TARGET_ESP32C3 && !CONFIG_IDF_TARGET_ESP32S2
|
||||||
case UART_SELECTION_UART2:
|
case UART_SELECTION_UART2:
|
||||||
uart_num_ = UART_NUM_2;
|
uart_num_ = UART_NUM_2;
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
uart_config_t uart_config{};
|
uart_config_t uart_config{};
|
||||||
uart_config.baud_rate = (int) baud_rate_;
|
uart_config.baud_rate = (int) baud_rate_;
|
||||||
|
|
Loading…
Reference in a new issue