2021-10-03 10:36:05 +00:00
|
|
|
/**
|
2022-01-05 16:10:18 +00:00
|
|
|
* @file furi_hal_bt.h
|
2021-10-03 10:36:05 +00:00
|
|
|
* BT/BLE HAL API
|
|
|
|
*/
|
|
|
|
|
2020-12-10 14:25:20 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <m-string.h>
|
|
|
|
#include <stdbool.h>
|
2021-10-12 16:41:42 +00:00
|
|
|
#include <gap.h>
|
|
|
|
#include <serial_service.h>
|
2021-11-04 17:26:41 +00:00
|
|
|
#include <ble_glue.h>
|
|
|
|
#include <ble_app.h>
|
|
|
|
|
2022-01-05 16:10:18 +00:00
|
|
|
#include "furi_hal_bt_serial.h"
|
2020-12-10 14:25:20 +00:00
|
|
|
|
2022-01-02 22:36:42 +00:00
|
|
|
#define FURI_HAL_BT_STACK_VERSION_MAJOR (1)
|
|
|
|
#define FURI_HAL_BT_STACK_VERSION_MINOR (13)
|
|
|
|
|
2020-12-10 14:25:20 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2022-01-02 22:36:42 +00:00
|
|
|
typedef enum {
|
|
|
|
FuriHalBtStackUnknown,
|
|
|
|
FuriHalBtStackHciLayer,
|
|
|
|
FuriHalBtStackLight,
|
|
|
|
} FuriHalBtStack;
|
|
|
|
|
2021-12-08 11:28:01 +00:00
|
|
|
typedef enum {
|
|
|
|
FuriHalBtProfileSerial,
|
|
|
|
FuriHalBtProfileHidKeyboard,
|
|
|
|
|
|
|
|
// Keep last for Profiles number calculation
|
|
|
|
FuriHalBtProfileNumber,
|
|
|
|
} FuriHalBtProfile;
|
|
|
|
|
2021-10-03 10:36:05 +00:00
|
|
|
/** Initialize
|
|
|
|
*/
|
2021-08-08 18:03:25 +00:00
|
|
|
void furi_hal_bt_init();
|
2020-12-10 14:25:20 +00:00
|
|
|
|
2021-11-10 09:53:00 +00:00
|
|
|
/** Lock core2 state transition */
|
|
|
|
void furi_hal_bt_lock_core2();
|
|
|
|
|
|
|
|
/** Lock core2 state transition */
|
|
|
|
void furi_hal_bt_unlock_core2();
|
|
|
|
|
2022-01-02 22:36:42 +00:00
|
|
|
/** Start radio stack
|
|
|
|
*
|
|
|
|
* @return true on successfull radio stack start
|
|
|
|
*/
|
|
|
|
bool furi_hal_bt_start_radio_stack();
|
|
|
|
|
|
|
|
/** Get radio stack type
|
|
|
|
*
|
|
|
|
* @return FuriHalBtStack instance
|
|
|
|
*/
|
|
|
|
FuriHalBtStack furi_hal_bt_get_radio_stack();
|
|
|
|
|
2021-12-08 11:28:01 +00:00
|
|
|
/** Start BLE app
|
2021-11-04 17:26:41 +00:00
|
|
|
*
|
2021-12-08 11:28:01 +00:00
|
|
|
* @param profile FuriHalBtProfile instance
|
2022-01-02 22:36:42 +00:00
|
|
|
* @param event_cb GapEventCallback instance
|
2021-12-08 11:28:01 +00:00
|
|
|
* @param context pointer to context
|
|
|
|
*
|
|
|
|
* @return true on success
|
|
|
|
*/
|
2022-01-02 22:36:42 +00:00
|
|
|
bool furi_hal_bt_start_app(FuriHalBtProfile profile, GapEventCallback event_cb, void* context);
|
2021-11-04 17:26:41 +00:00
|
|
|
|
2021-12-08 11:28:01 +00:00
|
|
|
/** Change BLE app
|
|
|
|
* Restarts 2nd core
|
|
|
|
*
|
|
|
|
* @param profile FuriHalBtProfile instance
|
2022-01-02 22:36:42 +00:00
|
|
|
* @param event_cb GapEventCallback instance
|
2021-12-08 11:28:01 +00:00
|
|
|
* @param context pointer to context
|
|
|
|
*
|
|
|
|
* @return true on success
|
2021-10-12 16:41:42 +00:00
|
|
|
*/
|
2022-01-02 22:36:42 +00:00
|
|
|
bool furi_hal_bt_change_app(FuriHalBtProfile profile, GapEventCallback event_cb, void* context);
|
2021-12-08 11:28:01 +00:00
|
|
|
|
|
|
|
/** Update battery level
|
|
|
|
*
|
|
|
|
* @param battery_level battery level
|
|
|
|
*/
|
|
|
|
void furi_hal_bt_update_battery_level(uint8_t battery_level);
|
2021-09-15 16:58:32 +00:00
|
|
|
|
2021-10-03 10:36:05 +00:00
|
|
|
/** Start advertising
|
|
|
|
*/
|
2021-09-15 16:58:32 +00:00
|
|
|
void furi_hal_bt_start_advertising();
|
|
|
|
|
2021-10-03 10:36:05 +00:00
|
|
|
/** Stop advertising
|
|
|
|
*/
|
2021-09-15 16:58:32 +00:00
|
|
|
void furi_hal_bt_stop_advertising();
|
2021-03-11 09:31:07 +00:00
|
|
|
|
2021-10-03 10:36:05 +00:00
|
|
|
/** Get BT/BLE system component state
|
|
|
|
*
|
|
|
|
* @param[in] buffer string_t buffer to write to
|
|
|
|
*/
|
2021-08-08 18:03:25 +00:00
|
|
|
void furi_hal_bt_dump_state(string_t buffer);
|
2020-12-10 14:25:20 +00:00
|
|
|
|
2021-10-03 10:36:05 +00:00
|
|
|
/** Get BT/BLE system component state
|
|
|
|
*
|
|
|
|
* @return true if core2 is alive
|
|
|
|
*/
|
2021-08-08 18:03:25 +00:00
|
|
|
bool furi_hal_bt_is_alive();
|
2020-12-10 14:25:20 +00:00
|
|
|
|
2021-11-04 17:26:41 +00:00
|
|
|
/** Get key storage buffer address and size
|
|
|
|
*
|
2021-11-13 02:41:54 +00:00
|
|
|
* @param key_buff_addr pointer to store buffer address
|
|
|
|
* @param key_buff_size pointer to store buffer size
|
2021-11-04 17:26:41 +00:00
|
|
|
*/
|
2021-11-13 02:41:54 +00:00
|
|
|
void furi_hal_bt_get_key_storage_buff(uint8_t** key_buff_addr, uint16_t* key_buff_size);
|
2021-11-04 17:26:41 +00:00
|
|
|
|
|
|
|
/** Get SRAM2 hardware semaphore
|
|
|
|
* @note Must be called before SRAM2 read/write operations
|
|
|
|
*/
|
|
|
|
void furi_hal_bt_nvm_sram_sem_acquire();
|
|
|
|
|
|
|
|
/** Release SRAM2 hardware semaphore
|
|
|
|
* @note Must be called after SRAM2 read/write operations
|
|
|
|
*/
|
|
|
|
void furi_hal_bt_nvm_sram_sem_release();
|
|
|
|
|
2022-01-21 17:32:03 +00:00
|
|
|
/** Clear key storage
|
|
|
|
*
|
|
|
|
* @return true on success
|
|
|
|
*/
|
|
|
|
bool furi_hal_bt_clear_white_list();
|
|
|
|
|
2021-11-04 17:26:41 +00:00
|
|
|
/** Set key storage change callback
|
|
|
|
*
|
|
|
|
* @param callback BleGlueKeyStorageChangedCallback instance
|
|
|
|
* @param context pointer to context
|
|
|
|
*/
|
2022-01-05 16:10:18 +00:00
|
|
|
void furi_hal_bt_set_key_storage_change_callback(
|
|
|
|
BleGlueKeyStorageChangedCallback callback,
|
|
|
|
void* context);
|
2021-11-04 17:26:41 +00:00
|
|
|
|
2021-10-03 10:36:05 +00:00
|
|
|
/** Start ble tone tx at given channel and power
|
|
|
|
*
|
|
|
|
* @param[in] channel The channel
|
|
|
|
* @param[in] power The power
|
|
|
|
*/
|
2021-08-08 18:03:25 +00:00
|
|
|
void furi_hal_bt_start_tone_tx(uint8_t channel, uint8_t power);
|
2021-03-11 09:31:07 +00:00
|
|
|
|
2021-10-03 10:36:05 +00:00
|
|
|
/** Stop ble tone tx
|
|
|
|
*/
|
2021-08-08 18:03:25 +00:00
|
|
|
void furi_hal_bt_stop_tone_tx();
|
2021-03-11 09:31:07 +00:00
|
|
|
|
2021-10-03 10:36:05 +00:00
|
|
|
/** Start sending ble packets at a given frequency and datarate
|
|
|
|
*
|
|
|
|
* @param[in] channel The channel
|
|
|
|
* @param[in] pattern The pattern
|
|
|
|
* @param[in] datarate The datarate
|
|
|
|
*/
|
2021-08-08 18:03:25 +00:00
|
|
|
void furi_hal_bt_start_packet_tx(uint8_t channel, uint8_t pattern, uint8_t datarate);
|
2021-03-11 09:31:07 +00:00
|
|
|
|
2021-10-03 10:36:05 +00:00
|
|
|
/** Stop sending ble packets
|
|
|
|
*
|
|
|
|
* @return sent packet count
|
|
|
|
*/
|
2021-08-08 18:03:25 +00:00
|
|
|
uint16_t furi_hal_bt_stop_packet_test();
|
2021-05-28 22:57:11 +00:00
|
|
|
|
2021-10-03 10:36:05 +00:00
|
|
|
/** Start receiving packets
|
|
|
|
*
|
|
|
|
* @param[in] channel RX channel
|
|
|
|
* @param[in] datarate Datarate
|
|
|
|
*/
|
2021-08-08 18:03:25 +00:00
|
|
|
void furi_hal_bt_start_packet_rx(uint8_t channel, uint8_t datarate);
|
2021-03-11 09:31:07 +00:00
|
|
|
|
2021-10-03 10:36:05 +00:00
|
|
|
/** Set up the RF to listen to a given RF channel
|
|
|
|
*
|
|
|
|
* @param[in] channel RX channel
|
|
|
|
*/
|
2021-08-08 18:03:25 +00:00
|
|
|
void furi_hal_bt_start_rx(uint8_t channel);
|
2021-03-11 09:31:07 +00:00
|
|
|
|
2021-10-03 10:36:05 +00:00
|
|
|
/** Stop RF listenning
|
|
|
|
*/
|
2021-08-08 18:03:25 +00:00
|
|
|
void furi_hal_bt_stop_rx();
|
2021-03-11 09:31:07 +00:00
|
|
|
|
2021-10-03 10:36:05 +00:00
|
|
|
/** Get RSSI
|
|
|
|
*
|
|
|
|
* @return RSSI in dBm
|
|
|
|
*/
|
2021-08-08 18:03:25 +00:00
|
|
|
float furi_hal_bt_get_rssi();
|
2021-05-28 22:57:11 +00:00
|
|
|
|
2021-10-03 10:36:05 +00:00
|
|
|
/** Get number of transmitted packets
|
|
|
|
*
|
|
|
|
* @return packet count
|
|
|
|
*/
|
2021-08-08 18:03:25 +00:00
|
|
|
uint32_t furi_hal_bt_get_transmitted_packets();
|
2021-05-28 22:57:11 +00:00
|
|
|
|
2022-01-02 22:36:42 +00:00
|
|
|
/** Start MAC addresses scan
|
|
|
|
* @note Works only with HciLayer 2nd core firmware
|
|
|
|
*
|
|
|
|
* @param callback GapScanCallback instance
|
|
|
|
* @param context pointer to context
|
|
|
|
*/
|
|
|
|
bool furi_hal_bt_start_scan(GapScanCallback callback, void* context);
|
|
|
|
|
|
|
|
/** Stop MAC addresses scan */
|
|
|
|
void furi_hal_bt_stop_scan();
|
|
|
|
|
2020-12-10 14:25:20 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|