File tree Expand file tree Collapse file tree 12 files changed +165
-37
lines changed Expand file tree Collapse file tree 12 files changed +165
-37
lines changed Original file line number Diff line number Diff line change 2
2
3
3
## Unreleased
4
4
5
- (no changes)
5
+ ### Changed
6
+
7
+ - Unified how pins are are returned in `free` calls
6
8
7
9
## [0.14.1]
8
10
Original file line number Diff line number Diff line change @@ -748,8 +748,42 @@ where
748
748
}
749
749
750
750
/// Consumes `self` and returns back the raw peripheral.
751
- pub fn free(self) -> T {
752
- self.pwm
751
+ pub fn free(
752
+ self,
753
+ ) -> (
754
+ T,
755
+ Option<Pin<Output<PushPull>>>,
756
+ Option<Pin<Output<PushPull>>>,
757
+ Option<Pin<Output<PushPull>>>,
758
+ Option<Pin<Output<PushPull>>>,
759
+ ) {
760
+ let ch0 = self.pwm.psel.out[0].read();
761
+ let ch1 = self.pwm.psel.out[1].read();
762
+ let ch2 = self.pwm.psel.out[2].read();
763
+ let ch3 = self.pwm.psel.out[3].read();
764
+ (
765
+ self.pwm,
766
+ if ch0.connect().bit_is_set() {
767
+ Some(unsafe { Pin::from_psel_bits(ch0.bits()) })
768
+ } else {
769
+ None
770
+ },
771
+ if ch1.connect().bit_is_set() {
772
+ Some(unsafe { Pin::from_psel_bits(ch1.bits()) })
773
+ } else {
774
+ None
775
+ },
776
+ if ch2.connect().bit_is_set() {
777
+ Some(unsafe { Pin::from_psel_bits(ch2.bits()) })
778
+ } else {
779
+ None
780
+ },
781
+ if ch3.connect().bit_is_set() {
782
+ Some(unsafe { Pin::from_psel_bits(ch3.bits()) })
783
+ } else {
784
+ None
785
+ },
786
+ )
753
787
}
754
788
}
755
789
Original file line number Diff line number Diff line change 11
11
/// A safe wrapper around the `QDEC` peripheral with associated pins.
12
12
pub struct Qdec {
13
13
qdec: QDEC,
14
- pin_a: Pin<Input<PullUp>>,
15
- pin_b: Pin<Input<PullUp>>,
16
- pin_led: Option<Pin<Input<PullUp>>>,
17
14
}
18
15
19
16
impl Qdec {
@@ -55,12 +52,7 @@ impl Qdec {
55
52
SamplePeriod::_131ms => qdec.sampleper.write(|w| w.sampleper()._131ms()),
56
53
}
57
54
58
- Self {
59
- qdec,
60
- pin_a,
61
- pin_b,
62
- pin_led,
63
- }
55
+ Self { qdec }
64
56
}
65
57
66
58
/// Enables/disables input debounce filters.
@@ -155,7 +147,18 @@ impl Qdec {
155
147
Pin<Input<PullUp>>,
156
148
Option<Pin<Input<PullUp>>>,
157
149
) {
158
- (self.qdec, self.pin_a, self.pin_b, self.pin_led)
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 = {
153
+ let led = self.qdec.psel.led.read();
154
+ if led.connect().bit_is_set() {
155
+ Some(unsafe { Pin::from_psel_bits(led.bits()) })
156
+ } else {
157
+ None
158
+ }
159
+ };
160
+
161
+ (self.qdec, pin_a, pin_b, pin_led)
159
162
}
160
163
}
161
164
Original file line number Diff line number Diff line change @@ -97,12 +97,23 @@ where
97
97
.write(|w| unsafe { w.bits(pins.sck.pin().into()) });
98
98
99
99
// Optional pins.
100
- if let Some(ref pin) = pins.mosi {
101
- spi.pselmosi.write(|w| unsafe { w.bits(pin.pin().into()) });
102
- }
103
- if let Some(ref pin) = pins.miso {
104
- spi.pselmiso.write(|w| unsafe { w.bits(pin.pin().into()) });
105
- }
100
+ spi.pselmosi.write(|w| unsafe {
101
+ if let Some(ref pin) = pins.mosi {
102
+ w.bits(pin.pin().into())
103
+ } else {
104
+ // Disconnect
105
+ w.bits(0xFFFFFFFF)
106
+ }
107
+ });
108
+
109
+ spi.pselmiso.write(|w| unsafe {
110
+ if let Some(ref pin) = pins.miso {
111
+ w.bits(pin.pin().into())
112
+ } else {
113
+ // Disconnect
114
+ w.bits(0xFFFFFFFF)
115
+ }
116
+ });
106
117
}
107
118
108
119
#[cfg(not(feature = "51"))]
Original file line number Diff line number Diff line change @@ -358,8 +358,26 @@ where
358
358
}
359
359
360
360
/// Return the raw interface to the underlying SPIM peripheral.
361
- pub fn free(self) -> T {
362
- self.0
361
+ pub fn free(self) -> (T, Pins) {
362
+ let sck = self.0.psel.sck.read();
363
+ let mosi = self.0.psel.mosi.read();
364
+ let miso = self.0.psel.miso.read();
365
+ (
366
+ self.0,
367
+ Pins {
368
+ sck: unsafe { Pin::from_psel_bits(sck.bits()) },
369
+ mosi: if mosi.connect().bit_is_set() {
370
+ Some(unsafe { Pin::from_psel_bits(mosi.bits()) })
371
+ } else {
372
+ None
373
+ },
374
+ miso: if miso.connect().bit_is_set() {
375
+ Some(unsafe { Pin::from_psel_bits(miso.bits()) })
376
+ } else {
377
+ None
378
+ },
379
+ },
380
+ )
363
381
}
364
382
}
365
383
Original file line number Diff line number Diff line change @@ -37,7 +37,6 @@ use embedded_dma::*;
37
37
/// Interface to a SPIS instance.
38
38
pub struct Spis<T: Instance> {
39
39
spis: T,
40
- pins: Pins,
41
40
}
42
41
43
42
impl<T> Spis<T>
75
74
spis.config
76
75
.modify(|_r, w| w.cpha().bit(Phase::Trailing.into()));
77
76
spis.enable.write(|w| w.enable().enabled());
78
- Self { spis, pins }
77
+ Self { spis }
79
78
}
80
79
81
80
/// Sets the ´default´ character (character clocked out in case of an ignored transaction).
@@ -406,7 +405,27 @@ where
406
405
407
406
/// Returns the raw interface to the underlying SPIS peripheral.
408
407
pub fn free(self) -> (T, Pins) {
409
- (self.spis, self.pins)
408
+ let sck = self.spis.psel.sck.read();
409
+ let cs = self.spis.psel.csn.read();
410
+ let copi = self.spis.psel.mosi.read();
411
+ let cipo = self.spis.psel.miso.read();
412
+ (
413
+ self.spis,
414
+ Pins {
415
+ sck: unsafe { Pin::from_psel_bits(sck.bits()) },
416
+ cs: unsafe { Pin::from_psel_bits(cs.bits()) },
417
+ copi: if copi.connect().bit_is_set() {
418
+ Some(unsafe { Pin::from_psel_bits(copi.bits()) })
419
+ } else {
420
+ None
421
+ },
422
+ cipo: if cipo.connect().bit_is_set() {
423
+ Some(unsafe { Pin::from_psel_bits(cipo.bits()) })
424
+ } else {
425
+ None
426
+ },
427
+ },
428
+ )
410
429
}
411
430
}
412
431
Original file line number Diff line number Diff line change @@ -235,8 +235,16 @@ where
235
235
}
236
236
237
237
/// Return the raw interface to the underlying TWI peripheral.
238
- pub fn free(self) -> T {
239
- self.0
238
+ pub fn free(self) -> (T, Pins) {
239
+ let scl = self.0.pselscl.read();
240
+ let sda = self.0.pselsda.read();
241
+ (
242
+ self.0,
243
+ Pins {
244
+ scl: unsafe { Pin::from_psel_bits(scl.bits()) },
245
+ sda: unsafe { Pin::from_psel_bits(sda.bits()) },
246
+ },
247
+ )
240
248
}
241
249
}
242
250
Original file line number Diff line number Diff line change @@ -378,8 +378,16 @@ where
378
378
}
379
379
380
380
/// Return the raw interface to the underlying TWIM peripheral.
381
- pub fn free(self) -> T {
382
- self.0
381
+ pub fn free(self) -> (T, Pins) {
382
+ let scl = self.0.psel.scl.read();
383
+ let sda = self.0.psel.sda.read();
384
+ (
385
+ self.0,
386
+ Pins {
387
+ scl: unsafe { Pin::from_psel_bits(scl.bits()) },
388
+ sda: unsafe { Pin::from_psel_bits(sda.bits()) },
389
+ },
390
+ )
383
391
}
384
392
}
385
393
Original file line number Diff line number Diff line change @@ -450,8 +450,16 @@ where
450
450
}
451
451
452
452
/// Return the raw interface to the underlying TWIS peripheral.
453
- pub fn free(self) -> T {
454
- self.0
453
+ pub fn free(self) -> (T, Pins) {
454
+ let scl = self.0.psel.scl.read();
455
+ let sda = self.0.psel.sda.read();
456
+ (
457
+ self.0,
458
+ Pins {
459
+ scl: unsafe { Pin::from_psel_bits(scl.bits()) },
460
+ sda: unsafe { Pin::from_psel_bits(sda.bits()) },
461
+ },
462
+ )
455
463
}
456
464
}
457
465
Original file line number Diff line number Diff line change 70
70
}
71
71
72
72
/// Return the raw interface to the underlying UARTE peripheral.
73
- pub fn free(self) -> T {
74
- self.0
73
+ pub fn free(self) -> (T, Pins) {
74
+ let rxd = self.0.pselrxd.read();
75
+ let txd = self.0.pseltxd.read();
76
+ let cts = self.0.pselcts.read();
77
+ let rts = self.0.pselrts.read();
78
+ (
79
+ self.0,
80
+ Pins {
81
+ rxd: unsafe { Pin::from_psel_bits(rxd.bits()) },
82
+ txd: unsafe { Pin::from_psel_bits(txd.bits()) },
83
+ cts: if cts.bits() != 0xFFFFFFFF {
84
+ Some(unsafe { Pin::from_psel_bits(cts.bits()) })
85
+ } else {
86
+ None
87
+ },
88
+ rts: if rts.bits() != 0xFFFFFFFF {
89
+ Some(unsafe { Pin::from_psel_bits(rts.bits()) })
90
+ } else {
91
+ None
92
+ },
93
+ },
94
+ )
75
95
}
76
96
}
77
97
You can’t perform that action at this time.
0 commit comments