Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable empty transfers for tud_vendor_n_write() #911

Merged
merged 3 commits into from May 9, 2024

Conversation

thierer
Copy link
Contributor

@thierer thierer commented Jun 22, 2021

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?).

@hathach
Copy link
Owner

hathach commented Jul 5, 2021

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 .

@thierer thierer force-pushed the vendor_class_zero_length_transfer branch from 51580a1 to f607a99 Compare July 20, 2021 17:13
@thierer
Copy link
Contributor Author

thierer commented Jul 20, 2021

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).

{
TU_ASSERT( usbd_edpt_xfer(TUD_OPT_RHPORT, p_itf->ep_in, p_itf->epin_buf, count) );
}
last_in_transfer_was_epsize = count && (count == CFG_TUD_VENDOR_EPSIZE);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

condition seems to be overkill (only right side of && makes a difference) or wrong (&& where || should be)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

&& ist correct, but you're right, it's redundant.

@HiFiPhile
Copy link
Collaborator

HiFiPhile commented May 9, 2024

Sorry for the extra long delay, I've merged latest ZLP handling from CDC class.
Tested with webusb_serial example.

@HiFiPhile HiFiPhile merged commit 63e64f3 into hathach:master May 9, 2024
76 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

4 participants