luat_lib_nimble.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. static int l_nimble_server_init(lua_State* L) {
  44. test_server_api_init();
  45. return 0;
  46. }
  47. static int l_nimble_server_deinit(lua_State* L) {
  48. test_server_api_deinit();
  49. return 0;
  50. }
  51. static int l_nimble_gap_adv(lua_State* L) {
  52. return 0;
  53. }
  54. #include "rotable.h"
  55. static const rotable_Reg reg_nimble[] =
  56. {
  57. { "init", l_nimble_init, 0},
  58. { "deinit", l_nimble_deinit, 0},
  59. { "debug", l_nimble_debug, 0},
  60. { "server_init", l_nimble_server_init, 0},
  61. { "server_deinit", l_nimble_server_deinit, 0},
  62. { "gap_adv", l_nimble_gap_adv, 0},
  63. { NULL, NULL , 0}
  64. };
  65. LUAMOD_API int luaopen_nimble( lua_State *L ) {
  66. luat_newlib(L, reg_nimble);
  67. return 1;
  68. }