stm32/hrtim: shorten names

This commit is contained in:
xoviat 2023-07-28 17:37:14 -05:00
parent ec787d3518
commit a8d3bcbb75
2 changed files with 88 additions and 95 deletions

View file

@ -7,7 +7,7 @@ use embassy_hal_internal::{into_ref, PeripheralRef};
#[allow(unused_imports)]
use crate::gpio::sealed::{AFType, Pin};
use crate::gpio::AnyPin;
use crate::hrtim::traits::HighResolutionCaptureCompare16bitInstance;
use crate::hrtim::traits::Instance;
use crate::time::Hertz;
use crate::Peripheral;
@ -20,37 +20,37 @@ pub enum Source {
ChE,
}
pub struct BurstController<T: HighResolutionCaptureCompare16bitInstance> {
pub struct BurstController<T: Instance> {
phantom: PhantomData<T>,
}
pub struct Master<T: HighResolutionCaptureCompare16bitInstance> {
pub struct Master<T: Instance> {
phantom: PhantomData<T>,
}
pub struct ChA<T: HighResolutionCaptureCompare16bitInstance> {
pub struct ChA<T: Instance> {
phantom: PhantomData<T>,
}
pub struct ChB<T: HighResolutionCaptureCompare16bitInstance> {
pub struct ChB<T: Instance> {
phantom: PhantomData<T>,
}
pub struct ChC<T: HighResolutionCaptureCompare16bitInstance> {
pub struct ChC<T: Instance> {
phantom: PhantomData<T>,
}
pub struct ChD<T: HighResolutionCaptureCompare16bitInstance> {
pub struct ChD<T: Instance> {
phantom: PhantomData<T>,
}
pub struct ChE<T: HighResolutionCaptureCompare16bitInstance> {
pub struct ChE<T: Instance> {
phantom: PhantomData<T>,
}
mod sealed {
use super::HighResolutionCaptureCompare16bitInstance;
use super::Instance;
pub trait AdvancedChannel<T: HighResolutionCaptureCompare16bitInstance> {
pub trait AdvancedChannel<T: Instance> {
fn raw() -> usize;
}
}
pub trait AdvancedChannel<T: HighResolutionCaptureCompare16bitInstance>: sealed::AdvancedChannel<T> {}
pub trait AdvancedChannel<T: Instance>: sealed::AdvancedChannel<T> {}
pub struct PwmPin<'d, Perip, Channel> {
_pin: PeripheralRef<'d, AnyPin>,
@ -64,7 +64,7 @@ pub struct ComplementaryPwmPin<'d, Perip, Channel> {
macro_rules! advanced_channel_impl {
($new_chx:ident, $channel:tt, $ch_num:expr, $pin_trait:ident, $complementary_pin_trait:ident) => {
impl<'d, Perip: HighResolutionCaptureCompare16bitInstance> PwmPin<'d, Perip, $channel<Perip>> {
impl<'d, Perip: Instance> PwmPin<'d, Perip, $channel<Perip>> {
pub fn $new_chx(pin: impl Peripheral<P = impl $pin_trait<Perip>> + 'd) -> Self {
into_ref!(pin);
critical_section::with(|_| {
@ -80,7 +80,7 @@ macro_rules! advanced_channel_impl {
}
}
impl<'d, Perip: HighResolutionCaptureCompare16bitInstance> ComplementaryPwmPin<'d, Perip, $channel<Perip>> {
impl<'d, Perip: Instance> ComplementaryPwmPin<'d, Perip, $channel<Perip>> {
pub fn $new_chx(pin: impl Peripheral<P = impl $complementary_pin_trait<Perip>> + 'd) -> Self {
into_ref!(pin);
critical_section::with(|_| {
@ -96,12 +96,12 @@ macro_rules! advanced_channel_impl {
}
}
impl<T: HighResolutionCaptureCompare16bitInstance> sealed::AdvancedChannel<T> for $channel<T> {
impl<T: Instance> sealed::AdvancedChannel<T> for $channel<T> {
fn raw() -> usize {
$ch_num
}
}
impl<T: HighResolutionCaptureCompare16bitInstance> AdvancedChannel<T> for $channel<T> {}
impl<T: Instance> AdvancedChannel<T> for $channel<T> {}
};
}
@ -112,7 +112,7 @@ advanced_channel_impl!(new_chd, ChD, 3, ChannelDPin, ChannelDComplementaryPin);
advanced_channel_impl!(new_che, ChE, 4, ChannelEPin, ChannelEComplementaryPin);
/// Struct used to divide a high resolution timer into multiple channels
pub struct AdvancedPwm<'d, T: HighResolutionCaptureCompare16bitInstance> {
pub struct AdvancedPwm<'d, T: Instance> {
_inner: PeripheralRef<'d, T>,
pub master: Master<T>,
pub burst_controller: BurstController<T>,
@ -123,7 +123,7 @@ pub struct AdvancedPwm<'d, T: HighResolutionCaptureCompare16bitInstance> {
pub ch_e: ChE<T>,
}
impl<'d, T: HighResolutionCaptureCompare16bitInstance> AdvancedPwm<'d, T> {
impl<'d, T: Instance> AdvancedPwm<'d, T> {
pub fn new(
tim: impl Peripheral<P = T> + 'd,
_cha: Option<PwmPin<'d, T, ChA<T>>>,
@ -171,7 +171,7 @@ impl<'d, T: HighResolutionCaptureCompare16bitInstance> AdvancedPwm<'d, T> {
}
}
impl<T: HighResolutionCaptureCompare16bitInstance> BurstController<T> {
impl<T: Instance> BurstController<T> {
pub fn set_source(&mut self, _source: Source) {
todo!("burst mode control registers not implemented")
}
@ -186,7 +186,7 @@ impl<T: HighResolutionCaptureCompare16bitInstance> BurstController<T> {
/// It is important to remember that in synchronous topologies, energy can flow in reverse during
/// light loading conditions, and that the low-side switch must be active for a short time to drive
/// a bootstrapped high-side switch.
pub struct BridgeConverter<T: HighResolutionCaptureCompare16bitInstance, C: AdvancedChannel<T>> {
pub struct BridgeConverter<T: Instance, C: AdvancedChannel<T>> {
timer: PhantomData<T>,
channel: PhantomData<C>,
dead_time: u16,
@ -195,7 +195,7 @@ pub struct BridgeConverter<T: HighResolutionCaptureCompare16bitInstance, C: Adva
max_secondary_duty: u16,
}
impl<T: HighResolutionCaptureCompare16bitInstance, C: AdvancedChannel<T>> BridgeConverter<T, C> {
impl<T: Instance, C: AdvancedChannel<T>> BridgeConverter<T, C> {
pub fn new(_channel: C, frequency: Hertz) -> Self {
use crate::pac::hrtim::vals::{Activeeffect, Inactiveeffect};
@ -333,14 +333,14 @@ impl<T: HighResolutionCaptureCompare16bitInstance, C: AdvancedChannel<T>> Bridge
/// This implementation of a resonsant converter is appropriate for a half or full bridge,
/// but does not include secondary rectification, which is appropriate for applications
/// with a low-voltage on the secondary side.
pub struct ResonantConverter<T: HighResolutionCaptureCompare16bitInstance, C: AdvancedChannel<T>> {
pub struct ResonantConverter<T: Instance, C: AdvancedChannel<T>> {
timer: PhantomData<T>,
channel: PhantomData<C>,
min_period: u16,
max_period: u16,
}
impl<T: HighResolutionCaptureCompare16bitInstance, C: AdvancedChannel<T>> ResonantConverter<T, C> {
impl<T: Instance, C: AdvancedChannel<T>> ResonantConverter<T, C> {
pub fn new(_channel: C, min_frequency: Hertz, max_frequency: Hertz) -> Self {
T::set_channel_frequency(C::raw(), min_frequency);
@ -397,13 +397,13 @@ impl<T: HighResolutionCaptureCompare16bitInstance, C: AdvancedChannel<T>> Resona
}
}
pin_trait!(ChannelAPin, HighResolutionCaptureCompare16bitInstance);
pin_trait!(ChannelAComplementaryPin, HighResolutionCaptureCompare16bitInstance);
pin_trait!(ChannelBPin, HighResolutionCaptureCompare16bitInstance);
pin_trait!(ChannelBComplementaryPin, HighResolutionCaptureCompare16bitInstance);
pin_trait!(ChannelCPin, HighResolutionCaptureCompare16bitInstance);
pin_trait!(ChannelCComplementaryPin, HighResolutionCaptureCompare16bitInstance);
pin_trait!(ChannelDPin, HighResolutionCaptureCompare16bitInstance);
pin_trait!(ChannelDComplementaryPin, HighResolutionCaptureCompare16bitInstance);
pin_trait!(ChannelEPin, HighResolutionCaptureCompare16bitInstance);
pin_trait!(ChannelEComplementaryPin, HighResolutionCaptureCompare16bitInstance);
pin_trait!(ChannelAPin, Instance);
pin_trait!(ChannelAComplementaryPin, Instance);
pin_trait!(ChannelBPin, Instance);
pin_trait!(ChannelBComplementaryPin, Instance);
pin_trait!(ChannelCPin, Instance);
pin_trait!(ChannelCComplementaryPin, Instance);
pin_trait!(ChannelDPin, Instance);
pin_trait!(ChannelDComplementaryPin, Instance);
pin_trait!(ChannelEPin, Instance);
pin_trait!(ChannelEComplementaryPin, Instance);

View file

@ -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 {
}
};