mirror of
https://github.com/esphome/esphome.git
synced 2025-09-04 04:12:23 +01:00
fix config dump over cdc
This commit is contained in:
@@ -40,7 +40,7 @@ from esphome.components.libretiny.const import (
|
||||
COMPONENT_BK72XX,
|
||||
COMPONENT_RTL87XX,
|
||||
)
|
||||
from esphome.components.nrf52 import add_zephyr_overlay
|
||||
from esphome.components.nrf52 import add_zephyr_overlay, add_zephyr_prj_conf_option
|
||||
|
||||
CODEOWNERS = ["@esphome/core"]
|
||||
logger_ns = cg.esphome_ns.namespace("logger")
|
||||
@@ -299,6 +299,8 @@ async def to_code(config):
|
||||
if CORE.using_zephyr:
|
||||
if config[CONF_HARDWARE_UART] == UART0:
|
||||
add_zephyr_overlay("""&uart0 { status = "okay";};""")
|
||||
if config[CONF_HARDWARE_UART] == USB_CDC:
|
||||
add_zephyr_prj_conf_option("CONFIG_UART_LINE_CTRL", True)
|
||||
|
||||
# Register at end for safe mode
|
||||
await cg.register_component(log, config)
|
||||
|
@@ -152,6 +152,7 @@ Logger::Logger(uint32_t baud_rate, size_t tx_buffer_size) : baud_rate_(baud_rate
|
||||
}
|
||||
|
||||
#ifdef USE_USB_CDC
|
||||
# ifndef USE_ZEPHYR
|
||||
void Logger::loop() {
|
||||
#ifdef USE_ARDUINO
|
||||
if (this->uart_ != UART_SELECTION_USB_CDC) {
|
||||
@@ -168,6 +169,7 @@ void Logger::loop() {
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void Logger::set_baud_rate(uint32_t baud_rate) { this->baud_rate_ = baud_rate; }
|
||||
void Logger::set_log_level(const std::string &tag, int log_level) {
|
||||
|
@@ -21,6 +21,10 @@
|
||||
#include <driver/uart.h>
|
||||
#endif // USE_ESP_IDF
|
||||
|
||||
#ifdef USE_ZEPHYR
|
||||
struct device;
|
||||
#endif
|
||||
|
||||
namespace esphome {
|
||||
|
||||
namespace logger {
|
||||
@@ -157,7 +161,7 @@ class Logger : public Component {
|
||||
#elif defined(USE_ESP_IDF)
|
||||
uart_port_t uart_num_;
|
||||
#elif defined(USE_ZEPHYR)
|
||||
const struct device * uart_dev_{nullptr};
|
||||
const device * uart_dev_{nullptr};
|
||||
#endif
|
||||
struct LogLevelOverride {
|
||||
std::string tag;
|
||||
|
@@ -4,19 +4,41 @@
|
||||
#endif
|
||||
#include "logger.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace logger {
|
||||
#include "esphome/core/application.h"
|
||||
|
||||
#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
|
||||
|
||||
namespace esphome {
|
||||
namespace logger {
|
||||
|
||||
|
||||
static const char *const TAG = "logger";
|
||||
|
||||
#ifdef USE_ZEPHYR
|
||||
void Logger::loop() {
|
||||
if (this->uart_ != UART_SELECTION_USB_CDC || nullptr == uart_dev_) {
|
||||
return;
|
||||
}
|
||||
static bool opened = false;
|
||||
uint32_t dtr = 0;
|
||||
uart_line_ctrl_get(uart_dev_, UART_LINE_CTRL_DTR, &dtr);
|
||||
|
||||
/* Poll if the DTR flag was set, optional */
|
||||
if(opened == dtr) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(false == opened){
|
||||
App.schedule_dump_config();
|
||||
}
|
||||
opened = !opened;
|
||||
}
|
||||
#endif
|
||||
|
||||
void Logger::pre_setup() {
|
||||
if (this->baud_rate_ > 0) {
|
||||
#ifdef USE_ARDUINO
|
||||
|
Reference in New Issue
Block a user