ESPHome  2024.10.2
logger_libretiny.cpp
Go to the documentation of this file.
1 #ifdef USE_LIBRETINY
2 #include "logger.h"
3 
4 namespace esphome {
5 namespace logger {
6 
7 static const char *const TAG = "logger";
8 
9 void Logger::pre_setup() {
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 
53 void HOT Logger::write_msg_(const char *msg) { this->hw_serial_->println(msg); }
54 
55 const char *const UART_SELECTIONS[] = {"DEFAULT", "UART0", "UART1", "UART2"};
56 
57 const char *Logger::get_uart_selection_() { return UART_SELECTIONS[this->uart_]; }
58 
59 } // namespace logger
60 } // namespace esphome
61 
62 #endif // USE_LIBRETINY
UARTSelection
Enum for logging UART selection.
Definition: logger.h:33
Logger * global_logger
Definition: logger.cpp:198
const char * get_uart_selection_()
UARTSelection uart_
Definition: logger.h:151
void pre_setup()
Set up this component.
const char *const UART_SELECTIONS[]
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
void write_msg_(const char *msg)