Skip to content

Commit 84dcb91

Browse files
MarekPietakapi-no
authored andcommitted
applications: nrf_desktop: Use generic cb for HID notification events
Use a generic callback for HID input report notification events. This simplifies adding support for new HID input reports. Jira: NCSDK-33592 Signed-off-by: Marek Pieta <[email protected]> Signed-off-by: Pawel Dunaj <[email protected]> Signed-off-by: Francesco Domenico Servidio <[email protected]>
1 parent 4c5903d commit 84dcb91

File tree

2 files changed

+25
-40
lines changed

2 files changed

+25
-40
lines changed

applications/nrf_desktop/src/modules/hids.c

Lines changed: 19 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ static void sync_notif_handler(const struct hid_notification_event *event)
140140
broadcast_subscription_change(report_id, enabled);
141141
}
142142

143-
static void async_notif_handler(uint8_t report_id, enum bt_hids_notify_evt evt)
143+
static void notification_change_handler_async(uint8_t report_id, enum bt_hids_notify_evt evt)
144144
{
145145
struct hid_notification_event *event = new_hid_notification_event();
146146

@@ -169,7 +169,7 @@ static void boot_mouse_report_sent_cb(struct bt_conn *conn, void *user_data)
169169
static void boot_mouse_notif_handler(enum bt_hids_notify_evt evt)
170170
{
171171
__ASSERT_NO_MSG(IS_ENABLED(CONFIG_DESKTOP_HID_BOOT_INTERFACE_MOUSE));
172-
async_notif_handler(REPORT_ID_BOOT_MOUSE, evt);
172+
notification_change_handler_async(REPORT_ID_BOOT_MOUSE, evt);
173173
}
174174

175175
static void boot_keyboard_report_sent_cb(struct bt_conn *conn, void *user_data)
@@ -180,7 +180,7 @@ static void boot_keyboard_report_sent_cb(struct bt_conn *conn, void *user_data)
180180
static void boot_keyboard_notif_handler(enum bt_hids_notify_evt evt)
181181
{
182182
__ASSERT_NO_MSG(IS_ENABLED(CONFIG_DESKTOP_HID_BOOT_INTERFACE_KEYBOARD));
183-
async_notif_handler(REPORT_ID_BOOT_KEYBOARD, evt);
183+
notification_change_handler_async(REPORT_ID_BOOT_KEYBOARD, evt);
184184
}
185185

186186
static void report_sent_cb(struct bt_conn *conn, void *user_data)
@@ -191,25 +191,6 @@ static void report_sent_cb(struct bt_conn *conn, void *user_data)
191191

192192
hid_report_sent(conn, report_id, false);
193193
}
194-
static void mouse_notif_handler(enum bt_hids_notify_evt evt)
195-
{
196-
async_notif_handler(REPORT_ID_MOUSE, evt);
197-
}
198-
199-
static void keyboard_keys_notif_handler(enum bt_hids_notify_evt evt)
200-
{
201-
async_notif_handler(REPORT_ID_KEYBOARD_KEYS, evt);
202-
}
203-
204-
static void system_ctrl_notif_handler(enum bt_hids_notify_evt evt)
205-
{
206-
async_notif_handler(REPORT_ID_SYSTEM_CTRL, evt);
207-
}
208-
209-
static void consumer_ctrl_notif_handler(enum bt_hids_notify_evt evt)
210-
{
211-
async_notif_handler(REPORT_ID_CONSUMER_CTRL, evt);
212-
}
213194

214195
static void broadcast_kbd_leds_report(struct bt_hids_rep *rep, struct bt_conn *conn, bool write)
215196
{
@@ -286,10 +267,10 @@ static int module_init(void)
286267
(sizeof(mask) == DIV_ROUND_UP(REPORT_SIZE_MOUSE, 8)));
287268
BUILD_ASSERT(REPORT_ID_MOUSE < ARRAY_SIZE(report_index));
288269

289-
input_report[ir_pos].id = REPORT_ID_MOUSE;
290-
input_report[ir_pos].size = REPORT_SIZE_MOUSE;
291-
input_report[ir_pos].handler = mouse_notif_handler;
292-
input_report[ir_pos].rep_mask = (sizeof(mask) == 0)?(NULL):(mask);
270+
input_report[ir_pos].id = REPORT_ID_MOUSE;
271+
input_report[ir_pos].size = REPORT_SIZE_MOUSE;
272+
input_report[ir_pos].handler_ext = notification_change_handler_async;
273+
input_report[ir_pos].rep_mask = (sizeof(mask) == 0)?(NULL):(mask);
293274

