ESPHome 2026.5.0b1
Loading...
Searching...
No Matches
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
5namespace esphome::debug {
6
7static const char *const TAG = "debug";
8
9const char *DebugComponent::get_reset_reason_(std::span<char, RESET_REASON_BUFFER_SIZE> buffer) {
10 // Return the static string directly
11 return lt_get_reboot_reason_name(lt_get_reboot_reason());
12}
13
14const char *DebugComponent::get_wakeup_cause_(std::span<char, WAKEUP_CAUSE_BUFFER_SIZE> buffer) { return ""; }
15
16uint32_t DebugComponent::get_free_heap_() { return lt_heap_get_free(); }
17
18size_t DebugComponent::get_device_info_(std::span<char, DEVICE_INFO_BUFFER_SIZE> buffer, size_t pos) {
19 constexpr size_t size = DEVICE_INFO_BUFFER_SIZE;
20 char *buf = buffer.data();
21
22 char reason_buffer[RESET_REASON_BUFFER_SIZE];
23 const char *reset_reason = get_reset_reason_(std::span<char, RESET_REASON_BUFFER_SIZE>(reason_buffer));
24 uint32_t flash_kib = lt_flash_get_size() / 1024;
25 uint32_t ram_kib = lt_ram_get_size() / 1024;
26 uint32_t mac_id = lt_cpu_get_mac_id();
27
28 ESP_LOGD(TAG,
29 "LibreTiny debug info:\n"
30 " Version: %s\n"
31 " Chip: %s (%04x) @ %u MHz\n"
32 " Chip ID: 0x%06" PRIX32 "\n"
33 " Board: %s\n"
34 " Flash: %" PRIu32 " KiB\n"
35 " RAM: %" PRIu32 " KiB\n"
36 " Reset Reason: %s",
37 lt_get_version(), lt_cpu_get_model_name(), lt_cpu_get_model(), lt_cpu_get_freq_mhz(), mac_id,
38 lt_get_board_code(), flash_kib, ram_kib, reset_reason);
39
40 pos = buf_append_str(buf, size, pos, "|Version: ");
41 pos = buf_append_str(buf, size, pos, LT_BANNER_STR + 10);
42 pos = buf_append_str(buf, size, pos, "|Reset Reason: ");
43 pos = buf_append_str(buf, size, pos, reset_reason);
44 pos = buf_append_str(buf, size, pos, "|Chip Name: ");
45 pos = buf_append_str(buf, size, pos, lt_cpu_get_model_name());
46 pos = buf_append_printf(buf, size, pos, "|Chip ID: 0x%06" PRIX32, mac_id);
47 pos = buf_append_printf(buf, size, pos, "|Flash: %" PRIu32 " KiB", flash_kib);
48 pos = buf_append_printf(buf, size, pos, "|RAM: %" PRIu32 " KiB", ram_kib);
49
50 return pos;
51}
52
54#ifdef USE_SENSOR
55 if (this->block_sensor_ != nullptr) {
56 this->block_sensor_->publish_state(lt_heap_get_max_alloc());
57 }
58 if (this->min_free_sensor_ != nullptr) {
59 this->min_free_sensor_->publish_state(lt_heap_get_min_free());
60 }
61#endif
62}
63
64} // namespace esphome::debug
65#endif
const char * get_wakeup_cause_(std::span< char, WAKEUP_CAUSE_BUFFER_SIZE > buffer)
size_t get_device_info_(std::span< char, DEVICE_INFO_BUFFER_SIZE > buffer, size_t pos)
const char * get_reset_reason_(std::span< char, RESET_REASON_BUFFER_SIZE > buffer)
void publish_state(float state)
Publish a new state to the front-end.
Definition sensor.cpp:68
size_t buf_append_str(char *buf, size_t size, size_t pos, const char *str)
Safely append a string to buffer, returning new position (capped at size).
Definition helpers.h:1087
uint16_t size
Definition helpers.cpp:25
size_t size_t pos
Definition helpers.h:1038
static void uint32_t