furi-hal-bt.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /**
  2. * @file furi-hal-bt.h
  3. * BT/BLE HAL API
  4. */
  5. #pragma once
  6. #include <m-string.h>
  7. #include <stdbool.h>
  8. #include <gap.h>
  9. #include <serial_service.h>
  10. #include <ble_glue.h>
  11. #include <ble_app.h>
  12. #define FURI_HAL_BT_PACKET_SIZE_MAX SERIAL_SVC_DATA_LEN_MAX
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. /** Initialize
  17. */
  18. void furi_hal_bt_init();
  19. /** Lock core2 state transition */
  20. void furi_hal_bt_lock_core2();
  21. /** Lock core2 state transition */
  22. void furi_hal_bt_unlock_core2();
  23. /** Start 2nd core and BLE stack
  24. *
  25. * @return true on success
  26. */
  27. bool furi_hal_bt_start_core2();
  28. /** Start BLE app
  29. * @param event_cb - BleEventCallback instance
  30. * @param context - pointer to context
  31. */
  32. bool furi_hal_bt_init_app(BleEventCallback event_cb, void* context);
  33. /** Start advertising
  34. */
  35. void furi_hal_bt_start_advertising();
  36. /** Stop advertising
  37. */
  38. void furi_hal_bt_stop_advertising();
  39. /** Returns true if BLE is advertising
  40. *
  41. * @return true if BLE advertising
  42. */
  43. bool furi_hal_bt_is_active();
  44. /** Get BT/BLE system component state
  45. *
  46. * @param[in] buffer string_t buffer to write to
  47. */
  48. void furi_hal_bt_dump_state(string_t buffer);
  49. /** Get BT/BLE system component state
  50. *
  51. * @return true if core2 is alive
  52. */
  53. bool furi_hal_bt_is_alive();
  54. /** Get key storage buffer address and size
  55. *
  56. * @param key_buff_addr pointer to store buffer address
  57. * @param key_buff_size pointer to store buffer size
  58. */
  59. void furi_hal_bt_get_key_storage_buff(uint8_t** key_buff_addr, uint16_t* key_buff_size);
  60. /** Get SRAM2 hardware semaphore
  61. * @note Must be called before SRAM2 read/write operations
  62. */
  63. void furi_hal_bt_nvm_sram_sem_acquire();
  64. /** Release SRAM2 hardware semaphore
  65. * @note Must be called after SRAM2 read/write operations
  66. */
  67. void furi_hal_bt_nvm_sram_sem_release();
  68. /** Set key storage change callback
  69. *
  70. * @param callback BleGlueKeyStorageChangedCallback instance
  71. * @param context pointer to context
  72. */
  73. void furi_hal_bt_set_key_storage_change_callback(BleGlueKeyStorageChangedCallback callback, void* context);
  74. /** Set data event callbacks
  75. * @param on_received_cb - SerialSvcDataReceivedCallback instance
  76. * @param on_sent_cb - SerialSvcDataSentCallback instance
  77. * @param context - pointer to context
  78. */
  79. void furi_hal_bt_set_data_event_callbacks(uint16_t buff_size, SerialSvcDataReceivedCallback on_received_cb, SerialSvcDataSentCallback on_sent_cb, void* context);
  80. /** Notify that buffer is empty */
  81. void furi_hal_bt_notify_buffer_is_empty();
  82. /** Send data through BLE
  83. * @param data - data buffer
  84. * @param size - data buffer size
  85. */
  86. bool furi_hal_bt_tx(uint8_t* data, uint16_t size);
  87. /** Start ble tone tx at given channel and power
  88. *
  89. * @param[in] channel The channel
  90. * @param[in] power The power
  91. */
  92. void furi_hal_bt_start_tone_tx(uint8_t channel, uint8_t power);
  93. /** Stop ble tone tx
  94. */
  95. void furi_hal_bt_stop_tone_tx();
  96. /** Start sending ble packets at a given frequency and datarate
  97. *
  98. * @param[in] channel The channel
  99. * @param[in] pattern The pattern
  100. * @param[in] datarate The datarate
  101. */
  102. void furi_hal_bt_start_packet_tx(uint8_t channel, uint8_t pattern, uint8_t datarate);
  103. /** Stop sending ble packets
  104. *
  105. * @return sent packet count
  106. */
  107. uint16_t furi_hal_bt_stop_packet_test();
  108. /** Start receiving packets
  109. *
  110. * @param[in] channel RX channel
  111. * @param[in] datarate Datarate
  112. */
  113. void furi_hal_bt_start_packet_rx(uint8_t channel, uint8_t datarate);
  114. /** Set up the RF to listen to a given RF channel
  115. *
  116. * @param[in] channel RX channel
  117. */
  118. void furi_hal_bt_start_rx(uint8_t channel);
  119. /** Stop RF listenning
  120. */
  121. void furi_hal_bt_stop_rx();
  122. /** Get RSSI
  123. *
  124. * @return RSSI in dBm
  125. */
  126. float furi_hal_bt_get_rssi();
  127. /** Get number of transmitted packets
  128. *
  129. * @return packet count
  130. */
  131. uint32_t furi_hal_bt_get_transmitted_packets();
  132. #ifdef __cplusplus
  133. }
  134. #endif