furi-hal-bt.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. /** Start 2nd core and BLE stack
  20. *
  21. * @return true on success
  22. */
  23. bool furi_hal_bt_start_core2();
  24. /** Start BLE app
  25. * @param event_cb - BleEventCallback instance
  26. * @param context - pointer to context
  27. */
  28. bool furi_hal_bt_init_app(BleEventCallback event_cb, void* context);
  29. /** Start advertising
  30. */
  31. void furi_hal_bt_start_advertising();
  32. /** Stop advertising
  33. */
  34. void furi_hal_bt_stop_advertising();
  35. /** Returns true if BLE is advertising
  36. *
  37. * @return true if BLE advertising
  38. */
  39. bool furi_hal_bt_is_active();
  40. /** Get BT/BLE system component state
  41. *
  42. * @param[in] buffer string_t buffer to write to
  43. */
  44. void furi_hal_bt_dump_state(string_t buffer);
  45. /** Get BT/BLE system component state
  46. *
  47. * @return true if core2 is alive
  48. */
  49. bool furi_hal_bt_is_alive();
  50. /** Get key storage buffer address and size
  51. *
  52. * @param key_buff_addr pointer to store buffer address
  53. * @param key_buff_size pointer to store buffer size
  54. *
  55. * @return true on success
  56. */
  57. bool furi_hal_bt_get_key_storage_buff(uint8_t** key_buff_addr, uint16_t* key_buff_size);
  58. /** Get SRAM2 hardware semaphore
  59. * @note Must be called before SRAM2 read/write operations
  60. */
  61. void furi_hal_bt_nvm_sram_sem_acquire();
  62. /** Release SRAM2 hardware semaphore
  63. * @note Must be called after SRAM2 read/write operations
  64. */
  65. void furi_hal_bt_nvm_sram_sem_release();
  66. /** Set key storage change callback
  67. *
  68. * @param callback BleGlueKeyStorageChangedCallback instance
  69. * @param context pointer to context
  70. */
  71. void furi_hal_bt_set_key_storage_change_callback(BleGlueKeyStorageChangedCallback callback, void* context);
  72. /** Set data event callbacks
  73. * @param on_received_cb - SerialSvcDataReceivedCallback instance
  74. * @param on_sent_cb - SerialSvcDataSentCallback instance
  75. * @param context - pointer to context
  76. */
  77. void furi_hal_bt_set_data_event_callbacks(uint16_t buff_size, SerialSvcDataReceivedCallback on_received_cb, SerialSvcDataSentCallback on_sent_cb, void* context);
  78. /** Notify that buffer is empty */
  79. void furi_hal_bt_notify_buffer_is_empty();
  80. /** Send data through BLE
  81. * @param data - data buffer
  82. * @param size - data buffer size
  83. */
  84. bool furi_hal_bt_tx(uint8_t* data, uint16_t size);
  85. /** Lock shared access to flash controller
  86. *
  87. * @param[in] erase_flag true if erase operation
  88. */
  89. void furi_hal_bt_lock_flash(bool erase_flag);
  90. /** Unlock shared access to flash controller
  91. *
  92. * @param[in] erase_flag true if erase operation
  93. */
  94. void furi_hal_bt_unlock_flash(bool erase_flag);
  95. /** Start ble tone tx at given channel and power
  96. *
  97. * @param[in] channel The channel
  98. * @param[in] power The power
  99. */
  100. void furi_hal_bt_start_tone_tx(uint8_t channel, uint8_t power);
  101. /** Stop ble tone tx
  102. */
  103. void furi_hal_bt_stop_tone_tx();
  104. /** Start sending ble packets at a given frequency and datarate
  105. *
  106. * @param[in] channel The channel
  107. * @param[in] pattern The pattern
  108. * @param[in] datarate The datarate
  109. */
  110. void furi_hal_bt_start_packet_tx(uint8_t channel, uint8_t pattern, uint8_t datarate);
  111. /** Stop sending ble packets
  112. *
  113. * @return sent packet count
  114. */
  115. uint16_t furi_hal_bt_stop_packet_test();
  116. /** Start receiving packets
  117. *
  118. * @param[in] channel RX channel
  119. * @param[in] datarate Datarate
  120. */
  121. void furi_hal_bt_start_packet_rx(uint8_t channel, uint8_t datarate);
  122. /** Set up the RF to listen to a given RF channel
  123. *
  124. * @param[in] channel RX channel
  125. */
  126. void furi_hal_bt_start_rx(uint8_t channel);
  127. /** Stop RF listenning
  128. */
  129. void furi_hal_bt_stop_rx();
  130. /** Get RSSI
  131. *
  132. * @return RSSI in dBm
  133. */
  134. float furi_hal_bt_get_rssi();
  135. /** Get number of transmitted packets
  136. *
  137. * @return packet count
  138. */
  139. uint32_t furi_hal_bt_get_transmitted_packets();
  140. #ifdef __cplusplus
  141. }
  142. #endif