Skip to content

Commit

Permalink
Implemented Pwm trait for complementary pwm from embedded_hal
Browse files Browse the repository at this point in the history
  • Loading branch information
HelloWorldTeraByte committed Oct 6, 2023
1 parent b217d14 commit 7108740
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions embassy-stm32/src/timer/complementary_pwm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,46 @@ impl<'d, T: ComplementaryCaptureCompare16bitInstance> ComplementaryPwm<'d, T> {
}
}

impl<'d, T: ComplementaryCaptureCompare16bitInstance> embedded_hal_02::Pwm for ComplementaryPwm<'d, T> {
type Channel = Channel;
type Time = Hertz;
type Duty = u16;

fn disable(&mut self, channel: Self::Channel) {
self.inner.enable_complementary_channel(channel, false);
self.inner.enable_channel(channel, false);
}

fn enable(&mut self, channel: Self::Channel) {
self.inner.enable_channel(channel, true);
self.inner.enable_complementary_channel(channel, true);
}

fn get_period(&self) -> Self::Time {
self.inner.get_frequency().into()
}

fn get_duty(&self, channel: Self::Channel) -> Self::Duty {
self.inner.get_compare_value(channel)
}

fn get_max_duty(&self) -> Self::Duty {
self.inner.get_max_compare_value() + 1
}

fn set_duty(&mut self, channel: Self::Channel, duty: Self::Duty) {
assert!(duty <= self.get_max_duty());
self.inner.set_compare_value(channel, duty)
}

fn set_period<P>(&mut self, period: P)
where
P: Into<Self::Time>,
{
self.inner.set_frequency(period.into());
}
}

fn compute_dead_time_value(value: u16) -> (Ckd, u8) {
/*
Dead-time = T_clk * T_dts * T_dtg
Expand Down

0 comments on commit 7108740

Please sign in to comment.