furi-hal-bt.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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(SerialSvcDataReceivedCallback on_received_cb, SerialSvcDataSentCallback on_sent_cb, void* context);
  78. /** Send data through BLE
  79. * @param data - data buffer
  80. * @param size - data buffer size
  81. */
  82. bool furi_hal_bt_tx(uint8_t* data, uint16_t size);
  83. /** Lock shared access to flash controller
  84. *
  85. * @param[in] erase_flag true if erase operation
  86. */
  87. void furi_hal_bt_lock_flash(bool erase_flag);
  88. /** Unlock shared access to flash controller
  89. *
  90. * @param[in] erase_flag true if erase operation
  91. */
  92. void furi_hal_bt_unlock_flash(bool erase_flag);
  93. /** Start ble tone tx at given channel and power
  94. *
  95. * @param[in] channel The channel
  96. * @param[in] power The power
  97. */
  98. void furi_hal_bt_start_tone_tx(uint8_t channel, uint8_t power);
  99. /** Stop ble tone tx
  100. */
  101. void furi_hal_bt_stop_tone_tx();
  102. /** Start sending ble packets at a given frequency and datarate
  103. *
  104. * @param[in] channel The channel
  105. * @param[in] pattern The pattern
  106. * @param[in] datarate The datarate
  107. */
  108. void furi_hal_bt_start_packet_tx(uint8_t channel, uint8_t pattern, uint8_t datarate);
  109. /** Stop sending ble packets
  110. *
  111. * @return sent packet count
  112. */
  113. uint16_t furi_hal_bt_stop_packet_test();
  114. /** Start receiving packets
  115. *
  116. * @param[in] channel RX channel
  117. * @param[in] datarate Datarate
  118. */
  119. void furi_hal_bt_start_packet_rx(uint8_t channel, uint8_t datarate);
  120. /** Set up the RF to listen to a given RF channel
  121. *
  122. * @param[in] channel RX channel
  123. */
  124. void furi_hal_bt_start_rx(uint8_t channel);
  125. /** Stop RF listenning
  126. */
  127. void furi_hal_bt_stop_rx();
  128. /** Get RSSI
  129. *
  130. * @return RSSI in dBm
  131. */
  132. float furi_hal_bt_get_rssi();
  133. /** Get number of transmitted packets
  134. *
  135. * @return packet count
  136. */
  137. uint32_t furi_hal_bt_get_transmitted_packets();
  138. #ifdef __cplusplus
  139. }
  140. #endif