tinyusb icon indicating copy to clipboard operation
tinyusb copied to clipboard

Enable empty transfers for tud_vendor_n_write()

Open thierer opened this issue 4 years ago • 2 comments

Extend tud_vendor_n_write() to make a zero length transfer when buffer==NULL && bufsize==0, as discussed in #903.

I consider implementing this via a flag to maybe_transmit() the best solution:

  • tud_vendor_n_write() doesn't have access to neither buffer nor bufsize, so it can't make the decision.
  • Implementing it completely in tud_vendor_n_write() would mean duplicating some functionality of maybe_transmit() (but judging by your latest comment maybe that's what you prefer?).

thierer avatar Jun 22 '21 16:06 thierer

I have a second thought though, I think ZLP should only be sent when there is no data and the last packet is multiple of endpoint size) much like cdc https://github.com/hathach/tinyusb/blob/master/src/class/cdc/cdc_device.c#L469 .

hathach avatar Jul 05 '21 12:07 hathach

Something like this? (Compiles, but not tested).

It does not exactly what you wrote in that it doesn't check for a multiple, but the equivalent of the endpoint size, because the actual transfer can't really be bigger than the EP size? Or were you referring to the last bufsize parameter to tud_vendor_n_write()? If so, I don't understand what you want to achieve.

Even so I don't fully get the rationale behind that requirement. On the protocol level, the device can still send packages that are smaller than the EP size and in that case there would still be no way to send a ZLP? (I don't think change would help for the problem that lead me to open this thread).

thierer avatar Jul 20 '21 17:07 thierer