[Logger] ESP32 S3 serial logger (#4853)

* Add support for ESP32 S3 logger.

* fix default

* Remove cpp & h changes to combine with PR #4658

* Not enough attention to details.

* Add build flag

* Validation fix

* Fix validation for real this time

---------

Co-authored-by: Your Name <you@example.com>
Co-authored-by: Keith Burzinski <kbx81x@gmail.com>
This commit is contained in:
Fabian 2023-12-14 05:47:31 +01:00 committed by GitHub
parent 777cdb1c21
commit 8c37066ed9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 58 additions and 5 deletions

View file

@ -97,7 +97,7 @@ UART_SELECTION_LIBRETINY = {
COMPONENT_RTL87XX: [DEFAULT, UART0, UART1, UART2], COMPONENT_RTL87XX: [DEFAULT, UART0, UART1, UART2],
} }
ESP_IDF_UARTS = [USB_CDC, USB_SERIAL_JTAG] ESP_ARDUINO_UNSUPPORTED_USB_UARTS = [USB_SERIAL_JTAG]
UART_SELECTION_RP2040 = [USB_CDC, UART0, UART1] UART_SELECTION_RP2040 = [USB_CDC, UART0, UART1]
@ -124,6 +124,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 CORE.using_arduino and value.upper() in ESP_ARDUINO_UNSUPPORTED_USB_UARTS:
raise cv.Invalid(f"Arduino framework does not support {value}.")
variant = get_esp32_variant() variant = get_esp32_variant()
if variant in UART_SELECTION_ESP32: if variant in UART_SELECTION_ESP32:
return cv.one_of(*UART_SELECTION_ESP32[variant], upper=True)(value) return cv.one_of(*UART_SELECTION_ESP32[variant], upper=True)(value)
@ -169,6 +171,8 @@ CONFIG_SCHEMA = cv.All(
CONF_HARDWARE_UART, CONF_HARDWARE_UART,
esp8266=UART0, esp8266=UART0,
esp32=UART0, esp32=UART0,
esp32_s2=USB_CDC,
esp32_s3=USB_CDC,
rp2040=USB_CDC, rp2040=USB_CDC,
bk72xx=DEFAULT, bk72xx=DEFAULT,
rtl87xx=DEFAULT, rtl87xx=DEFAULT,
@ -256,6 +260,10 @@ async def to_code(config):
if config.get(CONF_ESP8266_STORE_LOG_STRINGS_IN_FLASH): if config.get(CONF_ESP8266_STORE_LOG_STRINGS_IN_FLASH):
cg.add_build_flag("-DUSE_STORE_LOG_STR_IN_FLASH") cg.add_build_flag("-DUSE_STORE_LOG_STR_IN_FLASH")
if CORE.using_arduino:
if config[CONF_HARDWARE_UART] == USB_CDC:
cg.add_build_flag("-DARDUINO_USB_CDC_ON_BOOT=1")
if CORE.using_esp_idf: if CORE.using_esp_idf:
if config[CONF_HARDWARE_UART] == USB_CDC: if config[CONF_HARDWARE_UART] == USB_CDC:
add_idf_sdkconfig_option("CONFIG_ESP_CONSOLE_USB_CDC", True) add_idf_sdkconfig_option("CONFIG_ESP_CONSOLE_USB_CDC", True)

View file

@ -1528,6 +1528,12 @@ class SplitDefault(Optional):
esp32=vol.UNDEFINED, esp32=vol.UNDEFINED,
esp32_arduino=vol.UNDEFINED, esp32_arduino=vol.UNDEFINED,
esp32_idf=vol.UNDEFINED, esp32_idf=vol.UNDEFINED,
esp32_s2=vol.UNDEFINED,
esp32_s2_arduino=vol.UNDEFINED,
esp32_s2_idf=vol.UNDEFINED,
esp32_s3=vol.UNDEFINED,
esp32_s3_arduino=vol.UNDEFINED,
esp32_s3_idf=vol.UNDEFINED,
rp2040=vol.UNDEFINED, rp2040=vol.UNDEFINED,
bk72xx=vol.UNDEFINED, bk72xx=vol.UNDEFINED,
rtl87xx=vol.UNDEFINED, rtl87xx=vol.UNDEFINED,
@ -1541,6 +1547,26 @@ class SplitDefault(Optional):
self._esp32_idf_default = vol.default_factory( self._esp32_idf_default = vol.default_factory(
esp32_idf if esp32 is vol.UNDEFINED else esp32 esp32_idf if esp32 is vol.UNDEFINED else esp32
) )
self._esp32_s2_arduino_default = vol.default_factory(
(esp32_s2_arduino if esp32 is vol.UNDEFINED else esp32)
if esp32_s2 is vol.UNDEFINED
else esp32_s2
)
self._esp32_s2_idf_default = vol.default_factory(
(esp32_s2_idf if esp32 is vol.UNDEFINED else esp32)
if esp32_s2 is vol.UNDEFINED
else esp32_s2
)
self._esp32_s3_arduino_default = vol.default_factory(
(esp32_s3_arduino if esp32 is vol.UNDEFINED else esp32)
if esp32_s3 is vol.UNDEFINED
else esp32_s3
)
self._esp32_s3_idf_default = vol.default_factory(
(esp32_s3_idf if esp32 is vol.UNDEFINED else esp32)
if esp32_s3 is vol.UNDEFINED
else esp32_s3
)
self._rp2040_default = vol.default_factory(rp2040) self._rp2040_default = vol.default_factory(rp2040)
self._bk72xx_default = vol.default_factory(bk72xx) self._bk72xx_default = vol.default_factory(bk72xx)
self._rtl87xx_default = vol.default_factory(rtl87xx) self._rtl87xx_default = vol.default_factory(rtl87xx)
@ -1550,10 +1576,29 @@ class SplitDefault(Optional):
def default(self): def default(self):
if CORE.is_esp8266: if CORE.is_esp8266:
return self._esp8266_default return self._esp8266_default
if CORE.is_esp32 and CORE.using_arduino: if CORE.is_esp32:
return self._esp32_arduino_default from esphome.components.esp32 import get_esp32_variant
if CORE.is_esp32 and CORE.using_esp_idf: from esphome.components.esp32.const import (
return self._esp32_idf_default VARIANT_ESP32S2,
VARIANT_ESP32S3,
)
variant = get_esp32_variant()
if variant == VARIANT_ESP32S2:
if CORE.using_arduino:
return self._esp32_s2_arduino_default
if CORE.using_esp_idf:
return self._esp32_s2_idf_default
elif variant == VARIANT_ESP32S3:
if CORE.using_arduino:
return self._esp32_s3_arduino_default
if CORE.using_esp_idf:
return self._esp32_s3_idf_default
else:
if CORE.using_arduino:
return self._esp32_arduino_default
if CORE.using_esp_idf:
return self._esp32_idf_default
if CORE.is_rp2040: if CORE.is_rp2040:
return self._rp2040_default return self._rp2040_default
if CORE.is_bk72xx: if CORE.is_bk72xx: