浏览代码

change: 调整lcd库的buff分配方式,先psram在sram

Wendal Chen 1 年之前
父节点
当前提交
9236b97edb
共有 1 个文件被更改,包括 6 次插入2 次删除
  1. 6 2
      components/lcd/luat_lib_lcd.c

+ 6 - 2
components/lcd/luat_lib_lcd.c

@@ -1505,7 +1505,11 @@ static int l_lcd_setup_buff(lua_State* L) {
     return 0;
   }
   if (lua_isboolean(L, 2) && lua_toboolean(L, 2)) {
-    conf->buff = luat_heap_malloc(sizeof(luat_color_t) * conf->w * conf->h);
+    conf->buff = luat_heap_opt_malloc(LUAT_HEAP_PSRAM, sizeof(luat_color_t) * conf->w * conf->h);
+    if (conf->buff == NULL) {
+      LLOGW("psram 分配 lcd buff失败, 尝试在sram分配");
+      conf->buff = luat_heap_opt_malloc(LUAT_HEAP_SRAM, sizeof(luat_color_t) * conf->w * conf->h);
+    }
   }
   else {
     conf->buff = lua_newuserdata(L, sizeof(luat_color_t) * conf->w * conf->h);
@@ -1514,7 +1518,7 @@ static int l_lcd_setup_buff(lua_State* L) {
     }
   }
   if (conf->buff == NULL) {
-    LLOGE("lcd buff malloc fail, out of memory?");
+    LLOGE("lcd buff malloc fail, out of memory? size %d", sizeof(luat_color_t) * conf->w * conf->h);
     return 0;
   }
   // 先设置为不需要的区间