[FL-1976] BLE HID (#852)

* ble: prototype ble hid
* ble: add HID service and characteristics
* debug tools: add ble keyboard app
* ble: change appearance
* ble: working keyboard
* bt: introduce furi-hal-bt-hid
* bt: restart hid service on each keyboard app enter
* bt: introduce switch profile
* bt: add profile to ble glue
* bt: working profile switch
* bt: introduce bt serial profile, rework API
* bt: rewotk HID profile
* bt: rework gap with profile configuration
* bt: move change profile routine to furi hal bt
* bt: change switch profile API to blocking
* bt: move battery update to furi hal bt
* bt: cleanup
* bt: add support for f6 target
* bt: update documentation
* bt: clean up code
* bt: remove NO OUTPUT setting
* bt: set numeric comparison pairing in BLE HID
* bt: support f6 target
* bt: set mac address in profile configuration
* bt: set advertise name in profile config
* bt: rework with furi thread
* bt: support f6 target
* bt: clear hci command buffer on core2 restart
* bt: correct thread kill sequence
* bt: fix freertos functions calls
* bt: add some enterprise delays fo correct memory free
* bt: code cleanup
* bt: change terminate -> stop
* bt: fix memory leakage

Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
gornekich
2021-12-08 14:28:01 +03:00
committed by GitHub
parent bb96509ed1
commit 7170864fe4
46 changed files with 2288 additions and 439 deletions

View File

@@ -0,0 +1,34 @@
#pragma once
#include <stdint.h>
#include <stdbool.h>
/** Start Hid Keyboard Profile
*/
void furi_hal_bt_hid_start();
/** Stop Hid Keyboard Profile
*/
void furi_hal_bt_hid_stop();
/** Press key button
*
* @param button button code from HID specification
*
* @return true on success
*/
bool furi_hal_bt_hid_kb_press(uint16_t button);
/** Release key button
*
* @param button button code from HID specification
*
* @return true on success
*/
bool furi_hal_bt_hid_kb_release(uint16_t button);
/** Release all key buttons
*
* @return true on success
*/
bool furi_hal_bt_hid_kb_release_all();

View File

@@ -0,0 +1,37 @@
#pragma once
#include "serial_service.h"
#define FURI_HAL_BT_SERIAL_PACKET_SIZE_MAX SERIAL_SVC_DATA_LEN_MAX
/** Serial service callback type */
typedef SerialServiceEventCallback FuriHalBtSerialCallback;
/** Start Serial Profile
*/
void furi_hal_bt_serial_start();
/** Stop Serial Profile
*/
void furi_hal_bt_serial_stop();
/** Set Serial service events callback
*
* @param buffer_size Applicaition buffer size
* @param calback FuriHalBtSerialCallback instance
* @param context pointer to context
*/
void furi_hal_bt_serial_set_event_callback(uint16_t buff_size, FuriHalBtSerialCallback callback, void* context);
/** Notify that application buffer is empty
*/
void furi_hal_bt_serial_notify_buffer_is_empty();
/** Send data through BLE
*
* @param data data buffer
* @param size data buffer size
*
* @return true on success
*/
bool furi_hal_bt_serial_tx(uint8_t* data, uint16_t size);

View File

@@ -12,13 +12,20 @@
#include <ble_glue.h>
#include <ble_app.h>
#define FURI_HAL_BT_PACKET_SIZE_MAX SERIAL_SVC_DATA_LEN_MAX
#include "furi-hal-bt-serial.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
FuriHalBtProfileSerial,
FuriHalBtProfileHidKeyboard,
// Keep last for Profiles number calculation
FuriHalBtProfileNumber,
} FuriHalBtProfile;
/** Initialize
*/
void furi_hal_bt_init();
@@ -29,17 +36,32 @@ void furi_hal_bt_lock_core2();
/** Lock core2 state transition */
void furi_hal_bt_unlock_core2();
/** Start 2nd core and BLE stack
*
* @return true on success
*/
bool furi_hal_bt_start_core2();
/** Start BLE app
* @param event_cb - BleEventCallback instance
* @param context - pointer to context
*
* @param profile FuriHalBtProfile instance
* @param event_cb BleEventCallback instance
* @param context pointer to context
*
* @return true on success
*/
bool furi_hal_bt_init_app(BleEventCallback event_cb, void* context);
bool furi_hal_bt_start_app(FuriHalBtProfile profile, BleEventCallback event_cb, void* context);
/** Change BLE app
* Restarts 2nd core
*
* @param profile FuriHalBtProfile instance
* @param event_cb BleEventCallback instance
* @param context pointer to context
*
* @return true on success
*/
bool furi_hal_bt_change_app(FuriHalBtProfile profile, BleEventCallback event_cb, void* context);
/** Update battery level
*
* @param battery_level battery level
*/
void furi_hal_bt_update_battery_level(uint8_t battery_level);
/** Start advertising
*/
@@ -91,22 +113,6 @@ void furi_hal_bt_nvm_sram_sem_release();
*/
void furi_hal_bt_set_key_storage_change_callback(BleGlueKeyStorageChangedCallback callback, void* context);
/** Set data event callbacks
* @param on_received_cb - SerialSvcDataReceivedCallback instance
* @param on_sent_cb - SerialSvcDataSentCallback instance
* @param context - pointer to context
*/
void furi_hal_bt_set_data_event_callbacks(uint16_t buff_size, SerialSvcDataReceivedCallback on_received_cb, SerialSvcDataSentCallback on_sent_cb, void* context);
/** Notify that buffer is empty */
void furi_hal_bt_notify_buffer_is_empty();
/** Send data through BLE
* @param data - data buffer
* @param size - data buffer size
*/
bool furi_hal_bt_tx(uint8_t* data, uint16_t size);
/** Start ble tone tx at given channel and power
*
* @param[in] channel The channel