@@ -35,6 +35,47 @@ impl CdevPin {
35
35
}
36
36
return flags;
37
37
}
38
+
39
+ /// Set this pin to input mode
40
+ pub fn into_input_pin ( self ) -> Result < CdevPin , gpio_cdev:: errors:: Error > {
41
+ if self . 1 . direction ( ) == gpio_cdev:: LineDirection :: In {
42
+ return Ok ( self ) ;
43
+ }
44
+ let line = self . 0 . line ( ) . clone ( ) ;
45
+ let input_flags = self . get_input_flags ( ) ;
46
+ let consumer = self . 1 . consumer ( ) . unwrap_or ( "" ) . to_owned ( ) ;
47
+
48
+ // Drop self to free the line before re-requesting it in a new mode.
49
+ std:: mem:: drop ( self ) ;
50
+
51
+ CdevPin :: new ( line. request ( input_flags, 0 , & consumer) ?)
52
+ }
53
+
54
+ /// Set this pin to output mode
55
+ pub fn into_output_pin (
56
+ self ,
57
+ state : embedded_hal:: digital:: PinState ,
58
+ ) -> Result < CdevPin , gpio_cdev:: errors:: Error > {
59
+ if self . 1 . direction ( ) == gpio_cdev:: LineDirection :: Out {
60
+ return Ok ( self ) ;
61
+ }
62
+
63
+ let line = self . 0 . line ( ) . clone ( ) ;
64
+ let output_flags = self . get_output_flags ( ) ;
65
+ let consumer = self . 1 . consumer ( ) . unwrap_or ( "" ) . to_owned ( ) ;
66
+
67
+ // Drop self to free the line before re-requesting it in a new mode.
68
+ std:: mem:: drop ( self ) ;
69
+
70
+ CdevPin :: new ( line. request (
71
+ output_flags,
72
+ state_to_value (
73
+ state,
74
+ output_flags. intersects ( gpio_cdev:: LineRequestFlags :: ACTIVE_LOW ) ,
75
+ ) ,
76
+ & consumer,
77
+ ) ?)
78
+ }
38
79
}
39
80
40
81
/// Converts a pin state to the gpio_cdev compatible numeric value, accounting
@@ -57,7 +98,7 @@ impl embedded_hal::digital::ErrorType for CdevPin {
57
98
type Error = gpio_cdev:: errors:: Error ;
58
99
}
59
100
60
- impl embedded_hal:: digital:: blocking :: OutputPin for CdevPin {
101
+ impl embedded_hal:: digital:: OutputPin for CdevPin {
61
102
fn set_low ( & mut self ) -> Result < ( ) , Self :: Error > {
62
103
self . 0 . set_value ( state_to_value (
63
104
embedded_hal:: digital:: PinState :: Low ,
@@ -73,7 +114,7 @@ impl embedded_hal::digital::blocking::OutputPin for CdevPin {
73
114
}
74
115
}
75
116
76
- impl embedded_hal:: digital:: blocking :: InputPin for CdevPin {
117
+ impl embedded_hal:: digital:: InputPin for CdevPin {
77
118
fn is_high ( & self ) -> Result < bool , Self :: Error > {
78
119
self . 0 . get_value ( ) . map ( |val| {
79
120
val == state_to_value (
@@ -88,49 +129,6 @@ impl embedded_hal::digital::blocking::InputPin for CdevPin {
88
129
}
89
130
}
90
131
91
- impl embedded_hal:: digital:: blocking:: IoPin < CdevPin , CdevPin > for CdevPin {
92
- type Error = gpio_cdev:: errors:: Error ;
93
-
94
- fn into_input_pin ( self ) -> Result < CdevPin , Self :: Error > {
95
- if self . 1 . direction ( ) == gpio_cdev:: LineDirection :: In {
96
- return Ok ( self ) ;
97
- }
98
- let line = self . 0 . line ( ) . clone ( ) ;
99
- let input_flags = self . get_input_flags ( ) ;
100
- let consumer = self . 1 . consumer ( ) . unwrap_or ( "" ) . to_owned ( ) ;
101
-
102
- // Drop self to free the line before re-requesting it in a new mode.
103
- std:: mem:: drop ( self ) ;
104
-
105
- CdevPin :: new ( line. request ( input_flags, 0 , & consumer) ?)
106
- }
107
-
108
- fn into_output_pin (
109
- self ,
110
- state : embedded_hal:: digital:: PinState ,
111
- ) -> Result < CdevPin , Self :: Error > {
112
- if self . 1 . direction ( ) == gpio_cdev:: LineDirection :: Out {
113
- return Ok ( self ) ;
114
- }
115
-
116
- let line = self . 0 . line ( ) . clone ( ) ;
117
- let output_flags = self . get_output_flags ( ) ;
118
- let consumer = self . 1 . consumer ( ) . unwrap_or ( "" ) . to_owned ( ) ;
119
-
120
- // Drop self to free the line before re-requesting it in a new mode.
121
- std:: mem:: drop ( self ) ;
122
-
123
- CdevPin :: new ( line. request (
124
- output_flags,
125
- state_to_value (
126
- state,
127
- output_flags. intersects ( gpio_cdev:: LineRequestFlags :: ACTIVE_LOW ) ,
128
- ) ,
129
- & consumer,
130
- ) ?)
131
- }
132
- }
133
-
134
132
impl core:: ops:: Deref for CdevPin {
135
133
type Target = gpio_cdev:: LineHandle ;
136
134
0 commit comments