Own the sequence buffer

This approach owns the sequence buffers which, while introducing an extra move, it eliminates the need to guard the lifetime of the sequence buffer. Given ownership, the buffer will be retained until the PWM sequence task is stopped.
This commit is contained in:
huntc
2022-01-29 15:26:31 +11:00
parent 9ac52a768b
commit 482389a691
4 changed files with 108 additions and 68 deletions

View File

@ -16,7 +16,7 @@ use embassy_nrf::Peripherals;
#[embassy::main]
async fn main(_spawner: Spawner, p: Peripherals) {
let mut seq_words: [u16; 5] = [1000, 250, 100, 50, 0];
let seq_words: [u16; 5] = [1000, 250, 100, 50, 0];
let mut config = Config::default();
config.prescaler = Prescaler::Div128;
@ -31,11 +31,12 @@ async fn main(_spawner: Spawner, p: Peripherals) {
p.PWM0, p.P0_13, NoPin, NoPin, NoPin, config,
));
let _ = pwm.start(
Sequence::new(&mut seq_words, seq_config),
None,
SequenceMode::Infinite,
);
// If we loop in any way i.e. not Times(1), then we must provide
// the PWM peripheral with two sequences.
let seq_0 = Sequence::new(seq_words, seq_config);
let seq_1 = seq_0.clone();
unwrap!(pwm.start(seq_0, seq_1, SequenceMode::Infinite));
// pwm.stop() deconfigures pins, and then the task_start_seq0 task cant work
// so its going to have to start running in order load the configuration