From 85cfe33262187eae622b106c55c853dcd4f42ecc Mon Sep 17 00:00:00 2001 From: Andrei Emeltchenko Date: Tue, 13 Nov 2018 10:48:17 +0200 Subject: [PATCH] usb: hid: Define helper definitions and cleanup code Use newly defined definitions for cleaning the code. Signed-off-by: Andrei Emeltchenko --- include/usb/class/usb_hid.h | 5 +++++ subsys/usb/class/hid/core.c | 8 +++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/include/usb/class/usb_hid.h b/include/usb/class/usb_hid.h index cc652a5285b..76a64bd392d 100644 --- a/include/usb/class/usb_hid.h +++ b/include/usb/class/usb_hid.h @@ -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 diff --git a/subsys/usb/class/hid/core.c b/subsys/usb/class/hid/core.c index dfe38652d37..84bcad7cf53 100644 --- a/subsys/usb/class/hid/core.c +++ b/subsys/usb/class/hid/core.c @@ -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