Skip to content

Commit

Permalink
update(class/hid/usbh_hid): export usbh_hid_get_report_descriptor api
Browse files Browse the repository at this point in the history
  • Loading branch information
sakumisu committed Sep 27, 2024
1 parent 58ccd1f commit 7043cf7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
20 changes: 5 additions & 15 deletions class/hid/usbh_hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ static void usbh_hid_class_free(struct usbh_hid *hid_class)
memset(hid_class, 0, sizeof(struct usbh_hid));
}

static int usbh_hid_get_report_descriptor(struct usbh_hid *hid_class, uint8_t *buffer)
int usbh_hid_get_report_descriptor(struct usbh_hid *hid_class, uint8_t *buffer, uint32_t buflen)
{
struct usb_setup_packet *setup;
int ret;

if (!hid_class || !hid_class->hport) {
return -USB_ERR_INVAL;
Expand All @@ -64,14 +63,9 @@ static int usbh_hid_get_report_descriptor(struct usbh_hid *hid_class, uint8_t *b
setup->bRequest = USB_REQUEST_GET_DESCRIPTOR;
setup->wValue = HID_DESCRIPTOR_TYPE_HID_REPORT << 8;
setup->wIndex = hid_class->intf;
setup->wLength = hid_class->report_size;
setup->wLength = buflen;

ret = usbh_control_transfer(hid_class->hport, setup, g_hid_buf[hid_class->minor]);
if (ret < 8) {
return ret;
}
memcpy(buffer, g_hid_buf[hid_class->minor], ret - 8);
return ret;
return usbh_control_transfer(hid_class->hport, setup, buffer);
}

int usbh_hid_set_idle(struct usbh_hid *hid_class, uint8_t report_id, uint8_t duration)
Expand Down Expand Up @@ -215,11 +209,6 @@ int usbh_hid_connect(struct usbh_hubport *hport, uint8_t intf)
}

hid_class->report_size = desc->subdesc[0].wDescriptorLength;

if (hid_class->report_size > sizeof(g_hid_buf[hid_class->minor])) {
USB_LOG_ERR("HID report descriptor too large\r\n");
return -USB_ERR_INVAL;
}
found = true;
goto found;
}
Expand Down Expand Up @@ -247,7 +236,8 @@ int usbh_hid_connect(struct usbh_hubport *hport, uint8_t intf)
USB_LOG_WRN("Do not support set idle\r\n");
}

ret = usbh_hid_get_report_descriptor(hid_class, hid_class->report_desc);
/* We read report desc but do nothing (because of too much memory usage for parsing report desc, parsed by users) */
ret = usbh_hid_get_report_descriptor(hid_class, g_hid_buf[hid_class->minor], MIN(sizeof(g_hid_buf[hid_class->minor]), hid_class->report_size));
if (ret < 0) {
return ret;
}
Expand Down
2 changes: 1 addition & 1 deletion class/hid/usbh_hid.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ struct usbh_hid {
struct usbh_urb intin_urb; /* INTR IN urb */
struct usbh_urb intout_urb; /* INTR OUT urb */

uint8_t report_desc[256];
uint16_t report_size;

uint8_t protocol;
Expand All @@ -29,6 +28,7 @@ struct usbh_hid {
extern "C" {
#endif

int usbh_hid_get_report_descriptor(struct usbh_hid *hid_class, uint8_t *buffer, uint32_t buflen);
int usbh_hid_set_idle(struct usbh_hid *hid_class, uint8_t report_id, uint8_t duration);
int usbh_hid_get_idle(struct usbh_hid *hid_class, uint8_t *buffer);
int usbh_hid_set_report(struct usbh_hid *hid_class, uint8_t report_type, uint8_t report_id, uint8_t *buffer, uint32_t buflen);
Expand Down

0 comments on commit 7043cf7

Please sign in to comment.