mirror of
https://github.com/hathach/tinyusb.git
synced 2025-02-19 15:40:41 +00:00
Cache pointer to HID descriptor.
This commit is contained in:
parent
915f52730d
commit
05164c5a27
@ -46,12 +46,13 @@ typedef struct
|
||||
uint8_t boot_protocol; // Boot mouse or keyboard
|
||||
bool boot_mode; // default = false (Report)
|
||||
uint8_t idle_rate; // up to application to handle idle rate
|
||||
uint16_t reprot_desc_len;
|
||||
uint16_t report_desc_len;
|
||||
|
||||
CFG_TUSB_MEM_ALIGN uint8_t epin_buf[CFG_TUD_HID_BUFSIZE];
|
||||
CFG_TUSB_MEM_ALIGN uint8_t epout_buf[CFG_TUD_HID_BUFSIZE];
|
||||
|
||||
}hidd_interface_t;
|
||||
tusb_hid_descriptor_hid_t const * hid_descriptor;
|
||||
} hidd_interface_t;
|
||||
|
||||
CFG_TUSB_MEM_SECTION static hidd_interface_t _hidd_itf[CFG_TUD_HID];
|
||||
|
||||
@ -167,8 +168,8 @@ bool hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint16_t
|
||||
|
||||
//------------- HID descriptor -------------//
|
||||
p_desc = tu_desc_next(p_desc);
|
||||
tusb_hid_descriptor_hid_t const *desc_hid = (tusb_hid_descriptor_hid_t const *) p_desc;
|
||||
TU_ASSERT(HID_DESC_TYPE_HID == desc_hid->bDescriptorType);
|
||||
p_hid->hid_descriptor = (tusb_hid_descriptor_hid_t const *) p_desc;
|
||||
TU_ASSERT(HID_DESC_TYPE_HID == p_hid->hid_descriptor->bDescriptorType);
|
||||
|
||||
//------------- Endpoint Descriptor -------------//
|
||||
p_desc = tu_desc_next(p_desc);
|
||||
@ -178,7 +179,7 @@ bool hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint16_t
|
||||
|
||||
p_hid->boot_mode = false; // default mode is REPORT
|
||||
p_hid->itf_num = desc_itf->bInterfaceNumber;
|
||||
memcpy(&p_hid->reprot_desc_len, &desc_hid->wReportLength, 2);
|
||||
memcpy(&p_hid->report_desc_len, &(p_hid->hid_descriptor->wReportLength), 2);
|
||||
|
||||
*p_len = sizeof(tusb_desc_interface_t) + sizeof(tusb_hid_descriptor_hid_t) + desc_itf->bNumEndpoints*sizeof(tusb_desc_endpoint_t);
|
||||
|
||||
@ -205,6 +206,7 @@ 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);
|
||||
@ -227,7 +229,7 @@ bool hidd_control_request(uint8_t rhport, tusb_control_request_t const * p_reque
|
||||
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->reprot_desc_len);
|
||||
tud_control_xfer(rhport, p_request, (void*) desc_report, p_hid->report_desc_len);
|
||||
}else
|
||||
{
|
||||
return false; // stall unsupported request
|
||||
@ -273,7 +275,7 @@ bool hidd_control_request(uint8_t rhport, tusb_control_request_t const * p_reque
|
||||
|
||||
case HID_REQ_CONTROL_GET_PROTOCOL:
|
||||
{
|
||||
uint8_t protocol = 1-p_hid->boot_mode; // 0 is Boot, 1 is Report protocol
|
||||
uint8_t protocol = (uint8_t)(1-p_hid->boot_mode); // 0 is Boot, 1 is Report protocol
|
||||
tud_control_xfer(rhport, p_request, &protocol, 1);
|
||||
}
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user