stm32/hrtim: move traits out of macro def'n
This commit is contained in:
parent
20ea76c19c
commit
322a4a8401
@ -78,38 +78,12 @@ pub(crate) mod sealed {
|
||||
pub trait Instance: RccPeripheral {
|
||||
fn regs() -> crate::pac::hrtim::Hrtim;
|
||||
|
||||
fn set_master_frequency(frequency: Hertz);
|
||||
|
||||
fn set_channel_frequency(channnel: usize, frequency: Hertz);
|
||||
|
||||
/// Set the dead time as a proportion of max_duty
|
||||
fn set_channel_dead_time(channnel: usize, dead_time: u16);
|
||||
|
||||
// fn enable_outputs(enable: bool);
|
||||
//
|
||||
// fn enable_channel(&mut self, channel: usize, enable: bool);
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Instance: sealed::Instance + 'static {}
|
||||
|
||||
foreach_interrupt! {
|
||||
($inst:ident, hrtim, HRTIM, MASTER, $irq:ident) => {
|
||||
impl sealed::Instance for crate::peripherals::$inst {
|
||||
fn regs() -> crate::pac::hrtim::Hrtim {
|
||||
crate::pac::$inst
|
||||
}
|
||||
|
||||
fn set_master_frequency(frequency: Hertz) {
|
||||
use crate::rcc::sealed::RccPeripheral;
|
||||
|
||||
let f = frequency.0;
|
||||
#[cfg(not(stm32f334))]
|
||||
let timer_f = Self::frequency().0;
|
||||
#[cfg(stm32f334)]
|
||||
let timer_f = unsafe { crate::rcc::get_freqs() }.hrtim.unwrap_or(
|
||||
Self::frequency()
|
||||
).0;
|
||||
let timer_f = unsafe { crate::rcc::get_freqs() }.hrtim.unwrap_or(Self::frequency()).0;
|
||||
|
||||
let psc_min = (timer_f / f) / (u16::MAX as u32 / 32);
|
||||
let psc = if Self::regs().isr().read().dllrdy() {
|
||||
@ -128,15 +102,11 @@ foreach_interrupt! {
|
||||
}
|
||||
|
||||
fn set_channel_frequency(channel: usize, frequency: Hertz) {
|
||||
use crate::rcc::sealed::RccPeripheral;
|
||||
|
||||
let f = frequency.0;
|
||||
#[cfg(not(stm32f334))]
|
||||
let timer_f = Self::frequency().0;
|
||||
#[cfg(stm32f334)]
|
||||
let timer_f = unsafe { crate::rcc::get_freqs() }.hrtim.unwrap_or(
|
||||
Self::frequency()
|
||||
).0;
|
||||
let timer_f = unsafe { crate::rcc::get_freqs() }.hrtim.unwrap_or(Self::frequency()).0;
|
||||
|
||||
let psc_min = (timer_f / f) / (u16::MAX as u32 / 32);
|
||||
let psc = if Self::regs().isr().read().dllrdy() {
|
||||
@ -154,8 +124,9 @@ foreach_interrupt! {
|
||||
regs.tim(channel).per().modify(|w| w.set_per(per));
|
||||
}
|
||||
|
||||
fn set_channel_dead_time(channel: usize, dead_time: u16) {
|
||||
/// Set the dead time as a proportion of max_duty
|
||||
|
||||
fn set_channel_dead_time(channel: usize, dead_time: u16) {
|
||||
let regs = Self::regs();
|
||||
|
||||
let channel_psc: Prescaler = regs.tim(channel).cr().read().ckpsc().into();
|
||||
@ -177,6 +148,21 @@ foreach_interrupt! {
|
||||
w.set_dtr(dt_val as u16);
|
||||
});
|
||||
}
|
||||
|
||||
// fn enable_outputs(enable: bool);
|
||||
//
|
||||
// fn enable_channel(&mut self, channel: usize, enable: bool);
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Instance: sealed::Instance + 'static {}
|
||||
|
||||
foreach_interrupt! {
|
||||
($inst:ident, hrtim, HRTIM, MASTER, $irq:ident) => {
|
||||
impl sealed::Instance for crate::peripherals::$inst {
|
||||
fn regs() -> crate::pac::hrtim::Hrtim {
|
||||
crate::pac::$inst
|
||||
}
|
||||
}
|
||||
|
||||
impl Instance for crate::peripherals::$inst {
|
||||
|
Loading…
Reference in New Issue
Block a user