Skip to content

Commit 902650b

Browse files
committed
PWM refactor and added Pins
1 parent 8e55631 commit 902650b

File tree

1 file changed

+34
-28
lines changed

1 file changed

+34
-28
lines changed

nrf-hal-common/src/pwm.rs

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -748,15 +748,7 @@ where
748748
}
749749

750750
/// Consumes `self` and returns back the raw peripheral.
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-
) {
751+
pub fn free(self) -> (T, Pins) {
760752
let ch0 = self.pwm.psel.out[0].read();
761753
let ch1 = self.pwm.psel.out[1].read();
762754
let ch2 = self.pwm.psel.out[2].read();
@@ -767,30 +759,44 @@ where
767759
self.pwm.psel.out[3].reset();
768760
(
769761
self.pwm,
770-
if ch0.connect().bit_is_set() {
771-
Some(unsafe { Pin::from_psel_bits(ch0.bits()) })
772-
} else {
773-
None
774-
},
775-
if ch1.connect().bit_is_set() {
776-
Some(unsafe { Pin::from_psel_bits(ch1.bits()) })
777-
} else {
778-
None
779-
},
780-
if ch2.connect().bit_is_set() {
781-
Some(unsafe { Pin::from_psel_bits(ch2.bits()) })
782-
} else {
783-
None
784-
},
785-
if ch3.connect().bit_is_set() {
786-
Some(unsafe { Pin::from_psel_bits(ch3.bits()) })
787-
} else {
788-
None
762+
Pins {
763+
ch0: if ch0.connect().bit_is_set() {
764+
Some(unsafe { Pin::from_psel_bits(ch0.bits()) })
765+
} else {
766+
None
767+
},
768+
ch1: if ch1.connect().bit_is_set() {
769+
Some(unsafe { Pin::from_psel_bits(ch1.bits()) })
770+
} else {
771+
None
772+
},
773+
ch2: if ch2.connect().bit_is_set() {
774+
Some(unsafe { Pin::from_psel_bits(ch2.bits()) })
775+
} else {
776+
None
777+
},
778+
ch3: if ch3.connect().bit_is_set() {
779+
Some(unsafe { Pin::from_psel_bits(ch3.bits()) })
780+
} else {
781+
None
782+
},
789783
},
790784
)
791785
}
792786
}
793787

788+
/// Pins for the Pwm
789+
pub struct Pins {
790+
/// Channel 0 pin, `None` if it was unused
791+
pub ch0: Option<Pin<Output<PushPull>>>,
792+
/// Channel 1 pin, `None` if it was unused
793+
pub ch1: Option<Pin<Output<PushPull>>>,
794+
/// Channel 2 pin, `None` if it was unused
795+
pub ch2: Option<Pin<Output<PushPull>>>,
796+
/// Channel 3 pin, `None` if it was unused
797+
pub ch3: Option<Pin<Output<PushPull>>>,
798+
}
799+
794800
/// A Pwm sequence wrapper
795801
#[derive(Debug)]
796802
pub struct PwmSeq<T: Instance, B0, B1> {

0 commit comments

Comments
 (0)