Dozingfiretruck 10 месяцев назад
Родитель
Сommit
7ae0738e27

+ 1 - 0
components/lcd/luat_lcd.h

@@ -102,6 +102,7 @@ typedef struct luat_lcd_conf {
     uint16_t vfp;
     luat_color_t* buff;
     luat_color_t* buff_ex;
+    luat_color_t* buff_draw;
     struct luat_lcd_opts* opts;
     luat_spi_device_t* lcd_spi_device;
     int lcd_spi_ref;

+ 10 - 5
components/lvgl/binding/luat_lib_lvgl7.c

@@ -148,10 +148,15 @@ int luat_lv_init(lua_State *L) {
 
     if (lcd_conf != NULL && lcd_conf->buff != NULL) {
         // LLOGD("use LCD buff");
-        fbuffer = lcd_conf->buff;
-        // fbuff_size = w * h;
-        fbuff_size = w * 10;
-        buffmode = 3;
+        if (lcd_conf->buff_ex){
+            fbuffer = lcd_conf->buff;
+            fbuffer2 = lcd_conf->buff_ex;
+            fbuff_size = w * h;
+            buffmode = 0x04; //使用LCD的双buff模式
+        }else{
+            fbuff_size = w * 10;
+            buffmode = 0x03; //申请双buff模式
+        }
     }
     if (buffmode & 0x02) {
         //LLOGD("use HEAP buff");
@@ -169,7 +174,7 @@ int luat_lv_init(lua_State *L) {
             }
         }
     }
-    else {
+    else if(buffmode==0){
         //LLOGD("use VM buff");
         fbuffer = lua_newuserdata(L, fbuff_size * sizeof(lv_color_t));
         if (fbuffer == NULL) {

+ 3 - 0
components/lvgl8/lv_conf.h

@@ -48,7 +48,10 @@
  *=========================*/
 
 /*1: use custom malloc/free, 0: use the built-in `lv_mem_alloc()` and `lv_mem_free()`*/
+
+#ifndef LV_MEM_CUSTOM
 #define LV_MEM_CUSTOM 1
+#endif
 #if LV_MEM_CUSTOM == 0
     /*Size of the memory available for `lv_mem_alloc()` in bytes (>= 2kB)*/
     #define LV_MEM_SIZE (48U * 1024U)          /*[bytes]*/

+ 23 - 10
components/lvgl8/porting/lv_port_disp.c

@@ -57,14 +57,19 @@ void lv_port_disp_init(luat_lcd_conf_t* lcd_conf)
     static lv_disp_draw_buf_t lv_disp_draw_buf;
     lv_color_t* buf_2_1 = NULL;
     lv_color_t* buf_2_2 = NULL;
+    uint32_t size_in_px_cnt = (lcd_conf->w * 10);
+    
+    if (lcd_conf->buff_ex) {
+        size_in_px_cnt = lcd_conf->w * lcd_conf->h;
+        buf_2_1 = lcd_conf->buff;
+        buf_2_2 = lcd_conf->buff_ex;
+    }else{
+        uint32_t draw_buffer_size = size_in_px_cnt * sizeof(lv_color_t);
+        buf_2_1 = luat_heap_opt_malloc(LUAT_HEAP_SRAM, draw_buffer_size);
+        buf_2_2 = luat_heap_opt_malloc(LUAT_HEAP_SRAM, draw_buffer_size);
+    }
 
-    #define SIZE_IN_PX_CNT     (lcd_conf->w * 10)
-    #define DRAW_BUFFER_SIZE    SIZE_IN_PX_CNT * sizeof(lv_color_t)
-
-    buf_2_1 = luat_heap_opt_malloc(LUAT_HEAP_SRAM, DRAW_BUFFER_SIZE);
-    buf_2_2 = luat_heap_opt_malloc(LUAT_HEAP_SRAM, DRAW_BUFFER_SIZE);
-
-    lv_disp_draw_buf_init(&lv_disp_draw_buf, buf_2_1, buf_2_2, SIZE_IN_PX_CNT);
+    lv_disp_draw_buf_init(&lv_disp_draw_buf, buf_2_1, buf_2_2, size_in_px_cnt);
 
     // lv_disp_draw_buf_init(&lv_disp_draw_buf, lcd_conf->buff, lcd_conf->buff1, lcd_conf->w * lcd_conf->h);
 
@@ -88,7 +93,9 @@ void lv_port_disp_init(luat_lcd_conf_t* lcd_conf)
     disp_drv.draw_buf = &lv_disp_draw_buf;
 
     /*Required for Example 3)*/
-    //disp_drv.full_refresh = 1;
+    if (lcd_conf->buff_ex){
+        disp_drv.full_refresh = 1;
+    }
 
     /* Fill a memory array with a color if you have GPU.
      * Note that, in lv_conf.h you can enable GPUs that has built-in support in LVGL.
@@ -134,9 +141,15 @@ static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_colo
 {
     if(disp_flush_enabled) {
         luat_lcd_conf_t* lcd_conf = disp_drv->user_data;
-        luat_lcd_draw(lcd_conf, area->x1, area->y1, area->x2, area->y2, color_p);
-        if (lv_disp_flush_is_last(disp_drv))
+        if (lcd_conf->buff_ex == NULL){
+            luat_lcd_draw(lcd_conf, area->x1, area->y1, area->x2, area->y2, color_p);
+        }
+        if (lv_disp_flush_is_last(disp_drv)){
+            if (lcd_conf->buff_ex){
+                lcd_conf->buff_draw = color_p;
+            }
             luat_lcd_flush(lcd_conf);
+        }
     }
 
     /*IMPORTANT!!!