diff options
| author | jacqueline <me@jacqueline.id.au> | 2024-01-17 17:50:57 +1100 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2024-01-17 17:50:57 +1100 |
| commit | c1b7a0c9f2192121fad972dccc7d0a1fe0dee45e (patch) | |
| tree | c07f49517d64aed041f45ca4870d68a6cdee16c8 | |
| parent | ea8a7b0f93aa3b391e92d7b930f667d1ff439d04 (diff) | |
| download | tangara-fw-c1b7a0c9f2192121fad972dccc7d0a1fe0dee45e.tar.gz | |
move lua ui-related data to spi ram
| -rw-r--r-- | lib/luavgl/src/event.c | 9 | ||||
| -rw-r--r-- | src/ui/ui_fsm.cpp | 10 |
2 files changed, 15 insertions, 4 deletions
diff --git a/lib/luavgl/src/event.c b/lib/luavgl/src/event.c index 88748a6f..29cf8830 100644 --- a/lib/luavgl/src/event.c +++ b/lib/luavgl/src/event.c @@ -1,6 +1,8 @@ #include "luavgl.h" #include "private.h" +#include "esp_heap_caps.h" + static void luavgl_obj_event_cb(lv_event_t *e) { lua_State *L = e->user_data; @@ -102,7 +104,8 @@ static int luavgl_obj_on_event(lua_State *L) /* create obj->lobj->events, if NULL, realloc if existing and find no slot */ if (events == NULL) { - events = calloc(sizeof(struct event_callback_s), 1); + events = + heap_caps_calloc(sizeof(struct event_callback_s), 1, MALLOC_CAP_SPIRAM); if (events == NULL) { return luaL_error(L, "No memory."); } @@ -113,7 +116,9 @@ static int luavgl_obj_on_event(lua_State *L) /* realloc? */ if (slot && slot == lobj->n_events) { struct event_callback_s *_events; - _events = realloc(lobj->events, (lobj->n_events + 1) * sizeof(*_events)); + _events = heap_caps_realloc(lobj->events, + (lobj->n_events + 1) * sizeof(*_events), + MALLOC_CAP_SPIRAM); if (_events == NULL) { return luaL_error(L, "No memory."); } diff --git a/src/ui/ui_fsm.cpp b/src/ui/ui_fsm.cpp index 20d52f8e..7f94abc5 100644 --- a/src/ui/ui_fsm.cpp +++ b/src/ui/ui_fsm.cpp @@ -7,6 +7,7 @@ #include "ui_fsm.hpp" #include <memory> +#include <memory_resource> #include <variant> #include "bluetooth_types.hpp" @@ -26,6 +27,7 @@ #include "lauxlib.h" #include "lua_thread.hpp" #include "luavgl.h" +#include "memory_resource.hpp" #include "misc/lv_gc.h" #include "audio_events.hpp" @@ -449,8 +451,12 @@ auto Lua::PushLuaScreen(lua_State* s) -> int { luaL_checktype(s, 1, LUA_TFUNCTION); // First, create a new plain old Screen object. We will use its root and - // group for the Lua screen. - auto new_screen = std::make_shared<screens::Lua>(); + // group for the Lua screen. Allocate it in external ram so that arbitrarily + // deep screen stacks don't cause too much memory pressure. + auto new_screen = + std::allocate_shared<screens::Lua, + std::pmr::polymorphic_allocator<screens::Lua>>( + &memory::kSpiRamResource); // Tell lvgl about the new roots. luavgl_set_root(s, new_screen->content()); |
