Quellcode durchsuchen

add:luat_lcd_setup_buff

Dozingfiretruck vor 1 Jahr
Ursprung
Commit
3dfd19f808
3 geänderte Dateien mit 16 neuen und 5 gelöschten Zeilen
  1. 13 0
      components/lcd/luat_lcd.c
  2. 2 0
      components/lcd/luat_lcd.h
  3. 1 5
      components/lcd/luat_lib_lcd.c

+ 13 - 0
components/lcd/luat_lcd.c

@@ -183,6 +183,19 @@ INIT_DONE:
     return -1;
 }
 
+LUAT_WEAK int luat_lcd_setup_buff(luat_lcd_conf_t* conf){
+    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);
+    }
+    if (conf->buff == NULL) {
+        LLOGE("分配 lcd buff失败");
+        return -1;
+    }
+    return 0;
+}
+
 LUAT_WEAK int luat_lcd_init(luat_lcd_conf_t* conf) {
     return luat_lcd_init_default(conf);
 }

+ 2 - 0
components/lcd/luat_lcd.h

@@ -101,6 +101,7 @@ typedef struct luat_lcd_conf {
     uint16_t vspw;
     uint16_t vfp;
     luat_color_t* buff;
+    luat_color_t* buff_ex;
     struct luat_lcd_opts* opts;
     luat_spi_device_t* lcd_spi_device;
     int lcd_spi_ref;
@@ -162,6 +163,7 @@ int luat_lcd_draw_default(luat_lcd_conf_t* conf, int16_t x1, int16_t y1, int16_t
 luat_lcd_conf_t* luat_lcd_get_default(void);
 const char* luat_lcd_name(luat_lcd_conf_t* conf);
 int luat_lcd_init(luat_lcd_conf_t* conf);
+int luat_lcd_setup_buff(luat_lcd_conf_t* conf);
 int luat_lcd_close(luat_lcd_conf_t* conf);
 int luat_lcd_display_on(luat_lcd_conf_t* conf);
 int luat_lcd_display_off(luat_lcd_conf_t* conf);

+ 1 - 5
components/lcd/luat_lib_lcd.c

@@ -1480,11 +1480,7 @@ static int l_lcd_setup_buff(lua_State* L) {
     return 0;
   }
   if (lua_isboolean(L, 2) && lua_toboolean(L, 2)) {
-    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);
-    }
+    luat_lcd_setup_buff(conf);
   }
   else {
     conf->buff = lua_newuserdata(L, sizeof(luat_color_t) * conf->w * conf->h);