Expose PWM
This commit is contained in:
parent
25be00878c
commit
fe5501293f
@ -321,7 +321,7 @@ impl<'s> Sequence<'s> {
|
||||
/// is used.
|
||||
#[non_exhaustive]
|
||||
pub struct Sequences<'d, 's, T: Instance> {
|
||||
_pwm: &'s mut SequencePwm<'d, T>,
|
||||
pub pwm: &'s mut SequencePwm<'d, T>,
|
||||
sequence0: Sequence<'s>,
|
||||
sequence1: Option<Sequence<'s>>,
|
||||
}
|
||||
@ -333,7 +333,7 @@ impl<'d, 's, T: Instance> Sequences<'d, 's, T> {
|
||||
sequence1: Option<Sequence<'s>>,
|
||||
) -> Self {
|
||||
Sequences {
|
||||
_pwm: pwm,
|
||||
pwm,
|
||||
sequence0,
|
||||
sequence1,
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -7,11 +7,12 @@ mod example_common;
|
||||
use defmt::*;
|
||||
use embassy::executor::Spawner;
|
||||
use embassy::time::{Duration, Timer};
|
||||
use embassy::util::Forever;
|
||||
use embassy_nrf::gpio::NoPin;
|
||||
use embassy_nrf::pwm::{
|
||||
Config, Prescaler, Sequence, SequenceConfig, SequenceLoad, SequenceMode, SequencePwm, Sequences,
|
||||
};
|
||||
use embassy_nrf::Peripherals;
|
||||
use embassy_nrf::{peripherals, Peripherals};
|
||||
|
||||
// WS2812B LED light demonstration. Drives just one light.
|
||||
// The following reference on WS2812B may be of use:
|
||||
@ -26,6 +27,8 @@ const T1H: u16 = 0x8000 | 13; // Duty = 13/20 ticks (0.8us/1.25us) for a 1
|
||||
const T0H: u16 = 0x8000 | 7; // Duty 7/20 ticks (0.4us/1.25us) for a 0
|
||||
const RES: u16 = 0x8000;
|
||||
|
||||
static PWM: Forever<SequencePwm<peripherals::PWM0>> = Forever::new();
|
||||
|
||||
// Provides data to a WS2812b (Neopixel) LED and makes it go blue. The data
|
||||
// line is assumed to be P1_05.
|
||||
#[embassy::main]
|
||||
@ -34,10 +37,12 @@ async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
config.sequence_load = SequenceLoad::Common;
|
||||
config.prescaler = Prescaler::Div1;
|
||||
config.max_duty = 20; // 1.25us (1s / 16Mhz * 20)
|
||||
let mut pwm = unwrap!(SequencePwm::new(
|
||||
let pwm = unwrap!(SequencePwm::new(
|
||||
p.PWM0, p.P1_05, NoPin, NoPin, NoPin, config,
|
||||
));
|
||||
|
||||
let mut pwm = PWM.put(pwm);
|
||||
|
||||
// Declare the bits of 24 bits in a buffer we'll be
|
||||
// mutating later.
|
||||
let mut seq_words = [
|
||||
|
Loading…
Reference in New Issue
Block a user