usb: hid: Define helper definitions and cleanup code

Use newly defined definitions for cleaning the code.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
This commit is contained in:
Andrei Emeltchenko 2018-11-13 10:48:17 +02:00 committed by Carles Cufí
parent f6a20b83d6
commit 85cfe33262
2 changed files with 10 additions and 3 deletions

View File

@ -40,6 +40,11 @@ struct usb_hid_descriptor {
struct usb_hid_class_subdescriptor subdesc[1];
} __packed;
/* HID Class Descriptor Types */
#define HID_CLASS_DESCRIPTOR_HID (REQTYPE_TYPE_CLASS << 5 | 0x01)
#define HID_CLASS_DESCRIPTOR_REPORT (REQTYPE_TYPE_CLASS << 5 | 0x02)
/* HID Class Specific Requests */
#define HID_GET_REPORT 0x01

View File

@ -186,14 +186,16 @@ static int hid_custom_handle_req(struct usb_setup_packet *setup,
REQTYPE_GET_RECIP(setup->bmRequestType) ==
REQTYPE_RECIP_INTERFACE &&
setup->bRequest == REQ_GET_DESCRIPTOR) {
switch (setup->wValue) {
case 0x2100:
u8_t value = sys_le16_to_cpu(setup->wValue) >> 8;
switch (value) {
case HID_CLASS_DESCRIPTOR_HID:
LOG_DBG("Return HID Descriptor");
*len = min(*len, hid_cfg.if0_hid.bLength);
*data = (u8_t *)&hid_cfg.if0_hid;
break;
case 0x2200:
case HID_CLASS_DESCRIPTOR_REPORT:
LOG_DBG("Return Report Descriptor");
/* Some buggy system may be pass a larger wLength when