Expose PWM

This commit is contained in:
huntc
2022-02-04 16:26:23 +11:00
parent 25be00878c
commit fe5501293f
3 changed files with 19 additions and 13 deletions

View File

@ -11,12 +11,14 @@ use embassy::executor::Spawner;
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, SequenceMode, SequencePwm};
use embassy_nrf::pwm::{
Config, Prescaler, Sequence, SequenceConfig, SequenceMode, SequencePwm, Sequences,
};
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 +33,10 @@ 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,
);
let sequence0 = Sequence::new(&seq_words, seq_config);
let sequences = Sequences::new(&mut pwm, sequence0, None);
unwrap!(sequences.start(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
@ -53,8 +54,8 @@ async fn main(_spawner: Spawner, p: Peripherals) {
// messing with the pwm tasks is ill advised
// Times::Ininite and Times even are seq0, Times odd is seq1
let start = unsafe { pwm.task_start_seq0() };
let stop = unsafe { pwm.task_stop() };
let start = unsafe { sequences.pwm.task_start_seq0() };
let stop = unsafe { sequences.pwm.task_stop() };
let mut ppi = Ppi::new_one_to_one(p.PPI_CH1, button1.event_in(), start);
ppi.enable();