luat_base_pico.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. // int luaopen_lfs(lua_State * L);
  7. static const luaL_Reg loadedlibs[] = {
  8. {"_G", luaopen_base}, // _G
  9. {LUA_LOADLIBNAME, luaopen_package}, // require
  10. {LUA_COLIBNAME, luaopen_coroutine}, // coroutine协程库
  11. {LUA_TABLIBNAME, luaopen_table}, // table库,操作table类型的数据结构
  12. {LUA_IOLIBNAME, luaopen_io}, // io库,操作文件
  13. {LUA_OSLIBNAME, luaopen_os}, // os库,已精简
  14. {LUA_STRLIBNAME, luaopen_string}, // string库,字符串操作
  15. {LUA_MATHLIBNAME, luaopen_math}, // math 数值计算
  16. // {LUA_UTF8LIBNAME, luaopen_utf8},
  17. {LUA_DBLIBNAME, luaopen_debug}, // debug库,已精简
  18. #if defined(LUA_COMPAT_BITLIB)
  19. {LUA_BITLIBNAME, luaopen_bit32}, // 不太可能启用
  20. #endif
  21. // 往下是LuatOS定制的库, 如需精简请仔细测试
  22. //----------------------------------------------------------------------
  23. // 核心支撑库, 不可禁用!!
  24. {"rtos", luaopen_rtos}, // rtos底层库, 核心功能是队列和定时器
  25. {"log", luaopen_log}, // 日志库
  26. {"timer", luaopen_timer}, // 延时库
  27. //-----------------------------------------------------------------------
  28. // 设备驱动类, 可按实际情况删减. 即使最精简的固件, 也强烈建议保留uart库
  29. {"uart", luaopen_uart}, // 串口操作
  30. {"gpio", luaopen_gpio}, // GPIO脚的操作
  31. // {"i2c", luaopen_i2c}, // I2C操作
  32. // {"spi", luaopen_spi}, // SPI操作
  33. // {"adc", luaopen_adc}, // ADC模块
  34. // {"pwm", luaopen_pwm}, // PWM模块
  35. //-----------------------------------------------------------------------
  36. // 工具库, 按需选用
  37. // {"json", luaopen_cjson}, // json的序列化和反序列化
  38. // {"pack", luaopen_pack}, // pack.pack/pack.unpack
  39. // {"mqttcore",luaopen_mqttcore}, // MQTT 协议封装
  40. // {"libcoap", luaopen_libcoap}, // 处理COAP消息
  41. // {"libgnss", luaopen_libgnss}, // 处理GNSS定位数据
  42. // {"fs", luaopen_fs}, // 文件系统库,在io库之外再提供一些方法
  43. // {"sensor", luaopen_sensor}, // 传感器库,支持DS18B20
  44. // {"disp", luaopen_disp}, // OLED显示模块,支持SSD1306
  45. // {"u8g2", luaopen_u8g2}, // u8g2
  46. // {"crypto",luaopen_crypto}, // 加密和hash模块
  47. // {"eink", luaopen_eink}, // 电子墨水屏,试验阶段
  48. //{"iconv", luaopen_iconv}, // 编码转换,暂不可用
  49. {NULL, NULL}
  50. };
  51. // 按不同的rtconfig加载不同的库函数
  52. void luat_openlibs(lua_State *L) {
  53. // 初始化队列服务
  54. luat_msgbus_init();
  55. //print_list_mem("done>luat_msgbus_init");
  56. // 加载系统库
  57. const luaL_Reg *lib;
  58. /* "require" functions from 'loadedlibs' and set results to global table */
  59. for (lib = loadedlibs; lib->func; lib++) {
  60. luaL_requiref(L, lib->name, lib->func, 1);
  61. lua_pop(L, 1); /* remove lib */
  62. }
  63. }
  64. void luat_meminfo_sys(size_t* total, size_t* used, size_t* max_used)
  65. {
  66. }
  67. const char* luat_os_bsp(void) {
  68. return "pico";
  69. }
  70. void luat_os_reboot(int code)
  71. {
  72. }
  73. void luat_os_standy(int timeout)
  74. {
  75. }
  76. void luat_timer_us_delay(size_t us)
  77. {
  78. }