diff options
| author | Nathan Conrad <[email protected]> | 2019-09-19 21:04:51 -0400 |
|---|---|---|
| committer | Nathan Conrad <[email protected]> | 2019-09-19 21:04:51 -0400 |
| commit | 05164c5a27eaad25f28a4fc8926297d6cd32e3fc (patch) | |
| tree | 9b1cea3b7efbfe3b7795757226dbc315fec6275f /src/class | |
| parent | 915f52730d4bd91642bfcf74a8ebfb18536517e9 (diff) | |
Cache pointer to HID descriptor.
Diffstat (limited to 'src/class')
| -rw-r--r-- | src/class/hid/hid_device.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/class/hid/hid_device.c b/src/class/hid/hid_device.c index 2d579f475..7dabdbc17 100644 --- a/src/class/hid/hid_device.c +++ b/src/class/hid/hid_device.c @@ -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;
|
