luat_nimble_idf5.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include "luat_base.h"
  2. #include "luat_msgbus.h"
  3. #include "luat_nimble.h"
  4. // #include "esp_log.h"
  5. // /* BLE */
  6. #include "nimble/nimble_port.h"
  7. #include "nimble/nimble_port_freertos.h"
  8. // #include "host/ble_hs.h"
  9. // #include "host/util/util.h"
  10. // // #include "console/console.h"
  11. // #include "services/gap/ble_svc_gap.h"
  12. // #include "services/gatt/ble_svc_gatt.h"
  13. // #include "blehr_sens.h"
  14. #define LUAT_LOG_TAG "nimble"
  15. #include "luat_log.h"
  16. void bleprph_host_task(void *param)
  17. {
  18. LLOGI("BLE Host Task Started");
  19. /* This function will return only when nimble_port_stop() is executed */
  20. nimble_port_run();
  21. nimble_port_freertos_deinit();
  22. }
  23. int luat_nimble_deinit() {
  24. int rc = nimble_port_stop();
  25. if (rc != 0)
  26. {
  27. LLOGE("Error at nimble port stop");
  28. return -1;
  29. }
  30. rc = nimble_port_deinit();
  31. if (rc != 0)
  32. {
  33. LLOGE("Error at nimble_port_deinit %d", rc);
  34. return rc;
  35. }
  36. return 0;
  37. }
  38. int luat_nimble_trace_level(int level) {
  39. return 0;
  40. }
  41. int luat_nimble_init_peripheral(uint8_t uart_idx, char* name, int mode);
  42. int luat_nimble_init_central(uint8_t uart_idx, char* name, int mode);
  43. int luat_nimble_init_ibeacon(uint8_t uart_idx, char* name, int mode);
  44. int luat_nimble_init(uint8_t uart_idx, char* name, int mode) {
  45. int ret = -1;
  46. if (mode == 0) {
  47. ret = luat_nimble_init_peripheral(uart_idx, name, mode);
  48. }
  49. else if (mode == 1) {
  50. ret = luat_nimble_init_central(uart_idx, name, mode);
  51. }
  52. else if (mode == 2) {
  53. ret = luat_nimble_init_ibeacon(uart_idx, name, mode);
  54. }
  55. if (ret == 0) {
  56. nimble_port_freertos_init(bleprph_host_task);
  57. }
  58. return ret;
  59. }
  60. int luat_nimble_mac_set(const char* tmac) {
  61. return -1;
  62. }