mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-12-20 01:33:18 +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>
96 lines
2.6 KiB
C
96 lines
2.6 KiB
C
#include "app_common.h"
|
|
|
|
#include <core/check.h>
|
|
#include <core/thread.h>
|
|
#include <core/log.h>
|
|
|
|
#include <interface/patterns/ble_thread/tl/shci_tl.h>
|
|
#include <interface/patterns/ble_thread/tl/hci_tl.h>
|
|
|
|
#define TAG "BleEvt"
|
|
|
|
#define BLE_EVENT_THREAD_FLAG_SHCI_EVENT (1UL << 0)
|
|
#define BLE_EVENT_THREAD_FLAG_HCI_EVENT (1UL << 1)
|
|
#define BLE_EVENT_THREAD_FLAG_KILL_THREAD (1UL << 2)
|
|
|
|
#define BLE_EVENT_THREAD_FLAG_ALL \
|
|
(BLE_EVENT_THREAD_FLAG_SHCI_EVENT | BLE_EVENT_THREAD_FLAG_HCI_EVENT | \
|
|
BLE_EVENT_THREAD_FLAG_KILL_THREAD)
|
|
|
|
static FuriThread* event_thread = NULL;
|
|
|
|
static int32_t ble_event_thread(void* context) {
|
|
UNUSED(context);
|
|
uint32_t flags = 0;
|
|
|
|
while((flags & BLE_EVENT_THREAD_FLAG_KILL_THREAD) == 0) {
|
|
flags =
|
|
furi_thread_flags_wait(BLE_EVENT_THREAD_FLAG_ALL, FuriFlagWaitAny, FuriWaitForever);
|
|
if(flags & BLE_EVENT_THREAD_FLAG_SHCI_EVENT) {
|
|
#ifdef FURI_BLE_EXTRA_LOG
|
|
FURI_LOG_W(TAG, "shci_user_evt_proc");
|
|
#endif
|
|
shci_user_evt_proc();
|
|
}
|
|
if(flags & BLE_EVENT_THREAD_FLAG_HCI_EVENT) {
|
|
#ifdef FURI_BLE_EXTRA_LOG
|
|
FURI_LOG_W(TAG, "hci_user_evt_proc");
|
|
#endif
|
|
hci_user_evt_proc();
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
void shci_notify_asynch_evt(void* pdata) {
|
|
UNUSED(pdata);
|
|
if(!event_thread) {
|
|
#ifdef FURI_BLE_EXTRA_LOG
|
|
FURI_LOG_E(TAG, "shci: event_thread is NULL");
|
|
#endif
|
|
return;
|
|
}
|
|
|
|
FuriThreadId thread_id = furi_thread_get_id(event_thread);
|
|
furi_assert(thread_id);
|
|
furi_thread_flags_set(thread_id, BLE_EVENT_THREAD_FLAG_SHCI_EVENT);
|
|
}
|
|
|
|
void hci_notify_asynch_evt(void* pdata) {
|
|
UNUSED(pdata);
|
|
if(!event_thread) {
|
|
#ifdef FURI_BLE_EXTRA_LOG
|
|
FURI_LOG_E(TAG, "hci: event_thread is NULL");
|
|
#endif
|
|
return;
|
|
}
|
|
|
|
FuriThreadId thread_id = furi_thread_get_id(event_thread);
|
|
furi_assert(thread_id);
|
|
furi_thread_flags_set(thread_id, BLE_EVENT_THREAD_FLAG_HCI_EVENT);
|
|
}
|
|
|
|
void ble_event_thread_stop(void) {
|
|
if(!event_thread) {
|
|
#ifdef FURI_BLE_EXTRA_LOG
|
|
FURI_LOG_E(TAG, "thread_stop: event_thread is NULL");
|
|
#endif
|
|
return;
|
|
}
|
|
|
|
FuriThreadId thread_id = furi_thread_get_id(event_thread);
|
|
furi_assert(thread_id);
|
|
furi_thread_flags_set(thread_id, BLE_EVENT_THREAD_FLAG_KILL_THREAD);
|
|
furi_thread_join(event_thread);
|
|
furi_thread_free(event_thread);
|
|
event_thread = NULL;
|
|
}
|
|
|
|
void ble_event_thread_start(void) {
|
|
furi_check(event_thread == NULL);
|
|
|
|
event_thread = furi_thread_alloc_ex("BleEventWorker", 1024, ble_event_thread, NULL);
|
|
furi_thread_set_priority(event_thread, FuriThreadPriorityHigh);
|
|
furi_thread_start(event_thread);
|
|
}
|