ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
logger_libretiny.cpp
Go to the documentation of this file.
1#ifdef USE_LIBRETINY
2#include "logger.h"
3
5#ifdef USE_LIBRETINY_CRASH_HANDLER
7#endif
8
9namespace esphome::logger {
10
11ESPHOME_LOG_TAG(TAG, "logger");
12
13void Logger::pre_setup() {
14 if (this->baud_rate_ > 0) {
15 switch (this->uart_) {
16#if LT_HW_UART0
18 this->hw_serial_ = &Serial0;
20 Serial0.begin(this->baud_rate_);
21 break;
22#endif
23#if LT_HW_UART1
25 this->hw_serial_ = &Serial1;
27 Serial1.begin(this->baud_rate_);
28 break;
29#endif
30#if LT_HW_UART2
32 this->hw_serial_ = &Serial2;
34 Serial2.begin(this->baud_rate_);
35 break;
36#endif
37 default:
38 this->hw_serial_ = &Serial;
39 Serial.begin(this->baud_rate_);
40 if (this->uart_ != UART_SELECTION_DEFAULT) {
41 ESP_LOGW(TAG, " The chosen logger UART port is not available on this board."
42 "The default port was used instead.");
43 }
44 break;
45 }
46
47 // change lt_log() port to match default Serial
48 if (this->uart_ == UART_SELECTION_DEFAULT) {
49 this->uart_ = (UARTSelection) (LT_UART_DEFAULT_SERIAL + 1);
50 lt_log_set_port(LT_UART_DEFAULT_SERIAL);
51 } else {
52 lt_log_set_port(this->uart_ - 1);
53 }
54 }
55
56 global_logger = this;
57 ESP_LOGI(TAG, "Log initialized");
58#ifdef USE_LIBRETINY_CRASH_HANDLER
60#endif
61}
62
63const LogString *Logger::get_uart_selection_() {
64 switch (this->uart_) {
66 return LOG_STR("DEFAULT");
68 return LOG_STR("UART0");
70 return LOG_STR("UART1");
72 default:
73 return LOG_STR("UART2");
74 }
75}
76
77#ifdef USE_LIBRETINY_CRASH_HANDLER
80#endif
81
82} // namespace esphome::logger
83
84#endif // USE_LIBRETINY
UARTSelection uart_
Definition logger.h:396
const LogString * get_uart_selection_()
void pre_setup()
Set up this component.
void crash_handler_log()
Log crash data if a crash was detected on previous boot.
void ensure_serial_handle(uint8_t port)
Give a hardware UART its SDK handle before its Serial begin()s.
Definition core.cpp:16
bool crash_handler_has_data()
Returns true if crash data was found this boot, reading it first if needed.
bool crash_log_pending()
Whether a crash record from before this boot is waiting to be reported.
UARTSelection
Enum for logging UART selection.
Definition logger.h:109
@ UART_SELECTION_UART2
Definition logger.h:118
@ UART_SELECTION_DEFAULT
Definition logger.h:111
@ UART_SELECTION_UART0
Definition logger.h:112
@ UART_SELECTION_UART1
Definition logger.h:116
Logger * global_logger
Definition logger.cpp:396
void log_crash_to_client()
Log the previous crash for a client that just subscribed to the logs.
ESPHOME_LOG_TAG(TAG, "logger")