Skip to content

Commit b65f514

Browse files
committed
feature: Uses PSRAM (8MB available) instead of regular RAM (176KB limited).
1 parent 8c1ce73 commit b65f514

7 files changed

Lines changed: 40312 additions & 40269 deletions

File tree

256 Bytes
Binary file not shown.
464 Bytes
Binary file not shown.

webscreen/build/esp32.esp32.esp32s3/webscreen.ino.map

Lines changed: 40261 additions & 40262 deletions
Large diffs are not rendered by default.
0 Bytes
Binary file not shown.

webscreen/lvgl_elk.h

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,37 @@ static unsigned long lastWiFiReconnectAttempt = 0;
4444
/******************************************************************************
4545
* A) Elk Memory + Global Instances
4646
******************************************************************************/
47-
#define ELK_HEAP_BYTES (96 * 1024) // Increased to 96KB for better long-term stability
48-
static uint8_t elk_memory[ELK_HEAP_BYTES];
47+
#define ELK_HEAP_BYTES (256 * 1024) // 256KB in PSRAM for complex scripts
48+
static uint8_t *elk_memory = NULL;
49+
static size_t elk_memory_size = 0;
4950
struct js *js = NULL; // Global Elk instance
51+
52+
// Initialize Elk memory from PSRAM (must be called before js_create)
53+
static bool init_elk_memory() {
54+
if (elk_memory != NULL) {
55+
return true; // Already initialized
56+
}
57+
58+
// Try to allocate from PSRAM first
59+
elk_memory = (uint8_t*)ps_malloc(ELK_HEAP_BYTES);
60+
if (elk_memory != NULL) {
61+
elk_memory_size = ELK_HEAP_BYTES;
62+
LOGF("Elk heap allocated in PSRAM: %u KB\n", ELK_HEAP_BYTES / 1024);
63+
return true;
64+
}
65+
66+
// Fallback to regular heap with smaller size
67+
size_t fallback_size = 96 * 1024;
68+
elk_memory = (uint8_t*)malloc(fallback_size);
69+
if (elk_memory != NULL) {
70+
elk_memory_size = fallback_size;
71+
LOGF("Elk heap allocated in RAM (fallback): %u KB\n", fallback_size / 1024);
72+
return true;
73+
}
74+
75+
LOG("ERROR: Failed to allocate Elk heap!");
76+
return false;
77+
}
5078
// Adjust as needed
5179
#define MAX_RAM_IMAGES 16
5280

@@ -3272,7 +3300,14 @@ void register_js_functions() {
32723300
// K) The elk_task -- runs Elk + bridging in a separate FreeRTOS task
32733301

32743302
static void elk_task(void *pvParam) {
3275-
js = js_create(elk_memory, sizeof(elk_memory));
3303+
// Initialize Elk memory from PSRAM
3304+
if (!init_elk_memory()) {
3305+
LOG("Failed to allocate Elk memory in elk_task");
3306+
vTaskDelete(NULL);
3307+
return;
3308+
}
3309+
3310+
js = js_create(elk_memory, elk_memory_size);
32763311
if (!js) {
32773312
LOG("Failed to initialize Elk in elk_task");
32783313
// Delete this task if you want

webscreen/webscreen_config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#define WEBSCREEN_VERSION_MAJOR 2
1717
#define WEBSCREEN_VERSION_MINOR 0
1818
#define WEBSCREEN_VERSION_PATCH 0
19-
#define WEBSCREEN_VERSION_STRING "2.0.2"
19+
#define WEBSCREEN_VERSION_STRING "2.0.3"
2020

2121
// ============================================================================
2222
// HARDWARE CONFIGURATION

webscreen/webscreen_runtime.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ static uint32_t g_runtime_start_time = 0;
2121
static bool g_lvgl_initialized = false;
2222

2323
extern struct js* js;
24-
extern uint8_t elk_memory[];
24+
extern uint8_t *elk_memory;
25+
extern size_t elk_memory_size;
26+
extern bool init_elk_memory();
2527
static TaskHandle_t g_js_task_handle = NULL;
2628
static bool g_js_engine_initialized = false;
2729
static String g_js_script_content = "";
@@ -336,15 +338,22 @@ bool webscreen_runtime_init_javascript_engine(void) {
336338
}
337339

338340
WEBSCREEN_DEBUG_PRINTLN("Initializing Elk JavaScript engine...");
339-
js = js_create(elk_memory, sizeof(elk_memory));
341+
342+
// Initialize Elk memory from PSRAM
343+
if (!init_elk_memory()) {
344+
WEBSCREEN_DEBUG_PRINTLN("Failed to allocate Elk memory");
345+
return false;
346+
}
347+
348+
js = js_create(elk_memory, elk_memory_size);
340349
if (!js) {
341350
WEBSCREEN_DEBUG_PRINTLN("Failed to initialize Elk JavaScript engine");
342351
return false;
343352
}
344353

345354
// Set aggressive GC threshold to trigger garbage collection more often
346355
// This helps prevent memory fragmentation during long-running scripts
347-
js_setgct(js, sizeof(elk_memory) / 4); // Trigger GC when 25% of heap is used
356+
js_setgct(js, elk_memory_size / 4); // Trigger GC when 25% of heap is used
348357

349358
webscreen_runtime_register_js_functions();
350359

0 commit comments

Comments
 (0)