ESPHome 2025.9.0-dev
Loading...
Searching...
No Matches
logger_libretiny.cpp
Go to the documentation of this file.
1#ifdef USE_LIBRETINY
2#include "logger.h"
3
4namespace esphome::logger {
5
6static const char *const TAG = "logger";
7
9 if (this->baud_rate_ > 0) {
10 switch (this->uart_) {
11#if LT_HW_UART0
13 this->hw_serial_ = &Serial0;
14 Serial0.begin(this->baud_rate_);
15 break;
16#endif
17#if LT_HW_UART1
19 this->hw_serial_ = &Serial1;
20 Serial1.begin(this->baud_rate_);
21 break;
22#endif
23#if LT_HW_UART2
25 this->hw_serial_ = &Serial2;
26 Serial2.begin(this->baud_rate_);
27 break;
28#endif
29 default:
30 this->hw_serial_ = &Serial;
31 Serial.begin(this->baud_rate_);
32 if (this->uart_ != UART_SELECTION_DEFAULT) {
33 ESP_LOGW(TAG, " The chosen logger UART port is not available on this board."
34 "The default port was used instead.");
35 }
36 break;
37 }
38
39 // change lt_log() port to match default Serial
40 if (this->uart_ == UART_SELECTION_DEFAULT) {
41 this->uart_ = (UARTSelection) (LT_UART_DEFAULT_SERIAL + 1);
42 lt_log_set_port(LT_UART_DEFAULT_SERIAL);
43 } else {
44 lt_log_set_port(this->uart_ - 1);
45 }
46 }
47
48 global_logger = this;
49 ESP_LOGI(TAG, "Log initialized");
50}
51
52void HOT Logger::write_msg_(const char *msg) { this->hw_serial_->println(msg); }
53
54const char *const UART_SELECTIONS[] = {"DEFAULT", "UART0", "UART1", "UART2"};
55
56const char *Logger::get_uart_selection_() { return UART_SELECTIONS[this->uart_]; }
57
58} // namespace esphome::logger
59
60#endif // USE_LIBRETINY
UARTSelection uart_
Definition logger.h:267
const char * get_uart_selection_()
void pre_setup()
Set up this component.
void write_msg_(const char *msg)
const char *const UART_SELECTIONS[]
UARTSelection
Enum for logging UART selection.
Definition logger.h:67
@ UART_SELECTION_UART2
Definition logger.h:76
@ UART_SELECTION_DEFAULT
Definition logger.h:69
@ UART_SELECTION_UART0
Definition logger.h:70
@ UART_SELECTION_UART1
Definition logger.h:74
Logger * global_logger
Definition logger.cpp:283