@@ -15,23 +15,17 @@ pub struct Qdec {
1515
1616impl Qdec {
1717 /// 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 {
2519 qdec. psel . a . write ( |w| {
26- unsafe { w. bits ( pin_a . psel_bits ( ) ) } ;
20+ unsafe { w. bits ( pins . a . psel_bits ( ) ) } ;
2721 w. connect ( ) . connected ( )
2822 } ) ;
2923 qdec. psel . b . write ( |w| {
30- unsafe { w. bits ( pin_b . psel_bits ( ) ) } ;
24+ unsafe { w. bits ( pins . b . psel_bits ( ) ) } ;
3125 w. connect ( ) . connected ( )
3226 } ) ;
3327
34- if let Some ( p) = & pin_led {
28+ if let Some ( p) = & pins . led {
3529 qdec. psel . led . write ( |w| {
3630 unsafe { w. bits ( p. psel_bits ( ) ) } ;
3731 w. connect ( ) . connected ( )
@@ -139,17 +133,10 @@ impl Qdec {
139133
140134 /// Consumes `self` and returns back the raw `QDEC` peripheral.
141135 #[ 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 = {
153140 let led = self . qdec . psel . led . read ( ) ;
154141 if led. connect ( ) . bit_is_set ( ) {
155142 Some ( unsafe { Pin :: from_psel_bits ( led. bits ( ) ) } )
@@ -161,10 +148,17 @@ impl Qdec {
161148 self . qdec . psel . b . reset ( ) ;
162149 self . qdec . psel . led . reset ( ) ;
163150
164- ( self . qdec , pin_a , pin_b , pin_led )
151+ ( self . qdec , Pins { a , b , led } )
165152 }
166153}
167154
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+
168162#[ derive( Debug , Eq , PartialEq , Clone , Copy ) ]
169163pub enum SamplePeriod {
170164 _128us,
0 commit comments