From 4e7b2c17fc8be8c78bf1cdadef563a9199c2e75f Mon Sep 17 00:00:00 2001 From: Pawel Dunaj Date: Wed, 8 Jan 2025 13:30:16 +0100 Subject: [PATCH] bluetooth: services: report id in input report notification callback Add report identifier to input report notification callback. The old callback format is kept for backwards compatibility. Signed-off-by: Pawel Dunaj --- include/bluetooth/services/hids.h | 16 +++++++++++++++- subsys/bluetooth/services/hids.c | 17 +++++++++++------ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/include/bluetooth/services/hids.h b/include/bluetooth/services/hids.h index 41418fc7edd..d556761470f 100644 --- a/include/bluetooth/services/hids.h +++ b/include/bluetooth/services/hids.h @@ -170,6 +170,13 @@ struct bt_hids_rep { */ typedef void (*bt_hids_notify_handler_t) (enum bt_hids_notify_evt evt); +/** @brief HID notification event handler, with report identification. + * + * @param report_id Report ID defined in the HIDS Report Map. + * @param evt Notification event. + */ +typedef void (*bt_hids_notify_ext_handler_t) (uint8_t report_id, enum bt_hids_notify_evt evt); + /** @brief HID Report event handler. * * @param rep Pointer to the report descriptor. @@ -228,8 +235,15 @@ struct bt_hids_inp_rep { */ const uint8_t *rep_mask; - /** Callback with the notification event. */ + /** Callback with the notification event. + * Used if set and extended callback is not set. + */ bt_hids_notify_handler_t handler; + + /** Extended callback with the notification event. + * Has preference over the normal callback. + */ + bt_hids_notify_ext_handler_t handler_ext; }; diff --git a/subsys/bluetooth/services/hids.c b/subsys/bluetooth/services/hids.c index ed7f5faf249..06ad6011afd 100644 --- a/subsys/bluetooth/services/hids.c +++ b/subsys/bluetooth/services/hids.c @@ -477,16 +477,21 @@ static void hids_input_report_ccc_changed(struct bt_gatt_attr const *attr, CONTAINER_OF((struct _bt_gatt_ccc *)attr->user_data, struct bt_hids_inp_rep, ccc); + uint8_t report_id = inp_rep->id; + enum bt_hids_notify_evt evt; + if (value == BT_GATT_CCC_NOTIFY) { LOG_DBG("Notification has been turned on"); - if (inp_rep->handler != NULL) { - inp_rep->handler(BT_HIDS_CCCD_EVT_NOTIFY_ENABLED); - } + evt = BT_HIDS_CCCD_EVT_NOTIFY_ENABLED; } else { LOG_DBG("Notification has been turned off"); - if (inp_rep->handler != NULL) { - inp_rep->handler(BT_HIDS_CCCD_EVT_NOTIFY_DISABLED); - } + evt = BT_HIDS_CCCD_EVT_NOTIFY_DISABLED; + } + + if (inp_rep->handler_ext != NULL) { + inp_rep->handler_ext(report_id, evt); + } else if (inp_rep->handler != NULL) { + inp_rep->handler(evt); } }