ESPHome  2024.12.2
debug_libretiny.cpp
Go to the documentation of this file.
1 #include "debug_component.h"
2 #ifdef USE_LIBRETINY
3 #include "esphome/core/log.h"
4 
5 namespace esphome {
6 namespace debug {
7 
8 static const char *const TAG = "debug";
9 
10 std::string DebugComponent::get_reset_reason_() { return lt_get_reboot_reason_name(lt_get_reboot_reason()); }
11 
12 uint32_t DebugComponent::get_free_heap_() { return lt_heap_get_free(); }
13 
14 void DebugComponent::get_device_info_(std::string &device_info) {
15  std::string reset_reason = get_reset_reason_();
16  ESP_LOGD(TAG, "LibreTiny Version: %s", lt_get_version());
17  ESP_LOGD(TAG, "Chip: %s (%04x) @ %u MHz", lt_cpu_get_model_name(), lt_cpu_get_model(), lt_cpu_get_freq_mhz());
18  ESP_LOGD(TAG, "Chip ID: 0x%06X", lt_cpu_get_mac_id());
19  ESP_LOGD(TAG, "Board: %s", lt_get_board_code());
20  ESP_LOGD(TAG, "Flash: %u KiB / RAM: %u KiB", lt_flash_get_size() / 1024, lt_ram_get_size() / 1024);
21  ESP_LOGD(TAG, "Reset Reason: %s", reset_reason.c_str());
22 
23  device_info += "|Version: ";
24  device_info += LT_BANNER_STR + 10;
25  device_info += "|Reset Reason: ";
26  device_info += reset_reason;
27  device_info += "|Chip Name: ";
28  device_info += lt_cpu_get_model_name();
29  device_info += "|Chip ID: 0x" + format_hex(lt_cpu_get_mac_id());
30  device_info += "|Flash: " + to_string(lt_flash_get_size() / 1024) + " KiB";
31  device_info += "|RAM: " + to_string(lt_ram_get_size() / 1024) + " KiB";
32 }
33 
35 #ifdef USE_SENSOR
36  if (this->block_sensor_ != nullptr) {
37  this->block_sensor_->publish_state(lt_heap_get_max_alloc());
38  }
39 #endif
40 }
41 
42 } // namespace debug
43 } // namespace esphome
44 #endif
std::string format_hex(const uint8_t *data, size_t length)
Format the byte array data of length len in lowercased hex.
Definition: helpers.cpp:357
void get_device_info_(std::string &device_info)
void publish_state(float state)
Publish a new state to the front-end.
Definition: sensor.cpp:39
std::string to_string(int value)
Definition: helpers.cpp:81
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7