stm32/hrtim: shorten names
This commit is contained in:
@ -2,7 +2,7 @@ use crate::rcc::sealed::RccPeripheral;
|
||||
use crate::time::Hertz;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub(crate) enum HighResolutionControlPrescaler {
|
||||
pub(crate) enum Prescaler {
|
||||
Div1,
|
||||
Div2,
|
||||
Div4,
|
||||
@ -13,87 +13,83 @@ pub(crate) enum HighResolutionControlPrescaler {
|
||||
Div128,
|
||||
}
|
||||
|
||||
impl From<HighResolutionControlPrescaler> for u32 {
|
||||
fn from(val: HighResolutionControlPrescaler) -> Self {
|
||||
impl From<Prescaler> for u32 {
|
||||
fn from(val: Prescaler) -> Self {
|
||||
match val {
|
||||
HighResolutionControlPrescaler::Div1 => 1,
|
||||
HighResolutionControlPrescaler::Div2 => 2,
|
||||
HighResolutionControlPrescaler::Div4 => 4,
|
||||
HighResolutionControlPrescaler::Div8 => 8,
|
||||
HighResolutionControlPrescaler::Div16 => 16,
|
||||
HighResolutionControlPrescaler::Div32 => 32,
|
||||
HighResolutionControlPrescaler::Div64 => 64,
|
||||
HighResolutionControlPrescaler::Div128 => 128,
|
||||
Prescaler::Div1 => 1,
|
||||
Prescaler::Div2 => 2,
|
||||
Prescaler::Div4 => 4,
|
||||
Prescaler::Div8 => 8,
|
||||
Prescaler::Div16 => 16,
|
||||
Prescaler::Div32 => 32,
|
||||
Prescaler::Div64 => 64,
|
||||
Prescaler::Div128 => 128,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<HighResolutionControlPrescaler> for u8 {
|
||||
fn from(val: HighResolutionControlPrescaler) -> Self {
|
||||
impl From<Prescaler> for u8 {
|
||||
fn from(val: Prescaler) -> Self {
|
||||
match val {
|
||||
HighResolutionControlPrescaler::Div1 => 0b000,
|
||||
HighResolutionControlPrescaler::Div2 => 0b001,
|
||||
HighResolutionControlPrescaler::Div4 => 0b010,
|
||||
HighResolutionControlPrescaler::Div8 => 0b011,
|
||||
HighResolutionControlPrescaler::Div16 => 0b100,
|
||||
HighResolutionControlPrescaler::Div32 => 0b101,
|
||||
HighResolutionControlPrescaler::Div64 => 0b110,
|
||||
HighResolutionControlPrescaler::Div128 => 0b111,
|
||||
Prescaler::Div1 => 0b000,
|
||||
Prescaler::Div2 => 0b001,
|
||||
Prescaler::Div4 => 0b010,
|
||||
Prescaler::Div8 => 0b011,
|
||||
Prescaler::Div16 => 0b100,
|
||||
Prescaler::Div32 => 0b101,
|
||||
Prescaler::Div64 => 0b110,
|
||||
Prescaler::Div128 => 0b111,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<u8> for HighResolutionControlPrescaler {
|
||||
impl From<u8> for Prescaler {
|
||||
fn from(val: u8) -> Self {
|
||||
match val {
|
||||
0b000 => HighResolutionControlPrescaler::Div1,
|
||||
0b001 => HighResolutionControlPrescaler::Div2,
|
||||
0b010 => HighResolutionControlPrescaler::Div4,
|
||||
0b011 => HighResolutionControlPrescaler::Div8,
|
||||
0b100 => HighResolutionControlPrescaler::Div16,
|
||||
0b101 => HighResolutionControlPrescaler::Div32,
|
||||
0b110 => HighResolutionControlPrescaler::Div64,
|
||||
0b111 => HighResolutionControlPrescaler::Div128,
|
||||
0b000 => Prescaler::Div1,
|
||||
0b001 => Prescaler::Div2,
|
||||
0b010 => Prescaler::Div4,
|
||||
0b011 => Prescaler::Div8,
|
||||
0b100 => Prescaler::Div16,
|
||||
0b101 => Prescaler::Div32,
|
||||
0b110 => Prescaler::Div64,
|
||||
0b111 => Prescaler::Div128,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl HighResolutionControlPrescaler {
|
||||
impl Prescaler {
|
||||
pub fn compute_min_high_res(val: u32) -> Self {
|
||||
*[
|
||||
HighResolutionControlPrescaler::Div1,
|
||||
HighResolutionControlPrescaler::Div2,
|
||||
HighResolutionControlPrescaler::Div4,
|
||||
HighResolutionControlPrescaler::Div8,
|
||||
HighResolutionControlPrescaler::Div16,
|
||||
HighResolutionControlPrescaler::Div32,
|
||||
HighResolutionControlPrescaler::Div64,
|
||||
HighResolutionControlPrescaler::Div128,
|
||||
Prescaler::Div1,
|
||||
Prescaler::Div2,
|
||||
Prescaler::Div4,
|
||||
Prescaler::Div8,
|
||||
Prescaler::Div16,
|
||||
Prescaler::Div32,
|
||||
Prescaler::Div64,
|
||||
Prescaler::Div128,
|
||||
]
|
||||
.iter()
|
||||
.skip_while(|psc| <HighResolutionControlPrescaler as Into<u32>>::into(**psc) <= val)
|
||||
.skip_while(|psc| <Prescaler as Into<u32>>::into(**psc) <= val)
|
||||
.next()
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
pub fn compute_min_low_res(val: u32) -> Self {
|
||||
*[
|
||||
HighResolutionControlPrescaler::Div32,
|
||||
HighResolutionControlPrescaler::Div64,
|
||||
HighResolutionControlPrescaler::Div128,
|
||||
]
|
||||
.iter()
|
||||
.skip_while(|psc| <HighResolutionControlPrescaler as Into<u32>>::into(**psc) <= val)
|
||||
.next()
|
||||
.unwrap()
|
||||
*[Prescaler::Div32, Prescaler::Div64, Prescaler::Div128]
|
||||
.iter()
|
||||
.skip_while(|psc| <Prescaler as Into<u32>>::into(**psc) <= val)
|
||||
.next()
|
||||
.unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) mod sealed {
|
||||
use super::*;
|
||||
|
||||
pub trait HighResolutionCaptureCompare16bitInstance: RccPeripheral {
|
||||
pub trait Instance: RccPeripheral {
|
||||
fn regs() -> crate::pac::hrtim::Hrtim;
|
||||
|
||||
fn set_master_frequency(frequency: Hertz);
|
||||
@ -109,14 +105,11 @@ pub(crate) mod sealed {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait HighResolutionCaptureCompare16bitInstance:
|
||||
sealed::HighResolutionCaptureCompare16bitInstance + 'static
|
||||
{
|
||||
}
|
||||
pub trait Instance: sealed::Instance + 'static {}
|
||||
|
||||
foreach_interrupt! {
|
||||
($inst:ident, hrtim, HRTIM, MASTER, $irq:ident) => {
|
||||
impl sealed::HighResolutionCaptureCompare16bitInstance for crate::peripherals::$inst {
|
||||
impl sealed::Instance for crate::peripherals::$inst {
|
||||
fn regs() -> crate::pac::hrtim::Hrtim {
|
||||
crate::pac::$inst
|
||||
}
|
||||
@ -128,9 +121,9 @@ foreach_interrupt! {
|
||||
let timer_f = Self::frequency().0;
|
||||
let psc_min = (timer_f / f) / (u16::MAX as u32 / 32);
|
||||
let psc = if Self::regs().isr().read().dllrdy() {
|
||||
HighResolutionControlPrescaler::compute_min_high_res(psc_min)
|
||||
Prescaler::compute_min_high_res(psc_min)
|
||||
} else {
|
||||
HighResolutionControlPrescaler::compute_min_low_res(psc_min)
|
||||
Prescaler::compute_min_low_res(psc_min)
|
||||
};
|
||||
|
||||
let psc_val: u32 = psc.into();
|
||||
@ -150,9 +143,9 @@ foreach_interrupt! {
|
||||
let timer_f = Self::frequency().0;
|
||||
let psc_min = (timer_f / f) / (u16::MAX as u32 / 32);
|
||||
let psc = if Self::regs().isr().read().dllrdy() {
|
||||
HighResolutionControlPrescaler::compute_min_high_res(psc_min)
|
||||
Prescaler::compute_min_high_res(psc_min)
|
||||
} else {
|
||||
HighResolutionControlPrescaler::compute_min_low_res(psc_min)
|
||||
Prescaler::compute_min_low_res(psc_min)
|
||||
};
|
||||
|
||||
let psc_val: u32 = psc.into();
|
||||
@ -169,7 +162,7 @@ foreach_interrupt! {
|
||||
|
||||
let regs = Self::regs();
|
||||
|
||||
let channel_psc: HighResolutionControlPrescaler = regs.tim(channel).cr().read().ckpsc().into();
|
||||
let channel_psc: Prescaler = regs.tim(channel).cr().read().ckpsc().into();
|
||||
let psc_val: u32 = channel_psc.into();
|
||||
|
||||
|
||||
@ -177,9 +170,9 @@ foreach_interrupt! {
|
||||
// u9::MAX = 511
|
||||
let psc_min = (psc_val * dead_time as u32) / (4 * 511);
|
||||
let psc = if Self::regs().isr().read().dllrdy() {
|
||||
HighResolutionControlPrescaler::compute_min_high_res(psc_min)
|
||||
Prescaler::compute_min_high_res(psc_min)
|
||||
} else {
|
||||
HighResolutionControlPrescaler::compute_min_low_res(psc_min)
|
||||
Prescaler::compute_min_low_res(psc_min)
|
||||
};
|
||||
|
||||
let dt_psc_val: u32 = psc.into();
|
||||
@ -193,7 +186,7 @@ foreach_interrupt! {
|
||||
}
|
||||
}
|
||||
|
||||
impl HighResolutionCaptureCompare16bitInstance for crate::peripherals::$inst {
|
||||
impl Instance for crate::peripherals::$inst {
|
||||
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user