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]
|
||||
/// Split Pwm driver to allow separate duty cycle control of each channel
|
||||
pub fn split(&self) -> (PwmOutput,PwmOutput){
|
||||
(PwmOutput::new(PwmChannel::A,self.slice.clone()),PwmOutput::new(PwmChannel::B,self.slice.clone()))
|
||||
}
|
||||
pub fn split(self) -> (Option<PwmOutput>, Option<PwmOutput>) {
|
||||
|
||||
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{
|
||||
A,
|
||||
B
|
||||
}
|
||||
|
||||
enum PwmChannelPin<'d> {
|
||||
A(PeripheralRef<'d, AnyPin>),
|
||||
B(PeripheralRef<'d, AnyPin>)
|
||||
}
|
||||
|
||||
/// Single channel of Pwm driver.
|
||||
pub struct PwmOutput {
|
||||
channel: PwmChannel,
|
||||
slice: usize
|
||||
pub struct PwmOutput<'d> {
|
||||
//pin that can be ether ChannelAPin or ChannelBPin
|
||||
channel_pin: PwmChannelPin<'d> ,
|
||||
slice: usize,
|
||||
}
|
||||
|
||||
impl PwmOutput {
|
||||
fn new(channel: PwmChannel,slice: usize) -> Self{
|
||||
Self { channel, slice }
|
||||
impl <'d> PwmOutput<'d> {
|
||||
fn new(channel_pin: PwmChannelPin<'d>, slice: usize) -> Self {
|
||||
Self { channel_pin ,slice }
|
||||
}
|
||||
}
|
||||
|
||||
@ -373,7 +384,7 @@ impl ErrorType for PwmOutput {
|
||||
type Error = PwmError;
|
||||
}
|
||||
|
||||
impl SetDutyCycle for PwmOutput {
|
||||
impl<'d> SetDutyCycle for PwmOutput<'d> {
|
||||
fn max_duty_cycle(&self) -> u16 {
|
||||
pac::PWM.ch(self.slice).top().read().top()
|
||||
}
|
||||
@ -385,17 +396,17 @@ impl SetDutyCycle for PwmOutput {
|
||||
}
|
||||
|
||||
let p = pac::PWM.ch(self.slice);
|
||||
match self.channel {
|
||||
PwmChannel::A => {
|
||||
match self.channel_pin {
|
||||
PwmChannelPin::A => {
|
||||
p.cc().modify(|w| {
|
||||
w.set_a(duty);
|
||||
});
|
||||
},
|
||||
PwmChannel::B => {
|
||||
}
|
||||
PwmChannelPin::B => {
|
||||
p.cc().modify(|w| {
|
||||
w.set_b(duty);
|
||||
});
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
Loading…
Reference in New Issue
Block a user