mirror of
https://github.com/embassy-rs/embassy.git
synced 2024-11-21 22:32:29 +00:00
Implemented owned split.
This commit is contained in:
parent
052463212b
commit
336ef01b05
@ -347,25 +347,36 @@ impl<'d> Pwm<'d> {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
/// Split Pwm driver to allow separate duty cycle control of each channel
|
/// Split Pwm driver to allow separate duty cycle control of each channel
|
||||||
pub fn split(&self) -> (PwmOutput,PwmOutput){
|
pub fn split(self) -> (Option<PwmOutput>, Option<PwmOutput>) {
|
||||||
(PwmOutput::new(PwmChannel::A,self.slice.clone()),PwmOutput::new(PwmChannel::B,self.slice.clone()))
|
|
||||||
|
let pwm_output_a = if let Some(pin_a) = self.pin_a {
|
||||||
|
Some(PwmOutput::new(PwmChannelPin::A(pin_a), self.slice.clone()))
|
||||||
|
};
|
||||||
|
|
||||||
|
let pwm_output_b = if let Some(pin_b) = self.pin_b {
|
||||||
|
Some(PwmOutput::new(PwmChannelPin::B(pin_b), self.slice.clone()))
|
||||||
|
};
|
||||||
|
|
||||||
|
(pwm_output_a,pwm_output_b)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
enum PwmChannel{
|
enum PwmChannelPin<'d> {
|
||||||
A,
|
A(PeripheralRef<'d, AnyPin>),
|
||||||
B
|
B(PeripheralRef<'d, AnyPin>)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Single channel of Pwm driver.
|
/// Single channel of Pwm driver.
|
||||||
pub struct PwmOutput {
|
pub struct PwmOutput<'d> {
|
||||||
channel: PwmChannel,
|
//pin that can be ether ChannelAPin or ChannelBPin
|
||||||
slice: usize
|
channel_pin: PwmChannelPin<'d> ,
|
||||||
|
slice: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PwmOutput {
|
impl <'d> PwmOutput<'d> {
|
||||||
fn new(channel: PwmChannel,slice: usize) -> Self{
|
fn new(channel_pin: PwmChannelPin<'d>, slice: usize) -> Self {
|
||||||
Self { channel, slice }
|
Self { channel_pin ,slice }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -373,7 +384,7 @@ impl ErrorType for PwmOutput {
|
|||||||
type Error = PwmError;
|
type Error = PwmError;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SetDutyCycle for PwmOutput {
|
impl<'d> SetDutyCycle for PwmOutput<'d> {
|
||||||
fn max_duty_cycle(&self) -> u16 {
|
fn max_duty_cycle(&self) -> u16 {
|
||||||
pac::PWM.ch(self.slice).top().read().top()
|
pac::PWM.ch(self.slice).top().read().top()
|
||||||
}
|
}
|
||||||
@ -385,19 +396,19 @@ impl SetDutyCycle for PwmOutput {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let p = pac::PWM.ch(self.slice);
|
let p = pac::PWM.ch(self.slice);
|
||||||
match self.channel {
|
match self.channel_pin {
|
||||||
PwmChannel::A => {
|
PwmChannelPin::A => {
|
||||||
p.cc().modify(|w| {
|
p.cc().modify(|w| {
|
||||||
w.set_a(duty);
|
w.set_a(duty);
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
PwmChannel::B => {
|
PwmChannelPin::B => {
|
||||||
p.cc().modify(|w| {
|
p.cc().modify(|w| {
|
||||||
w.set_b(duty);
|
w.set_b(duty);
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user