9
9
- [ Method renaming] ( #method-renaming )
10
10
- [ ` nb ` dependency] ( #nb-dependency )
11
11
- [ Prelude] ( #prelude )
12
+ - [ ` rng ` module] ( #rng-module )
12
13
- [ Features] ( #features )
13
14
- [ Use-case-specific help] ( #use-case-specific-help )
14
15
- [ For driver authors] ( #for-driver-authors )
@@ -26,10 +27,54 @@ non-blocking. In the future when we add asynchronous traits, we envision adding
26
27
All trait methods are now fallible so that they can be used in any possible situation.
27
28
However, HAL implementations can also provide infallible versions of the methods.
28
29
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
+
29
69
## Method renaming
30
70
31
71
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 ) .
33
78
34
79
## ` nb ` dependency
35
80
@@ -65,15 +110,21 @@ from the compiler should already tell you how it should look like in your case)
65
110
to limit the scope of the trait imports and thus avoid ambiguity.
66
111
Please note that it is also possible to import traits * inside a function* .
67
112
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
+
68
119
## Features
69
120
70
121
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.
72
123
Also, people tended to adopt ` unproven ` features quickly, but the features would take a very
73
124
long time to stabilize.
74
125
75
126
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.
77
128
78
129
## Use-case-specific help
79
130
0 commit comments