luat_base_air105.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. #include "luat_base.h"
  2. #include "luat_msgbus.h"
  3. #include "luat_fs.h"
  4. #include "luat_timer.h"
  5. #include "luat_lcd.h"
  6. #include "time.h"
  7. #include <stdlib.h>
  8. #include "app_interface.h"
  9. #ifdef LUAT_USE_LVGL
  10. #include "lvgl.h"
  11. void luat_lv_fs_init(void);
  12. void lv_bmp_init(void);
  13. void lv_png_init(void);
  14. void lv_split_jpeg_init(void);
  15. #endif
  16. LUAMOD_API int luaopen_gtfont( lua_State *L );
  17. static const luaL_Reg loadedlibs[] = {
  18. {"_G", luaopen_base}, // _G
  19. {LUA_LOADLIBNAME, luaopen_package}, // require
  20. {LUA_COLIBNAME, luaopen_coroutine}, // coroutine协程库
  21. {LUA_TABLIBNAME, luaopen_table}, // table库,操作table类型的数据结构
  22. {LUA_IOLIBNAME, luaopen_io}, // io库,操作文件
  23. {LUA_OSLIBNAME, luaopen_os}, // os库,已精简
  24. {LUA_STRLIBNAME, luaopen_string}, // string库,字符串操作
  25. {LUA_MATHLIBNAME, luaopen_math}, // math 数值计算
  26. // {LUA_UTF8LIBNAME, luaopen_utf8},
  27. {LUA_DBLIBNAME, luaopen_debug}, // debug库,已精简
  28. #ifdef LUAT_USE_DBG
  29. #ifndef LUAT_USE_SHELL
  30. #define LUAT_USE_SHELL
  31. #endif
  32. {"dbg", luaopen_dbg}, // 调试库
  33. #endif
  34. #if defined(LUA_COMPAT_BITLIB)
  35. {LUA_BITLIBNAME, luaopen_bit32}, // 不太可能启用
  36. #endif
  37. // 往下是LuatOS定制的库, 如需精简请仔细测试
  38. //----------------------------------------------------------------------
  39. // 核心支撑库, 不可禁用!!
  40. {"rtos", luaopen_rtos}, // rtos底层库, 核心功能是队列和定时器
  41. {"log", luaopen_log}, // 日志库
  42. {"timer", luaopen_timer}, // 延时库
  43. //-----------------------------------------------------------------------
  44. // 设备驱动类, 可按实际情况删减. 即使最精简的固件, 也强烈建议保留uart库
  45. #ifdef LUAT_USE_UART
  46. {"uart", luaopen_uart}, // 串口操作
  47. #endif
  48. #ifdef LUAT_USE_GPIO
  49. {"gpio", luaopen_gpio}, // GPIO脚的操作
  50. #endif
  51. #ifdef LUAT_USE_I2C
  52. {"i2c", luaopen_i2c}, // I2C操作
  53. #endif
  54. #ifdef LUAT_USE_SPI
  55. {"spi", luaopen_spi}, // SPI操作
  56. #endif
  57. #ifdef LUAT_USE_ADC
  58. {"adc", luaopen_adc}, // ADC模块
  59. #endif
  60. // #ifdef LUAT_USE_SDIO
  61. // {"sdio", luaopen_sdio}, // SDIO模块
  62. // #endif
  63. #ifdef LUAT_USE_PWM
  64. {"pwm", luaopen_pwm}, // PWM模块
  65. #endif
  66. #ifdef LUAT_USE_WDT
  67. {"wdt", luaopen_wdt}, // watchdog模块
  68. #endif
  69. // #ifdef LUAT_USE_PM
  70. // {"pm", luaopen_pm}, // 电源管理模块
  71. // #endif
  72. #ifdef LUAT_USE_MCU
  73. {"mcu", luaopen_mcu}, // MCU特有的一些操作
  74. #endif
  75. // #ifdef LUAT_USE_HWTIMER
  76. // {"hwtimer", luaopen_hwtimer}, // 硬件定时器
  77. // #endif
  78. #ifdef LUAT_USE_RTC
  79. {"rtc", luaopen_rtc}, // 实时时钟
  80. #endif
  81. {"pin", luaopen_pin}, // pin
  82. #ifdef LUAT_USE_DAC
  83. {"dac", luaopen_dac},
  84. #endif
  85. #ifdef LUAT_USE_KEYBOARD
  86. {"keyboard", luaopen_keyboard},
  87. #endif
  88. #ifdef LUAT_USE_OTP
  89. {"otp", luaopen_otp},
  90. #endif
  91. #ifdef LUAT_USE_CAMERA
  92. {"camera", luaopen_camera},
  93. #endif
  94. //-----------------------------------------------------------------------
  95. // 工具库, 按需选用
  96. #ifdef LUAT_USE_CRYPTO
  97. {"crypto",luaopen_crypto}, // 加密和hash模块
  98. #endif
  99. #ifdef LUAT_USE_CJSON
  100. {"json", luaopen_cjson}, // json的序列化和反序列化
  101. #endif
  102. #ifdef LUAT_USE_ZBUFF
  103. {"zbuff", luaopen_zbuff}, // 像C语言语言操作内存块
  104. #endif
  105. #ifdef LUAT_USE_PACK
  106. {"pack", luaopen_pack}, // pack.pack/pack.unpack
  107. #endif
  108. // {"mqttcore",luaopen_mqttcore}, // MQTT 协议封装
  109. // {"libcoap", luaopen_libcoap}, // 处理COAP消息
  110. #ifdef LUAT_USE_GNSS
  111. {"libgnss", luaopen_libgnss}, // 处理GNSS定位数据
  112. #endif
  113. #ifdef LUAT_USE_FS
  114. {"fs", luaopen_fs}, // 文件系统库,在io库之外再提供一些方法
  115. #endif
  116. #ifdef LUAT_USE_SENSOR
  117. {"sensor", luaopen_sensor}, // 传感器库,支持DS18B20
  118. #endif
  119. #ifdef LUAT_USE_SFUD
  120. {"sfud", luaopen_sfud}, // sfud
  121. #endif
  122. #ifdef LUAT_USE_SFD
  123. {"sfd", luaopen_sfd},
  124. #endif
  125. #ifdef LUAT_USE_DISP
  126. {"disp", luaopen_disp}, // OLED显示模块,支持SSD1306
  127. #endif
  128. #ifdef LUAT_USE_U8G2
  129. {"u8g2", luaopen_u8g2}, // u8g2
  130. #endif
  131. #ifdef LUAT_USE_EINK
  132. {"eink", luaopen_eink}, // 电子墨水屏,试验阶段
  133. #endif
  134. #ifdef LUAT_USE_LVGL
  135. #ifndef LUAT_USE_LCD
  136. #define LUAT_USE_LCD
  137. #endif
  138. {"lvgl", luaopen_lvgl},
  139. #endif
  140. #ifdef LUAT_USE_LCD
  141. {"lcd", luaopen_lcd},
  142. #endif
  143. #ifdef LUAT_USE_STATEM
  144. {"statem", luaopen_statem},
  145. #endif
  146. #ifdef LUAT_USE_GTFONT
  147. {"gtfont", luaopen_gtfont},
  148. #endif
  149. #ifdef LUAT_USE_COREMARK
  150. {"coremark", luaopen_coremark},
  151. #endif
  152. #ifdef LUAT_USE_FDB
  153. {"fdb", luaopen_fdb},
  154. #endif
  155. #ifdef LUAT_USE_ZLIB
  156. {"zlib", luaopen_zlib},
  157. #endif
  158. {NULL, NULL}
  159. };
  160. // 按不同的rtconfig加载不同的库函数
  161. void luat_openlibs(lua_State *L) {
  162. // 初始化队列服务
  163. luat_msgbus_init();
  164. //print_list_mem("done>luat_msgbus_init");
  165. // 加载系统库
  166. const luaL_Reg *lib;
  167. /* "require" functions from 'loadedlibs' and set results to global table */
  168. for (lib = loadedlibs; lib->func; lib++) {
  169. luaL_requiref(L, lib->name, lib->func, 1);
  170. lua_pop(L, 1); /* remove lib */
  171. }
  172. }
  173. void luat_os_reboot(int code) {
  174. SystemReset();
  175. }
  176. const char* luat_os_bsp(void) {
  177. return "air105";
  178. }
  179. void vConfigureTimerForRunTimeStats( void ) {}
  180. /** 设备进入待机模式 */
  181. void luat_os_standy(int timeout) {
  182. return; // nop
  183. }
  184. void luat_ota_reboot(int timeout_ms) {
  185. if (timeout_ms > 0)
  186. luat_timer_mdelay(timeout_ms);
  187. SystemReset();
  188. }
  189. #ifdef LUAT_USE_LVGL
  190. #include "app_interface.h"
  191. #define LVGL_TICK_PERIOD 10
  192. unsigned int gLVFlashTime;
  193. static timer_t *lv_timer;
  194. static int luat_lvg_handler(lua_State* L, void* ptr) {
  195. // DBG("%u", lv_tick_get());
  196. lv_task_handler();
  197. return 0;
  198. }
  199. static int32_t _lvgl_handler(void *pData, void *pParam) {
  200. rtos_msg_t msg = {0};
  201. msg.handler = luat_lvg_handler;
  202. luat_msgbus_put(&msg, 0);
  203. }
  204. #endif
  205. void luat_shell_poweron(int _drv);
  206. void luat_base_init(void)
  207. {
  208. luat_gpio_init();
  209. #ifdef LUAT_USE_SHELL
  210. luat_shell_poweron(0);
  211. #endif
  212. #ifdef LUAT_USE_LVGL
  213. gLVFlashTime = 33;
  214. lv_init();
  215. lv_timer = Timer_Create(_lvgl_handler, NULL, NULL);
  216. Timer_StartMS(lv_timer, LVGL_TICK_PERIOD, 1);
  217. #endif
  218. }
  219. time_t luat_time(time_t *_Time) {
  220. if (_Time != NULL) {
  221. *_Time = RTC_GetUTC();
  222. }
  223. return RTC_GetUTC();
  224. }
  225. //static uint32_t cri = 0;
  226. void luat_os_entry_cri(void) {
  227. // if (cri == 0)
  228. // cri = OS_EnterCritical();
  229. }
  230. void luat_os_exit_cri(void) {
  231. // if (cri != 0) {
  232. // OS_ExitCritical(cri);
  233. // cri = 0;
  234. // }
  235. }