-
Notifications
You must be signed in to change notification settings - Fork 1.1k
usb: Propagate the result of submit_xfer. #1035
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
Conversation
3b8bad4 to
3a7b150
Compare
Josverl
commented
Jul 31, 2025
Could you add a test to verify this in CI?
Or is this already covered by another test?
There is a comment in Interface.submit_xfer():
# If the function returns, the transfer is queued.
I guess that's either incorrect and should be changed, or is correct and then this PR is not needed.
@projectgus maybe we need your input here.
Hmm, yeah - the underlying machine.USBDevice can return False if the transfer fails to queue due to a DCD error. This is documented on Interface.submit_xfer() as being the third case where it can raise an exception, but the result isn't checked so it won't raise an exception (currently).
In general, submit_xfer() should only fail under "exceptional" circumstances (i.e. broken hardware or broken driver), so it probably is better to change hid.send_report() to ignore the submit_xfer() result and return True. Then also update Interface.submit_xfer() so it raises an exception if the lower layer returns False (i.e. make the behaviour the same as what is documented).
@hyx0329 Thanks for pointing this out and submitting the fix. Are you up for updating your PR along these lines?
3a7b150 to
6e46847
Compare
I've updated the PR with the proposed changes. It should work now.
As to the test, I have no idea how to do it with software only. Core depends on machine.USBDevice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @hyx0329, this fix looks good to me.
We don't currently have any way to test the micropython-lib usb classes in CI. Running the examples manually is the best we can do. 🫤
So the behavior matches the comment. Signed-off-by: Hyx <hyx0329@outlook.com>
This tells the caller that no error has occurred. The child classes can use this state to do double buffering correctly. If any fundamental error occurs in submit_xfer, the underlying code will raise an exception. Signed-off-by: Hyx <hyx0329@outlook.com>
6e46847 to
bdc4706
Compare
The result is used in the hid keyboard module but was not actually propagated. With this result, the report double buffering will work correctly.