aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Rosenthal <[email protected]>2021-11-02 11:56:01 -0700
committerJacob Rosenthal <[email protected]>2021-11-02 11:56:01 -0700
commit682274870f89f1a3585d3df497886d2bca9b1f88 (patch)
tree0b5fdfd34128f8c265611f77a826a2c2e918469c
parentc939edb8d03a6ddf965507e3b2de02b82ca255b4 (diff)
set_duty does indeed loop forever
-rw-r--r--embassy-nrf/src/pwm.rs26
1 files changed, 11 insertions, 15 deletions
diff --git a/embassy-nrf/src/pwm.rs b/embassy-nrf/src/pwm.rs
index 6468f2674..760f36a55 100644
--- a/embassy-nrf/src/pwm.rs
+++ b/embassy-nrf/src/pwm.rs
@@ -165,18 +165,16 @@ impl<'d, T: Instance> PwmSeq<'d, T> {
165 } 165 }
166 let r = T::regs(); 166 let r = T::regs();
167 167
168 r.shorts.reset(); 168 self.stop();
169
170 // tasks_stop doesnt exist in all svds so write its bit instead
171 r.tasks_stop.write(|w| unsafe { w.bits(0x01) });
172 169
173 r.enable.write(|w| w.enable().enabled()); 170 r.enable.write(|w| w.enable().enabled());
174 171
175 match times { 172 match times {
173 // todo why doesn't this play forever? set_duty does...
176 // just the one time, no loop count 174 // just the one time, no loop count
177 SequenceMode::Times(1) => { 175 SequenceMode::Times(1) => {
178 r.loop_.write(|w| w.cnt().disabled()); 176 r.loop_.write(|w| w.cnt().disabled());
179 // tasks_seqstart doesnt exist in all svds so write its bit instead 177 // tasks_seqstart() doesn't exist in all svds so write its bit instead
180 r.tasks_seqstart[0].write(|w| unsafe { w.bits(0x01) }); 178 r.tasks_seqstart[0].write(|w| unsafe { w.bits(0x01) });
181 } 179 }
182 // loop count is how many times to play BOTH sequences 180 // loop count is how many times to play BOTH sequences
@@ -190,10 +188,10 @@ impl<'d, T: Instance> PwmSeq<'d, T> {
190 188
191 // we can subtract 1 by starting at seq1 instead of seq0 189 // we can subtract 1 by starting at seq1 instead of seq0
192 if odd { 190 if odd {
193 // tasks_seqstart doesnt exist in all svds so write its bit instead 191 // tasks_seqstart() doesn't exist in all svds so write its bit instead
194 r.tasks_seqstart[1].write(|w| unsafe { w.bits(0x01) }); 192 r.tasks_seqstart[1].write(|w| unsafe { w.bits(0x01) });
195 } else { 193 } else {
196 // tasks_seqstart doesnt exist in all svds so write its bit instead 194 // tasks_seqstart() doesn't exist in all svds so write its bit instead
197 r.tasks_seqstart[0].write(|w| unsafe { w.bits(0x01) }); 195 r.tasks_seqstart[0].write(|w| unsafe { w.bits(0x01) });
198 } 196 }
199 } 197 }
@@ -201,7 +199,7 @@ impl<'d, T: Instance> PwmSeq<'d, T> {
201 SequenceMode::Infinite => { 199 SequenceMode::Infinite => {
202 r.loop_.write(|w| unsafe { w.cnt().bits(0x1) }); 200 r.loop_.write(|w| unsafe { w.cnt().bits(0x1) });
203 r.shorts.write(|w| w.loopsdone_seqstart0().enabled()); 201 r.shorts.write(|w| w.loopsdone_seqstart0().enabled());
204 // tasks_seqstart doesnt exist in all svds so write its bit instead 202 // tasks_seqstart() doesn't exist in all svds so write its bit instead
205 r.tasks_seqstart[0].write(|w| unsafe { w.bits(0x01) }); 203 r.tasks_seqstart[0].write(|w| unsafe { w.bits(0x01) });
206 } 204 }
207 } 205 }
@@ -216,7 +214,7 @@ impl<'d, T: Instance> PwmSeq<'d, T> {
216 214
217 r.shorts.reset(); 215 r.shorts.reset();
218 216
219 // tasks_stop doesnt exist in all svds so write its bit instead 217 // tasks_stop() doesn't exist in all svds so write its bit instead
220 r.tasks_stop.write(|w| unsafe { w.bits(0x01) }); 218 r.tasks_stop.write(|w| unsafe { w.bits(0x01) });
221 } 219 }
222 220
@@ -361,7 +359,7 @@ impl<'d, T: Instance> Pwm<'d, T> {
361 359
362 r.shorts.reset(); 360 r.shorts.reset();
363 361
364 // tasks_stop doesnt exist in all svds so write its bit instead 362 // tasks_stop() doesn't exist in all svds so write its bit instead
365 r.tasks_stop.write(|w| unsafe { w.bits(0x01) }); 363 r.tasks_stop.write(|w| unsafe { w.bits(0x01) });
366 } 364 }
367 365
@@ -383,17 +381,15 @@ impl<'d, T: Instance> Pwm<'d, T> {
383 381
384 /// Sets duty cycle (15 bit) for a PWM channel. 382 /// Sets duty cycle (15 bit) for a PWM channel.
385 pub fn set_duty(&self, channel: usize, duty: u16) { 383 pub fn set_duty(&self, channel: usize, duty: u16) {
384 let r = T::regs();
386 let s = T::state(); 385 let s = T::state();
387 unsafe { (*s.duty.get())[channel] = duty & 0x7FFF }; 386 unsafe { (*s.duty.get())[channel] = duty & 0x7FFF };
388 387
389 // todo justify? should i fence elsehwere we task start? or 388 // todo justify? should i fence elsehwere we task start? or
390 compiler_fence(Ordering::SeqCst); 389 compiler_fence(Ordering::SeqCst);
391 390
392 // play duty cycle infinitely 391 // todo why does this play forever when times(1) doesn't?
393 let r = T::regs(); 392 // tasks_seqstart() doesn't exist in all svds so write its bit instead
394 r.loop_.write(|w| unsafe { w.cnt().bits(0x1) });
395 r.shorts.write(|w| w.loopsdone_seqstart0().enabled());
396 // tasks_seqstart doesnt exist in all svds so write its bit instead
397 r.tasks_seqstart[0].write(|w| unsafe { w.bits(1) }); 393 r.tasks_seqstart[0].write(|w| unsafe { w.bits(1) });
398 } 394 }
399 395