Skip to content

Commit 8f59076

Browse files
MarekPietakapi-no
authored andcommitted
applications: nrf_desktop: Improve HID subscription in USB state
Change ensures that the module would unsubscribe from previously used HID protocol mode before subscribing for the new HID protocol mode. This ensures that HID boot and HID report protocol mode subscriptions are not enabled at the same time. Jira: NCSDK-34349 Signed-off-by: Marek Pieta <[email protected]>
1 parent d4cf3f2 commit 8f59076

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

applications/nrf_desktop/src/modules/usb_state.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,8 @@ static void broadcast_subscriber_change(struct usb_hid_device *usb_hid)
534534
APP_EVENT_SUBMIT(event);
535535
}
536536

537-
static void broadcast_subscription_change(struct usb_hid_device *usb_hid)
537+
static void broadcast_subscription_change_internal(struct usb_hid_device *usb_hid,
538+
bool enabled_filter)
538539
{
539540
bool new_rep_enabled = (usb_hid->enabled) && (usb_hid->hid_protocol == HID_PROTOCOL_REPORT);
540541
bool new_boot_enabled = (usb_hid->enabled) && (usb_hid->hid_protocol == HID_PROTOCOL_BOOT);
@@ -543,6 +544,10 @@ static void broadcast_subscription_change(struct usb_hid_device *usb_hid)
543544
uint8_t rep_id = input_reports[i];
544545
bool new_enabled = is_hid_boot_report(rep_id) ? new_boot_enabled : new_rep_enabled;
545546

547+
if (new_enabled != enabled_filter) {
548+
continue;
549+
}
550+
546551
if ((new_enabled != usb_hid->report_enabled[rep_id]) &&
547552
(usb_hid->report_bm & BIT(rep_id))) {
548553
struct hid_report_subscription_event *event =
@@ -557,6 +562,15 @@ static void broadcast_subscription_change(struct usb_hid_device *usb_hid)
557562
usb_hid->report_enabled[rep_id] = new_enabled;
558563
}
559564
}
565+
}
566+
567+
static void broadcast_subscription_change(struct usb_hid_device *usb_hid)
568+
{
569+
/* First disable old subscriptions, then enable new subscriptions. This is done to ensure
570+
* that HID boot and HID report mode subscriptions would never be enabled at the same time.
571+
*/
572+
broadcast_subscription_change_internal(usb_hid, false);
573+
broadcast_subscription_change_internal(usb_hid, true);
560574

561575
LOG_INF("USB HID %p %sabled", (void *)usb_hid, (usb_hid->enabled) ? ("en"):("dis"));
562576
if (usb_hid->enabled) {

0 commit comments

Comments
 (0)