ESPHome 2025.5.0
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 {
5namespace logger {
6
7static const char *const TAG = "logger";
8
10 if (this->baud_rate_ > 0) {
11 switch (this->uart_) {
12#if LT_HW_UART0
14 this->hw_serial_ = &Serial0;
15 Serial0.begin(this->baud_rate_);
16 break;
17#endif
18#if LT_HW_UART1
20 this->hw_serial_ = &Serial1;
21 Serial1.begin(this->baud_rate_);
22 break;
23#endif
24#if LT_HW_UART2
26 this->hw_serial_ = &Serial2;
27 Serial2.begin(this->baud_rate_);
28 break;
29#endif
30 default:
31 this->hw_serial_ = &Serial;
32 Serial.begin(this->baud_rate_);
33 if (this->uart_ != UART_SELECTION_DEFAULT) {
34 ESP_LOGW(TAG, " The chosen logger UART port is not available on this board."
35 "The default port was used instead.");
36 }
37 break;
38 }
39
40 // change lt_log() port to match default Serial
41 if (this->uart_ == UART_SELECTION_DEFAULT) {
42 this->uart_ = (UARTSelection) (LT_UART_DEFAULT_SERIAL + 1);
43 lt_log_set_port(LT_UART_DEFAULT_SERIAL);
44 } else {
45 lt_log_set_port(this->uart_ - 1);
46 }
47 }
48
49 global_logger = this;
50 ESP_LOGI(TAG, "Log initialized");
51}
52
53void HOT Logger::write_msg_(const char *msg) { this->hw_serial_->println(msg); }
54
55const char *const UART_SELECTIONS[] = {"DEFAULT", "UART0", "UART1", "UART2"};
56
57const char *Logger::get_uart_selection_() { return UART_SELECTIONS[this->uart_]; }
58
59} // namespace logger
60} // namespace esphome
61
62#endif // USE_LIBRETINY
UARTSelection uart_
Definition logger.h:231
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:64
@ UART_SELECTION_UART2
Definition logger.h:73
@ UART_SELECTION_DEFAULT
Definition logger.h:66
@ UART_SELECTION_UART0
Definition logger.h:67
@ UART_SELECTION_UART1
Definition logger.h:71
Logger * global_logger
Definition logger.cpp:251
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7