1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-04 12:22:20 +01:00

fix logging for nrf52

This commit is contained in:
Tomasz Duda
2024-02-03 10:08:37 +01:00
parent e1686aab55
commit d88ece9822
4 changed files with 46 additions and 8 deletions

View File

@@ -102,7 +102,7 @@ ESP_ARDUINO_UNSUPPORTED_USB_UARTS = [USB_SERIAL_JTAG]
UART_SELECTION_RP2040 = [USB_CDC, UART0, UART1]
UART_SELECTION_NRF52 = [USB_CDC]
UART_SELECTION_NRF52 = [USB_CDC, UART0]
HARDWARE_UART_TO_UART_SELECTION = {
UART0: logger_ns.UART_SELECTION_UART0,

View File

@@ -4,12 +4,6 @@
#include "esphome/core/hal.h"
#include "esphome/core/log.h"
#ifdef USE_NRF52
#ifdef USE_ARDUINO
#include <Adafruit_TinyUSB.h> // for Serial
#endif
#endif
namespace esphome {
namespace logger {

View File

@@ -35,10 +35,11 @@ enum UARTSelection {
UART_SELECTION_DEFAULT = 0,
UART_SELECTION_UART0,
#else
#ifndef USE_NRF52
UART_SELECTION_UART0 = 0,
#endif
#if !defined(USE_NRF52) || defined(PIN_SERIAL2_RX) && defined(PIN_SERIAL2_TX)
UART_SELECTION_UART1,
#endif
#if defined(USE_LIBRETINY) || defined(USE_ESP32_VARIANT_ESP32)
UART_SELECTION_UART2,
#endif

View File

@@ -0,0 +1,43 @@
#ifdef USE_NRF52
#ifdef USE_ARDUINO
#include <Adafruit_TinyUSB.h> // for Serial
#endif
#include "logger.h"
#include "esphome/core/log.h"
namespace esphome {
namespace logger {
static const char *const TAG = "logger";
void Logger::pre_setup() {
if (this->baud_rate_ > 0) {
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;
}
}
global_logger = this;
ESP_LOGI(TAG, "Log initialized");
}
const char *const UART_SELECTIONS[] = {"USB_CDC"};
const char *Logger::get_uart_selection_() { return UART_SELECTIONS[this->uart_]; }
} // namespace logger
} // namespace esphome
#endif