mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-12-24 19:53:08 +00:00
60a9d7e6cf
* 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>
114 lines
3.8 KiB
C
114 lines
3.8 KiB
C
#include "serial_profile.h"
|
|
|
|
#include <gap.h>
|
|
#include <furi_ble/profile_interface.h>
|
|
#include <services/dev_info_service.h>
|
|
#include <services/battery_service.h>
|
|
#include <services/serial_service.h>
|
|
#include <furi.h>
|
|
|
|
typedef struct {
|
|
FuriHalBleProfileBase base;
|
|
|
|
BleServiceDevInfo* dev_info_svc;
|
|
BleServiceBattery* battery_svc;
|
|
BleServiceSerial* serial_svc;
|
|
} BleProfileSerial;
|
|
_Static_assert(offsetof(BleProfileSerial, base) == 0, "Wrong layout");
|
|
|
|
static FuriHalBleProfileBase* ble_profile_serial_start(FuriHalBleProfileParams profile_params) {
|
|
UNUSED(profile_params);
|
|
|
|
BleProfileSerial* profile = malloc(sizeof(BleProfileSerial));
|
|
|
|
profile->base.config = ble_profile_serial;
|
|
|
|
profile->dev_info_svc = ble_svc_dev_info_start();
|
|
profile->battery_svc = ble_svc_battery_start(true);
|
|
profile->serial_svc = ble_svc_serial_start();
|
|
|
|
return &profile->base;
|
|
}
|
|
|
|
static void ble_profile_serial_stop(FuriHalBleProfileBase* profile) {
|
|
furi_check(profile);
|
|
furi_check(profile->config == ble_profile_serial);
|
|
|
|
BleProfileSerial* serial_profile = (BleProfileSerial*)profile;
|
|
ble_svc_battery_stop(serial_profile->battery_svc);
|
|
ble_svc_dev_info_stop(serial_profile->dev_info_svc);
|
|
ble_svc_serial_stop(serial_profile->serial_svc);
|
|
}
|
|
|
|
static GapConfig serial_template_config = {
|
|
.adv_service_uuid = 0x3080,
|
|
.appearance_char = 0x8600,
|
|
.bonding_mode = true,
|
|
.pairing_method = GapPairingPinCodeShow,
|
|
.conn_param = {
|
|
.conn_int_min = 0x18, // 30 ms
|
|
.conn_int_max = 0x24, // 45 ms
|
|
.slave_latency = 0,
|
|
.supervisor_timeout = 0,
|
|
}};
|
|
|
|
static void
|
|
ble_profile_serial_get_config(GapConfig* config, FuriHalBleProfileParams profile_params) {
|
|
UNUSED(profile_params);
|
|
|
|
furi_check(config);
|
|
memcpy(config, &serial_template_config, sizeof(GapConfig));
|
|
// Set mac address
|
|
memcpy(config->mac_address, furi_hal_version_get_ble_mac(), sizeof(config->mac_address));
|
|
// Set advertise name
|
|
strlcpy(
|
|
config->adv_name,
|
|
furi_hal_version_get_ble_local_device_name_ptr(),
|
|
FURI_HAL_VERSION_DEVICE_NAME_LENGTH);
|
|
config->adv_service_uuid |= furi_hal_version_get_hw_color();
|
|
}
|
|
|
|
static const FuriHalBleProfileTemplate profile_callbacks = {
|
|
.start = ble_profile_serial_start,
|
|
.stop = ble_profile_serial_stop,
|
|
.get_gap_config = ble_profile_serial_get_config,
|
|
};
|
|
|
|
const FuriHalBleProfileTemplate* ble_profile_serial = &profile_callbacks;
|
|
|
|
void ble_profile_serial_set_event_callback(
|
|
FuriHalBleProfileBase* profile,
|
|
uint16_t buff_size,
|
|
FuriHalBtSerialCallback callback,
|
|
void* context) {
|
|
furi_check(profile && (profile->config == ble_profile_serial));
|
|
|
|
BleProfileSerial* serial_profile = (BleProfileSerial*)profile;
|
|
ble_svc_serial_set_callbacks(serial_profile->serial_svc, buff_size, callback, context);
|
|
}
|
|
|
|
void ble_profile_serial_notify_buffer_is_empty(FuriHalBleProfileBase* profile) {
|
|
furi_check(profile && (profile->config == ble_profile_serial));
|
|
|
|
BleProfileSerial* serial_profile = (BleProfileSerial*)profile;
|
|
ble_svc_serial_notify_buffer_is_empty(serial_profile->serial_svc);
|
|
}
|
|
|
|
void ble_profile_serial_set_rpc_active(FuriHalBleProfileBase* profile, bool active) {
|
|
furi_check(profile && (profile->config == ble_profile_serial));
|
|
|
|
BleProfileSerial* serial_profile = (BleProfileSerial*)profile;
|
|
ble_svc_serial_set_rpc_active(serial_profile->serial_svc, active);
|
|
}
|
|
|
|
bool ble_profile_serial_tx(FuriHalBleProfileBase* profile, uint8_t* data, uint16_t size) {
|
|
furi_check(profile && (profile->config == ble_profile_serial));
|
|
|
|
BleProfileSerial* serial_profile = (BleProfileSerial*)profile;
|
|
|
|
if(size > BLE_PROFILE_SERIAL_PACKET_SIZE_MAX) {
|
|
return false;
|
|
}
|
|
|
|
return ble_svc_serial_update_tx(serial_profile->serial_svc, data, size);
|
|
}
|