فهرست منبع

add:linux添加lcd lvgl编译

Dozingfiretruck 3 سال پیش
والد
کامیت
df78d74b53
5فایلهای تغییر یافته به همراه133 افزوده شده و 25 حذف شده
  1. 10 1
      bsp/linux/include/luat_conf_bsp.h
  2. 8 4
      bsp/linux/port/luat_base_linux.c
  3. 49 0
      bsp/linux/port/luat_spi_device.c
  4. 30 16
      bsp/linux/port/luat_spi_linux.c
  5. 36 4
      bsp/linux/xmake.lua

+ 10 - 1
bsp/linux/include/luat_conf_bsp.h

@@ -24,12 +24,21 @@
 
 
 #define LUAT_USE_SM 1
 #define LUAT_USE_SM 1
 
 
-//#define LUAT_USE_LVGL 1
+#define LUAT_USE_LCD
+#define LUAT_LCD_COLOR_DEPTH 16
+#define LUAT_USE_TJPGD
+
+#define LV_COLOR_16_SWAP 1
+#define LV_COLOR_DEPTH 16
+
+
+// #define LUAT_USE_LVGL 1
 #define LUAT_USE_LVGL_SDL2 1
 #define LUAT_USE_LVGL_SDL2 1
 #define LUAT_USE_LCD_SDL2 1
 #define LUAT_USE_LCD_SDL2 1
 #define LUAT_USE_LCD_CUSTOM_DRAW 1
 #define LUAT_USE_LCD_CUSTOM_DRAW 1
 
 
 #define LV_TICK_CUSTOM     1
 #define LV_TICK_CUSTOM     1
+#define LV_TICK_CUSTOM_INCLUDE "stdio.h"
 #define LV_TICK_CUSTOM_SYS_TIME_EXPR (get_timestamp())     /*Expression evaluating to current systime in ms*/
 #define LV_TICK_CUSTOM_SYS_TIME_EXPR (get_timestamp())     /*Expression evaluating to current systime in ms*/
 
 
 #define LV_FONT_OPPOSANS_M_8
 #define LV_FONT_OPPOSANS_M_8

+ 8 - 4
bsp/linux/port/luat_base_linux.c

@@ -41,15 +41,19 @@ static const luaL_Reg loadedlibs[] = {
 //   {"sfd",   luaopen_sfd},
 //   {"sfd",   luaopen_sfd},
 //   {"lfs2",   luaopen_lfs2},
 //   {"lfs2",   luaopen_lfs2},
 //   {"gpio",   luaopen_gpio},
 //   {"gpio",   luaopen_gpio},
+  {"spi",   luaopen_spi},
   {"rsa", luaopen_rsa},
   {"rsa", luaopen_rsa},
 #ifdef __XMAKE_BUILD__
 #ifdef __XMAKE_BUILD__
   {"protobuf", luaopen_protobuf},
   {"protobuf", luaopen_protobuf},
   {"iotauth", luaopen_iotauth},
   {"iotauth", luaopen_iotauth},
 #endif
 #endif
-// #ifdef LUAT_USE_LVGL
-//   {"lvgl",   luaopen_lvgl},
-//   {"lcd",    luaopen_lcd},
-// #endif
+#ifdef LUAT_USE_LCD
+  {"lcd",    luaopen_lcd},
+#endif
+#ifdef LUAT_USE_LVGL
+  {"lvgl",   luaopen_lvgl},
+  {"lcd",    luaopen_lcd},
+#endif
   {NULL, NULL}
   {NULL, NULL}
 };
 };
 
 

+ 49 - 0
bsp/linux/port/luat_spi_device.c

