rename to SimplePwm and SequencePwm
This commit is contained in:
parent
9a6c2de4ea
commit
d961fd1015
@ -50,15 +50,15 @@ pub enum CounterMode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Interface to the PWM peripheral
|
/// Interface to the PWM peripheral
|
||||||
pub struct Pwm<'d, T: Instance> {
|
pub struct SimplePwm<'d, T: Instance> {
|
||||||
phantom: PhantomData<&'d mut T>,
|
phantom: PhantomData<&'d mut T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct PwmSeq<'d, T: Instance> {
|
pub struct SequencePwm<'d, T: Instance> {
|
||||||
phantom: PhantomData<&'d mut T>,
|
phantom: PhantomData<&'d mut T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'d, T: Instance> PwmSeq<'d, T> {
|
impl<'d, T: Instance> SequencePwm<'d, T> {
|
||||||
/// Creates the interface to a PWM Sequence interface.
|
/// Creates the interface to a PWM Sequence interface.
|
||||||
///
|
///
|
||||||
/// Must be started by calling `start`
|
/// Must be started by calling `start`
|
||||||
@ -67,7 +67,7 @@ impl<'d, T: Instance> PwmSeq<'d, T> {
|
|||||||
///
|
///
|
||||||
/// The returned API is safe unless you use `mem::forget` (or similar safe
|
/// The returned API is safe unless you use `mem::forget` (or similar safe
|
||||||
/// mechanisms) on stack allocated buffers which which have been passed to
|
/// mechanisms) on stack allocated buffers which which have been passed to
|
||||||
/// [`new()`](PwmSeq::new).
|
/// [`new()`](SequencePwm::new).
|
||||||
#[allow(unused_unsafe)]
|
#[allow(unused_unsafe)]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
_pwm: impl Unborrow<Target = T> + 'd,
|
_pwm: impl Unborrow<Target = T> + 'd,
|
||||||
@ -226,7 +226,7 @@ impl<'d, T: Instance> PwmSeq<'d, T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, T: Instance> Drop for PwmSeq<'a, T> {
|
impl<'a, T: Instance> Drop for SequencePwm<'a, T> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
self.stop();
|
self.stop();
|
||||||
self.disable();
|
self.disable();
|
||||||
@ -275,7 +275,7 @@ pub enum Error {
|
|||||||
DMABufferNotInDataMemory,
|
DMABufferNotInDataMemory,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'d, T: Instance> Pwm<'d, T> {
|
impl<'d, T: Instance> SimplePwm<'d, T> {
|
||||||
/// Creates the interface to a PWM instance.
|
/// Creates the interface to a PWM instance.
|
||||||
///
|
///
|
||||||
/// Defaults the freq to 1Mhz, max_duty 32767, duty 0, and channels low.
|
/// Defaults the freq to 1Mhz, max_duty 32767, duty 0, and channels low.
|
||||||
@ -285,7 +285,7 @@ impl<'d, T: Instance> Pwm<'d, T> {
|
|||||||
///
|
///
|
||||||
/// The returned API is safe unless you use `mem::forget` (or similar safe
|
/// The returned API is safe unless you use `mem::forget` (or similar safe
|
||||||
/// mechanisms) on stack allocated buffers which which have been passed to
|
/// mechanisms) on stack allocated buffers which which have been passed to
|
||||||
/// [`new()`](Pwm::new).
|
/// [`new()`](SimplePwm::new).
|
||||||
#[allow(unused_unsafe)]
|
#[allow(unused_unsafe)]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
_pwm: impl Unborrow<Target = T> + 'd,
|
_pwm: impl Unborrow<Target = T> + 'd,
|
||||||
@ -422,12 +422,6 @@ impl<'d, T: Instance> Pwm<'d, T> {
|
|||||||
.write(|w| unsafe { w.countertop().bits(duty.min(32767u16)) });
|
.write(|w| unsafe { w.countertop().bits(duty.min(32767u16)) });
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Additional number of PWM periods spent on each duty cycle value.
|
|
||||||
#[inline(always)]
|
|
||||||
pub fn set_time_stretch(&self, refresh: u32) {
|
|
||||||
T::regs().seq0.refresh.write(|w| unsafe { w.bits(refresh) });
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the maximum duty cycle value.
|
/// Returns the maximum duty cycle value.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn max_duty(&self) -> u16 {
|
pub fn max_duty(&self) -> u16 {
|
||||||
@ -451,7 +445,7 @@ impl<'d, T: Instance> Pwm<'d, T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, T: Instance> Drop for Pwm<'a, T> {
|
impl<'a, T: Instance> Drop for SimplePwm<'a, T> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
self.stop();
|
self.stop();
|
||||||
self.disable();
|
self.disable();
|
||||||
|
@ -7,7 +7,7 @@ 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::pwm::{Prescaler, Pwm};
|
use embassy_nrf::pwm::{Prescaler, SimplePwm};
|
||||||
use embassy_nrf::Peripherals;
|
use embassy_nrf::Peripherals;
|
||||||
|
|
||||||
// for i in range(1024): print(int((math.sin(i/512*math.pi)*0.4+0.5)**2*32767), ', ', end='')
|
// for i in range(1024): print(int((math.sin(i/512*math.pi)*0.4+0.5)**2*32767), ', ', end='')
|
||||||
@ -85,10 +85,9 @@ static DUTY: [u16; 1024] = [
|
|||||||
|
|
||||||
#[embassy::main]
|
#[embassy::main]
|
||||||
async fn main(_spawner: Spawner, p: Peripherals) {
|
async fn main(_spawner: Spawner, p: Peripherals) {
|
||||||
let pwm = Pwm::new(p.PWM0, p.P0_13, p.P0_14, p.P0_16, p.P0_15);
|
let pwm = SimplePwm::new(p.PWM0, p.P0_13, p.P0_14, p.P0_16, p.P0_15);
|
||||||
pwm.set_prescaler(Prescaler::Div1);
|
pwm.set_prescaler(Prescaler::Div1);
|
||||||
pwm.set_max_duty(32767);
|
pwm.set_max_duty(32767);
|
||||||
pwm.set_time_stretch(32);
|
|
||||||
info!("pwm initialized!");
|
info!("pwm initialized!");
|
||||||
|
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
|
@ -8,12 +8,12 @@ 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::gpio::NoPin;
|
||||||
use embassy_nrf::pwm::{Prescaler, Pwm};
|
use embassy_nrf::pwm::{Prescaler, SimplePwm};
|
||||||
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 pwm = Pwm::new(p.PWM0, p.P0_13, NoPin, NoPin, NoPin);
|
let pwm = SimplePwm::new(p.PWM0, p.P0_13, NoPin, NoPin, NoPin);
|
||||||
// set_period doesnt actually set what you give it, because it only has a
|
// set_period doesnt actually set what you give it, because it only has a
|
||||||
// few options from the hardhware so be explicit instead
|
// few options from the hardhware so be explicit instead
|
||||||
// Div128 is slowest, 125khz still crazy fast for our eyes
|
// Div128 is slowest, 125khz still crazy fast for our eyes
|
||||||
|
@ -8,7 +8,7 @@ use defmt::*;
|
|||||||
use embassy::executor::Spawner;
|
use embassy::executor::Spawner;
|
||||||
use embassy::time::{Duration, Timer};
|
use embassy::time::{Duration, Timer};
|
||||||
use embassy_nrf::pwm::{
|
use embassy_nrf::pwm::{
|
||||||
CounterMode, Prescaler, PwmSeq, SequenceConfig, SequenceLoad, SequenceMode,
|
CounterMode, Prescaler, SequenceConfig, SequenceLoad, SequenceMode, SequencePwm,
|
||||||
};
|
};
|
||||||
use embassy_nrf::Peripherals;
|
use embassy_nrf::Peripherals;
|
||||||
|
|
||||||
@ -28,7 +28,7 @@ async fn main(_spawner: Spawner, p: Peripherals) {
|
|||||||
end_delay: 0,
|
end_delay: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
let pwm = unwrap!(PwmSeq::new(
|
let pwm = unwrap!(SequencePwm::new(
|
||||||
p.PWM0, p.P0_13, p.P0_15, p.P0_16, p.P0_14, config
|
p.PWM0, p.P0_13, p.P0_15, p.P0_16, p.P0_14, config
|
||||||
));
|
));
|
||||||
let _ = pwm.start(SequenceMode::Times(5));
|
let _ = pwm.start(SequenceMode::Times(5));
|
||||||
|
@ -8,12 +8,12 @@ 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::gpio::NoPin;
|
||||||
use embassy_nrf::pwm::{Prescaler, Pwm};
|
use embassy_nrf::pwm::{Prescaler, SimplePwm};
|
||||||
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 pwm = Pwm::new(p.PWM0, p.P0_05, NoPin, NoPin, NoPin);
|
let pwm = SimplePwm::new(p.PWM0, p.P0_05, NoPin, NoPin, NoPin);
|
||||||
// sg90 microervo requires 50hz or 20ms period
|
// sg90 microervo requires 50hz or 20ms period
|
||||||
// set_period can only set down to 125khz so we cant use it directly
|
// set_period can only set down to 125khz so we cant use it directly
|
||||||
// Div128 is 125khz or 0.000008s or 0.008ms, 20/0.008 is 2500 is top
|
// Div128 is 125khz or 0.000008s or 0.008ms, 20/0.008 is 2500 is top
|
||||||
|
@ -10,7 +10,7 @@ use embassy::executor::Spawner;
|
|||||||
use embassy::time::{Duration, Timer};
|
use embassy::time::{Duration, Timer};
|
||||||
use embassy_nrf::gpio::NoPin;
|
use embassy_nrf::gpio::NoPin;
|
||||||
use embassy_nrf::pwm::{
|
use embassy_nrf::pwm::{
|
||||||
CounterMode, Prescaler, PwmSeq, SequenceConfig, SequenceLoad, SequenceMode,
|
CounterMode, Prescaler, SequenceConfig, SequenceLoad, SequenceMode, SequencePwm,
|
||||||
};
|
};
|
||||||
use embassy_nrf::Peripherals;
|
use embassy_nrf::Peripherals;
|
||||||
use micromath::F32Ext;
|
use micromath::F32Ext;
|
||||||
@ -32,7 +32,9 @@ async fn main(_spawner: Spawner, p: Peripherals) {
|
|||||||
end_delay: 0,
|
end_delay: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
let pwm = unwrap!(PwmSeq::new(p.PWM0, p.P0_13, NoPin, NoPin, NoPin, config));
|
let pwm = unwrap!(SequencePwm::new(
|
||||||
|
p.PWM0, p.P0_13, NoPin, NoPin, NoPin, config
|
||||||
|
));
|
||||||
let _ = pwm.start(SequenceMode::Infinite);
|
let _ = pwm.start(SequenceMode::Infinite);
|
||||||
info!("pwm started!");
|
info!("pwm started!");
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user