Further API simplification for the single seq scenario

This commit is contained in:
huntc 2022-02-05 08:05:23 +11:00
parent 81d31e43eb
commit df5ba727f2
4 changed files with 8 additions and 11 deletions

View File

@ -323,9 +323,9 @@ pub struct SingleSequencer<'d, 's, T: Instance> {
impl<'d, 's, T: Instance> SingleSequencer<'d, 's, T> {
/// Create a new sequencer
pub fn new(pwm: &'s mut SequencePwm<'d, T>, sequence: Sequence<'s>) -> Self {
pub fn new(pwm: &'s mut SequencePwm<'d, T>, words: &'s [u16], config: SequenceConfig) -> Self {
Self {
sequencer: Sequencer::new(pwm, sequence, None),
sequencer: Sequencer::new(pwm, Sequence::new(words, config), None),
}
}

View File

@ -9,7 +9,7 @@ use embassy::executor::Spawner;
use embassy::time::{Duration, Timer};
use embassy_nrf::gpio::NoPin;
use embassy_nrf::pwm::{
Config, Prescaler, Sequence, SequenceConfig, SequencePwm, SingleSequenceMode, SingleSequencer,
Config, Prescaler, SequenceConfig, SequencePwm, SingleSequenceMode, SingleSequencer,
};
use embassy_nrf::Peripherals;
@ -31,8 +31,7 @@ async fn main(_spawner: Spawner, p: Peripherals) {
p.PWM0, p.P0_13, NoPin, NoPin, NoPin, config,
));
let sequence = Sequence::new(&seq_words, seq_config);
let sequencer = SingleSequencer::new(&mut pwm, sequence);
let sequencer = SingleSequencer::new(&mut pwm, &seq_words, seq_config);
unwrap!(sequencer.start(SingleSequenceMode::Times(1)));
// we can abort a sequence if we need to before its complete with pwm.stop()

View File

@ -12,7 +12,7 @@ use embassy_nrf::gpio::{Input, NoPin, Pull};
use embassy_nrf::gpiote::{InputChannel, InputChannelPolarity};
use embassy_nrf::ppi::Ppi;
use embassy_nrf::pwm::{
Config, Prescaler, Sequence, SequenceConfig, SequencePwm, SingleSequenceMode, SingleSequencer,
Config, Prescaler, SequenceConfig, SequencePwm, SingleSequenceMode, SingleSequencer,
};
use embassy_nrf::Peripherals;
@ -53,8 +53,7 @@ async fn main(_spawner: Spawner, p: Peripherals) {
let start = unsafe { pwm.task_start_seq0() };
let stop = unsafe { pwm.task_stop() };
let sequence = Sequence::new(&seq_words, seq_config);
let sequencer = SingleSequencer::new(&mut pwm, sequence);
let sequencer = SingleSequencer::new(&mut pwm, &seq_words, seq_config);
unwrap!(sequencer.start(SingleSequenceMode::Infinite));
let mut ppi = Ppi::new_one_to_one(p.PPI_CH1, button1.event_in(), start);

View File

@ -9,7 +9,7 @@ use embassy::executor::Spawner;
use embassy::time::{Duration, Timer};
use embassy_nrf::gpio::NoPin;
use embassy_nrf::pwm::{
Config, Prescaler, Sequence, SequenceConfig, SequenceLoad, SequencePwm, SingleSequenceMode,
Config, Prescaler, SequenceConfig, SequenceLoad, SequencePwm, SingleSequenceMode,
SingleSequencer,
};
use embassy_nrf::Peripherals;
@ -54,8 +54,7 @@ async fn main(_spawner: Spawner, p: Peripherals) {
let mut bit_value = T0H;
loop {
let sequence0 = Sequence::new(&seq_words, seq_config.clone());
let sequences = SingleSequencer::new(&mut pwm, sequence0);
let sequences = SingleSequencer::new(&mut pwm, &seq_words, seq_config.clone());
unwrap!(sequences.start(SingleSequenceMode::Times(1)));
Timer::after(Duration::from_millis(50)).await;