From a0b2edd0eb595d2f90dfab8c6aa0b9f3209e0016 Mon Sep 17 00:00:00 2001 From: schneider <schneider@blinkenlichts.net> Date: Tue, 22 Dec 2020 22:53:12 +0100 Subject: [PATCH] feat(hid): Add ble_hid_enable config option --- Documentation/card10-cfg.rst | 2 ++ epicardium/ble/ble_main.c | 8 +++++--- epicardium/ble/hid.h | 2 ++ epicardium/ble/hid_work.c | 4 ++++ 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Documentation/card10-cfg.rst b/Documentation/card10-cfg.rst index c96a9a0dd..d37bedca4 100644 --- a/Documentation/card10-cfg.rst +++ b/Documentation/card10-cfg.rst @@ -47,6 +47,8 @@ Option name Type Description ------------------ ---------- ----------- ``ble_mac`` Boolean MAC address used for BLE. Format: ``ca:4d:10:xx:xx:xx``. ------------------ ---------- ----------- +``ble_hid_enable`` Boolean Enable the Human Interface Device (HID) characteristics on BLE. +------------------ ---------- ----------- ``ble_log_enable`` Boolean Activate HCI level logging of BLE data. Creates a new btsnoop compatible log file named ``ble.log`` in the ``logs`` folder after each boot if BLE is activated. Keeps the last 10 files. ------------------ ---------- ----------- ``right_scroll`` Boolean Use both right buttons to scroll up and down. Lower left button is SELECT. diff --git a/epicardium/ble/ble_main.c b/epicardium/ble/ble_main.c index b6d662bed..bd2f99482 100644 --- a/epicardium/ble/ble_main.c +++ b/epicardium/ble/ble_main.c @@ -42,11 +42,13 @@ #include "profiles/gap_api.h" #include "cccd.h" #include "ess.h" +#include "hid.h" #include "ble_api.h" #include "epicardium.h" #include "api/interrupt-sender.h" #include "modules/log.h" +#include "modules/config.h" #define SCAN_REPORTS_NUM 16 @@ -973,8 +975,6 @@ static void BleHandler(wsfEventMask_t event, wsfMsgHdr_t *pMsg) } } -void hid_init(void); - /*************************************************************************************************/ /*! * \brief Start the application. @@ -1003,7 +1003,9 @@ void BleStart(void) SvcBattCbackRegister(BasReadCback, NULL); SvcBattAddGroup(); - hid_init(); + if(config_get_boolean_with_default("ble_hid_enable", false)) { + hid_init(); + } /* Reset the device */ DmDevReset(); } diff --git a/epicardium/ble/hid.h b/epicardium/ble/hid.h index 6edd627a1..639ef6d5a 100644 --- a/epicardium/ble/hid.h +++ b/epicardium/ble/hid.h @@ -12,3 +12,5 @@ #define HIDAPP_KEYBOARD_REPORT_ID 1 #define HIDAPP_MOUSE_REPORT_ID 2 #define HIDAPP_CONSUMER_REPORT_ID 3 + +void hid_init(void); diff --git a/epicardium/ble/hid_work.c b/epicardium/ble/hid_work.c index 406f8bd0a..268fa3d9a 100644 --- a/epicardium/ble/hid_work.c +++ b/epicardium/ble/hid_work.c @@ -196,6 +196,10 @@ void hidAppInfoCback(dmConnId_t connId, uint8_t type, uint8_t value) void HidProcMsg(wsfMsgHdr_t *pMsg) { + if (!queue) { + /* Not initialized (yet). */ + return; + } if (pMsg->event == ATTS_HANDLE_VALUE_CNF) { if (pMsg->status == ATT_SUCCESS) { hidAppCb.txFlags |= HIDAPP_TX_FLAGS_READY; -- GitLab