aboutsummaryrefslogtreecommitdiff
path: root/embassy-nrf/src/pwm.rs
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2022-07-23 15:13:47 +0200
committerDario Nieuwenhuis <[email protected]>2022-07-23 15:13:47 +0200
commit709df0dc1dfff577fb79bbc2f67ea84670072456 (patch)
tree4a54aee47c0d3881b9e0bc809e075728cee8eeae /embassy-nrf/src/pwm.rs
parent19d1ef0e29fdd0bf0407cbe37c388e8a87e7ddfe (diff)
nrf: replace PhantomData usages with PeripheralRef.
Diffstat (limited to 'embassy-nrf/src/pwm.rs')
-rw-r--r--embassy-nrf/src/pwm.rs13
1 files changed, 8 insertions, 5 deletions
diff --git a/embassy-nrf/src/pwm.rs b/embassy-nrf/src/pwm.rs
index ecc674ce0..5f750a91e 100644
--- a/embassy-nrf/src/pwm.rs
+++ b/embassy-nrf/src/pwm.rs
@@ -1,6 +1,5 @@
1#![macro_use] 1#![macro_use]
2 2
3use core::marker::PhantomData;
4use core::sync::atomic::{compiler_fence, Ordering}; 3use core::sync::atomic::{compiler_fence, Ordering};
5 4
6use embassy_hal_common::{into_ref, PeripheralRef}; 5use embassy_hal_common::{into_ref, PeripheralRef};
@@ -15,7 +14,7 @@ use crate::{pac, Peripheral};
15/// SimplePwm is the traditional pwm interface you're probably used to, allowing 14/// SimplePwm is the traditional pwm interface you're probably used to, allowing
16/// to simply set a duty cycle across up to four channels. 15/// to simply set a duty cycle across up to four channels.
17pub struct SimplePwm<'d, T: Instance> { 16pub struct SimplePwm<'d, T: Instance> {
18 phantom: PhantomData<&'d mut T>, 17 _peri: PeripheralRef<'d, T>,
19 duty: [u16; 4], 18 duty: [u16; 4],
20 ch0: Option<PeripheralRef<'d, AnyPin>>, 19 ch0: Option<PeripheralRef<'d, AnyPin>>,
21 ch1: Option<PeripheralRef<'d, AnyPin>>, 20 ch1: Option<PeripheralRef<'d, AnyPin>>,
@@ -26,7 +25,7 @@ pub struct SimplePwm<'d, T: Instance> {
26/// SequencePwm allows you to offload the updating of a sequence of duty cycles 25/// SequencePwm allows you to offload the updating of a sequence of duty cycles
27/// to up to four channels, as well as repeat that sequence n times. 26/// to up to four channels, as well as repeat that sequence n times.
28pub struct SequencePwm<'d, T: Instance> { 27pub struct SequencePwm<'d, T: Instance> {
29 phantom: PhantomData<&'d mut T>, 28 _peri: PeripheralRef<'d, T>,
30 ch0: Option<PeripheralRef<'d, AnyPin>>, 29 ch0: Option<PeripheralRef<'d, AnyPin>>,
31 ch1: Option<PeripheralRef<'d, AnyPin>>, 30 ch1: Option<PeripheralRef<'d, AnyPin>>,
32 ch2: Option<PeripheralRef<'d, AnyPin>>, 31 ch2: Option<PeripheralRef<'d, AnyPin>>,
@@ -120,6 +119,8 @@ impl<'d, T: Instance> SequencePwm<'d, T> {
120 ch3: Option<PeripheralRef<'d, AnyPin>>, 119 ch3: Option<PeripheralRef<'d, AnyPin>>,
121 config: Config, 120 config: Config,
122 ) -> Result<Self, Error> { 121 ) -> Result<Self, Error> {
122 into_ref!(_pwm);
123
123 let r = T::regs(); 124 let r = T::regs();
124 125
125 if let Some(pin) = &ch0 { 126 if let Some(pin) = &ch0 {
@@ -168,7 +169,7 @@ impl<'d, T: Instance> SequencePwm<'d, T> {
168 r.countertop.write(|w| unsafe { w.countertop().bits(config.max_duty) }); 169 r.countertop.write(|w| unsafe { w.countertop().bits(config.max_duty) });
169 170
170 Ok(Self { 171 Ok(Self {
171 phantom: PhantomData, 172 _peri: _pwm,
172 ch0, 173 ch0,
173 ch1, 174 ch1,
174 ch2, 175 ch2,
@@ -639,6 +640,8 @@ impl<'d, T: Instance> SimplePwm<'d, T> {
639 ch2: Option<PeripheralRef<'d, AnyPin>>, 640 ch2: Option<PeripheralRef<'d, AnyPin>>,
640 ch3: Option<PeripheralRef<'d, AnyPin>>, 641 ch3: Option<PeripheralRef<'d, AnyPin>>,
641 ) -> Self { 642 ) -> Self {
643 into_ref!(_pwm);
644
642 let r = T::regs(); 645 let r = T::regs();
643 646
644 if let Some(pin) = &ch0 { 647 if let Some(pin) = &ch0 {
@@ -666,7 +669,7 @@ impl<'d, T: Instance> SimplePwm<'d, T> {
666 r.psel.out[3].write(|w| unsafe { w.bits(ch3.psel_bits()) }); 669 r.psel.out[3].write(|w| unsafe { w.bits(ch3.psel_bits()) });
667 670
668 let pwm = Self { 671 let pwm = Self {
669 phantom: PhantomData, 672 _peri: _pwm,
670 ch0, 673 ch0,
671 ch1, 674 ch1,
672 ch2, 675 ch2,