From ab74fc47fdb11479669950f24357c9dfa7d4d140 Mon Sep 17 00:00:00 2001 From: dimi Date: Thu, 24 Nov 2022 22:12:19 +0100 Subject: [PATCH] rename const generics --- esp-hal-common/src/mcpwm/mod.rs | 10 ++++---- esp-hal-common/src/mcpwm/operator.rs | 36 ++++++++++++++-------------- esp-hal-common/src/mcpwm/timer.rs | 12 +++++----- 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/esp-hal-common/src/mcpwm/mod.rs b/esp-hal-common/src/mcpwm/mod.rs index 124b66d32..541efeadd 100644 --- a/esp-hal-common/src/mcpwm/mod.rs +++ b/esp-hal-common/src/mcpwm/mod.rs @@ -241,7 +241,7 @@ pub unsafe trait PwmPeripheral { /// Get a pointer to the peripheral RegisterBlock fn block() -> *const crate::pac::pwm0::RegisterBlock; /// Get operator GPIO mux output signal - fn output_signal() -> OutputSignal; + fn output_signal() -> OutputSignal; } unsafe impl PwmPeripheral for crate::pac::PWM0 { @@ -253,8 +253,8 @@ unsafe impl PwmPeripheral for crate::pac::PWM0 { Self::ptr() } - fn output_signal() -> OutputSignal { - match (O, IS_A) { + fn output_signal() -> OutputSignal { + match (OP, IS_A) { (0, true) => OutputSignal::PWM0_0A, (1, true) => OutputSignal::PWM0_1A, (2, true) => OutputSignal::PWM0_1A, @@ -275,8 +275,8 @@ unsafe impl PwmPeripheral for crate::pac::PWM1 { Self::ptr() } - fn output_signal() -> OutputSignal { - match (O, IS_A) { + fn output_signal() -> OutputSignal { + match (OP, IS_A) { (0, true) => OutputSignal::PWM1_0A, (1, true) => OutputSignal::PWM1_1A, (2, true) => OutputSignal::PWM1_1A, diff --git a/esp-hal-common/src/mcpwm/operator.rs b/esp-hal-common/src/mcpwm/operator.rs index 39199bb24..8fc025b1a 100644 --- a/esp-hal-common/src/mcpwm/operator.rs +++ b/esp-hal-common/src/mcpwm/operator.rs @@ -15,11 +15,11 @@ use crate::{ /// * Superimposes a carrier on the PWM signal, if configured to do so. (Not yet /// implemented) /// * Handles response under fault conditions. (Not yet implemented) -pub struct Operator { +pub struct Operator { phantom: PhantomData, } -impl Operator { +impl Operator { pub(super) fn new() -> Self { // TODO maybe set timersel to 3 to disable? @@ -32,13 +32,13 @@ impl Operator { /// /// ### Note: /// By default TIMER0 is used - pub fn set_timer(&mut self, timer: &Timer) { + pub fn set_timer(&mut self, timer: &Timer) { let _ = timer; let block = unsafe { &*PWM::block() }; - block.operator_timersel.modify(|_, w| match O { - 0 => w.operator0_timersel().variant(T), - 1 => w.operator1_timersel().variant(T), - 2 => w.operator2_timersel().variant(T), + block.operator_timersel.modify(|_, w| match OP { + 0 => w.operator0_timersel().variant(TIM), + 1 => w.operator1_timersel().variant(TIM), + 2 => w.operator2_timersel().variant(TIM), _ => { unreachable!() } @@ -50,7 +50,7 @@ impl Operator { self, pin: Pin, config: PwmPinConfig, - ) -> PwmPin { + ) -> PwmPin { PwmPin::new(pin, config) } @@ -59,7 +59,7 @@ impl Operator { self, pin: Pin, config: PwmPinConfig, - ) -> PwmPin { + ) -> PwmPin { PwmPin::new(pin, config) } @@ -70,7 +70,7 @@ impl Operator { config_a: PwmPinConfig, pin_b: PinB, config_b: PwmPinConfig, - ) -> (PwmPin, PwmPin) { + ) -> (PwmPin, PwmPin) { (PwmPin::new(pin_a, config_a), PwmPin::new(pin_b, config_b)) } } @@ -104,14 +104,14 @@ impl PwmPinConfig { } /// A pin driven by an MCPWM operator -pub struct PwmPin { +pub struct PwmPin { _pin: Pin, phantom: PhantomData, } -impl PwmPin { +impl PwmPin { fn new(mut pin: Pin, config: PwmPinConfig) -> Self { - let output_signal = PWM::output_signal::(); + let output_signal = PWM::output_signal::(); pin.enable_output(true) .connect_peripheral_to_output(output_signal); let mut pin = PwmPin { @@ -134,7 +134,7 @@ impl PwmPin

block.gen0_a.write(|w| w.bits(bits)), (1, true) => block.gen1_a.write(|w| w.bits(bits)), (2, true) => block.gen2_a.write(|w| w.bits(bits)), @@ -151,7 +151,7 @@ impl PwmPin

block .gen0_stmp_cfg .modify(|_, w| w.gen0_a_upmethod().variant(bits)), @@ -181,7 +181,7 @@ impl PwmPin

block .cmpr0_cfg .modify(|_, w| w.cmpr0_a_upmethod().variant(bits)), @@ -212,7 +212,7 @@ impl PwmPin

block.gen0_tstmp_a.write(|w| w.gen0_a().variant(value)), (1, true) => block.gen1_tstmp_a.write(|w| w.gen1_a().variant(value)), (2, true) => block.gen2_tstmp_a.write(|w| w.gen2_a().variant(value)), @@ -231,7 +231,7 @@ impl PwmPin

block.cmpr0_value0.write(|w| w.cmpr0_a().variant(value)), (1, true) => block.cmpr1_value0.write(|w| w.cmpr1_a().variant(value)), (2, true) => block.cmpr2_value0.write(|w| w.cmpr2_a().variant(value)), diff --git a/esp-hal-common/src/mcpwm/timer.rs b/esp-hal-common/src/mcpwm/timer.rs index f39d3599a..74db11ae5 100644 --- a/esp-hal-common/src/mcpwm/timer.rs +++ b/esp-hal-common/src/mcpwm/timer.rs @@ -12,11 +12,11 @@ use crate::{ /// Every timer of a particular [`MCPWM`](super::MCPWM) peripheral can be used /// as a timing reference for every /// [`Operator`](super::operator::Operator) of that peripheral -pub struct Timer { +pub struct Timer { pub(super) phantom: PhantomData, } -impl Timer { +impl Timer { pub(super) fn new() -> Self { Timer { phantom: PhantomData, @@ -63,7 +63,7 @@ impl Timer { pub fn set_counter(&mut self, phase: u16) { // FIXME add phase_direction to SVD, then add CounterDirection as a parameter let block = unsafe { &*PWM::block() }; - match T { + match TIM { 0 => block.timer0_sync.modify(|r, w| { w.timer0_phase() .variant(phase as u32) @@ -92,7 +92,7 @@ impl Timer { pub fn status(&self) -> (u16, CounterDirection) { let block = unsafe { &*PWM::block() }; - match T { + match TIM { 0 => { let reg = block.timer0_status.read(); ( @@ -128,7 +128,7 @@ impl Timer { // SAFETY: // The CFG0 registers are identical for all timers so we can pretend they're // TIMER0_CFG0 - match T { + match TIM { 0 => &block.timer0_cfg0, 1 => unsafe { &*(&block.timer1_cfg0 as *const _ as *const _) }, 2 => unsafe { &*(&block.timer2_cfg0 as *const _ as *const _) }, @@ -145,7 +145,7 @@ impl Timer { // SAFETY: // The CFG1 registers are identical for all timers so we can pretend they're // TIMER0_CFG1 - match T { + match TIM { 0 => &block.timer0_cfg1, 1 => unsafe { &*(&block.timer1_cfg1 as *const _ as *const _) }, 2 => unsafe { &*(&block.timer2_cfg1 as *const _ as *const _) },