flipperzero-firmware/firmware/targets/furi_hal_include/furi_hal_bt.h

230 lines
5.0 KiB
C
Raw Normal View History

/**
* @file furi_hal_bt.h
* BT/BLE HAL API
*/
#pragma once
#include <furi.h>
#include <stdbool.h>
#include <gap.h>
#include <serial_service.h>
#include <ble_glue.h>
#include <ble_app.h>
#include "furi_hal_bt_serial.h"
#define FURI_HAL_BT_STACK_VERSION_MAJOR (1)
#define FURI_HAL_BT_STACK_VERSION_MINOR (12)
#define FURI_HAL_BT_C2_START_TIMEOUT 1000
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
FuriHalBtStackUnknown,
FuriHalBtStackLight,
FuriHalBtStackFull,
} FuriHalBtStack;
typedef enum {
FuriHalBtProfileSerial,
FuriHalBtProfileHidKeyboard,
// Keep last for Profiles number calculation
FuriHalBtProfileNumber,
} FuriHalBtProfile;
/** Initialize
*/
2021-08-08 18:03:25 +00:00
void furi_hal_bt_init();
/** Lock core2 state transition */
void furi_hal_bt_lock_core2();
/** Lock core2 state transition */
void furi_hal_bt_unlock_core2();
/** 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();
/** Check if radio stack supports BLE GAT/GAP
*
* @return true if supported
*/
bool furi_hal_bt_is_ble_gatt_gap_supported();
/** Check if radio stack supports testing
*
* @return true if supported
*/
bool furi_hal_bt_is_testing_supported();
/** Start BLE app
*
* @param profile FuriHalBtProfile instance
* @param event_cb GapEventCallback instance
* @param context pointer to context
*
* @return true on success
*/
bool furi_hal_bt_start_app(FuriHalBtProfile profile, GapEventCallback event_cb, void* context);
[FL-2399, FL-2261] Tickless sleep shenanigans (#1168) * Disable USART in sleep * Restore UART state on suspend/resume * FuriHal: Enable stop mode and add insomnia to I2C and SPI * Remove IDLE interrupt * FuriHal: add FPU isr and disable all FPU interrupt, add core2 stop mode configuration on deep sleep * FuriHal: tie stop mode debug with debug rtc flag * FuriHal: adjust flash latency on clock switch, tie mcu debug with RTC debug flag * FuriHal: move resource init to early stage * Add EXTI pending check, enable debug traps with compile-time flag * Wrap sleep debug functions in conditional compilation * Remove erroneous changed * Do not use CSS, remove it from everywhere * Enable/disable USB on VBUS connect (prototype) * FuriHal: add LPMS and DEEPSLEEP magic, workaround state inconsistency between cores * FuriHal: honor c1 LMPS * USB mode switch fix * Applications: add flags and insomnia bypass system * Correct spelling * FuriHal: cleanup insomnia usage, reset sleep flags on wakeup, add shutdown api * FuriHal: extra check on reinit request * FuriHal: rename gpio_display_rst pin to gpio_display_rst_n * FuriHal: add debug HAL * FuriHal: add some magic to core2 reload procedure, fix issue with crash on ble keyboard exit * FuriHal: cleanup ble glue, add BLE_GLUE_DEBUG flag * FuriHal: ble reinit API, move os timer to LPTIM1 for deep sleep capability, shutdown that works * FuriHal: take insomnia while shutdown * Remove USB switch on/off on VBUS change * Better tick skew handling * Improve tick consistency under load * Add USB_HP dummy IRQ handler * Move interrupt check closer to sleep * Clean up includes * Re-enable Insomnia globally * FuriHal: enable CSS * FuriHal: remove questionable core2 clock shenanigans * FuriHal: use core1 RCC registers in idle timer config * FuriHal: return back CSS handlers, add lptim isr dispatching Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com> Co-authored-by: nminaylov <nm29719@gmail.com>
2022-04-29 13:29:51 +00:00
/** Reinitialize core2
*
* Also can be used to prepare core2 for stop modes
*/
void furi_hal_bt_reinit();
/** Change BLE app
* Restarts 2nd core
*
* @param profile FuriHalBtProfile instance
* @param event_cb GapEventCallback instance
* @param context pointer to context
*
* @return true on success
*/
bool furi_hal_bt_change_app(FuriHalBtProfile profile, GapEventCallback event_cb, void* context);
/** Update battery level
*
* @param battery_level battery level
*/
void furi_hal_bt_update_battery_level(uint8_t battery_level);
/** Update battery power state */
void furi_hal_bt_update_power_state();
/** Checks if BLE state is active
*
* @return true if device is connected or advertising, false otherwise
*/
bool furi_hal_bt_is_active();
/** Start advertising
*/
void furi_hal_bt_start_advertising();
/** Stop advertising
*/
void furi_hal_bt_stop_advertising();
/** Get BT/BLE system component state
*
* @param[in] buffer FuriString* buffer to write to
*/
void furi_hal_bt_dump_state(FuriString* buffer);
/** 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();
/** Get key storage buffer address and size
*
* @param key_buff_addr pointer to store buffer address
* @param key_buff_size pointer to store buffer size
*/
void furi_hal_bt_get_key_storage_buff(uint8_t** key_buff_addr, uint16_t* key_buff_size);
/** 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();
/** Clear key storage
*
* @return true on success
*/
bool furi_hal_bt_clear_white_list();
/** Set key storage change callback
*
* @param callback BleGlueKeyStorageChangedCallback instance
* @param context pointer to context
*/
void furi_hal_bt_set_key_storage_change_callback(
BleGlueKeyStorageChangedCallback callback,
void* context);
/** 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);
/** Stop ble tone tx
*/
2021-08-08 18:03:25 +00:00
void furi_hal_bt_stop_tone_tx();
/** 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);
/** Stop sending ble packets
*
* @return sent packet count
*/
2021-08-08 18:03:25 +00:00
uint16_t furi_hal_bt_stop_packet_test();
/** 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);
/** 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);
/** Stop RF listenning
*/
2021-08-08 18:03:25 +00:00
void furi_hal_bt_stop_rx();
/** Get RSSI
*
* @return RSSI in dBm
*/
2021-08-08 18:03:25 +00:00
float furi_hal_bt_get_rssi();
/** Get number of transmitted packets
*
* @return packet count
*/
2021-08-08 18:03:25 +00:00
uint32_t furi_hal_bt_get_transmitted_packets();
/** Check & switch C2 to given mode
*
* @param[in] mode mode to switch into
*/
bool furi_hal_bt_ensure_c2_mode(BleGlueC2Mode mode);
#ifdef __cplusplus
}
#endif