furi-hal-bt.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. #include "furi-hal-bt-serial.h"
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. typedef enum {
  17. FuriHalBtProfileSerial,
  18. FuriHalBtProfileHidKeyboard,
  19. // Keep last for Profiles number calculation
  20. FuriHalBtProfileNumber,
  21. } FuriHalBtProfile;
  22. /** Initialize
  23. */
  24. void furi_hal_bt_init();
  25. /** Lock core2 state transition */
  26. void furi_hal_bt_lock_core2();
  27. /** Lock core2 state transition */
  28. void furi_hal_bt_unlock_core2();
  29. /** Start BLE app
  30. *
  31. * @param profile FuriHalBtProfile instance
  32. * @param event_cb BleEventCallback instance
  33. * @param context pointer to context
  34. *
  35. * @return true on success
  36. */
  37. bool furi_hal_bt_start_app(FuriHalBtProfile profile, BleEventCallback event_cb, void* context);
  38. /** Change BLE app
  39. * Restarts 2nd core
  40. *
  41. * @param profile FuriHalBtProfile instance
  42. * @param event_cb BleEventCallback instance
  43. * @param context pointer to context
  44. *
  45. * @return true on success
  46. */
  47. bool furi_hal_bt_change_app(FuriHalBtProfile profile, BleEventCallback event_cb, void* context);
  48. /** Update battery level
  49. *
  50. * @param battery_level battery level
  51. */
  52. void furi_hal_bt_update_battery_level(uint8_t battery_level);
  53. /** Start advertising
  54. */
  55. void furi_hal_bt_start_advertising();
  56. /** Stop advertising
  57. */
  58. void furi_hal_bt_stop_advertising();
  59. /** Returns true if BLE is advertising
  60. *
  61. * @return true if BLE advertising
  62. */
  63. bool furi_hal_bt_is_active();
  64. /** Get BT/BLE system component state
  65. *
  66. * @param[in] buffer string_t buffer to write to
  67. */
  68. void furi_hal_bt_dump_state(string_t buffer);
  69. /** Get BT/BLE system component state
  70. *
  71. * @return true if core2 is alive
  72. */
  73. bool furi_hal_bt_is_alive();
  74. /** Get key storage buffer address and size
  75. *
  76. * @param key_buff_addr pointer to store buffer address
  77. * @param key_buff_size pointer to store buffer size
  78. */
  79. void furi_hal_bt_get_key_storage_buff(uint8_t** key_buff_addr, uint16_t* key_buff_size);
  80. /** Get SRAM2 hardware semaphore
  81. * @note Must be called before SRAM2 read/write operations
  82. */
  83. void furi_hal_bt_nvm_sram_sem_acquire();
  84. /** Release SRAM2 hardware semaphore
  85. * @note Must be called after SRAM2 read/write operations
  86. */
  87. void furi_hal_bt_nvm_sram_sem_release();
  88. /** Set key storage change callback
  89. *
  90. * @param callback BleGlueKeyStorageChangedCallback instance
  91. * @param context pointer to context
  92. */
  93. void furi_hal_bt_set_key_storage_change_callback(BleGlueKeyStorageChangedCallback callback, void* context);
  94. /** Start ble tone tx at given channel and power
  95. *
  96. * @param[in] channel The channel
  97. * @param[in] power The power
  98. */
  99. void furi_hal_bt_start_tone_tx(uint8_t channel, uint8_t power);
  100. /** Stop ble tone tx
  101. */
  102. void furi_hal_bt_stop_tone_tx();
  103. /** Start sending ble packets at a given frequency and datarate
  104. *
  105. * @param[in] channel The channel
  106. * @param[in] pattern The pattern
  107. * @param[in] datarate The datarate
  108. */
  109. void furi_hal_bt_start_packet_tx(uint8_t channel, uint8_t pattern, uint8_t datarate);
  110. /** Stop sending ble packets
  111. *
  112. * @return sent packet count
  113. */
  114. uint16_t furi_hal_bt_stop_packet_test();
  115. /** Start receiving packets
  116. *
  117. * @param[in] channel RX channel
  118. * @param[in] datarate Datarate
  119. */
  120. void furi_hal_bt_start_packet_rx(uint8_t channel, uint8_t datarate);
  121. /** Set up the RF to listen to a given RF channel
  122. *
  123. * @param[in] channel RX channel
  124. */
  125. void furi_hal_bt_start_rx(uint8_t channel);
  126. /** Stop RF listenning
  127. */
  128. void furi_hal_bt_stop_rx();
  129. /** Get RSSI
  130. *
  131. * @return RSSI in dBm
  132. */
  133. float furi_hal_bt_get_rssi();
  134. /** Get number of transmitted packets
  135. *
  136. * @return packet count
  137. */
  138. uint32_t furi_hal_bt_get_transmitted_packets();
  139. #ifdef __cplusplus
  140. }
  141. #endif