@@ -15,23 +15,17 @@ pub struct Qdec {
15
15
16
16
impl Qdec {
17
17
/// Takes ownership of the `QDEC` peripheral and associated pins, returning a safe wrapper.
18
- pub fn new (
19
- qdec : QDEC ,
20
- pin_a : Pin < Input < PullUp > > ,
21
- pin_b : Pin < Input < PullUp > > ,
22
- pin_led : Option < Pin < Input < PullUp > > > ,
23
- sample_period : SamplePeriod ,
24
- ) -> Self {
18
+ pub fn new ( qdec : QDEC , pins : Pins , sample_period : SamplePeriod ) -> Self {
25
19
qdec. psel . a . write ( |w| {
26
- unsafe { w. bits ( pin_a . psel_bits ( ) ) } ;
20
+ unsafe { w. bits ( pins . a . psel_bits ( ) ) } ;
27
21
w. connect ( ) . connected ( )
28
22
} ) ;
29
23
qdec. psel . b . write ( |w| {
30
- unsafe { w. bits ( pin_b . psel_bits ( ) ) } ;
24
+ unsafe { w. bits ( pins . b . psel_bits ( ) ) } ;
31
25
w. connect ( ) . connected ( )
32
26
} ) ;
33
27
34
- if let Some ( p) = & pin_led {
28
+ if let Some ( p) = & pins . led {
35
29
qdec. psel . led . write ( |w| {
36
30
unsafe { w. bits ( p. psel_bits ( ) ) } ;
37
31
w. connect ( ) . connected ( )
@@ -139,17 +133,10 @@ impl Qdec {
139
133
140
134
/// Consumes `self` and returns back the raw `QDEC` peripheral.
141
135
#[ inline]
142
- pub fn free (
143
- self ,
144
- ) -> (
145
- QDEC ,
146
- Pin < Input < PullUp > > ,
147
- Pin < Input < PullUp > > ,
148
- Option < Pin < Input < PullUp > > > ,
149
- ) {
150
- let pin_a = unsafe { Pin :: from_psel_bits ( self . qdec . psel . a . read ( ) . bits ( ) ) } ;
151
- let pin_b = unsafe { Pin :: from_psel_bits ( self . qdec . psel . b . read ( ) . bits ( ) ) } ;
152
- let pin_led = {
136
+ pub fn free ( self ) -> ( QDEC , Pins ) {
137
+ let a = unsafe { Pin :: from_psel_bits ( self . qdec . psel . a . read ( ) . bits ( ) ) } ;
138
+ let b = unsafe { Pin :: from_psel_bits ( self . qdec . psel . b . read ( ) . bits ( ) ) } ;
139
+ let led = {
153
140
let led = self . qdec . psel . led . read ( ) ;
154
141
if led. connect ( ) . bit_is_set ( ) {
155
142
Some ( unsafe { Pin :: from_psel_bits ( led. bits ( ) ) } )
@@ -161,10 +148,17 @@ impl Qdec {
161
148
self . qdec . psel . b . reset ( ) ;
162
149
self . qdec . psel . led . reset ( ) ;
163
150
164
- ( self . qdec , pin_a , pin_b , pin_led )
151
+ ( self . qdec , Pins { a , b , led } )
165
152
}
166
153
}
167
154
155
+ /// Pins for the QDEC
156
+ pub struct Pins {
157
+ pub a : Pin < Input < PullUp > > ,
158
+ pub b : Pin < Input < PullUp > > ,
159
+ pub led : Option < Pin < Input < PullUp > > > ,
160
+ }
161
+
168
162
#[ derive( Debug , Eq , PartialEq , Clone , Copy ) ]
169
163
pub enum SamplePeriod {
170
164
_128us,
0 commit comments