Prechádzať zdrojové kódy

add: 暴露air302的luat_openlibs方法,方便用户自行添加lua c库

Wendal Chen 5 rokov pred
rodič
commit
77887a11f8
2 zmenil súbory, kde vykonal 68 pridanie a 1 odobranie
  1. 2 1
      Makefile.inc
  2. 66 0
      bsp/air302/src/luat_air302_base.c

+ 2 - 1
Makefile.inc

@@ -5,6 +5,7 @@ CFLAGS_INC    +=  -I $(LUATOS_DIR)/lua/include \
 				  -I $(LUATOS_DIR)/luat/packages/u8g2 \
 				  -I $(LUATOS_DIR)/luat/packages/minmea \
 				  -I $(LUATOS_DIR)/luat/packages/fatfs \
+				  -I $(LUATOS_DIR)/bsp/air302/include 
 
 
 LUATOS_SRC_DIRS += $(LUATOS_DIR)/lua/src \
@@ -14,7 +15,7 @@ LUATOS_SRC_DIRS += $(LUATOS_DIR)/lua/src \
 					$(LUATOS_DIR)/luat/packages/u8g2 \
 					$(LUATOS_DIR)/luat/packages/fatfs \
 					$(LUATOS_DIR)/luat/packages/minmea \
-					$(LUATOS_DIR)/luat/air302 
+					$(LUATOS_DIR)/bsp/air302/src 
 
 
 LUATOS_CSRC = $(foreach dir, $(LUATOS_SRC_DIRS), $(wildcard $(dir)/*.c))

+ 66 - 0
bsp/air302/src/luat_air302_base.c

@@ -0,0 +1,66 @@
+
+#include "luat_base.h"
+#include "luat_malloc.h"
+
+LUAMOD_API int luaopen_nbiot( lua_State *L );
+LUAMOD_API int luaopen_package_air302 (lua_State *L);
+LUAMOD_API int luaopen_libgnss( lua_State *L ) ;
+LUAMOD_API int luaopen_fatfs( lua_State *L );
+
+static const luaL_Reg loadedlibs[] = {
+  {"_G", luaopen_base}, // _G
+  {LUA_LOADLIBNAME, luaopen_package_air302}, // require
+//   {LUA_LOADLIBNAME, luaopen_package}, // require
+  {LUA_COLIBNAME, luaopen_coroutine}, // coroutine协程库
+  {LUA_TABLIBNAME, luaopen_table},    // table库,操作table类型的数据结构
+  {LUA_IOLIBNAME, luaopen_io},        // io库,操作文件
+  {LUA_OSLIBNAME, luaopen_os},        // os库,已精简
+  {LUA_STRLIBNAME, luaopen_string},   // string库,字符串操作
+  {LUA_MATHLIBNAME, luaopen_math},    // math 数值计算
+//  {LUA_UTF8LIBNAME, luaopen_utf8},
+  {LUA_DBLIBNAME, luaopen_debug},     // debug库,已精简
+#if defined(LUA_COMPAT_BITLIB)
+  {LUA_BITLIBNAME, luaopen_bit32},    // 不太可能启用
+#endif
+// 往下是RTT环境下加载的库
+  {"rtos", luaopen_rtos},             // rtos底层库, 核心功能是队列和定时器
+  {"log", luaopen_log},               // 日志库
+  {"timer", luaopen_timer},           // 延时库
+  {"json", luaopen_cjson},            // json的序列化和反序列化
+  {"pack", luaopen_pack},             // pack.pack/pack.unpack
+  {"uart", luaopen_uart},             // 串口操作
+  {"mqttcore",luaopen_mqttcore},      // MQTT 协议封装
+  {"gpio", luaopen_gpio},              // GPIO脚的操作
+  {"socket", luaopen_socket},          // 套接字操作
+  {"i2c", luaopen_i2c},                // I2C操作
+  {"spi", luaopen_spi},                // SPI操作
+  {"lpmem", luaopen_lpmem},            // 低功耗时仍工作的内存块
+  {"nbiot", luaopen_nbiot},            // NBIOT专属模块
+  {"adc",   luaopen_adc},              // ADC模块
+  {"pwm",   luaopen_pwm},              // PWM模块
+  {"crypto",luaopen_crypto},           // 加密和hash模块
+  {"disp",  luaopen_disp},             // OLED显示模块
+  //{"fatfs", luaopen_fatfs},            // TF卡
+  {"pm",    luaopen_pm},               // 低功耗模式
+  {"libcoap",luaopen_libcoap},         // 处理COAP消息
+  {"libgnss",luaopen_libgnss},         // 处理GNSS定位数据
+  {"sensor", luaopen_sensor},          // 传感器库,当前支持DS18B20
+  {"http", luaopen_http},              // http库
+  {NULL, NULL}
+};
+
+// 按不同的rtconfig加载不同的库函数
+void luat_openlibs(lua_State *L) {
+    //print_list_mem("done>luat_msgbus_init");
+    // 加载系统库
+    const luaL_Reg *lib;
+    /* "require" functions from 'loadedlibs' and set results to global table */
+    for (lib = loadedlibs; lib->func; lib++) {
+        luaL_requiref(L, lib->name, lib->func, 1);
+        lua_pop(L, 1);  /* remove lib */
+    }
+}
+
+const char* luat_os_bsp(void) {
+    return "ec616";
+}