Closed Dirbaio closed 2 years ago
There was some discussion about this on the Matrix chat
TLDR is: the register layout of many USB peripherals allows concurrently reading/writing to different endpoints (it is the case on nRF, STM32 USBD and OTG), so it's nice to keep that so that different classes can concurrently read/write to different endpoints without locking.
The problem is the current trait still allows things like concurrently writing to the same endpoint twice, which it shouldn't.
I now think some solution like the one in the WIP branch endpoint-trait
is better https://github.com/rust-embedded-community/usb-device/blob/endpoint-trait/src/usbcore.rs . Each endpoint is a separate struct, requires &mut self
to read/write, but is Send, so you can read/write to different endpoints concurrently.
embassy-usb
does it this way, the result is the whole USB stack (core+classes) is fully lock-free which makes it much faster.
I'm not going to keep working on this personally though, as embassy-usb
fits my needs.
Trivial update for the sole propuse that #89 gets an merge request is closed notification.
Currently
UsbBus
requiresSync
and has&self
receiver for all methods. This forces implementations to use global critical sections such ascortex_m::interrupt::free
. This is a problem for a few reasons:main
).This PR fixes this by changing all the
UsbBus
methods to require&mut self
, and passing exclusive borrows to the Bus around to all the places that need it.Disadvantages::
Advantages:
main
.