luat_base_linux.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #include "luat_base.h"
  2. #include "luat_msgbus.h"
  3. #include "luat_fs.h"
  4. #include "luat_timer.h"
  5. #include <stdlib.h>
  6. #ifdef LUAT_USE_LVGL
  7. #include "lvgl.h"
  8. void luat_lv_fs_init(void);
  9. void lv_bmp_init(void);
  10. void lv_png_init(void);
  11. void lv_split_jpeg_init(void);
  12. #endif
  13. LUAMOD_API int luaopen_win32( lua_State *L );
  14. int luaopen_lfs(lua_State * L);
  15. int luaopen_rs232_core(lua_State * L);
  16. static const luaL_Reg loadedlibs[] = {
  17. {"_G", luaopen_base}, // _G
  18. {LUA_LOADLIBNAME, luaopen_package}, // require
  19. {LUA_COLIBNAME, luaopen_coroutine}, // coroutine协程库
  20. {LUA_TABLIBNAME, luaopen_table}, // table库,操作table类型的数据结构
  21. {LUA_IOLIBNAME, luaopen_io}, // io库,操作文件
  22. {LUA_OSLIBNAME, luaopen_os}, // os库,已精简
  23. {LUA_STRLIBNAME, luaopen_string}, // string库,字符串操作
  24. {LUA_MATHLIBNAME, luaopen_math}, // math 数值计算
  25. // {LUA_UTF8LIBNAME, luaopen_utf8},
  26. {LUA_DBLIBNAME, luaopen_debug}, // debug库,已精简
  27. #if defined(LUA_COMPAT_BITLIB)
  28. {LUA_BITLIBNAME, luaopen_bit32}, // 不太可能启用
  29. #endif
  30. {"rtos", luaopen_rtos}, // rtos底层库, 核心功能是队列和定时器
  31. {"log", luaopen_log}, // 日志库
  32. {"timer", luaopen_timer}, // 延时库
  33. {"pack", luaopen_pack}, // pack.pack/pack.unpack
  34. {"json", luaopen_cjson}, // json
  35. {"zbuff", luaopen_zbuff}, //
  36. {"crypto", luaopen_crypto},
  37. // {"fatfs", luaopen_fatfs},
  38. // {"sfd", luaopen_sfd},
  39. // {"lfs2", luaopen_lfs2},
  40. // {"gpio", luaopen_gpio},
  41. {"spi", luaopen_spi},
  42. {"rsa", luaopen_rsa},
  43. #ifdef __XMAKE_BUILD__
  44. {"protobuf", luaopen_protobuf},
  45. {"iotauth", luaopen_iotauth},
  46. #endif
  47. #ifdef LUAT_USE_LCD
  48. {"lcd", luaopen_lcd},
  49. #endif
  50. #ifdef LUAT_USE_LVGL
  51. {"lvgl", luaopen_lvgl},
  52. {"lcd", luaopen_lcd},
  53. #endif
  54. {NULL, NULL}
  55. };
  56. // 按不同的rtconfig加载不同的库函数
  57. void luat_openlibs(lua_State *L) {
  58. // 初始化队列服务
  59. luat_msgbus_init();
  60. //print_list_mem("done>luat_msgbus_init");
  61. // 加载系统库
  62. const luaL_Reg *lib;
  63. /* "require" functions from 'loadedlibs' and set results to global table */
  64. for (lib = loadedlibs; lib->func; lib++) {
  65. luaL_requiref(L, lib->name, lib->func, 1);
  66. lua_pop(L, 1); /* remove lib */
  67. }
  68. }
  69. void luat_os_reboot(int code) {
  70. exit(code);
  71. }
  72. const char* luat_os_bsp(void) {
  73. return "linux";
  74. }
  75. extern const struct luat_vfs_filesystem vfs_fs_posix;
  76. extern const struct luat_vfs_filesystem vfs_fs_luadb;
  77. extern const char* luat_luadb_mock;
  78. int luat_fs_init(void) {
  79. #ifdef LUAT_USE_FS_VFS
  80. // vfs进行必要的初始化
  81. luat_vfs_init(NULL);
  82. // 注册vfs for posix 实现
  83. luat_vfs_reg(&vfs_fs_posix);
  84. luat_vfs_reg(&vfs_fs_luadb);
  85. luat_fs_conf_t conf = {
  86. .busname = "",
  87. .type = "posix",
  88. .filesystem = "posix",
  89. .mount_point = "", // window环境下, 需要支持任意路径的读取,不能强制要求必须是/
  90. };
  91. luat_fs_mount(&conf);
  92. #ifdef LUAT_USE_VFS_INLINE_LIB
  93. luat_fs_conf_t conf2 = {
  94. .busname = (char*)luat_luadb_mock,
  95. .type = "luadb",
  96. .filesystem = "luadb",
  97. .mount_point = "/luadb/",
  98. };
  99. luat_fs_mount(&conf2);
  100. #endif
  101. #endif
  102. #ifdef LUAT_USE_LVGL
  103. luat_lv_fs_init();
  104. lv_bmp_init();
  105. lv_png_init();
  106. lv_split_jpeg_init();
  107. #endif
  108. return 0;
  109. }
  110. void vConfigureTimerForRunTimeStats( void ) {}
  111. /** 设备进入待机模式 */
  112. void luat_os_standy(int timeout) {
  113. return; // nop
  114. }
  115. void luat_ota_reboot(int timeout_ms) {
  116. if (timeout_ms > 0)
  117. luat_timer_mdelay(timeout_ms);
  118. exit(0);
  119. }