ESPHome 2025.5.0
Loading...
Searching...
No Matches
psram.cpp
Go to the documentation of this file.
1
2#ifdef USE_ESP32
3#include "psram.h"
4#include <esp_idf_version.h>
5#if defined(USE_ESP_IDF) && ESP_IDF_VERSION_MAJOR >= 5
6#include <esp_psram.h>
7#endif // USE_ESP_IDF
8
9#include "esphome/core/log.h"
10
11#include <esp_heap_caps.h>
12
13namespace esphome {
14namespace psram {
15static const char *const TAG = "psram";
16
17void PsramComponent::dump_config() {
18 ESP_LOGCONFIG(TAG, "PSRAM:");
19#if defined(USE_ESP_IDF) && ESP_IDF_VERSION_MAJOR >= 5
20 bool available = esp_psram_is_initialized();
21
22 ESP_LOGCONFIG(TAG, " Available: %s", YESNO(available));
23 if (available) {
24 ESP_LOGCONFIG(TAG, " Size: %zu KB", esp_psram_get_size() / 1024);
25#if CONFIG_SPIRAM_ECC_ENABLE
26 ESP_LOGCONFIG(TAG, " ECC enabled: YES");
27#endif
28 }
29#else
30 // Technically this can be false if the PSRAM is full, but heap_caps_get_total_size() isn't always available, and it's
31 // very unlikely for the PSRAM to be full.
32 bool available = heap_caps_get_free_size(MALLOC_CAP_SPIRAM) > 0;
33 ESP_LOGCONFIG(TAG, " Available: %s", YESNO(available));
34
35 if (available) {
36 const size_t psram_total_size_bytes = heap_caps_get_total_size(MALLOC_CAP_SPIRAM);
37 const float psram_total_size_kb = psram_total_size_bytes / 1024.0f;
38
39 if (abs(std::round(psram_total_size_kb) - psram_total_size_kb) < 0.05f) {
40 ESP_LOGCONFIG(TAG, " Size: %.0f KB", psram_total_size_kb);
41 } else {
42 ESP_LOGCONFIG(TAG, " Size: %zu bytes", psram_total_size_bytes);
43 }
44 }
45#endif // USE_ESP_IDF
46}
47
48} // namespace psram
49} // namespace esphome
50
51#endif
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7