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 <johann.fischer@nordicsemi.no>
This commit is contained in:
Johann Fischer 2021-03-15 13:28:57 +01:00 committed by Anas Nashif
commit 91ddb8c9fe
5 changed files with 39 additions and 7 deletions

View file

@ -60,6 +60,10 @@ Deprecated in this release
* USB HID specific macros in ``<include/usb/class/usb_hid.h>`` are deprecated * USB HID specific macros in ``<include/usb/class/usb_hid.h>`` are deprecated
in favor of new common HID macros defined in ``<include/usb/class/hid.h>``. in favor of new common HID macros defined in ``<include/usb/class/hid.h>``.
* 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 * The ``CONFIG_OPENOCD_SUPPORT`` Kconfig option has been deprecated in favor
of ``CONFIG_DEBUG_THREAD_INFO``. of ``CONFIG_DEBUG_THREAD_INFO``.

View file

@ -53,6 +53,13 @@ extern "C" {
/** USB HID Class SetProtocol bRequest value */ /** USB HID Class SetProtocol bRequest value */
#define USB_HID_SET_PROTOCOL 0x0B #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 */ /** USB HID Class Boot protocol code */
#define HID_PROTOCOL_BOOT 0 #define HID_PROTOCOL_BOOT 0
/** USB HID Class Report protocol code */ /** USB HID Class Report protocol code */

View file

@ -108,6 +108,18 @@ int hid_int_ep_read(const struct device *dev,
uint32_t max_data_len, uint32_t max_data_len,
uint32_t *ret_bytes); 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 * @brief Initialize USB HID class support
* *

View file

@ -66,16 +66,12 @@ config USB_HID_BOOT_PROTOCOL
for more information. for more information.
config USB_HID_PROTOCOL_CODE config USB_HID_PROTOCOL_CODE
int "HID protocol code" int "HID Boot Interface protocol code (DEPRECATED)"
default 0 default 0
range 0 2 range 0 2
depends on USB_HID_BOOT_PROTOCOL depends on USB_HID_BOOT_PROTOCOL
help help
Sets bIntefaceProtocol in HID instance. This option is deprecated.
0 = None Please use usb_hid_set_proto_code() instead.
1 = Keyboard
2 = Mouse
See Chapter 4.3 of Device Class Definition for Human Interface Devices 1.11
for more information.
endif # USB_DEVICE_HID endif # USB_DEVICE_HID

View file

@ -675,6 +675,19 @@ static void hid_interface_config(struct usb_desc_header *head,
.endpoint = hid_ep_data_##x, \ .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) int usb_hid_init(const struct device *dev)
{ {
struct usb_cfg_data *cfg = (void *)dev->config; struct usb_cfg_data *cfg = (void *)dev->config;