mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-23 05:24:46 -07:00
ble: profile rework (#3272)
* ble: profile rework, initial * apps: hid: fix for pairing cleanup * app: hid: select transport based on #define * fixing PVS warnings * ble: serial service: fixed uid naming * bt service: on-demand dialog init; ble profiles: docs; battery svc: proper update * Added shci_cmd_resp_wait/shci_cmd_resp_release impl with semaphore * app: hid: separated transport code * ble: fixed service init order for serial svc; moved hardfault check to ble_glue * cli: ps: added thread prio to output, fixed heap display * ble_glue: naming changes; separate thread for event processing; * furi: added runtime stats; cli: added cpu% to `ps` * cli: fixed thread time calculation * furi: added getter for thread priority * fixing pvs warnings * hid profile: fixed naming * more naming fixes * hal: ble init small cleanup * cleanup & draft beacon api * f18: api sync * apps: moved example_custom_font from debug to examples * BLE extra beacon demo app * naming fix * UI fixes for demo app (wip) * desktop, ble svc: added statusbar icon for beacon * minor cleanup * Minor cleanup & naming fixes * api sync * Removed stale header * hal: added FURI_BLE_EXTRA_LOG for extra logging; comments & code cleanup * naming & macro fixes * quick fixes from review * Eliminated stock svc_ctl * cli: ps: removed runtime stats * minor include fixes * (void) * naming fixes * More naming fixes * fbt: always build all libs * fbt: explicitly globbing libs; dist: logging SDK path * scripts: fixed lib path precedence * hal: bt: profiles: naming changes, support for passing params to a profile; include cleanup * ble: hid: added parameter processing for profile template * api sync * BLE HID: long name trim * Removed unused check * desktop: updated beacon status icon; ble: hid: cleaner device name management * desktop: updated status icon Co-authored-by: あく <alleteam@gmail.com> Co-authored-by: nminaylov <nm29719@gmail.com>
This commit is contained in:
110
targets/f7/ble_glue/furi_ble/gatt.h
Normal file
110
targets/f7/ble_glue/furi_ble/gatt.h
Normal file
@@ -0,0 +1,110 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <ble/core/auto/ble_types.h>
|
||||
|
||||
/* Callback signature for getting characteristic data
|
||||
* Is called when characteristic is created to get max data length. Data ptr is NULL in this case
|
||||
* The result is passed to aci_gatt_add_char as "Char_Value_Length"
|
||||
* For updates, called with a context - see flipper_gatt_characteristic_update
|
||||
* Returns true if *data ownership is transferred to the caller and will be freed */
|
||||
typedef bool (
|
||||
*cbBleGattCharacteristicData)(const void* context, const uint8_t** data, uint16_t* data_len);
|
||||
|
||||
/* Used to specify the type of data for a characteristic - constant or callback-based */
|
||||
typedef enum {
|
||||
FlipperGattCharacteristicDataFixed,
|
||||
FlipperGattCharacteristicDataCallback,
|
||||
} BleGattCharacteristicDataType;
|
||||
|
||||
typedef struct {
|
||||
Char_Desc_Uuid_t uuid;
|
||||
struct {
|
||||
cbBleGattCharacteristicData fn;
|
||||
const void* context;
|
||||
} data_callback;
|
||||
uint8_t uuid_type;
|
||||
uint8_t max_length;
|
||||
uint8_t security_permissions;
|
||||
uint8_t access_permissions;
|
||||
uint8_t gatt_evt_mask;
|
||||
uint8_t is_variable;
|
||||
} BleGattCharacteristicDescriptorParams;
|
||||
|
||||
/* Describes a single characteristic, providing data or callbacks to get data */
|
||||
typedef struct {
|
||||
const char* name;
|
||||
BleGattCharacteristicDescriptorParams* descriptor_params;
|
||||
union {
|
||||
struct {
|
||||
const uint8_t* ptr;
|
||||
uint16_t length;
|
||||
} fixed;
|
||||
struct {
|
||||
cbBleGattCharacteristicData fn;
|
||||
const void* context;
|
||||
} callback;
|
||||
} data;
|
||||
Char_UUID_t uuid;
|
||||
// Some packed bitfields to save space
|
||||
BleGattCharacteristicDataType data_prop_type : 2;
|
||||
uint8_t is_variable : 2;
|
||||
uint8_t uuid_type : 2;
|
||||
uint8_t char_properties;
|
||||
uint8_t security_permissions;
|
||||
uint8_t gatt_evt_mask;
|
||||
} BleGattCharacteristicParams;
|
||||
|
||||
_Static_assert(
|
||||
sizeof(BleGattCharacteristicParams) == 36,
|
||||
"BleGattCharacteristicParams size must be 36 bytes");
|
||||
|
||||
typedef struct {
|
||||
const BleGattCharacteristicParams* characteristic;
|
||||
uint16_t handle;
|
||||
uint16_t descriptor_handle;
|
||||
} BleGattCharacteristicInstance;
|
||||
|
||||
/* Initialize a characteristic instance; copies the characteristic descriptor
|
||||
* into the instance */
|
||||
void ble_gatt_characteristic_init(
|
||||
uint16_t svc_handle,
|
||||
const BleGattCharacteristicParams* char_descriptor,
|
||||
BleGattCharacteristicInstance* char_instance);
|
||||
|
||||
/* Delete a characteristic instance; frees the copied characteristic
|
||||
* descriptor from the instance */
|
||||
void ble_gatt_characteristic_delete(
|
||||
uint16_t svc_handle,
|
||||
BleGattCharacteristicInstance* char_instance);
|
||||
|
||||
/* Update a characteristic instance; if source==NULL, uses the data from
|
||||
* the characteristic:
|
||||
* - For fixed data, fixed.ptr is used as the source if source==NULL
|
||||
* - For callback-based data, collback.context is passed as the context
|
||||
* if source==NULL
|
||||
*/
|
||||
bool ble_gatt_characteristic_update(
|
||||
uint16_t svc_handle,
|
||||
BleGattCharacteristicInstance* char_instance,
|
||||
const void* source);
|
||||
|
||||
bool ble_gatt_service_add(
|
||||
uint8_t Service_UUID_Type,
|
||||
const Service_UUID_t* Service_UUID,
|
||||
uint8_t Service_Type,
|
||||
uint8_t Max_Attribute_Records,
|
||||
uint16_t* Service_Handle);
|
||||
|
||||
bool ble_gatt_service_delete(uint16_t svc_handle);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user