294275
report_index[input_report[ir_pos].id] = ir_pos;
295276
ir_pos++;
@@ -301,10 +282,10 @@ static int module_init(void)
301282
(sizeof(mask) == DIV_ROUND_UP(REPORT_SIZE_KEYBOARD_KEYS, 8)));
302283
BUILD_ASSERT(REPORT_ID_KEYBOARD_KEYS < ARRAY_SIZE(report_index));
303284

304-
input_report[ir_pos].id = REPORT_ID_KEYBOARD_KEYS;
305-
input_report[ir_pos].size = REPORT_SIZE_KEYBOARD_KEYS;
306-
input_report[ir_pos].handler = keyboard_keys_notif_handler;
307-
input_report[ir_pos].rep_mask = (sizeof(mask) == 0)?(NULL):(mask);
285+
input_report[ir_pos].id = REPORT_ID_KEYBOARD_KEYS;
286+
input_report[ir_pos].size = REPORT_SIZE_KEYBOARD_KEYS;
287+
input_report[ir_pos].handler_ext = notification_change_handler_async;
288+
input_report[ir_pos].rep_mask = (sizeof(mask) == 0)?(NULL):(mask);
308289

309290
report_index[input_report[ir_pos].id] = ir_pos;
310291
ir_pos++;
@@ -316,10 +297,10 @@ static int module_init(void)
316297
(sizeof(mask) == DIV_ROUND_UP(REPORT_SIZE_SYSTEM_CTRL, 8)));
317298
BUILD_ASSERT(REPORT_ID_SYSTEM_CTRL < ARRAY_SIZE(report_index));
318299

319-
input_report[ir_pos].id = REPORT_ID_SYSTEM_CTRL;
320-
input_report[ir_pos].size = REPORT_SIZE_SYSTEM_CTRL;
321-
input_report[ir_pos].handler = system_ctrl_notif_handler;
322-
input_report[ir_pos].rep_mask = (sizeof(mask) == 0)?(NULL):(mask);
300+
input_report[ir_pos].id = REPORT_ID_SYSTEM_CTRL;
301+
input_report[ir_pos].size = REPORT_SIZE_SYSTEM_CTRL;
302+
input_report[ir_pos].handler_ext = notification_change_handler_async;
303+
input_report[ir_pos].rep_mask = (sizeof(mask) == 0)?(NULL):(mask);
323304

324305
report_index[input_report[ir_pos].id] = ir_pos;
325306
ir_pos++;
@@ -331,10 +312,10 @@ static int module_init(void)
331312
(sizeof(mask) == DIV_ROUND_UP(REPORT_SIZE_CONSUMER_CTRL, 8)));
332313
BUILD_ASSERT(REPORT_ID_CONSUMER_CTRL < ARRAY_SIZE(report_index));
333314

334-
input_report[ir_pos].id = REPORT_ID_CONSUMER_CTRL;
335-
input_report[ir_pos].size = REPORT_SIZE_CONSUMER_CTRL;
336-
input_report[ir_pos].handler = consumer_ctrl_notif_handler;
337-
input_report[ir_pos].rep_mask = (sizeof(mask) == 0)?(NULL):(mask);
315+
input_report[ir_pos].id = REPORT_ID_CONSUMER_CTRL;
316+
input_report[ir_pos].size = REPORT_SIZE_CONSUMER_CTRL;
317+
input_report[ir_pos].handler_ext = notification_change_handler_async;
318+
input_report[ir_pos].rep_mask = (sizeof(mask) == 0)?(NULL):(mask);
338319

339320
report_index[input_report[ir_pos].id] = ir_pos;
340321
ir_pos++;

doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,12 @@ nRF Desktop
233233
This helps to reduce RAM usage.
234234
* Link Time Optimization (:kconfig:option:`CONFIG_LTO`) to be enabled in MCUboot configurations of the nRF52840 DK (``mcuboot_smp``, ``mcuboot_qspi``).
235235
LTO no longer causes boot failures and it reduces the memory footprint.
236-
* The :ref:`nrf_desktop_hids` to use :c:func:`bt_hids_inp_rep_send_userdata` function to send HID input reports while in report mode.
237-
This enables the use of a shared callback for sending HID reports.
236+
* The :ref:`nrf_desktop_hids` to use shared callbacks for multiple HID reports:
237+
238+
* Use the :c:func:`bt_hids_inp_rep_send_userdata` function to send HID input reports while in report mode.
239+
* Use an extended callback with the notification event to handle subscriptions for HID input reports in report mode (:c:struct:`bt_hids_inp_rep`).
240+
241+
This approach simplifies the process of adding support for new HID reports.
238242

239243
nRF Machine Learning (Edge Impulse)
240244
-----------------------------------

0 commit comments

Comments
 (0)