mirror of
https://github.com/esphome/esphome.git
synced 2025-09-26 15:12:21 +01:00
add overlay config
This commit is contained in:
@@ -40,6 +40,7 @@ from esphome.components.libretiny.const import (
|
||||
COMPONENT_BK72XX,
|
||||
COMPONENT_RTL87XX,
|
||||
)
|
||||
from esphome.components.nrf52 import add_zephyr_overlay
|
||||
|
||||
CODEOWNERS = ["@esphome/core"]
|
||||
logger_ns = cg.esphome_ns.namespace("logger")
|
||||
@@ -283,6 +284,7 @@ async def to_code(config):
|
||||
add_idf_sdkconfig_option("CONFIG_ESP_CONSOLE_USB_CDC", True)
|
||||
elif config[CONF_HARDWARE_UART] == USB_SERIAL_JTAG:
|
||||
add_idf_sdkconfig_option("CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG", True)
|
||||
|
||||
try:
|
||||
uart_selection(USB_SERIAL_JTAG)
|
||||
cg.add_build_flag("-DUSE_USB_SERIAL_JTAG")
|
||||
@@ -294,6 +296,10 @@ async def to_code(config):
|
||||
except cv.Invalid:
|
||||
pass
|
||||
|
||||
if CORE.using_zephyr:
|
||||
if config[CONF_HARDWARE_UART] == UART0:
|
||||
add_zephyr_overlay("""&uart0 { status = "okay";};""")
|
||||
|
||||
# Register at end for safe mode
|
||||
await cg.register_component(log, config)
|
||||
|
||||
|
@@ -37,7 +37,7 @@ enum UARTSelection {
|
||||
#else
|
||||
UART_SELECTION_UART0 = 0,
|
||||
#endif
|
||||
#if !defined(USE_NRF52) || defined(PIN_SERIAL2_RX) && defined(PIN_SERIAL2_TX)
|
||||
#ifndef USE_NRF52
|
||||
UART_SELECTION_UART1,
|
||||
#endif
|
||||
#if defined(USE_LIBRETINY) || defined(USE_ESP32_VARIANT_ESP32)
|
||||
@@ -147,20 +147,17 @@ class Logger : public Component {
|
||||
char *tx_buffer_{nullptr};
|
||||
int tx_buffer_at_{0};
|
||||
int tx_buffer_size_{0};
|
||||
#if defined(USE_ESP32) || defined(USE_ESP8266) || defined(USE_RP2040)
|
||||
#if defined(USE_ESP32) || defined(USE_ESP8266) || defined(USE_RP2040) || defined(USE_NRF52)
|
||||
UARTSelection uart_{UART_SELECTION_UART0};
|
||||
#endif
|
||||
#ifdef USE_NRF52
|
||||
UARTSelection uart_{UART_SELECTION_USB_CDC};
|
||||
#endif
|
||||
#ifdef USE_LIBRETINY
|
||||
#elif defined(USE_LIBRETINY)
|
||||
UARTSelection uart_{UART_SELECTION_DEFAULT};
|
||||
#endif
|
||||
#ifdef USE_ARDUINO
|
||||
Stream *hw_serial_{nullptr};
|
||||
#endif
|
||||
#ifdef USE_ESP_IDF
|
||||
#elif defined(USE_ESP_IDF)
|
||||
uart_port_t uart_num_;
|
||||
#elif defined(USE_ZEPHYR)
|
||||
const struct device * uart_dev_{nullptr};
|
||||
#endif
|
||||
struct LogLevelOverride {
|
||||
std::string tag;
|
||||
|
@@ -8,32 +8,66 @@
|
||||
namespace esphome {
|
||||
namespace logger {
|
||||
|
||||
#ifdef USE_ZEPHYR
|
||||
// it must be inside namespace since there is duplicated macro EMPTY
|
||||
#include <zephyr/device.h>
|
||||
#include <zephyr/drivers/uart.h>
|
||||
#include <zephyr/usb/usb_device.h>
|
||||
#endif
|
||||
|
||||
static const char *const TAG = "logger";
|
||||
|
||||
void Logger::pre_setup() {
|
||||
if (this->baud_rate_ > 0) {
|
||||
#ifdef USE_ARDUINO
|
||||
switch (this->uart_) {
|
||||
case UART_SELECTION_UART0:
|
||||
this->hw_serial_ = &Serial1;
|
||||
Serial1.begin(this->baud_rate_);
|
||||
break;
|
||||
#if defined(PIN_SERIAL2_RX) && defined(PIN_SERIAL2_TX)
|
||||
case UART_SELECTION_UART1:
|
||||
this->hw_serial_ = &Serial2;
|
||||
Serial2.begin(this->baud_rate_);
|
||||
break;
|
||||
#endif
|
||||
case UART_SELECTION_USB_CDC:
|
||||
this->hw_serial_ = &Serial;
|
||||
Serial.begin(this->baud_rate_);
|
||||
break;
|
||||
}
|
||||
#elif defined(USE_ZEPHYR)
|
||||
static const struct device *uart_dev = nullptr;
|
||||
switch (this->uart_) {
|
||||
case UART_SELECTION_UART0:
|
||||
uart_dev = DEVICE_DT_GET_OR_NULL(DT_NODELABEL(uart0));
|
||||
break;
|
||||
case UART_SELECTION_USB_CDC:
|
||||
uart_dev = DEVICE_DT_GET_OR_NULL(zephyr_cdc_acm_uart);
|
||||
if(device_is_ready(uart_dev)) {
|
||||
usb_enable(NULL);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (!device_is_ready(uart_dev)) {
|
||||
ESP_LOGE(TAG, "%s is not ready.", get_uart_selection_());
|
||||
} else {
|
||||
uart_dev_ = uart_dev;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
global_logger = this;
|
||||
ESP_LOGI(TAG, "Log initialized");
|
||||
}
|
||||
|
||||
const char *const UART_SELECTIONS[] = {"USB_CDC"};
|
||||
#ifdef USE_ZEPHYR
|
||||
void HOT Logger::write_msg_(const char *msg) {
|
||||
if(nullptr == uart_dev_) {
|
||||
return;
|
||||
}
|
||||
while(*msg) {
|
||||
uart_poll_out(uart_dev_, *msg);
|
||||
++msg;
|
||||
}
|
||||
uart_poll_out(uart_dev_, '\n');
|
||||
}
|
||||
#endif
|
||||
|
||||
const char *const UART_SELECTIONS[] = {"UART0", "USB_CDC"};
|
||||
|
||||
const char *Logger::get_uart_selection_() { return UART_SELECTIONS[this->uart_]; }
|
||||
|
||||
|
@@ -27,6 +27,7 @@ KEY_NRF52 = "nrf52"
|
||||
def set_core_data(config):
|
||||
CORE.data[KEY_NRF52] = {}
|
||||
CORE.data[KEY_NRF52][KEY_PRJ_CONF_OPTIONS] = {}
|
||||
CORE.data[KEY_NRF52][KEY_ZEPHYR_OVERLAY] = ""
|
||||
CORE.data[KEY_CORE][KEY_TARGET_PLATFORM] = PLATFORM_NRF52
|
||||
CORE.data[KEY_CORE][KEY_TARGET_FRAMEWORK] = config[CONF_FRAMEWORK][CONF_TYPE]
|
||||
return config
|
||||
@@ -103,6 +104,7 @@ nrf52_ns = cg.esphome_ns.namespace("nrf52")
|
||||
|
||||
PrjConfValueType = Union[bool, str, int]
|
||||
KEY_PRJ_CONF_OPTIONS = "prj_conf_options"
|
||||
KEY_ZEPHYR_OVERLAY = "zephyr_overlay"
|
||||
|
||||
|
||||
def add_zephyr_prj_conf_option(name: str, value: PrjConfValueType):
|
||||
@@ -118,6 +120,12 @@ def add_zephyr_prj_conf_option(name: str, value: PrjConfValueType):
|
||||
CORE.data[KEY_NRF52][KEY_PRJ_CONF_OPTIONS][name] = value
|
||||
|
||||
|
||||
def add_zephyr_overlay(content):
|
||||
if not CORE.using_zephyr:
|
||||
raise ValueError("Not an zephyr project")
|
||||
CORE.data[KEY_NRF52][KEY_ZEPHYR_OVERLAY] += content
|
||||
|
||||
|
||||
@coroutine_with_priority(1000)
|
||||
async def to_code(config):
|
||||
cg.add(nrf52_ns.setup_preferences())
|
||||
@@ -206,10 +214,6 @@ def _format_prj_conf_val(value: PrjConfValueType) -> str:
|
||||
raise ValueError
|
||||
|
||||
|
||||
overlay = """
|
||||
"""
|
||||
|
||||
|
||||
# Called by writer.py
|
||||
def copy_files():
|
||||
if CORE.using_zephyr:
|
||||
@@ -223,7 +227,10 @@ def copy_files():
|
||||
)
|
||||
|
||||
write_file_if_changed(CORE.relative_build_path("zephyr/prj.conf"), contents)
|
||||
write_file_if_changed(CORE.relative_build_path("zephyr/app.overlay"), overlay)
|
||||
write_file_if_changed(
|
||||
CORE.relative_build_path("zephyr/app.overlay"),
|
||||
CORE.data[KEY_NRF52][KEY_ZEPHYR_OVERLAY],
|
||||
)
|
||||
|
||||
dir = os.path.dirname(__file__)
|
||||
build_zephyr_file = os.path.join(
|
||||
|
Reference in New Issue
Block a user