From 7fbe72ca27380d958670d9416d9d40321a2063ea Mon Sep 17 00:00:00 2001 From: Roman Leonov Date: Mon, 30 Jun 2025 11:19:42 +0200 Subject: [PATCH] refactor(usb_host_example): Added opening only for device with proto --- .../usb/host/hid/main/hid_host_example.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/examples/peripherals/usb/host/hid/main/hid_host_example.c b/examples/peripherals/usb/host/hid/main/hid_host_example.c index fde9f95dbd..3dfff0b931 100644 --- a/examples/peripherals/usb/host/hid/main/hid_host_example.c +++ b/examples/peripherals/usb/host/hid/main/hid_host_example.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -434,14 +434,16 @@ void hid_host_device_event(hid_host_device_handle_t hid_device_handle, .callback_arg = NULL }; - ESP_ERROR_CHECK(hid_host_device_open(hid_device_handle, &dev_config)); - if (HID_SUBCLASS_BOOT_INTERFACE == dev_params.sub_class) { - ESP_ERROR_CHECK(hid_class_request_set_protocol(hid_device_handle, HID_REPORT_PROTOCOL_BOOT)); - if (HID_PROTOCOL_KEYBOARD == dev_params.proto) { - ESP_ERROR_CHECK(hid_class_request_set_idle(hid_device_handle, 0, 0)); + if (dev_params.proto != HID_PROTOCOL_NONE) { + ESP_ERROR_CHECK(hid_host_device_open(hid_device_handle, &dev_config)); + if (HID_SUBCLASS_BOOT_INTERFACE == dev_params.sub_class) { + ESP_ERROR_CHECK(hid_class_request_set_protocol(hid_device_handle, HID_REPORT_PROTOCOL_BOOT)); + if (HID_PROTOCOL_KEYBOARD == dev_params.proto) { + ESP_ERROR_CHECK(hid_class_request_set_idle(hid_device_handle, 0, 0)); + } } + ESP_ERROR_CHECK(hid_host_device_start(hid_device_handle)); } - ESP_ERROR_CHECK(hid_host_device_start(hid_device_handle)); break; default: break;