Skip to content

Commit e835410

Browse files
bors[bot]eldruin
andauthored
Merge #276
276: Add documentation on how to support an alpha version side-by-side in a HAL impl r=therealprof a=eldruin Credit goes to @hannobraun. Thank you! See [here](https://github.com/flott-motion/stepper/blob/main/documentation/platform-support.md#embedded-hal-alpha) Co-authored-by: Diego Barrios Romero <eldruin@gmail.com>
2 parents 6944a97 + 9f0e938 commit e835410

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ They are provided as early previews for community testing and preparation for th
1717
If you use an alpha release, we recommend you choose an exact version specification in your
1818
`Cargo.toml` like: `embedded-hal = "=1.0.0-alpha.2"`
1919

20+
See below for a way to implement both an `embedded-hal` `0.2.x` version and an `-alpha` version
21+
side by side in a HAL.
22+
2023
[#177]: https://github.com/rust-embedded/embedded-hal/issues/177
2124

2225
## How-to: add a new trait
@@ -54,6 +57,29 @@ list.
5457

5558
[awesome-embedded-rust]: https://github.com/rust-embedded/awesome-embedded-rust#driver-crates
5659

60+
### Adding support for an `embedded-hal` `-alpha` version in a HAL implementation
61+
62+
It is possible for HAL implementations to support both the latest `0.2.x` version of `embedded-hal`
63+
as well as the latest `1.0.0-alpha` version side by side. This has several big advantadges:
64+
- Allows for a more gradual upgrade process within the community.
65+
- Allows for a faster upgrade to `1.0` once it comes out.
66+
- Provides more oportunities to test the new `embedded-hal` version.
67+
68+
This approach has been implemented in [LPC8xx HAL](https://github.com/lpc-rs/lpc8xx-hal). Here are the steps:
69+
70+
1. Add a dependency to the latest `embedded-hal` version to `Cargo.toml`.
71+
Use the `package` attribute to refer to it by another name, to prevent name collision
72+
([example](https://github.com/lpc-rs/lpc8xx-hal/blob/a2b774e8a9ef025fb5119ddfb09e1b190e510896/Cargo.toml#L44-L46)).
73+
2. Import the traits into the module where they should be implemented.
74+
Change their name using `as` to prevent name collisions
75+
([example](https://github.com/lpc-rs/lpc8xx-hal/blob/a2b774e8a9ef025fb5119ddfb09e1b190e510896/src/gpio.rs#L49-L53)).
76+
3. Implement the traits next to their non-alpha versions
77+
([example](https://github.com/lpc-rs/lpc8xx-hal/blob/a2b774e8a9ef025fb5119ddfb09e1b190e510896/src/gpio.rs#L767-L782)).
78+
79+
While none of this is hard, some HAL maintainers might prefer not to add a dependency on an alpha version.
80+
The main drawback of this approach is that it requires ongoing updates, as new `embedded-hal` alpha versions come out.
81+
As stated before, `embedded-hal` `-alpha` versions are _not guaranteed_ to be compatible with each other.
82+
5783
## Minimum Supported Rust Version (MSRV)
5884

5985
This crate is guaranteed to compile on stable Rust 1.35 and up. It *might*

0 commit comments

Comments
 (0)