Просмотр исходного кода

update: 在bsp/win32中跑通lvgl的绘制流程

Wendal Chen 4 лет назад
Родитель
Сommit
0952976e29

+ 3 - 0
bsp/win32/include/luat_conf_bsp.h

@@ -19,4 +19,7 @@
 
 #define LUAT_MEMORY_OPT_G_FUNCS 1
 
+
+#define LUAT_USE_LVGL 1
+
 #endif

+ 11 - 1
bsp/win32/port/luat_base_win32.c

@@ -4,6 +4,10 @@
 #include "luat_timer.h"
 #include <stdlib.h>
 
+#ifdef LUAT_USE_LVGL
+#include "lvgl.h"
+#endif
+
 LUAMOD_API int luaopen_win32( lua_State *L );
 int luaopen_lfs(lua_State * L);
 int luaopen_rs232_core(lua_State * L);
@@ -40,7 +44,9 @@ static const luaL_Reg loadedlibs[] = {
   {"sfd",   luaopen_sfd},
   {"lfs2",   luaopen_lfs2},
   {"gpio",   luaopen_gpio},
+#ifdef LUAT_USE_LVGL
   {"lvgl",   luaopen_lvgl},
+#endif
   {NULL, NULL}
 };
 
@@ -242,6 +248,10 @@ void vApplicationMallocFailedHook( void )
 /*-----------------------------------------------------------*/
 
 
-
+void vApplicationTickHook( void ) {
+	#ifdef LUAT_USE_LVGL
+	lv_tick_inc(1);
+	#endif
+}
 
 

+ 23 - 0
bsp/win32/src/main_win32.c

@@ -3,6 +3,7 @@
 
 #include "luat_base.h"
 #include "luat_malloc.h"
+#include "luat_msgbus.h"
 
 #include "bget.h"
 
@@ -16,6 +17,23 @@ uint8_t luavm_heap[LUAT_HEAP_SIZE] = {0};
 static void _luat_main(void* args) {
     luat_main();
 }
+#ifdef LUAT_USE_LVGL
+
+#include "lvgl.h"
+static int luat_lvg_handler(lua_State* L, void* ptr) {
+    lv_task_handler();
+    return 0;
+}
+
+static void _lvgl_handler(void* args) {
+    rtos_msg_t msg = {0};
+    msg.handler = luat_lvg_handler;
+    while (1) {
+        luat_msgbus_put(&msg, 0);
+        vTaskDelay(5);
+    };
+}
+#endif
 
 BOOL WINAPI consoleHandler(DWORD signal) {
     if (signal == CTRL_C_EVENT) {
@@ -35,6 +53,11 @@ int main(int argc, char** argv) {
     
     SetConsoleCtrlHandler(consoleHandler, TRUE);
     bpool(luavm_heap, LUAT_HEAP_SIZE);
+#ifdef LUAT_USE_LVGL
+    lv_init();
+    xTaskCreate( _lvgl_handler, "lvgl", 1024*2, NULL, 21, NULL );
+#endif
+
     xTaskCreate( _luat_main, "luatos", 1024*16, NULL, 21, NULL );
     vTaskStartScheduler();
     return 0;

+ 1 - 1
components/freertos/include/FreeRTOSConfig.h

@@ -41,7 +41,7 @@
 #define configUSE_PREEMPTION					1
 #define configUSE_PORT_OPTIMISED_TASK_SELECTION	0
 #define configUSE_IDLE_HOOK						1
-#define configUSE_TICK_HOOK						0
+#define configUSE_TICK_HOOK						1
 #define configUSE_DAEMON_TASK_STARTUP_HOOK		1
 #define configTICK_RATE_HZ						( 1000 ) /* In this non-real time simulated environment the tick frequency has to be at least a multiple of the Win32 tick frequency, and therefore very slow. */
 #define configMINIMAL_STACK_SIZE				( ( unsigned short ) 70 ) /* In this simulated case, the stack only has to hold one small structure as the real stack is part of the win32 thread. */

+ 0 - 1
components/lvgl/binding/luat_lib_lvgl.c

@@ -98,6 +98,5 @@ LUAT_LV_ENMU_RLT
 
 LUAMOD_API int luaopen_lvgl( lua_State *L ) {
     luat_newlib(L, reg_lvgl);
-    lv_init();
     return 1;
 }

+ 1 - 0
components/lvgl/binding/luat_lib_lvgl7.c

@@ -19,6 +19,7 @@ static void disp_flush(struct _disp_drv_t * disp_drv, const lv_area_t * area, lv
         }
     }
     //----
+    //LLOGD("CALL disp_flush (%d, %d, %d, %d)", area->x1, area->y1, area->x2, area->y2);
     lv_disp_flush_ready(disp_drv);
 }
 

+ 1 - 0
luat/include/luat_zbuff.h

@@ -4,6 +4,7 @@
 #include "luat_msgbus.h"
 
 #define LUAT_ZBUFF_TYPE "ZBUFF*"
+#define tozbuff(L) ((luat_zbuff *)luaL_checkudata(L, 1, LUAT_ZBUFF_TYPE))
 
 #define ZBUFF_SEEK_SET 0
 #define ZBUFF_SEEK_CUR 1

+ 0 - 2
luat/modules/luat_lib_zbuff.c

@@ -11,8 +11,6 @@
 #define LUAT_LOG_TAG "luat.zbuff"
 #include "luat_log.h"
 
-#define tozbuff(L) ((luat_zbuff *)luaL_checkudata(L, 1, LUAT_ZBUFF_TYPE))
-
 //在buff对象后添加数据,返回增加的字节数
 int add_bytes(luat_zbuff *buff, const char *source, size_t len)
 {