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

Merge branch 'master' of https://gitee.com/openLuat/LuatOS

alienwalker 3 лет назад
Родитель
Сommit
a289f11dfa

+ 1 - 0
.gitignore

@@ -81,6 +81,7 @@ bsp/air302/air302_sdk/**
 /bsp/air724/sdk/prebuilts/win32
 
 *.cmake
+*.xmake
 
 debug.log
 

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

@@ -26,12 +26,23 @@
 
 #define LUAT_USE_VFS_INLINE_LIB 1
 
+// #define LUAT_USE_FATFS 1
+
 // #define LUAT_MEMORY_OPT_G_FUNCS 1
 
 #define LUAT_USE_LOG_ASYNC_THREAD 0
 
 #define LUAT_FORCE_WIN32 1
 
+#define LUAT_USE_LVGL_SDL2 1
+#define LUAT_USE_LCD_SDL2 1
+#define LUAT_USE_LCD_CUSTOM_DRAW 1
+
+#define LUAT_USE_LCD
+#define LUAT_LCD_COLOR_DEPTH 32
+
+#define LUAT_USE_TJPGD
+
 #define LV_COLOR_16_SWAP 1
 #define LV_COLOR_DEPTH 16
 

+ 6 - 3
bsp/win32/port/luat_base_win32.c

@@ -37,15 +37,18 @@ static const luaL_Reg loadedlibs[] = {
   {"json", luaopen_cjson},             // json
   {"win32", luaopen_win32},            // windows 32 tools
   {"zbuff", luaopen_zbuff},            // 
-  {"mqttcore", luaopen_mqttcore},      // 
   {"libcoap", luaopen_libcoap},        // 
   {"crypto", luaopen_crypto},
-  {"fatfs", luaopen_fatfs},
+// #ifdef LUAT_USE_FATFS
+//   {"fatfs", luaopen_fatfs},
+// #endif
   {"sfd",   luaopen_sfd},
   {"lfs2",   luaopen_lfs2},
   {"gpio",   luaopen_gpio},
-  // {"vmx",    luaopen_vmx},
+  {"i2c",   luaopen_i2c},
+  {"spi",   luaopen_spi},
   {"uart",    luaopen_uart},
+  // {"vmx",    luaopen_vmx},
 #ifdef LUAT_USE_LCD
   {"lcd",    luaopen_lcd},
 #endif

+ 34 - 0
bsp/win32/port/luat_i2c_win32.c

@@ -0,0 +1,34 @@
+
+#include "luat_base.h"
+#include "luat_i2c.h"
+
+#define LUAT_LOG_TAG "luat.i2c"
+#include "luat_log.h"
+
+int luat_i2c_exist(int id) {
+    return id == 0;
+}
+    
+int luat_i2c_setup(int id, int speed) {
+    return 0;
+}
+
+int luat_i2c_close(int id) {
+    return 0;
+}
+
+int luat_i2c_send(int id, int addr, void* buff, size_t len, uint8_t stop) {
+    return 0;
+}
+
+int luat_i2c_recv(int id, int addr, void* buff, size_t len) {
+    return 0;
+}
+
+int luat_i2c_transfer(int id, int addr, uint8_t *reg, size_t reg_len, uint8_t *buff, size_t len) {
+    return 0;
+}
+
+int luat_i2c_no_block_transfer(int id, int addr, uint8_t is_read, uint8_t *reg, size_t reg_len, uint8_t *buff, size_t len, uint16_t Toms, void *CB, void *pParam) {
+	return 0;
+}

+ 3 - 1
bsp/win32/port/luat_spi_win32.c

@@ -76,7 +76,9 @@ int luat_spi_send(int spi_id, const char* send_buf, size_t length) {
     return length;
 }
 
-
+int luat_spi_change_speed(int spi_id, uint32_t speed){
+    return 0;
+}
 
 
 

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

@@ -96,12 +96,22 @@ luat_timer_t* luat_timer_get(size_t timer_id) {
 
 int luat_timer_mdelay(size_t ms) {
     if (ms > 0) {
-        usleep(ms * 1000);
+        Sleep(1000);
     }
     return 0;
 }
 
+static void usleep(unsigned long usec)
+{
+    HANDLE timer;
+    LARGE_INTEGER interval;
+    interval.QuadPart = -(10 * usec);
 
+    timer = CreateWaitableTimer(NULL, TRUE, NULL);
+    SetWaitableTimer(timer, &interval, 0, NULL, NULL, 0);
+    WaitForSingleObject(timer, INFINITE);
+    CloseHandle(timer);
+}
 
 void luat_timer_us_delay(size_t us) {
     if (us)

+ 29 - 0
bsp/win32/port/luat_u8g2_win32.c

@@ -0,0 +1,29 @@
+#include "luat_base.h"
+#include "u8g2.h"
+#include "luat_u8g2.h"
+
+uint8_t u8x8_luat_gpio_and_delay(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
+uint8_t u8x8_luat_byte_hw_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
+uint8_t u8x8_luat_byte_4wire_hw_spi(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
+
+uint8_t u8x8_luat_gpio_and_delay_default(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
+uint8_t u8x8_luat_byte_hw_i2c_default(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
+uint8_t u8x8_luat_byte_4wire_hw_spi_default(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
+
+int luat_u8g2_setup_default(luat_u8g2_conf_t *conf);
+
+int luat_u8g2_setup(luat_u8g2_conf_t *conf) {
+    return luat_u8g2_setup_default(conf);
+}
+
+uint8_t u8x8_luat_gpio_and_delay(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) {
+    return u8x8_luat_gpio_and_delay_default(u8x8, msg, arg_int, arg_ptr);
+}
+
+uint8_t u8x8_luat_byte_hw_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) {
+    return u8x8_luat_byte_hw_i2c_default(u8x8, msg, arg_int, arg_ptr);
+}
+
+uint8_t u8x8_luat_byte_4wire_hw_spi(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) {
+    return u8x8_luat_byte_4wire_hw_spi_default(u8x8, msg, arg_int, arg_ptr);
+}

+ 135 - 0
bsp/win32/xmake.lua

@@ -0,0 +1,135 @@
+set_project("LuatOS-BSP")
+set_xmakever("2.6.3")
+
+set_version("0.0.3", {build = "%Y%m%d%H%M"})
+add_rules("mode.debug", "mode.release")
+
+-- 这里用llvm和clang了,尝试一下
+add_requires("llvm")
+set_toolchains("@llvm")
+
+local luatos = "../../"
+
+-- set warning all as error
+set_warnings("allextra")
+set_optimize("fastest")
+-- set language: c11
+set_languages("c11", "cxx11")
+
+add_defines("__LUATOS__", "__XMAKE_BUILD__", "WIN32")
+add_ldflags("-lwinmm","-luser32","-lncrypt","-lAdvapi32","-lGdi32")
+
+add_requires("libsdl")
+add_packages("libsdl")
+
+target("luatos")
+    -- set kind
+    set_kind("binary")
+    set_targetdir("$(buildir)/out")
+    
+    -- add deps
+
+    add_files("src/*.c",{public = true})
+    add_files("port/*.c",{public = true})
+    add_includedirs("include",{public = true})
+
+    add_includedirs("lv_drivers",{public = true})
+    add_files("lv_drivers/*.c")
+
+    add_includedirs(luatos.."lua/include",{public = true})
+    add_files(luatos.."lua/src/*.c")
+
+    add_includedirs(luatos.."luat/include",{public = true})
+    -- add_files(luatos.."luat/modules/*.c")
+
+    add_files(luatos.."luat/modules/crc.c"
+            ,luatos.."luat/modules/luat_base.c"
+            ,luatos.."luat/modules/luat_lib_fs.c"
+            ,luatos.."luat/modules/luat_lib_rtos.c"
+            ,luatos.."luat/modules/luat_lib_timer.c"
+            ,luatos.."luat/modules/luat_lib_log.c"
+            ,luatos.."luat/modules/luat_lib_zbuff.c"
+            ,luatos.."luat/modules/luat_lib_pack.c"
+            ,luatos.."luat/modules/luat_lib_crypto.c"
+            ,luatos.."luat/modules/luat_lib_lfs2.c"
+            ,luatos.."luat/modules/luat_lib_libcoap.c"
+            ,luatos.."luat/modules/luat_lib_uart.c"
+            ,luatos.."luat/modules/luat_lib_gpio.c"
+            ,luatos.."luat/modules/luat_lib_i2c.c"
+            ,luatos.."luat/modules/luat_lib_spi.c"
+            ,luatos.."luat/modules/luat_irq.c"
+            )
+
+    add_files(luatos.."luat/vfs/*.c")
+
+    add_files(luatos.."components/lfs/*.c")
+    add_files(luatos.."components/sfd/*.c")
+
+    add_includedirs(luatos.."components/lua-cjson")
+    add_files(luatos.."components/lua-cjson/*.c")
+
+    add_includedirs(luatos.."components/miniz")
+    add_files(luatos.."components/miniz/*.c")
+
+    -- add_includedirs(luatos.."components/common")
+    -- add_files(luatos.."components/common/*.c")
+
+    -- add_includedirs(luatos.."components/fatfs")
+    -- add_files(luatos.."components/fatfs/*.c")
+
+    -- sdl2
+    add_includedirs(luatos.."components/ui/sdl2")
+    add_files(luatos.."components/ui/sdl2/*.c")
+
+    -- u8g2
+    add_includedirs(luatos.."components/u8g2")
+    add_files(luatos.."components/u8g2/*.c")
+
+    -- lcd
+    add_includedirs(luatos.."components/lcd")
+    add_files(luatos.."components/lcd/*.c")
+    
+    -- lvgl
+    add_includedirs(luatos.."components/lvgl")
+    add_includedirs(luatos.."components/lvgl/binding")
+    add_includedirs(luatos.."components/lvgl/gen")
+    add_includedirs(luatos.."components/lvgl/src")
+    add_includedirs(luatos.."components/lvgl/font")
+    add_includedirs(luatos.."components/lvgl/src/lv_font")
+
+    add_files(luatos.."components/lvgl/**.c")
+    -- 默认不编译lv的demos, 节省大量的编译时间
+    remove_files(luatos.."components/lvgl/lv_demos/**.c")
+
+    -- tjpgd
+    add_files(luatos.."components/tjpgd/*.c")
+    add_includedirs(luatos.."components/tjpgd")
+
+    add_includedirs(luatos.."components/cjson",{public = true})
+    add_files(luatos.."components/cjson/*.c")
+    
+
+    add_includedirs(luatos.."components/lfs")
+    
+    -- add_includedirs(luatos.."components/minmea")
+    add_includedirs(luatos.."components/fatfs")
+
+
+    add_files(luatos.."components/mbedtls/library/*.c")
+    add_includedirs(luatos.."components/mbedtls/include")
+
+    -- iotauth
+    add_files(luatos.."components/iotauth/luat_lib_iotauth.c")
+
+    -- qrcode
+    add_includedirs(luatos.."components/qrcode",{public = true})
+    add_files(luatos.."components/qrcode/*.c")
+
+    -- crypto
+    add_files(luatos.."components/crypto/**.c")
+
+    -- protobuf
+    add_includedirs(luatos.."components/serialization/protobuf")
+    add_files(luatos.."components/serialization/protobuf/*.c")
+    
+target_end()

+ 0 - 2
components/lua-cjson/lua_cjson.c

@@ -109,7 +109,6 @@ static const u_char charmap[] = {
 	'\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377',
 };
 
-#ifndef LUA_USE_WINDOWS
 int
 strcasecmp(const char *s1, const char *s2)
 {
@@ -140,7 +139,6 @@ strncasecmp(const char *s1, const char *s2, size_t n)
   }
 	return (0);
 }
-#endif
 
 #endif
 

+ 1 - 1
components/network/libemqtt/luat_lib_mqtt.c

@@ -172,7 +172,7 @@ mqttc:subscribe({["/luatos/1234567"]=1,["/luatos/12345678"]=2})
 */
 static int l_mqtt_subscribe(lua_State *L) {
 	size_t len = 0;
-	int ret = 0;
+	int ret = 1;
 	uint16_t msgid = 0;
 	luat_mqtt_ctrl_t * mqtt_ctrl = (luat_mqtt_ctrl_t *)lua_touserdata(L, 1);
 	if (lua_isstring(L, 2)){

+ 1 - 1
luat/vfs/luat_fs_fatfs.c

@@ -6,7 +6,7 @@
 #define LUAT_LOG_TAG "fatfs"
 #include "luat_log.h"
 
-#ifdef LUAT_USE_FS_VFS
+#if defined(LUAT_USE_FS_VFS) && defined(LUAT_USE_FATFS)
 
 #include "ff.h"
 #include "diskio.h"