Merge branch 'master' into center-align

This commit is contained in:
Dion Dokter
2023-10-20 14:17:55 +02:00
433 changed files with 6915 additions and 7018 deletions

View File

@ -65,8 +65,7 @@ impl<'d, T: ComplementaryCaptureCompare16bitInstance> ComplementaryPwm<'d, T> {
fn new_inner(tim: impl Peripheral<P = T> + 'd, freq: Hertz, counting_mode: CountingMode) -> Self {
into_ref!(tim);
T::enable();
<T as crate::rcc::sealed::RccPeripheral>::reset();
T::enable_and_reset();
let mut this = Self { inner: tim };
@ -74,7 +73,7 @@ impl<'d, T: ComplementaryCaptureCompare16bitInstance> ComplementaryPwm<'d, T> {
this.set_freq(freq);
this.inner.start();
this.inner.enable_outputs(true);
this.inner.enable_outputs();
this.inner
.set_output_compare_mode(Channel::Ch1, OutputCompareMode::PwmMode1);
@ -129,6 +128,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

View File

@ -77,6 +77,16 @@ pub(crate) mod sealed {
fn set_autoreload_preload(&mut self, enable: vals::Arpe) {
Self::regs().cr1().modify(|r| r.set_arpe(enable));
}
fn get_frequency(&self) -> Hertz {
let timer_f = Self::frequency();
let regs = Self::regs();
let arr = regs.arr().read().arr();
let psc = regs.psc().read().psc();
timer_f / arr / (psc + 1)
}
}
pub trait GeneralPurpose16bitInstance: Basic16bitInstance {
@ -123,6 +133,16 @@ pub(crate) mod sealed {
regs.egr().write(|r| r.set_ug(true));
regs.cr1().modify(|r| r.set_urs(vals::Urs::ANYEVENT));
}
fn get_frequency(&self) -> Hertz {
let timer_f = Self::frequency();
let regs = Self::regs_gp32();
let arr = regs.arr().read().arr();
let psc = regs.psc().read().psc();
timer_f / arr / (psc + 1)
}
}
pub trait AdvancedControlInstance: GeneralPurpose16bitInstance {
@ -173,7 +193,7 @@ pub(crate) mod sealed {
}
});
}
fn enable_outputs(&mut self, _enable: bool) {}
fn enable_outputs(&mut self);
fn set_output_compare_mode(&mut self, channel: Channel, mode: OutputCompareMode) {
let r = Self::regs_gp16();
@ -203,6 +223,10 @@ pub(crate) mod sealed {
fn get_max_compare_value(&self) -> u16 {
Self::regs_gp16().arr().read().arr()
}
fn get_compare_value(&self, channel: Channel) -> u16 {
Self::regs_gp16().ccr(channel.raw()).read().ccr()
}
}
pub trait ComplementaryCaptureCompare16bitInstance: CaptureCompare16bitInstance + AdvancedControlInstance {
@ -239,6 +263,10 @@ pub(crate) mod sealed {
fn get_max_compare_value(&self) -> u32 {
Self::regs_gp32().arr().read().arr()
}
fn get_compare_value(&self, channel: Channel) -> u32 {
Self::regs_gp32().ccr(channel.raw()).read().ccr()
}
}
}
@ -460,7 +488,9 @@ macro_rules! impl_32bit_timer {
#[allow(unused)]
macro_rules! impl_compare_capable_16bit {
($inst:ident) => {
impl sealed::CaptureCompare16bitInstance for crate::peripherals::$inst {}
impl sealed::CaptureCompare16bitInstance for crate::peripherals::$inst {
fn enable_outputs(&mut self) {}
}
};
}
@ -509,7 +539,13 @@ foreach_interrupt! {
impl CaptureCompare16bitInstance for crate::peripherals::$inst {}
impl ComplementaryCaptureCompare16bitInstance for crate::peripherals::$inst {}
impl AdvancedControlInstance for crate::peripherals::$inst {}
impl sealed::CaptureCompare16bitInstance for crate::peripherals::$inst {}
impl sealed::CaptureCompare16bitInstance for crate::peripherals::$inst {
fn enable_outputs(&mut self) {
use crate::timer::sealed::AdvancedControlInstance;
let r = Self::regs_advanced();
r.bdtr().modify(|w| w.set_moe(true));
}
}
impl sealed::ComplementaryCaptureCompare16bitInstance for crate::peripherals::$inst {}
impl sealed::GeneralPurpose16bitInstance for crate::peripherals::$inst {
fn regs_gp16() -> crate::pac::timer::TimGp16 {

View File

@ -55,8 +55,7 @@ impl<'d, T: CaptureCompare16bitInstance> Qei<'d, T> {
fn new_inner(tim: impl Peripheral<P = T> + 'd) -> Self {
into_ref!(tim);
T::enable();
<T as crate::rcc::sealed::RccPeripheral>::reset();
T::enable_and_reset();
// Configure TxC1 and TxC2 as captures
T::regs_gp16().ccmr_input(0).modify(|w| {

View File

@ -64,8 +64,7 @@ impl<'d, T: CaptureCompare16bitInstance> SimplePwm<'d, T> {
fn new_inner(tim: impl Peripheral<P = T> + 'd, freq: Hertz, counting_mode: CountingMode) -> Self {
into_ref!(tim);
T::enable();
<T as crate::rcc::sealed::RccPeripheral>::reset();
T::enable_and_reset();
let mut this = Self { inner: tim };
@ -73,7 +72,7 @@ impl<'d, T: CaptureCompare16bitInstance> SimplePwm<'d, T> {
this.set_freq(freq);
this.inner.start();
this.inner.enable_outputs(true);
this.inner.enable_outputs();
this.inner
.set_output_compare_mode(Channel::Ch1, OutputCompareMode::PwmMode1);
@ -116,3 +115,41 @@ impl<'d, T: CaptureCompare16bitInstance> SimplePwm<'d, T> {
self.inner.set_output_polarity(channel, polarity);
}
}
impl<'d, T: CaptureCompare16bitInstance> embedded_hal_02::Pwm for SimplePwm<'d, T> {
type Channel = Channel;
type Time = Hertz;
type Duty = u16;
fn disable(&mut self, channel: Self::Channel) {
self.inner.enable_channel(channel, false);
}
fn enable(&mut self, channel: Self::Channel) {
self.inner.enable_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());
}
}