From 91ddb8c9fe594cfa75a14780b55f949e00428ebd Mon Sep 17 00:00:00 2001 From: Johann Fischer Date: Mon, 15 Mar 2021 13:28:57 +0100 Subject: [PATCH] usb: hid: allow boot interface Protocol Code to be set per device Kconfig option USB_HID_PROTOCOL_CODE does not allow to set boot interface protocol code for specific HID device but only to set the same value for all device. Add new API function to allow the application to set Protocol Code per device. Deprecate USB_HID_PROTOCOL_CODE option. Fixes: #32778 Signed-off-by: Johann Fischer --- doc/releases/release-notes-2.6.rst | 4 ++++ include/usb/class/hid.h | 7 +++++++ include/usb/class/usb_hid.h | 12 ++++++++++++ subsys/usb/class/hid/Kconfig | 10 +++------- subsys/usb/class/hid/core.c | 13 +++++++++++++ 5 files changed, 39 insertions(+), 7 deletions(-) diff --git a/doc/releases/release-notes-2.6.rst b/doc/releases/release-notes-2.6.rst index f8c14930743..2c412105b90 100644 --- a/doc/releases/release-notes-2.6.rst +++ b/doc/releases/release-notes-2.6.rst @@ -60,6 +60,10 @@ Deprecated in this release * USB HID specific macros in ```` are deprecated in favor of new common HID macros defined in ````. +* USB HID Kconfig option USB_HID_PROTOCOL_CODE is deprecated. + USB_HID_PROTOCOL_CODE does not allow to set boot protocol code for specific + HID device. USB HID API function usb_hid_set_proto_code() can be used instead. + * The ``CONFIG_OPENOCD_SUPPORT`` Kconfig option has been deprecated in favor of ``CONFIG_DEBUG_THREAD_INFO``. diff --git a/include/usb/class/hid.h b/include/usb/class/hid.h index fe597f4ae69..7814fa5163e 100644 --- a/include/usb/class/hid.h +++ b/include/usb/class/hid.h @@ -53,6 +53,13 @@ extern "C" { /** USB HID Class SetProtocol bRequest value */ #define USB_HID_SET_PROTOCOL 0x0B +/** USB HID Boot Interface Protocol (bInterfaceProtocol) Code None */ +#define HID_BOOT_IFACE_CODE_NONE 0 +/** USB HID Boot Interface Protocol (bInterfaceProtocol) Code Keyboard */ +#define HID_BOOT_IFACE_CODE_KEYBOARD 1 +/** USB HID Boot Interface Protocol (bInterfaceProtocol) Code Mouse */ +#define HID_BOOT_IFACE_CODE_MOUSE 2 + /** USB HID Class Boot protocol code */ #define HID_PROTOCOL_BOOT 0 /** USB HID Class Report protocol code */ diff --git a/include/usb/class/usb_hid.h b/include/usb/class/usb_hid.h index 971693fba30..173df62eea9 100644 --- a/include/usb/class/usb_hid.h +++ b/include/usb/class/usb_hid.h @@ -108,6 +108,18 @@ int hid_int_ep_read(const struct device *dev, uint32_t max_data_len, uint32_t *ret_bytes); +/** + * @brief Set USB HID class Protocol Code + * + * @details Should be called before usb_hid_init(). + * + * @param[in] dev Pointer to USB HID device + * @param[in] proto_code Protocol Code to be used for bInterfaceProtocol + * + * @return 0 on success, negative errno code on fail. + */ +int usb_hid_set_proto_code(const struct device *dev, uint8_t proto_code); + /** * @brief Initialize USB HID class support * diff --git a/subsys/usb/class/hid/Kconfig b/subsys/usb/class/hid/Kconfig index 7a4c6dc32dc..1a42532e205 100644 --- a/subsys/usb/class/hid/Kconfig +++ b/subsys/usb/class/hid/Kconfig @@ -66,16 +66,12 @@ config USB_HID_BOOT_PROTOCOL for more information. config USB_HID_PROTOCOL_CODE - int "HID protocol code" + int "HID Boot Interface protocol code (DEPRECATED)" default 0 range 0 2 depends on USB_HID_BOOT_PROTOCOL help - Sets bIntefaceProtocol in HID instance. - 0 = None - 1 = Keyboard - 2 = Mouse - See Chapter 4.3 of Device Class Definition for Human Interface Devices 1.11 - for more information. + This option is deprecated. + Please use usb_hid_set_proto_code() instead. endif # USB_DEVICE_HID diff --git a/subsys/usb/class/hid/core.c b/subsys/usb/class/hid/core.c index c01f16598c1..9e9bc19ec98 100644 --- a/subsys/usb/class/hid/core.c +++ b/subsys/usb/class/hid/core.c @@ -675,6 +675,19 @@ static void hid_interface_config(struct usb_desc_header *head, .endpoint = hid_ep_data_##x, \ }; +int usb_hid_set_proto_code(const struct device *dev, uint8_t proto_code) +{ + const struct usb_cfg_data *cfg = dev->config; + struct usb_if_descriptor *if_desc = cfg->interface_descriptor; + + if (IS_ENABLED(CONFIG_USB_HID_BOOT_PROTOCOL)) { + if_desc->bInterfaceProtocol = proto_code; + return 0; + } + + return -ENOTSUP; +} + int usb_hid_init(const struct device *dev) { struct usb_cfg_data *cfg = (void *)dev->config;