luat_base_win32.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. {"win32", luaopen_win32}, // windows 32 tools
  36. {"zbuff", luaopen_zbuff}, //
  37. {"libcoap", luaopen_libcoap}, //
  38. {"crypto", luaopen_crypto},
  39. // #ifdef LUAT_USE_FATFS
  40. // {"fatfs", luaopen_fatfs},
  41. // #endif
  42. {"sfd", luaopen_sfd},
  43. {"lfs2", luaopen_lfs2},
  44. {"gpio", luaopen_gpio},
  45. {"i2c", luaopen_i2c},
  46. {"spi", luaopen_spi},
  47. {"uart", luaopen_uart},
  48. // {"vmx", luaopen_vmx},
  49. #ifdef LUAT_USE_LCD
  50. {"lcd", luaopen_lcd},
  51. #endif
  52. #ifdef LUAT_USE_LCD
  53. {"u8g2", luaopen_u8g2},
  54. #endif
  55. #ifdef LUAT_USE_LVGL
  56. {"lvgl", luaopen_lvgl},
  57. #endif
  58. {"iotauth", luaopen_iotauth},
  59. {"miniz", luaopen_miniz},
  60. {"protobuf", luaopen_protobuf},
  61. {"libgnss", luaopen_libgnss},
  62. {"rsa", luaopen_rsa},
  63. {NULL, NULL}
  64. };
  65. // 按不同的rtconfig加载不同的库函数
  66. void luat_openlibs(lua_State *L) {
  67. // 初始化队列服务
  68. luat_msgbus_init();
  69. //print_list_mem("done>luat_msgbus_init");
  70. // 加载系统库
  71. const luaL_Reg *lib;
  72. /* "require" functions from 'loadedlibs' and set results to global table */
  73. for (lib = loadedlibs; lib->func; lib++) {
  74. luaL_requiref(L, lib->name, lib->func, 1);
  75. lua_pop(L, 1); /* remove lib */
  76. //extern void print_list_mem(const char* name);
  77. //print_list_mem(lib->name);
  78. }
  79. }
  80. void luat_os_reboot(int code) {
  81. exit(code);
  82. }
  83. const char* luat_os_bsp(void) {
  84. #ifdef LUA_USE_WINDOWS
  85. return "win32";
  86. #else
  87. return "posix";
  88. #endif
  89. }
  90. void vConfigureTimerForRunTimeStats( void ) {}
  91. /** 设备进入待机模式 */
  92. void luat_os_standy(int timeout) {
  93. return; // nop
  94. }
  95. void luat_ota_reboot(int timeout_ms) {
  96. if (timeout_ms > 0)
  97. luat_timer_mdelay(timeout_ms);
  98. exit(0);
  99. }
  100. #include "windows.h"
  101. #include <io.h>
  102. #include <time.h>
  103. #include <math.h>
  104. // 获取当前时间
  105. uint32_t get_timestamp(void) {
  106. // struct timespec _t;
  107. // clock_gettime(CLOCK_REALTIME, &_t);
  108. // uint32_t timenow = _t.tv_sec*1000 + lround(_t.tv_nsec/1e6);
  109. // //printf("time now > %u\n", timenow);
  110. LARGE_INTEGER ticks;
  111. QueryPerformanceCounter(&ticks);
  112. return ticks.QuadPart;
  113. }