ataradov / dgw

USB HID Data Gateway
51 stars 11 forks source link

Question for usb_handle_standard_request... #4

Open telix001 opened 5 years ago

telix001 commented 5 years ago

Hello Alex, I have one question: If the usb hid report descriptor has a size of 64 bytes or a multiple of 64 bytes, we shouldn't check this and send a zero-length packet at end?

https://github.com/ataradov/dgw/blob/40b6b1587850cd2b32505ace08076b0dad5247db/embedded/usb.c#L255

Maybe like this:

case USB_CMD(IN, INTERFACE, STANDARD, GET_DESCRIPTOR):
{
     uint16_t length = request->wLength;
     uint16_t total_len= sizeof(usb_hid_report_descriptor);
     bool need_zlp = !(length & (usb_device_descriptor.bMaxPacketSize0 - 1));

    if (length <= total_len)
        need_zlp = false;
    else 
        length = total_len;

    udc_control_send((uint8_t *)usb_hid_report_descriptor, length);

    if (need_zlp)
    udc_control_send_zlp(); 
} break;
ataradov commented 5 years ago

Probably, I just did not care, since none of the descriptors were multiple of 64 bytes.

And this change would need to be made in usb_control_send(), so it applies to all descriptors, not just the HID.

Newer and better version of the USB code is located in this project https://github.com/ataradov/vcp, so if you want to use it in your project, then I would definitely go with that one. It still does not send ZLPs there though.