simplify api, more interesting example
This commit is contained in:
parent
eb0bf1fd7a
commit
1d1d8a848e
2 changed files with 10 additions and 26 deletions
|
@ -153,7 +153,6 @@ impl<'d, T: Instance> Pwm<'d, T> {
|
|||
ch2: impl Unborrow<Target = impl GpioOptionalPin> + 'd,
|
||||
ch3: impl Unborrow<Target = impl GpioOptionalPin> + 'd,
|
||||
config: LoopingConfig,
|
||||
count: u16,
|
||||
) -> Result<Self, Error> {
|
||||
slice_in_ram_or(config.sequence, Error::DMABufferNotInDataMemory)?;
|
||||
|
||||
|
@ -163,8 +162,6 @@ impl<'d, T: Instance> Pwm<'d, T> {
|
|||
|
||||
unborrow!(ch0, ch1, ch2, ch3);
|
||||
|
||||
let odd: bool = count & 1 == 1;
|
||||
|
||||
let r = T::regs();
|
||||
|
||||
if let Some(pin) = ch0.pin_mut() {
|
||||
|
@ -224,25 +221,12 @@ impl<'d, T: Instance> Pwm<'d, T> {
|
|||
.enddelay
|
||||
.write(|w| unsafe { w.bits(config.enddelay) });
|
||||
|
||||
let mut loop_: u16 = count / 2;
|
||||
if odd {
|
||||
loop_ += 1;
|
||||
}
|
||||
r.loop_.write(|w| unsafe { w.cnt().bits(0x1) });
|
||||
|
||||
r.loop_.write(|w| unsafe { w.cnt().bits(loop_) });
|
||||
|
||||
if odd {
|
||||
r.shorts.write(|w| w.loopsdone_seqstart1().set_bit());
|
||||
} else {
|
||||
r.shorts.write(|w| w.loopsdone_seqstart0().set_bit());
|
||||
}
|
||||
r.shorts.write(|w| w.loopsdone_seqstart1().set_bit());
|
||||
|
||||
// tasks_seqstart doesnt exist in all svds so write its bit instead
|
||||
if odd {
|
||||
r.tasks_seqstart[1].write(|w| unsafe { w.bits(0x01) });
|
||||
} else {
|
||||
r.tasks_seqstart[0].write(|w| unsafe { w.bits(0x01) });
|
||||
}
|
||||
r.tasks_seqstart[1].write(|w| unsafe { w.bits(0x01) });
|
||||
|
||||
Ok(Self {
|
||||
phantom: PhantomData,
|
||||
|
|
|
@ -7,26 +7,26 @@ mod example_common;
|
|||
use defmt::*;
|
||||
use embassy::executor::Spawner;
|
||||
use embassy::time::{Duration, Timer};
|
||||
use embassy_nrf::gpio::NoPin;
|
||||
use embassy_nrf::pwm::{CounterMode, LoopingConfig, Prescaler, Pwm, SequenceLoad};
|
||||
use embassy_nrf::Peripherals;
|
||||
|
||||
#[embassy::main]
|
||||
async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
let seq_values: [u16; 2] = [0, 0x8000];
|
||||
|
||||
let seq_values: [u16; 16] = [
|
||||
0x8000, 0, 0, 0, 0, 0x8000, 0, 0, 0, 0, 0x8000, 0, 0, 0, 0, 0x8000,
|
||||
];
|
||||
let config = LoopingConfig {
|
||||
counter_mode: CounterMode::Up,
|
||||
top: 31250,
|
||||
top: 15625,
|
||||
prescaler: Prescaler::Div128,
|
||||
sequence: &seq_values,
|
||||
sequence_load: SequenceLoad::Common,
|
||||
repeats: 1,
|
||||
sequence_load: SequenceLoad::Individual,
|
||||
repeats: 0,
|
||||
enddelay: 0,
|
||||
};
|
||||
|
||||
let pwm = unwrap!(Pwm::simple_playback(
|
||||
p.PWM0, p.P0_13, NoPin, NoPin, NoPin, config, 1
|
||||
p.PWM0, p.P0_13, p.P0_15, p.P0_16, p.P0_14, config
|
||||
));
|
||||
info!("pwm started!");
|
||||
|
||||
|
|
Loading…
Reference in a new issue