Skip to content

Commit f39663d

Browse files
committed
bluetooth: services: User data in HID service callback
Allow user to set argument with which notification completion callback is called. Signed-off-by: Pawel Dunaj <[email protected]>
1 parent 478cee1 commit f39663d

File tree

2 files changed

+31
-7
lines changed
  • include/bluetooth/services
  • subsys/bluetooth/services

2 files changed

+31
-7
lines changed

include/bluetooth/services/hids.h

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,26 @@ int bt_hids_connected(struct bt_hids *hids_obj, struct bt_conn *conn);
532532
*/
533533
int bt_hids_disconnected(struct bt_hids *hids_obj, struct bt_conn *conn);
534534

535+
/** @brief Send Input Report, operation complete callback has user data as argument.
536+
*
537+
* @note The function is not thread safe.
538+
* It cannot be called from multiple threads at the same time.
539+
*
540+
* @param hids_obj Pointer to HIDS instance.
541+
* @param conn Pointer to Connection Object.
542+
* @param rep_index Index of report descriptor.
543+
* @param rep Pointer to the report data.
544+
* @param len Length of report data.
545+
* @param cb Notification complete callback (can be NULL).
546+
* @param userdata Argument passed to notificaion complete callback.
547+
*
548+
* @return 0 If the operation was successful. Otherwise, a (negative) error
549+
* code is returned.
550+
*/
551+
int bt_hids_inp_rep_send_userdata(struct bt_hids *hids_obj, struct bt_conn *conn,
552+
uint8_t rep_index, uint8_t const *rep, uint8_t len,
553+
bt_gatt_complete_func_t cb, void *userdata);
554+
535555
/** @brief Send Input Report.
536556
*
537557
* @note The function is not thread safe.
@@ -547,9 +567,12 @@ int bt_hids_disconnected(struct bt_hids *hids_obj, struct bt_conn *conn);
547567
* @return 0 If the operation was successful. Otherwise, a (negative) error
548568
* code is returned.
549569
*/
550-
int bt_hids_inp_rep_send(struct bt_hids *hids_obj, struct bt_conn *conn,
551-
uint8_t rep_index, uint8_t const *rep, uint8_t len,
552-
bt_gatt_complete_func_t cb);
570+
static inline int bt_hids_inp_rep_send(struct bt_hids *hids_obj, struct bt_conn *conn,
571+
uint8_t rep_index, uint8_t const *rep, uint8_t len,
572+
bt_gatt_complete_func_t cb)
573+
{
574+
return bt_hids_inp_rep_send_userdata(hids_obj, conn, rep_index, rep, len, cb, NULL);
575+
}
553576

554577
/** @brief Send Boot Mouse Input Report.
555578
*

subsys/bluetooth/services/hids.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,10 +1106,10 @@ static int inp_rep_notify_all(struct bt_hids *hids_obj,
11061106
}
11071107
}
11081108

1109-
int bt_hids_inp_rep_send(struct bt_hids *hids_obj,
1110-
struct bt_conn *conn, uint8_t rep_index,
1111-
uint8_t const *rep, uint8_t len,
1112-
bt_gatt_complete_func_t cb)
1109+
int bt_hids_inp_rep_send_userdata(struct bt_hids *hids_obj,
1110+
struct bt_conn *conn, uint8_t rep_index,
1111+
uint8_t const *rep, uint8_t len,
1112+
bt_gatt_complete_func_t cb, void *userdata)
11131113
{
11141114
struct bt_hids_inp_rep *hids_inp_rep =
11151115
&hids_obj->inp_rep_group.reports[rep_index];
@@ -1147,6 +1147,7 @@ int bt_hids_inp_rep_send(struct bt_hids *hids_obj,
11471147
params.data = rep;
11481148
params.len = hids_inp_rep->size;
11491149
params.func = cb;
1150+
params.user_data = userdata;
11501151

11511152
int err = bt_gatt_notify_cb(conn, &params);
11521153

0 commit comments

Comments
 (0)