aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-nrf/src/pwm.rs18
-rw-r--r--examples/nrf/src/bin/pwm_sequence.rs8
2 files changed, 9 insertions, 17 deletions
diff --git a/embassy-nrf/src/pwm.rs b/embassy-nrf/src/pwm.rs
index 08e9add0e..642620673 100644
--- a/embassy-nrf/src/pwm.rs
+++ b/embassy-nrf/src/pwm.rs
@@ -24,7 +24,7 @@ pub struct SimplePwm<'d, T: Instance> {
24 24
25/// 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
26/// 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.
27pub struct SequencePwm<'d, T: Instance> { 27pub struct SequencePwm<'d, T: Instance, const N: usize> {
28 phantom: PhantomData<&'d mut T>, 28 phantom: PhantomData<&'d mut T>,
29 ch0: Option<AnyPin>, 29 ch0: Option<AnyPin>,
30 ch1: Option<AnyPin>, 30 ch1: Option<AnyPin>,
@@ -44,7 +44,7 @@ pub enum Error {
44 DMABufferNotInDataMemory, 44 DMABufferNotInDataMemory,
45} 45}
46 46
47impl<'d, T: Instance> SequencePwm<'d, T> { 47impl<'d, T: Instance, const N: usize> SequencePwm<'d, T, N> {
48 /// Creates the interface to a `SequencePwm`. 48 /// Creates the interface to a `SequencePwm`.
49 /// 49 ///
50 /// Must be started by calling `start` 50 /// Must be started by calling `start`
@@ -55,18 +55,18 @@ impl<'d, T: Instance> SequencePwm<'d, T> {
55 /// mechanisms) on stack allocated buffers which which have been passed to 55 /// mechanisms) on stack allocated buffers which which have been passed to
56 /// [`new()`](SequencePwm::new). 56 /// [`new()`](SequencePwm::new).
57 #[allow(unused_unsafe)] 57 #[allow(unused_unsafe)]
58 pub fn new<'a>( 58 pub fn new(
59 _pwm: impl Unborrow<Target = T> + 'd, 59 _pwm: impl Unborrow<Target = T> + 'd,
60 ch0: impl Unborrow<Target = impl GpioOptionalPin> + 'd, 60 ch0: impl Unborrow<Target = impl GpioOptionalPin> + 'd,
61 ch1: impl Unborrow<Target = impl GpioOptionalPin> + 'd, 61 ch1: impl Unborrow<Target = impl GpioOptionalPin> + 'd,
62 ch2: impl Unborrow<Target = impl GpioOptionalPin> + 'd, 62 ch2: impl Unborrow<Target = impl GpioOptionalPin> + 'd,
63 ch3: impl Unborrow<Target = impl GpioOptionalPin> + 'd, 63 ch3: impl Unborrow<Target = impl GpioOptionalPin> + 'd,
64 config: SequenceConfig, 64 config: SequenceConfig,
65 sequence: &'a [u16], 65 sequence: [u16; N],
66 ) -> Result<Self, Error> { 66 ) -> Result<Self, Error> {
67 slice_in_ram_or(sequence, Error::DMABufferNotInDataMemory)?; 67 slice_in_ram_or(&sequence, Error::DMABufferNotInDataMemory)?;
68 68
69 if sequence.len() > 32767 { 69 if N > 32767 {
70 return Err(Error::SequenceTooLong); 70 return Err(Error::SequenceTooLong);
71 } 71 }
72 72
@@ -108,9 +108,7 @@ impl<'d, T: Instance> SequencePwm<'d, T> {
108 r.seq0 108 r.seq0
109 .ptr 109 .ptr
110 .write(|w| unsafe { w.bits(sequence.as_ptr() as u32) }); 110 .write(|w| unsafe { w.bits(sequence.as_ptr() as u32) });
111 r.seq0 111 r.seq0.cnt.write(|w| unsafe { w.bits(N as u32) });
112 .cnt
113 .write(|w| unsafe { w.bits(sequence.len() as u32) });
114 r.seq0.refresh.write(|w| unsafe { w.bits(config.refresh) }); 112 r.seq0.refresh.write(|w| unsafe { w.bits(config.refresh) });
115 r.seq0 113 r.seq0
116 .enddelay 114 .enddelay
@@ -224,7 +222,7 @@ impl<'d, T: Instance> SequencePwm<'d, T> {
224 } 222 }
225} 223}
226 224
227impl<'a, T: Instance> Drop for SequencePwm<'a, T> { 225impl<'a, T: Instance, const N: usize> Drop for SequencePwm<'a, T, N> {
228 fn drop(&mut self) { 226 fn drop(&mut self) {
229 let r = T::regs(); 227 let r = T::regs();
230 228
diff --git a/examples/nrf/src/bin/pwm_sequence.rs b/examples/nrf/src/bin/pwm_sequence.rs
index d02b0c9c5..2b8a3a7d6 100644
--- a/examples/nrf/src/bin/pwm_sequence.rs
+++ b/examples/nrf/src/bin/pwm_sequence.rs
@@ -98,13 +98,7 @@ async fn main(_spawner: Spawner, p: Peripherals) {
98 config.refresh = 3; 98 config.refresh = 3;
99 99
100 let pwm = unwrap!(SequencePwm::new( 100 let pwm = unwrap!(SequencePwm::new(
101 p.PWM0, 101 p.PWM0, p.P0_13, NoPin, NoPin, NoPin, config, seq_values
102 p.P0_13,
103 NoPin,
104 NoPin,
105 NoPin,
106 config,
107 &seq_values
108 )); 102 ));
109 let _ = pwm.start(SequenceMode::Infinite); 103 let _ = pwm.start(SequenceMode::Infinite);
110 info!("pwm started!"); 104 info!("pwm started!");