Skip to content

Commit e12003f

Browse files
committed
Add more content
1 parent b7c75f6 commit e12003f

File tree

1 file changed

+54
-3
lines changed

1 file changed

+54
-3
lines changed

MIGRATING-0.2-1.0.md

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- [Method renaming](#method-renaming)
1010
- [`nb` dependency](#nb-dependency)
1111
- [Prelude](#prelude)
12+
- [`rng` module](#rng-module)
1213
- [Features](#features)
1314
- [Use-case-specific help](#use-case-specific-help)
1415
- [For driver authors](#for-driver-authors)
@@ -26,10 +27,54 @@ non-blocking. In the future when we add asynchronous traits, we envision adding
2627
All trait methods are now fallible so that they can be used in any possible situation.
2728
However, HAL implementations can also provide infallible versions of the methods.
2829

30+
For example, an implementation similar to the one below would allow to use the GPIO pins as `OutputPin`s
31+
in any generic driver or implementation-agnostic code (by importing the `OutputPin` trait),
32+
as well as using the infallible methods in non-generic code, thus avoiding the need to use `unwrap()`
33+
the results in many cases and resulting in more succinct code.
34+
35+
It should be noted that given this implementation, importing the `OutputPin` trait can result in
36+
ambiguous calls, so please remove the trait imports if you do not need them.
37+
38+
```rust
39+
use core::convert::Infallible;
40+
use embedded_hal::blocking::digital::OutputPin;
41+
42+
struct GpioPin;
43+
44+
impl OutputPin for GpioPin {
45+
type Error = Infallible;
46+
47+
fn set_high(&mut self) -> Result<(), Self::Error> {
48+
// ...
49+
Ok(())
50+
}
51+
52+
fn set_low(&mut self) -> Result<(), Self::Error> {
53+
// ...
54+
Ok(())
55+
}
56+
}
57+
58+
impl GpioPin {
59+
fn set_high(&mut self) {
60+
// ...
61+
}
62+
63+
fn set_low(&mut self) {
64+
// ...
65+
}
66+
}
67+
```
68+
2969
## Method renaming
3070

3171
The methods in `SPI`, `I2C` and `Serial` traits for both `blocking` and `nb` execution models have been renamed
32-
to `write()`, `read()` and `flush()`.
72+
to `write()`, `read()` and `flush()` for consistency.
73+
74+
In order to avoid method call ambiguity, only the traits from the corresponding execution model should be imported
75+
into the relevant scope. This is the reason why we have removed the prelude.
76+
77+
For more on this, see [Prelude](#prelude).
3378

3479
## `nb` dependency
3580

@@ -65,15 +110,21 @@ from the compiler should already tell you how it should look like in your case)
65110
to limit the scope of the trait imports and thus avoid ambiguity.
66111
Please note that it is also possible to import traits *inside a function*.
67112

113+
## `rng` module
114+
115+
The `rng` module and its traits have been removed in favor of the [`rand_core`] traits.
116+
117+
[`rand_core`]: https://crates.io/crates/rand_core
118+
68119
## Features
69120

70121
The `unproven` feature has been removed and the traits have been marked as proven.
71-
In the past, managing unproven features, and having "sort of breaking" changes have been a struggling point.
122+
In the past, managing unproven features, and having "sort of breaking" changes has been a struggling point.
72123
Also, people tended to adopt `unproven` features quickly, but the features would take a very
73124
long time to stabilize.
74125

75126
Instead, we would like to push experimentation OUT of the `embedded-hal` crate, allowing people to
76-
experiment externally, and merge when some kind of feasability had been proven.
127+
experiment externally, and merge when some kind of feasibility had been proven.
77128

78129
## Use-case-specific help
79130

0 commit comments

Comments
 (0)