@@ -0,0 +1,49 @@
+#include "luat_base.h"
+#include "luat_gpio.h"
+#include "luat_spi.h"
+
+#define LUAT_SPI_CS_SELECT 0
+#define LUAT_SPI_CS_CLEAR  1
+
+
+// luat_spi_device_t* 在lua层看到的是一个userdata
+int luat_spi_device_setup(luat_spi_device_t* spi_dev) {
+    luat_spi_bus_setup(spi_dev);
+    luat_gpio_mode(spi_dev->spi_config.cs, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_HIGH); // CS
+    return 0;
+}
+
+//关闭SPI设备,成功返回0
+int luat_spi_device_close(luat_spi_device_t* spi_dev) {
+    return luat_spi_close(spi_dev->bus_id);
+}
+
+//收发SPI数据,返回接收字节数
+int luat_spi_device_transfer(luat_spi_device_t* spi_dev, const char* send_buf, size_t send_length, char* recv_buf, size_t recv_length) {
+    luat_spi_device_config(spi_dev);
+    luat_gpio_set(spi_dev->spi_config.cs, LUAT_SPI_CS_SELECT);
+    int ret = luat_spi_transfer(spi_dev->bus_id, send_buf, send_length, recv_buf, recv_length);
+    // int ret = luat_spi_send(spi_dev->bus_id, send_buf, send_length);
+    // ret = luat_spi_recv(spi_dev->bus_id, recv_buf, recv_length);
+    luat_gpio_set(spi_dev->spi_config.cs, LUAT_SPI_CS_CLEAR);
+    return ret;
+}
+
+//收SPI数据,返回接收字节数
+int luat_spi_device_recv(luat_spi_device_t* spi_dev, char* recv_buf, size_t length) {
+    luat_spi_device_config(spi_dev);
+    luat_gpio_set(spi_dev->spi_config.cs, LUAT_SPI_CS_SELECT);
+    int ret = luat_spi_recv(spi_dev->bus_id, recv_buf, length);
+    luat_gpio_set(spi_dev->spi_config.cs, LUAT_SPI_CS_CLEAR);
+    return ret;
+}
+
+//发SPI数据,返回发送字节数
+int luat_spi_device_send(luat_spi_device_t* spi_dev, const char* send_buf, size_t length) {
+    luat_spi_device_config(spi_dev);
+    luat_gpio_set(spi_dev->spi_config.cs, LUAT_SPI_CS_SELECT);
+    int ret = luat_spi_send(spi_dev->bus_id, send_buf, length);
+    luat_gpio_set(spi_dev->spi_config.cs, LUAT_SPI_CS_CLEAR);
+    return ret;
+}
+

+ 30 - 16
bsp/linux/port/luat_spi_linux.c

@@ -4,60 +4,74 @@
 #include "luat_msgbus.h"
 #include "luat_msgbus.h"
 #include "luat_spi.h"
 #include "luat_spi.h"
 
 
-// 模拟SPI在win32下的实现
+// 模拟SPI在linux下的实现
 // TODO 当需要返回数据时, 调用lua方法获取需要返回的数据
 // TODO 当需要返回数据时, 调用lua方法获取需要返回的数据
 
 
