|
1 | 1 | //! Digital I/O
|
2 | 2 | //!
|
3 |
| -//! The traits in this module are now deprecated. Please use the new versions included |
4 |
| -//! in `digital::v2`. |
5 |
| -
|
6 |
| -/// Single digital push-pull output pin |
7 |
| -/// |
8 |
| -/// *This version of the trait is now deprecated. Please use the new `OutputPin` trait in |
9 |
| -/// `digital::v2::OutputPin`*. |
10 |
| -#[deprecated(since = "0.2.2", note = "Deprecated because the methods cannot return errors. \ |
11 |
| - Users should use the traits in digital::v2.")] |
12 |
| -pub trait OutputPin { |
13 |
| - /// Drives the pin low |
14 |
| - /// |
15 |
| - /// *NOTE* the actual electrical state of the pin may not actually be low, e.g. due to external |
16 |
| - /// electrical sources |
17 |
| - fn set_low(&mut self); |
18 |
| - |
19 |
| - /// Drives the pin high |
20 |
| - /// |
21 |
| - /// *NOTE* the actual electrical state of the pin may not actually be high, e.g. due to external |
22 |
| - /// electrical sources |
23 |
| - fn set_high(&mut self); |
24 |
| -} |
25 |
| - |
26 |
| -/// Push-pull output pin that can read its output state |
27 |
| -/// |
28 |
| -/// *This trait is available if embedded-hal is built with the `"unproven"` feature.* |
29 |
| -/// |
30 |
| -/// *This version of the trait is now deprecated. Please use the new `StatefulOutputPin` trait in |
31 |
| -/// `digital::v2::StatefulOutputPin`*. |
32 |
| -#[deprecated(since = "0.2.2", note = "Deprecated because the methods cannot return errors. \ |
33 |
| - Users should use the traits in digital::v2.")] |
34 |
| -#[cfg(feature = "unproven")] |
35 |
| -pub trait StatefulOutputPin { |
36 |
| - /// Is the pin in drive high mode? |
37 |
| - /// |
38 |
| - /// *NOTE* this does *not* read the electrical state of the pin |
39 |
| - fn is_set_high(&self) -> bool; |
40 |
| - |
41 |
| - /// Is the pin in drive low mode? |
42 |
| - /// |
43 |
| - /// *NOTE* this does *not* read the electrical state of the pin |
44 |
| - fn is_set_low(&self) -> bool; |
45 |
| -} |
46 |
| - |
47 |
| -/// Output pin that can be toggled |
48 |
| -/// |
49 |
| -/// *This trait is available if embedded-hal is built with the `"unproven"` feature.* |
50 |
| -/// |
51 |
| -/// *This version of the trait is now deprecated. Please use the new `ToggleableOutputPin` |
52 |
| -/// trait in `digital::v2::ToggleableOutputPin`*. |
53 |
| -/// |
54 |
| -/// See [toggleable](toggleable) to use a software implementation if |
55 |
| -/// both [OutputPin](trait.OutputPin.html) and |
56 |
| -/// [StatefulOutputPin](trait.StatefulOutputPin.html) are |
57 |
| -/// implemented. Otherwise, implement this using hardware mechanisms. |
58 |
| -#[deprecated(since = "0.2.2", note = "Deprecated because the methods cannot return errors. \ |
59 |
| - Users should use the traits in digital::v2.")] |
60 |
| -#[cfg(feature = "unproven")] |
61 |
| -pub trait ToggleableOutputPin { |
62 |
| - /// Toggle pin output. |
63 |
| - fn toggle(&mut self); |
64 |
| -} |
| 3 | +//! |
| 4 | +//! |
65 | 5 |
|
66 |
| -/// If you can read **and** write the output state, a pin is |
67 |
| -/// toggleable by software. |
68 |
| -/// |
69 |
| -/// *This version of the module is now deprecated. Please use the new `toggleable` module in |
70 |
| -/// `digital::v2::toggleable`*. |
71 |
| -/// |
72 |
| -/// ``` |
73 |
| -/// use embedded_hal::digital::{OutputPin, StatefulOutputPin, ToggleableOutputPin}; |
74 |
| -/// use embedded_hal::digital::toggleable; |
75 |
| -/// |
76 |
| -/// /// A virtual output pin that exists purely in software |
77 |
| -/// struct MyPin { |
78 |
| -/// state: bool |
79 |
| -/// } |
80 |
| -/// |
81 |
| -/// impl OutputPin for MyPin { |
82 |
| -/// fn set_low(&mut self) { |
83 |
| -/// self.state = false; |
84 |
| -/// } |
85 |
| -/// fn set_high(&mut self) { |
86 |
| -/// self.state = true; |
87 |
| -/// } |
88 |
| -/// } |
89 |
| -/// |
90 |
| -/// impl StatefulOutputPin for MyPin { |
91 |
| -/// fn is_set_low(&self) -> bool { |
92 |
| -/// !self.state |
93 |
| -/// } |
94 |
| -/// fn is_set_high(&self) -> bool { |
95 |
| -/// self.state |
96 |
| -/// } |
97 |
| -/// } |
98 |
| -/// |
99 |
| -/// /// Opt-in to the software implementation. |
100 |
| -/// impl toggleable::Default for MyPin {} |
101 |
| -/// |
102 |
| -/// let mut pin = MyPin { state: false }; |
103 |
| -/// pin.toggle(); |
104 |
| -/// assert!(pin.is_set_high()); |
105 |
| -/// pin.toggle(); |
106 |
| -/// assert!(pin.is_set_low()); |
107 |
| -/// ``` |
| 6 | +// Deprecated / infallible traits |
108 | 7 | #[deprecated(since = "0.2.2", note = "Deprecated because the methods cannot return errors. \
|
109 | 8 | Users should use the traits in digital::v2.")]
|
110 |
| -#[cfg(feature = "unproven")] |
111 |
| -pub mod toggleable { |
112 |
| - #[allow(deprecated)] |
113 |
| - use super::{OutputPin, StatefulOutputPin, ToggleableOutputPin}; |
| 9 | +pub mod v1; |
114 | 10 |
|
115 |
| - /// Software-driven `toggle()` implementation. |
116 |
| - /// |
117 |
| - /// *This trait is available if embedded-hal is built with the `"unproven"` feature.* |
118 |
| - #[allow(deprecated)] |
119 |
| - pub trait Default: OutputPin + StatefulOutputPin {} |
| 11 | +// New / fallible traits |
| 12 | +pub mod v2; |
120 | 13 |
|
121 |
| - #[allow(deprecated)] |
122 |
| - impl<P> ToggleableOutputPin for P |
123 |
| - where |
124 |
| - P: Default, |
125 |
| - { |
126 |
| - /// Toggle pin output |
127 |
| - fn toggle(&mut self) { |
128 |
| - if self.is_set_low() { |
129 |
| - self.set_high(); |
130 |
| - } else { |
131 |
| - self.set_low(); |
132 |
| - } |
133 |
| - } |
134 |
| - } |
135 |
| -} |
| 14 | +// v2 -> v1 compatibility wrappers |
| 15 | +// These require explicit casts from v2 -> v1 |
| 16 | +pub mod v1_compat; |
136 | 17 |
|
137 |
| -/// Single digital input pin |
138 |
| -/// |
139 |
| -/// *This trait is available if embedded-hal is built with the `"unproven"` feature.* |
140 |
| -/// |
141 |
| -/// *This version of the trait is now deprecated. Please use the new `InputPin` trait in |
142 |
| -/// `digital::v2::InputPin`*. |
143 |
| -#[deprecated(since = "0.2.2", note = "Deprecated because the methods cannot return errors. \ |
144 |
| - Users should use the traits in digital::v2.")] |
145 |
| -#[cfg(feature = "unproven")] |
146 |
| -pub trait InputPin { |
147 |
| - /// Is the input pin high? |
148 |
| - fn is_high(&self) -> bool; |
| 18 | +// v1 -> v2 compatibility shims |
| 19 | +// These are implicit over v1 implementations |
| 20 | +pub mod v2_compat; |
149 | 21 |
|
150 |
| - /// Is the input pin low? |
151 |
| - fn is_low(&self) -> bool; |
152 |
| -} |
| 22 | +// Re-export old traits so this isn't a breaking change |
| 23 | +#[allow(deprecated)] |
| 24 | +pub use self::v1::*; |
153 | 25 |
|
154 |
| -/// Improved version of the digital traits where the methods can also return an error. |
155 |
| -pub mod v2; |
0 commit comments