Improve PSRAM support (#2884)

This commit is contained in:
Oxan van Leeuwen
2022-01-03 22:35:15 +01:00
committed by GitHub
parent dce3713f12
commit dbc2812022
11 changed files with 162 additions and 69 deletions
+29
View File
@@ -0,0 +1,29 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components.esp32 import add_idf_sdkconfig_option
from esphome.core import CORE
from esphome.const import (
CONF_ID,
)
CODEOWNERS = ["@esphome/core"]
psram_ns = cg.esphome_ns.namespace("psram")
PsramComponent = psram_ns.class_("PsramComponent", cg.Component)
CONFIG_SCHEMA = cv.All(
cv.Schema({cv.GenerateID(): cv.declare_id(PsramComponent)}), cv.only_on_esp32
)
async def to_code(config):
if CORE.using_arduino:
cg.add_build_flag("-DBOARD_HAS_PSRAM")
if CORE.using_esp_idf:
add_idf_sdkconfig_option("CONFIG_ESP32_SPIRAM_SUPPORT", True)
add_idf_sdkconfig_option("CONFIG_SPIRAM_USE_CAPS_ALLOC", True)
add_idf_sdkconfig_option("CONFIG_SPIRAM_IGNORE_NOTFOUND", True)
var = cg.new_Pvariable(config[CONF_ID])
await cg.register_component(var, config)
+32
View File
@@ -0,0 +1,32 @@
#include "psram.h"
#ifdef USE_ESP32
#include "esphome/core/log.h"
#include <esp_heap_caps.h>
#include <esp_idf_version.h>
namespace esphome {
namespace psram {
static const char *const TAG = "psram";
void PsramComponent::dump_config() {
// Technically this can be false if the PSRAM is full, but heap_caps_get_total_size() isn't always available, and it's
// very unlikely for the PSRAM to be full.
bool available = heap_caps_get_free_size(MALLOC_CAP_SPIRAM) > 0;
ESP_LOGCONFIG(TAG, "PSRAM:");
ESP_LOGCONFIG(TAG, " Available: %s", YESNO(available));
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 1, 0)
if (available) {
ESP_LOGCONFIG(TAG, " Size: %d MB", heap_caps_get_total_size(MALLOC_CAP_SPIRAM) / 1024 / 1024);
}
#endif
}
} // namespace psram
} // namespace esphome
#endif
+17
View File
@@ -0,0 +1,17 @@
#pragma once
#ifdef USE_ESP32
#include "esphome/core/component.h"
namespace esphome {
namespace psram {
class PsramComponent : public Component {
void dump_config() override;
};
} // namespace psram
} // namespace esphome
#endif