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