pwm_sequence consume buffer
This commit is contained in:
parent
4112759a8f
commit
ec66fcd01a
@ -24,7 +24,7 @@ pub struct SimplePwm<'d, T: Instance> {
|
|||||||
|
|
||||||
/// SequencePwm allows you to offload the updating of a sequence of duty cycles
|
/// SequencePwm allows you to offload the updating of a sequence of duty cycles
|
||||||
/// to up to four channels, as well as repeat that sequence n times.
|
/// to up to four channels, as well as repeat that sequence n times.
|
||||||
pub struct SequencePwm<'d, T: Instance> {
|
pub struct SequencePwm<'d, T: Instance, const N: usize> {
|
||||||
phantom: PhantomData<&'d mut T>,
|
phantom: PhantomData<&'d mut T>,
|
||||||
ch0: Option<AnyPin>,
|
ch0: Option<AnyPin>,
|
||||||
ch1: Option<AnyPin>,
|
ch1: Option<AnyPin>,
|
||||||
@ -44,7 +44,7 @@ pub enum Error {
|
|||||||
DMABufferNotInDataMemory,
|
DMABufferNotInDataMemory,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'d, T: Instance> SequencePwm<'d, T> {
|
impl<'d, T: Instance, const N: usize> SequencePwm<'d, T, N> {
|
||||||
/// Creates the interface to a `SequencePwm`.
|
/// Creates the interface to a `SequencePwm`.
|
||||||
///
|
///
|
||||||
/// Must be started by calling `start`
|
/// Must be started by calling `start`
|
||||||
@ -55,18 +55,18 @@ impl<'d, T: Instance> SequencePwm<'d, T> {
|
|||||||
/// mechanisms) on stack allocated buffers which which have been passed to
|
/// mechanisms) on stack allocated buffers which which have been passed to
|
||||||
/// [`new()`](SequencePwm::new).
|
/// [`new()`](SequencePwm::new).
|
||||||
#[allow(unused_unsafe)]
|
#[allow(unused_unsafe)]
|
||||||
pub fn new<'a>(
|
pub fn new(
|
||||||
_pwm: impl Unborrow<Target = T> + 'd,
|
_pwm: impl Unborrow<Target = T> + 'd,
|
||||||
ch0: impl Unborrow<Target = impl GpioOptionalPin> + 'd,
|
ch0: impl Unborrow<Target = impl GpioOptionalPin> + 'd,
|
||||||
ch1: impl Unborrow<Target = impl GpioOptionalPin> + 'd,
|
ch1: impl Unborrow<Target = impl GpioOptionalPin> + 'd,
|
||||||
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: SequenceConfig,
|
config: SequenceConfig,
|
||||||
sequence: &'a [u16],
|
sequence: [u16; N],
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
slice_in_ram_or(sequence, Error::DMABufferNotInDataMemory)?;
|
slice_in_ram_or(&sequence, Error::DMABufferNotInDataMemory)?;
|
||||||
|
|
||||||
if sequence.len() > 32767 {
|
if N > 32767 {
|
||||||
return Err(Error::SequenceTooLong);
|
return Err(Error::SequenceTooLong);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,9 +108,7 @@ impl<'d, T: Instance> SequencePwm<'d, T> {
|
|||||||
r.seq0
|
r.seq0
|
||||||
.ptr
|
.ptr
|
||||||
.write(|w| unsafe { w.bits(sequence.as_ptr() as u32) });
|
.write(|w| unsafe { w.bits(sequence.as_ptr() as u32) });
|
||||||
r.seq0
|
r.seq0.cnt.write(|w| unsafe { w.bits(N as u32) });
|
||||||
.cnt
|
|
||||||
.write(|w| unsafe { w.bits(sequence.len() as u32) });
|
|
||||||
r.seq0.refresh.write(|w| unsafe { w.bits(config.refresh) });
|
r.seq0.refresh.write(|w| unsafe { w.bits(config.refresh) });
|
||||||
r.seq0
|
r.seq0
|
||||||
.enddelay
|
.enddelay
|
||||||
@ -224,7 +222,7 @@ impl<'d, T: Instance> SequencePwm<'d, T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, T: Instance> Drop for SequencePwm<'a, T> {
|
impl<'a, T: Instance, const N: usize> Drop for SequencePwm<'a, T, N> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
let r = T::regs();
|
let r = T::regs();
|
||||||
|
|
||||||
|
@ -98,13 +98,7 @@ async fn main(_spawner: Spawner, p: Peripherals) {
|
|||||||
config.refresh = 3;
|
config.refresh = 3;
|
||||||
|
|
||||||
let pwm = unwrap!(SequencePwm::new(
|
let pwm = unwrap!(SequencePwm::new(
|
||||||
p.PWM0,
|
p.PWM0, p.P0_13, NoPin, NoPin, NoPin, config, seq_values
|
||||||
p.P0_13,
|
|
||||||
NoPin,
|
|
||||||
NoPin,
|
|
||||||
NoPin,
|
|
||||||
config,
|
|
||||||
&seq_values
|
|
||||||
));
|
));
|
||||||
let _ = pwm.start(SequenceMode::Infinite);
|
let _ = pwm.start(SequenceMode::Infinite);
|
||||||
info!("pwm started!");
|
info!("pwm started!");
|
||||||
|
Loading…
Reference in New Issue
Block a user