From 140cbdd4099c637560281b48263c4e326ce485ef Mon Sep 17 00:00:00 2001
From: Edward Firmo <94725493+edwardtfn@users.noreply.github.com>
Date: Fri, 5 Apr 2024 00:54:51 +0200
Subject: [PATCH] Enables PSRAM
Supports #1983
Supports #1946
Supports #1815
Could support esphome/feature-requests#2369
---
components/nspanel_ha_blueprint/__init__.py | 15 +++++-
docs/version_compatibility.md | 3 +-
esphome/nspanel_esphome_core.yaml | 52 ++++++++++++---------
3 files changed, 47 insertions(+), 23 deletions(-)
diff --git a/components/nspanel_ha_blueprint/__init__.py b/components/nspanel_ha_blueprint/__init__.py
index 9ba0e44..8dba9eb 100644
--- a/components/nspanel_ha_blueprint/__init__.py
+++ b/components/nspanel_ha_blueprint/__init__.py
@@ -1,7 +1,8 @@
# __init__.py
import esphome.codegen as cg
import esphome.config_validation as cv
-from esphome.core import coroutine_with_priority
+from esphome.components.esp32 import add_idf_sdkconfig_option, get_esp32_variant
+from esphome.core import CORE, coroutine_with_priority
CODEOWNERS = ["@edwardtfn"]
@@ -14,5 +15,17 @@ CONFIG_SCHEMA = cv.All(
@coroutine_with_priority(1.0)
async def to_code(config):
+ if CORE.using_arduino:
+ cg.add_build_flag("-DCONFIG_D0WD_PSRAM_CLK_IO=5")
+ cg.add_build_flag("-DCONFIG_D0WD_PSRAM_CS_IO=18")
+
+ if CORE.using_esp_idf:
+ add_idf_sdkconfig_option("CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST", True)
+ add_idf_sdkconfig_option("CONFIG_BT_BLE_DYNAMIC_ENV_MEMORY", True)
+ add_idf_sdkconfig_option("CONFIG_ESP32_REV_MIN_3", True)
+ add_idf_sdkconfig_option("CONFIG_D0WD_PSRAM_CLK_IO", 5)
+ add_idf_sdkconfig_option("CONFIG_D0WD_PSRAM_CS_IO", 18)
+
cg.add_define("USE_NSPANEL_HA_BLUEPRINT")
cg.add_global(nspanel_ha_blueprint_ns.using)
+
diff --git a/docs/version_compatibility.md b/docs/version_compatibility.md
index e27c185..c0e74c4 100644
--- a/docs/version_compatibility.md
+++ b/docs/version_compatibility.md
@@ -3,7 +3,8 @@
| NSPanel_HA_Blueprint
Version | Home Assistant
Min version | ESPHome
Min version |
| :--: | :--: | :--: |
-| v4.3.1 | 2024.3.0 | 2024.3.0 |
+| v4.3.3 | 2024.3.0 | 2023.12.0 |
+| v4.3.2
v4.3.1 | 2024.3.0 | 2024.3.0 |
| v4.3.0 | 2024.3.0 | 2023.12.0 |
| v4.2.2+ | 2023.12.0 | 2023.12.0 |
| v4.2.1
v4.2 | 2023.9.0 | 2023.12.0 |
diff --git a/esphome/nspanel_esphome_core.yaml b/esphome/nspanel_esphome_core.yaml
index 81dda6c..b4b9957 100644
--- a/esphome/nspanel_esphome_core.yaml
+++ b/esphome/nspanel_esphome_core.yaml
@@ -27,7 +27,7 @@ external_components:
# path: packages/Blackymas/components
type: git
url: https://github.com/Blackymas/NSPanel_HA_Blueprint
- ref: v4.3.2
+ ref: dev # To do: Change to tag when releasing
components:
- nspanel_ha_blueprint
refresh: 300s
@@ -50,16 +50,10 @@ external_components:
esphome:
name: ${name}
friendly_name: ${friendly_name}
- min_version: 2024.3.0
+ min_version: 2023.12.0
platformio_options:
build_flags:
- -Wno-missing-field-initializers
- # - -mfix-esp32-psram-cache-issue
- # - -fdata-sections
- # - -ffunction-sections
- # - -Wl,--gc-sections
- # - -Os
- # - -flto
on_boot:
- priority: 600.0 # This is where most sensors are set up.
@@ -106,6 +100,11 @@ esp32:
framework:
type: esp-idf
+debug:
+
+psram:
+ id: ext_ram
+
##### WIFI SETUP #####
wifi:
id: wifi_component
@@ -2212,7 +2211,11 @@ script:
- lambda: |-
boot_progress->execute(3);
if (current_page->state == "boot") {
+ #if ESPHOME_VERSION_CODE < VERSION_CODE(2024, 3, 0) // Code for ESPHome earlier than v2024.3.0
+ disp1->set_component_text("ip_addr", network::get_ip_address().str().c_str());
+ #else // Code for ESPHome v2024.3.0 or newer
disp1->set_component_text("ip_addr", network::get_ip_addresses()[0].str().c_str());
+ #endif // ESPHome version based code
set_brightness->execute(100);
}
- logger.log: Wait for API
@@ -3166,25 +3169,32 @@ script:
// Report ESPHome
ESP_LOGI(TAG, "ESPHome:");
ESP_LOGI(TAG, " Version: ${version}");
+ ESP_LOGI(TAG, " Compiler: %s", ESPHOME_VERSION);
// Report framework
#ifdef ARDUINO
ESP_LOGI(TAG, " Framework: Arduino");
- size_t total_heap_size = ESP.getHeapSize();
- size_t free_heap_size = ESP.getFreeHeap();
#elif defined(USE_ESP_IDF)
ESP_LOGI(TAG, " Framework: ESP-IDF");
- size_t total_heap_size = heap_caps_get_total_size(MALLOC_CAP_DEFAULT);
- size_t free_heap_size = esp_get_free_heap_size();
#endif
- if (total_heap_size != 0) {
- std::string numStr = std::to_string(free_heap_size);
- int insertPosition = numStr.length() - 3;
- while (insertPosition > 0) {
- numStr.insert(insertPosition, " ");
- insertPosition -= 3;
- }
- ESP_LOGI(TAG, " Free heap: %s bytes (%d%%)", numStr.c_str(),
- int(round(((float)free_heap_size / total_heap_size) * 100.0f)));
+ // Report memory
+ const size_t internal_heap_size = heap_caps_get_total_size(MALLOC_CAP_INTERNAL);
+ const size_t internal_heap_size_free = heap_caps_get_free_size(MALLOC_CAP_INTERNAL);
+ const size_t psram_heap_size = heap_caps_get_total_size(MALLOC_CAP_SPIRAM);
+ const size_t psram_heap_size_free = heap_caps_get_free_size(MALLOC_CAP_SPIRAM);
+ ESP_LOGI(TAG, " Free heap:");
+
+ if (internal_heap_size != 0) {
+ ESP_LOGI(TAG, " Internal: %7d bytes (%0.1f%%)", internal_heap_size_free,
+ ((float)internal_heap_size_free / internal_heap_size) * 100.0f);
+ } else {
+ ESP_LOGI(TAG, " Internal: %7d bytes", internal_heap_size_free);
+ }
+
+ if (psram_heap_size != 0) {
+ ESP_LOGI(TAG, " PSRAM: %7d bytes (%0.1f%%)", psram_heap_size_free,
+ ((float)psram_heap_size_free / psram_heap_size) * 100.0f);
+ } else {
+ ESP_LOGI(TAG, " PSRAM: %7d bytes", psram_heap_size_free);
}
// Report UART
ESP_LOGI(TAG, "UART:");