-#define LUAT_WIN32_SPI_COUNT (3)
+#define LUAT_LINUX_SPI_COUNT (3)
 
 
-typedef struct win32spi {
+typedef struct linuxspi {
     luat_spi_t spi;
     luat_spi_t spi;
     uint8_t open;
     uint8_t open;
-}win32spi_t;
+}linuxspi_t;
 
 
-win32spi_t win32spis[LUAT_WIN32_SPI_COUNT] = {0};
+linuxspi_t linuxspis[LUAT_LINUX_SPI_COUNT] = {0};
+
+int luat_spi_device_config(luat_spi_device_t* spi_dev){
+    return 0;
+}
+
+int luat_spi_bus_setup(luat_spi_device_t* spi_dev){
+    int bus_id = spi_dev->bus_id;
+    if (bus_id < 0 || bus_id >= LUAT_LINUX_SPI_COUNT) {
+        return -1;
+    }
+    memcpy(&linuxspis[bus_id].spi, &(spi_dev->spi_config), sizeof(luat_spi_t));
+    linuxspis[bus_id].open = 1;
+    return 0;
+}
 
 
 int luat_spi_setup(luat_spi_t* spi) {
 int luat_spi_setup(luat_spi_t* spi) {
-    if (spi->id < 0 || spi->id >= LUAT_WIN32_SPI_COUNT) {
+    if (spi->id < 0 || spi->id >= LUAT_LINUX_SPI_COUNT) {
         return -1;
         return -1;
     }
     }
-    memcpy(&win32spis[spi->id].spi, spi, sizeof(luat_spi_t));
-    win32spis[spi->id].open = 1;
+    memcpy(&linuxspis[spi->id].spi, spi, sizeof(luat_spi_t));
+    linuxspis[spi->id].open = 1;
     return 0;
     return 0;
 }
 }
 //关闭SPI,成功返回0
 //关闭SPI,成功返回0
 int luat_spi_close(int spi_id) {
 int luat_spi_close(int spi_id) {
-    if (spi_id < 0 || spi_id >= LUAT_WIN32_SPI_COUNT) {
+    if (spi_id < 0 || spi_id >= LUAT_LINUX_SPI_COUNT) {
         return -1;
         return -1;
     }
     }
-    win32spis[spi_id].open = 0;
+    linuxspis[spi_id].open = 0;
     return 0;
     return 0;
 }
 }
 //收发SPI数据,返回接收字节数
 //收发SPI数据,返回接收字节数
 int luat_spi_transfer(int spi_id, const char* send_buf, size_t send_length, char* recv_buf, size_t recv_length) {
 int luat_spi_transfer(int spi_id, const char* send_buf, size_t send_length, char* recv_buf, size_t recv_length) {
-    if (spi_id < 0 || spi_id >= LUAT_WIN32_SPI_COUNT) {
+    if (spi_id < 0 || spi_id >= LUAT_LINUX_SPI_COUNT) {
         return -1;
         return -1;
     }
     }
-    if (win32spis[spi_id].open == 0)
+    if (linuxspis[spi_id].open == 0)
         return -1;
         return -1;
     memset(recv_buf, 0, recv_length);
     memset(recv_buf, 0, recv_length);
     return recv_length;
     return recv_length;
 }
 }
 //收SPI数据,返回接收字节数
 //收SPI数据,返回接收字节数
 int luat_spi_recv(int spi_id, char* recv_buf, size_t length) {
 int luat_spi_recv(int spi_id, char* recv_buf, size_t length) {
-    if (spi_id < 0 || spi_id >= LUAT_WIN32_SPI_COUNT) {
+    if (spi_id < 0 || spi_id >= LUAT_LINUX_SPI_COUNT) {
         return -1;
         return -1;
     }
     }
-    if (win32spis[spi_id].open == 0)
+    if (linuxspis[spi_id].open == 0)
         return -1;
         return -1;
     memset(recv_buf, 0, length);
     memset(recv_buf, 0, length);
     return length;
     return length;
 }
 }
 //发SPI数据,返回发送字节数
 //发SPI数据,返回发送字节数
 int luat_spi_send(int spi_id, const char* send_buf, size_t length) {
 int luat_spi_send(int spi_id, const char* send_buf, size_t length) {
-    if (spi_id < 0 || spi_id >= LUAT_WIN32_SPI_COUNT) {
+    if (spi_id < 0 || spi_id >= LUAT_LINUX_SPI_COUNT) {
         return -1;
         return -1;
     }
     }
-    if (win32spis[spi_id].open == 0)
+    if (linuxspis[spi_id].open == 0)
         return -1;
         return -1;
     return length;
     return length;
 }
 }

+ 36 - 4
bsp/linux/xmake.lua

@@ -17,9 +17,12 @@ set_optimize("fastest")
 set_languages("c11", "cxx11")
 set_languages("c11", "cxx11")
 
 
 add_defines("__LUATOS__", "__XMAKE_BUILD__")
 add_defines("__LUATOS__", "__XMAKE_BUILD__")
-add_cflags("-ffunction-sections","-fdata-sections", "-Wl,--gc-sections")
+add_cflags("-ffunction-sections","-fdata-sections", "-Wl,--gc-sections","-D_POSIX_C_SOURCE=199309L")
 add_ldflags("-ffunction-sections","-fdata-sections", "-Wl,--gc-sections", "-lreadline","-lm")
 add_ldflags("-ffunction-sections","-fdata-sections", "-Wl,--gc-sections", "-lreadline","-lm")
 
 
+add_requires("libsdl")
+add_packages("libsdl")
+
 target("luatos")
 target("luatos")
     -- set kind
     -- set kind
     set_kind("binary")
     set_kind("binary")
@@ -153,9 +156,9 @@ target("luatos")
     -- iotauth
     -- iotauth
     add_files(luatos.."components/iotauth/luat_lib_iotauth.c")
     add_files(luatos.."components/iotauth/luat_lib_iotauth.c")
 
 
-    -- -- qrcode
-    -- add_includedirs(luatos.."components/qrcode",{public = true})
-    -- add_files(luatos.."components/qrcode/*.c")
+    -- qrcode
+    add_includedirs(luatos.."components/qrcode",{public = true})
+    add_files(luatos.."components/qrcode/*.c")
 
 
     -- -- lora
     -- -- lora
     -- add_includedirs(luatos.."components/lora",{public = true})
     -- add_includedirs(luatos.."components/lora",{public = true})
@@ -179,4 +182,33 @@ target("luatos")
     -- -- 添加fskv
     -- -- 添加fskv
     -- add_includedirs(luatos.."components/fskv")
     -- add_includedirs(luatos.."components/fskv")
     -- add_files(luatos.."components/fskv/*.c")
     -- add_files(luatos.."components/fskv/*.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")
+
 target_end()
 target_end()