Skip to content

Commit

Permalink
Enables PSRAM
Browse files Browse the repository at this point in the history
Supports #1983
Supports #1946
Supports #1815

Could support esphome/feature-requests#2369
  • Loading branch information
edwardtfn committed Apr 4, 2024
1 parent 0e6853f commit 140cbdd
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 23 deletions.
15 changes: 14 additions & 1 deletion components/nspanel_ha_blueprint/__init__.py
Original file line number Diff line number Diff line change
@@ -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"]

Expand All @@ -14,5 +15,17 @@

@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)

3 changes: 2 additions & 1 deletion docs/version_compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
<!-- markdownlint-disable MD013 MD033 -->
| NSPanel_HA_Blueprint<br><sub><sup>Version</sup></sub> | Home Assistant<br><sub><sup>Min version</sup></sub> | ESPHome<br><sub><sup>Min version</sup></sub> |
| :--: | :--: | :--: |
| v4.3.1 | 2024.3.0 | 2024.3.0 |
| v4.3.3 | 2024.3.0 | 2023.12.0 |
| v4.3.2<br>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<br>v4.2 | 2023.9.0 | 2023.12.0 |
Expand Down
52 changes: 31 additions & 21 deletions esphome/nspanel_esphome_core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -106,6 +100,11 @@ esp32:
framework:
type: esp-idf

debug:

psram:
id: ext_ram

##### WIFI SETUP #####
wifi:
id: wifi_component
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:");
Expand Down

0 comments on commit 140cbdd

Please sign in to comment.