mirror of
https://github.com/hathach/tinyusb.git
synced 2025-01-31 05:52:55 +08:00
Use cached HID descriptor.
This commit is contained in:
parent
05164c5a27
commit
a8a65d6cea
@ -205,32 +205,15 @@ bool hidd_control_request(uint8_t rhport, tusb_control_request_t const * p_reque
|
||||
|
||||
if (p_request->bRequest == TUSB_REQ_GET_DESCRIPTOR && desc_type == HID_DESC_TYPE_HID)
|
||||
{
|
||||
// FIXME: Should check which is the active configuration, but no callback in usbd currently exists to do that
|
||||
TU_VERIFY(p_hid->hid_descriptor != NULL);
|
||||
tusb_desc_configuration_t const* desc_cfg =
|
||||
(tusb_desc_configuration_t const*) tud_descriptor_configuration_cb(0);
|
||||
uint8_t const * p_desc = ((uint8_t const*) desc_cfg) + sizeof(tusb_desc_configuration_t);
|
||||
uint8_t const * desc_end = ((uint8_t const*) desc_cfg) + desc_cfg->wTotalLength;
|
||||
|
||||
while( p_desc < desc_end )
|
||||
{
|
||||
tusb_hid_descriptor_hid_t *p_desc_hid =(tusb_hid_descriptor_hid_t*)p_desc;
|
||||
if(p_desc_hid->bDescriptorType == HID_DESC_TYPE_HID) {
|
||||
tud_control_xfer(rhport, p_request, (void*) p_desc_hid, p_desc_hid->bLength);
|
||||
break;
|
||||
}
|
||||
p_desc += p_desc_hid->bLength; // next desc
|
||||
}
|
||||
if(p_desc >= desc_end)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
TU_VERIFY(tud_control_xfer(rhport, p_request, (void*) p_hid->hid_descriptor, p_hid->hid_descriptor->bLength));
|
||||
}
|
||||
else if (p_request->bRequest == TUSB_REQ_GET_DESCRIPTOR && desc_type == HID_DESC_TYPE_REPORT)
|
||||
{
|
||||
uint8_t const * desc_report = tud_hid_descriptor_report_cb();
|
||||
tud_control_xfer(rhport, p_request, (void*) desc_report, p_hid->report_desc_len);
|
||||
}else
|
||||
}
|
||||
else
|
||||
{
|
||||
return false; // stall unsupported request
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user