luat_base_air105.c 6.8 KB

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