You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am working on a USB Host implementation, working with the STM32G0B1/C1 family.
Currently I have a basic working example doing enumeration of a HID keyboard and I can receive keystrokes.
I am looking into how to fit this best in embassy (assuming embassy would like to add usbhost functionality), and there are quite some decisions to make about what should go where and about the API surface for each layer.
This is what I have now
Simple HIDKeyboard implementation. Could serve as an example project
UsbHost (knows about control requests, enumeration, parsing descriptors).
USBHostDriverTrait that is used by USBHostDriver and imlpemented by HAL
USBHostDriver HAL implementation for stm32 with usb_v4 IP
STM32 USBHostDriver
Via cfg_attr the HAL choses between 'usb' and 'otg' IP. My current usbhost hal implementation is for usb_v4. As far as I know only _v4 supports host. How to fit in this functionality in with the current usb module structure? I guess we don't want to expose this for non-v4 IP.
My current host implementation is independent of the usb driver implementation. For usb_v4 you could have both, but you cannot use them at the same time since it is the same peripheral. One way is to specify compile time which one you want.
Which is what I did hardcoded during development:
//! Universal Serial Bus (USB)// #[cfg_attr(usb, path = "usb.rs")]// #[cfg_attr(otg, path = "otg.rs")]// mod _version;// pub use _version::*;#[cfg_attr(usb, path = "usb_host.rs")]mod _host_version;pubuse _host_version::*;
Simplest way is to add a usb-host config option to select usb_host.rs instead.
In theory one may wish to switch between host and device runtime, that wouldn't be supported like this.
Another advantage is that this approach does not risk breaking any existing usb functionality. Can always combine it later.
Alternatively if the "usb" implementation supports both device and host then you have to deal with not allowing that for _v1 - _v3. And you end up with a lot of if host { some host logic } else { device logic }
Any ideas?
USBHostDriverTrait
embassy-usb-driver contains the traits for usb device implementations. Currently I have added a host module to this crate for the host traits.
I called it USBHostDriverTrait to differentiate with the USBHostDriver but better naming is desirable.
The embassy-usb crate implements various Device Classes. Would USBHost fit in here and how? Or better in a new separate crate such as embassy-usb-host? There are of course some shared data types such as descriptors, but not much shared logic I believe.
Also wondering what would be the preferred way to go about the PR process? Everything in one go is a lot to review. but you kinda need all layers for context I think
Happy to discuss!
The text was updated successfully, but these errors were encountered:
What about multiple connected devices (via usb hub)? I see that now there is only method for changing current device address in user-facing UsbHost struct.
I am not really sure how a hub would change things exactly. I guess it would required an extra level of abstraction since the host would have to channel everything via the hub.
I was aiming for very specific embedded host implementations only.
Given that there are things like low-speed preamble, host indeed needs to handle hub specially. I want host support on rp2040 to control 2 usb devices, so I probably will be implementing my own solution inspired from yours. So far I have CONTROL and INTERRUPT IN channels working, and keyboard example works too.
I am working on a USB Host implementation, working with the STM32G0B1/C1 family.
Currently I have a basic working example doing enumeration of a HID keyboard and I can receive keystrokes.
I am looking into how to fit this best in embassy (assuming embassy would like to add usbhost functionality), and there are quite some decisions to make about what should go where and about the API surface for each layer.
This is what I have now
usb_v4
IPSTM32 USBHostDriver
Via
cfg_attr
the HAL choses between'usb'
and'otg'
IP. My current usbhost hal implementation is forusb_v4
. As far as I know only_v4
supports host. How to fit in this functionality in with the current usb module structure? I guess we don't want to expose this for non-v4 IP.My current host implementation is independent of the usb driver implementation. For
usb_v4
you could have both, but you cannot use them at the same time since it is the same peripheral. One way is to specify compile time which one you want.Which is what I did hardcoded during development:
Simplest way is to add a
usb-host
config option to selectusb_host.rs
instead.In theory one may wish to switch between host and device runtime, that wouldn't be supported like this.
Another advantage is that this approach does not risk breaking any existing usb functionality. Can always combine it later.
Alternatively if the
"usb"
implementation supports both device and host then you have to deal with not allowing that for_v1
-_v3
. And you end up with a lot ofif host { some host logic } else { device logic }
Any ideas?
USBHostDriverTrait
embassy-usb-driver
contains the traits for usb device implementations. Currently I have added ahost
module to this crate for the host traits.I called it
USBHostDriverTrait
to differentiate with theUSBHostDriver
but better naming is desirable.So far I ended up with this API:
USBHost
The
embassy-usb
crate implements various Device Classes. WouldUSBHost
fit in here and how? Or better in a new separate crate such asembassy-usb-host
? There are of course some shared data types such as descriptors, but not much shared logic I believe.Also wondering what would be the preferred way to go about the PR process? Everything in one go is a lot to review. but you kinda need all layers for context I think
Happy to discuss!
The text was updated successfully, but these errors were encountered: