furi-hal-bt.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. #define FURI_HAL_BT_PACKET_SIZE_MAX SERIAL_SVC_DATA_LEN_MAX
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. /** Initialize
  15. */
  16. void furi_hal_bt_init();
  17. /** Start BLE app
  18. * @param event_cb - BleEventCallback instance
  19. * @param context - pointer to context
  20. */
  21. bool furi_hal_bt_init_app(BleEventCallback event_cb, void* context);
  22. /** Start advertising
  23. */
  24. void furi_hal_bt_start_advertising();
  25. /** Stop advertising
  26. */
  27. void furi_hal_bt_stop_advertising();
  28. /** Returns true if BLE is advertising
  29. *
  30. * @return true if BLE advertising
  31. */
  32. bool furi_hal_bt_is_active();
  33. /** Get BT/BLE system component state
  34. *
  35. * @param[in] buffer string_t buffer to write to
  36. */
  37. void furi_hal_bt_dump_state(string_t buffer);
  38. /** Get BT/BLE system component state
  39. *
  40. * @return true if core2 is alive
  41. */
  42. bool furi_hal_bt_is_alive();
  43. /** Set data event callbacks
  44. * @param on_received_cb - SerialSvcDataReceivedCallback instance
  45. * @param on_sent_cb - SerialSvcDataSentCallback instance
  46. * @param context - pointer to context
  47. */
  48. void furi_hal_bt_set_data_event_callbacks(SerialSvcDataReceivedCallback on_received_cb, SerialSvcDataSentCallback on_sent_cb, void* context);
  49. /** Send data through BLE
  50. * @param data - data buffer
  51. * @param size - data buffer size
  52. */
  53. bool furi_hal_bt_tx(uint8_t* data, uint16_t size);
  54. /** Wait for Core2 startup */
  55. bool furi_hal_bt_wait_startup();
  56. /** Lock shared access to flash controller
  57. *
  58. * @param[in] erase_flag true if erase operation
  59. *
  60. * @return true if lock was successful, false if not
  61. */
  62. bool furi_hal_bt_lock_flash(bool erase_flag);
  63. /** Unlock shared access to flash controller
  64. *
  65. * @param[in] erase_flag true if erase operation
  66. */
  67. void furi_hal_bt_unlock_flash(bool erase_flag);
  68. /** Start ble tone tx at given channel and power
  69. *
  70. * @param[in] channel The channel
  71. * @param[in] power The power
  72. */
  73. void furi_hal_bt_start_tone_tx(uint8_t channel, uint8_t power);
  74. /** Stop ble tone tx
  75. */
  76. void furi_hal_bt_stop_tone_tx();
  77. /** Start sending ble packets at a given frequency and datarate
  78. *
  79. * @param[in] channel The channel
  80. * @param[in] pattern The pattern
  81. * @param[in] datarate The datarate
  82. */
  83. void furi_hal_bt_start_packet_tx(uint8_t channel, uint8_t pattern, uint8_t datarate);
  84. /** Stop sending ble packets
  85. *
  86. * @return sent packet count
  87. */
  88. uint16_t furi_hal_bt_stop_packet_test();
  89. /** Start receiving packets
  90. *
  91. * @param[in] channel RX channel
  92. * @param[in] datarate Datarate
  93. */
  94. void furi_hal_bt_start_packet_rx(uint8_t channel, uint8_t datarate);
  95. /** Set up the RF to listen to a given RF channel
  96. *
  97. * @param[in] channel RX channel
  98. */
  99. void furi_hal_bt_start_rx(uint8_t channel);
  100. /** Stop RF listenning
  101. */
  102. void furi_hal_bt_stop_rx();
  103. /** Get RSSI
  104. *
  105. * @return RSSI in dBm
  106. */
  107. float furi_hal_bt_get_rssi();
  108. /** Get number of transmitted packets
  109. *
  110. * @return packet count
  111. */
  112. uint32_t furi_hal_bt_get_transmitted_packets();
  113. #ifdef __cplusplus
  114. }
  115. #endif