luat_lib_nimble.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include "luat_base.h"
  2. #include "luat_msgbus.h"
  3. #include "luat_malloc.h"
  4. #include "luat_spi.h"
  5. #include "luat_nimble.h"
  6. #define LUAT_LOG_TAG "nimble"
  7. #include "luat_log.h"
  8. static int l_nimble_init(lua_State* L) {
  9. int rc = 0;
  10. rc = luat_nimble_init(0xFF);
  11. if (rc) {
  12. lua_pushboolean(L, 0);
  13. lua_pushinteger(L, rc);
  14. return 2;
  15. }
  16. else {
  17. lua_pushboolean(L, 1);
  18. return 1;
  19. }
  20. }
  21. static int l_nimble_deinit(lua_State* L) {
  22. int rc = 0;
  23. rc = luat_nimble_deinit();
  24. if (rc) {
  25. lua_pushboolean(L, 0);
  26. lua_pushinteger(L, rc);
  27. return 2;
  28. }
  29. else {
  30. lua_pushboolean(L, 1);
  31. return 1;
  32. }
  33. }
  34. static int l_nimble_debug(lua_State* L) {
  35. int level;
  36. if (lua_gettop(L) > 0)
  37. level = luat_nimble_trace_level(luaL_checkinteger(L, 1));
  38. else
  39. level = luat_nimble_trace_level(-1);
  40. lua_pushinteger(L, level);
  41. return 1;
  42. }
  43. #include "rotable.h"
  44. static const rotable_Reg reg_nimble[] =
  45. {
  46. { "init", l_nimble_init, 0},
  47. { "deinit", l_nimble_deinit, 0},
  48. { "debug", l_nimble_debug, 0},
  49. { NULL, NULL , 0}
  50. };
  51. LUAMOD_API int luaopen_nimble( lua_State *L ) {
  52. luat_newlib(L, reg_nimble);
  53. return 1;
  54. }