Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subsys: bluetooth: pass information on report id in callbacks #19693

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion include/bluetooth/services/hids.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ enum bt_hids_notify_evt {
/** @brief Report data.
*/
struct bt_hids_rep {
/** Report ID defined in the HIDS Report Map. Not valid for boot reports. */
uint8_t id;

/** Pointer to the report data. */
uint8_t *data;

Expand All @@ -167,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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would consider deprecating the old approach to keep API simple. Similarly as here: #19692 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no deprecation - explained in the other PR


/** @brief HID Report event handler.
*
* @param rep Pointer to the report descriptor.
Expand Down Expand Up @@ -225,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;
};


Expand Down
23 changes: 17 additions & 6 deletions subsys/bluetooth/services/hids.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ static ssize_t hids_outp_rep_read(struct bt_conn *conn,

if (rep->handler) {
struct bt_hids_rep report = {
.id = rep->id,
.data = buf,
.size = rep->size,
};
Expand Down Expand Up @@ -333,6 +334,7 @@ static ssize_t hids_outp_rep_write(struct bt_conn *conn,

if (rep->handler) {
struct bt_hids_rep report = {
.id = rep->id,
.data = rep_data,
.size = rep->size,
};
Expand Down Expand Up @@ -388,6 +390,7 @@ static ssize_t hids_feat_rep_read(struct bt_conn *conn,

if (rep->handler) {
struct bt_hids_rep report = {
.id = rep->id,
.data = buf,
.size = rep->size,
};
Expand Down Expand Up @@ -438,6 +441,7 @@ static ssize_t hids_feat_rep_write(struct bt_conn *conn,

if (rep->handler) {
struct bt_hids_rep report = {
.id = rep->id,
.data = rep_data,
.size = rep->size,
};
Expand Down Expand Up @@ -473,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);
}
}

Expand Down Expand Up @@ -628,6 +637,7 @@ static ssize_t hids_boot_kb_outp_report_read(struct bt_conn *conn,

if (rep->handler) {
struct bt_hids_rep report = {
.id = 0,
.data = buf,
.size = sizeof(conn_data->hids_boot_kb_outp_rep_ctx),
};
Expand Down Expand Up @@ -670,6 +680,7 @@ static ssize_t hids_boot_kb_outp_report_write(struct bt_conn *conn,

if (rep->handler) {
struct bt_hids_rep report = {
.id = 0,
.data = rep_data,
.size = sizeof(conn_data->hids_boot_kb_outp_rep_ctx),
};
Expand Down