@@ -9,13 +9,13 @@ pub trait OutputPin {
9
9
///
10
10
/// *NOTE* the actual electrical state of the pin may not actually be low, e.g. due to external
11
11
/// electrical sources
12
- fn set_low ( & mut self ) -> Result < ( ) , Self :: Error > ;
12
+ fn try_set_low ( & mut self ) -> Result < ( ) , Self :: Error > ;
13
13
14
14
/// Drives the pin high
15
15
///
16
16
/// *NOTE* the actual electrical state of the pin may not actually be high, e.g. due to external
17
17
/// electrical sources
18
- fn set_high ( & mut self ) -> Result < ( ) , Self :: Error > ;
18
+ fn try_set_high ( & mut self ) -> Result < ( ) , Self :: Error > ;
19
19
}
20
20
21
21
/// Push-pull output pin that can read its output state
@@ -26,12 +26,12 @@ pub trait StatefulOutputPin: OutputPin {
26
26
/// Is the pin in drive high mode?
27
27
///
28
28
/// *NOTE* this does *not* read the electrical state of the pin
29
- fn is_set_high ( & self ) -> Result < bool , Self :: Error > ;
29
+ fn try_is_set_high ( & self ) -> Result < bool , Self :: Error > ;
30
30
31
31
/// Is the pin in drive low mode?
32
32
///
33
33
/// *NOTE* this does *not* read the electrical state of the pin
34
- fn is_set_low ( & self ) -> Result < bool , Self :: Error > ;
34
+ fn try_is_set_low ( & self ) -> Result < bool , Self :: Error > ;
35
35
}
36
36
37
37
/// Output pin that can be toggled
@@ -48,7 +48,7 @@ pub trait ToggleableOutputPin {
48
48
type Error ;
49
49
50
50
/// Toggle pin output.
51
- fn toggle ( & mut self ) -> Result < ( ) , Self :: Error > ;
51
+ fn try_toggle ( & mut self ) -> Result < ( ) , Self :: Error > ;
52
52
}
53
53
54
54
/// If you can read **and** write the output state, a pin is
@@ -57,7 +57,7 @@ pub trait ToggleableOutputPin {
57
57
/// ```
58
58
/// use embedded_hal::digital::{OutputPin, StatefulOutputPin, ToggleableOutputPin};
59
59
/// use embedded_hal::digital::toggleable;
60
- /// use std ::convert::Infallible;
60
+ /// use core ::convert::Infallible;
61
61
///
62
62
/// /// A virtual output pin that exists purely in software
63
63
/// struct MyPin {
@@ -67,21 +67,21 @@ pub trait ToggleableOutputPin {
67
67
/// impl OutputPin for MyPin {
68
68
/// type Error = Infallible;
69
69
///
70
- /// fn set_low (&mut self) -> Result<(), Self::Error> {
70
+ /// fn try_set_low (&mut self) -> Result<(), Self::Error> {
71
71
/// self.state = false;
72
72
/// Ok(())
73
73
/// }
74
- /// fn set_high (&mut self) -> Result<(), Self::Error> {
74
+ /// fn try_set_high (&mut self) -> Result<(), Self::Error> {
75
75
/// self.state = true;
76
76
/// Ok(())
77
77
/// }
78
78
/// }
79
79
///
80
80
/// impl StatefulOutputPin for MyPin {
81
- /// fn is_set_low (&self) -> Result<bool, Self::Error> {
81
+ /// fn try_is_set_low (&self) -> Result<bool, Self::Error> {
82
82
/// Ok(!self.state)
83
83
/// }
84
- /// fn is_set_high (&self) -> Result<bool, Self::Error> {
84
+ /// fn try_is_set_high (&self) -> Result<bool, Self::Error> {
85
85
/// Ok(self.state)
86
86
/// }
87
87
/// }
@@ -90,10 +90,10 @@ pub trait ToggleableOutputPin {
90
90
/// impl toggleable::Default for MyPin {}
91
91
///
92
92
/// let mut pin = MyPin { state: false };
93
- /// pin.toggle ().unwrap();
94
- /// assert!(pin.is_set_high ().unwrap());
95
- /// pin.toggle ().unwrap();
96
- /// assert!(pin.is_set_low ().unwrap());
93
+ /// pin.try_toggle ().unwrap();
94
+ /// assert!(pin.try_is_set_high ().unwrap());
95
+ /// pin.try_toggle ().unwrap();
96
+ /// assert!(pin.try_is_set_low ().unwrap());
97
97
/// ```
98
98
#[ cfg( feature = "unproven" ) ]
99
99
pub mod toggleable {
@@ -111,11 +111,11 @@ pub mod toggleable {
111
111
type Error = P :: Error ;
112
112
113
113
/// Toggle pin output
114
- fn toggle ( & mut self ) -> Result < ( ) , Self :: Error > {
115
- if self . is_set_low ( ) ? {
116
- self . set_high ( )
114
+ fn try_toggle ( & mut self ) -> Result < ( ) , Self :: Error > {
115
+ if self . try_is_set_low ( ) ? {
116
+ self . try_set_high ( )
117
117
} else {
118
- self . set_low ( )
118
+ self . try_set_low ( )
119
119
}
120
120
}
121
121
}
@@ -127,8 +127,8 @@ pub trait InputPin {
127
127
type Error ;
128
128
129
129
/// Is the input pin high?
130
- fn is_high ( & self ) -> Result < bool , Self :: Error > ;
130
+ fn try_is_high ( & self ) -> Result < bool , Self :: Error > ;
131
131
132
132
/// Is the input pin low?
133
- fn is_low ( & self ) -> Result < bool , Self :: Error > ;
133
+ fn try_is_low ( & self ) -> Result < bool , Self :: Error > ;
134
134
}
0 commit comments