Skip to content

Implement AsyncRead and AsyncWrite for bulk_in and bulk_out #97

Answered by kevinmehall
teamclouday asked this question in Q&A
Discussion options

You must be logged in to vote

One way USB differs from sockets is that you need to explicitly start transfers before you get data, and the data is batched in transfers instead of arbitrary length read and write calls.

A struct wrapping Queue and a buffer of received-but-unread bytes could handle this and implement AsyncRead, and nusb should probably include this as a convenience API. poll_read would copy bytes from the buffer if available, or call poll_next on the Queue to get the next buffer, and resubmit the transfer.

Similarly for AsyncWrite, it would buffer a transfer's worth of data and submit it on flush or when the buffer fills.

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by teamclouday
Comment options

You must be logged in to vote
4 replies
@kevinmehall
Comment options

@teamclouday
Comment options

@kevinmehall
Comment options

@teamclouday
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants