Skip to content
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

Avoid breaking changes when one hal is upgraded #14

Closed
TeXitoi opened this issue Sep 24, 2019 · 4 comments
Closed

Avoid breaking changes when one hal is upgraded #14

TeXitoi opened this issue Sep 24, 2019 · 4 comments

Comments

@TeXitoi
Copy link
Contributor

TeXitoi commented Sep 24, 2019

An idea for solving this problem. I had this idea reading atsamd-rs/atsamd#11 (comment)

A trait (or a set of trait) is present in a dedicated crate that expose the low level stm32 usb api of the hardware. Each hal provide a simple constructor that create a struct that implement this trait. Then, the stm32-usbd provide a constructor that take a type implementing the trait and do the hard stuffs.

Breaking changes in the hal is then transparent to stm32-usbd, it's only coupled with the crate describing the trait. This trait, as a trivial proxy of the hardware, should be stable (as the -sys crates).

I have no idea of the implementation of this crate, so I may tell something not doable, but in case it's working, I share the idea.

@Disasm
Copy link
Member

Disasm commented Sep 24, 2019

Thanks for pointing out!
I have a pretty similar idea with this "trait" crate, but it's not clear how to express peripheral features. For example, old USBFS peripherals in STM32s has multiple boolean and u32 features (expressed as feature flags in this crate). They can be implemented as associated constants, but what if I face with a new feature later, which is not present in the trait? Additionally, traits are not mutual exclusive, but peripheral types are. This can cause some problems. I believe this is doable, but I need to figure out the exact way.

@twitchyliquid64
Copy link

Make a new trait for each new version of the API?

EG: What embedded-hal did for digital pins (the V1 and V2 traits, with a conversion trait implemented on V2)

@Disasm
Copy link
Member

Disasm commented Nov 7, 2019

I came up with the following idea.
stm32-usbd provides a trait for peripheral, that provides an "enable and reset" method and pointers to the peripheral registers and endpoint memory. Each stm32 hal contains a struct with USB and PINS and implements this trait for the struct.
Turns out that with this construction endpoint memory access type is extremely difficult to pass around, so it's better to leave it as a crate feature.
@mvirkkunen, any thoughts?

@Disasm
Copy link
Member

Disasm commented Dec 18, 2019

I believe that I managed to solve this problem!

@Disasm Disasm closed this as completed Dec 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants