ESPHome  2025.2.0
psram.cpp
Go to the documentation of this file.
1 #include "psram.h"
2 
3 #ifdef USE_ESP32
4 
5 #include "esphome/core/log.h"
6 
7 #include <esp_heap_caps.h>
8 #include <esp_idf_version.h>
9 
10 namespace esphome {
11 namespace psram {
12 
13 static const char *const TAG = "psram";
14 
15 void PsramComponent::dump_config() {
16  // Technically this can be false if the PSRAM is full, but heap_caps_get_total_size() isn't always available, and it's
17  // very unlikely for the PSRAM to be full.
18  bool available = heap_caps_get_free_size(MALLOC_CAP_SPIRAM) > 0;
19 
20  ESP_LOGCONFIG(TAG, "PSRAM:");
21  ESP_LOGCONFIG(TAG, " Available: %s", YESNO(available));
22 #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 1, 0)
23  if (available) {
24  const size_t psram_total_size_bytes = heap_caps_get_total_size(MALLOC_CAP_SPIRAM);
25  const float psram_total_size_kb = psram_total_size_bytes / 1024.0f;
26 
27  if (abs(std::round(psram_total_size_kb) - psram_total_size_kb) < 0.05f) {
28  ESP_LOGCONFIG(TAG, " Size: %.0f KB", psram_total_size_kb);
29  } else {
30  ESP_LOGCONFIG(TAG, " Size: %zu bytes", psram_total_size_bytes);
31  }
32  }
33 #endif
34 }
35 
36 } // namespace psram
37 } // namespace esphome
38 
39 #endif
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7