-
Notifications
You must be signed in to change notification settings - Fork 67
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
Add USB driver and example #24
Conversation
Note that any of the |
pub use stm32_usbd::UsbBus; | ||
|
||
pub struct Peripheral { | ||
pub usb: USB, |
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.
It seems like it’s more common (though I’m still fairly new to embedded rust) to keep structs opaque and then use “smart” constructor” functions that return them.
It seems like it might be worth doing so to keep the fields out of the public API, so it could be modified later.
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.
While that's true, this is also a very non-complicated struct that has properties publicly available through other interfaces. I think folks can expect breaking changes whilst we've yet to get to v1.0. A sister create stm32f1xx-hal
has already merged a similar struct so there's bit of precedent now to use something like this.
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.
Your approach is more compact in terms of code, but you have to keep in mind the order of the arguments. With this structure, you have named entities that you can set in any order.
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.
Agreed on all counts, especially if there’s precedence already—more curiosity than anything else!
I was able to test these changes successfully with a simple keyboard example: dfrankland/proton-c@7e1d54e |
See also: stm32-rs/stm32-usbd#16