diff options
| -rw-r--r-- | embassy-stm32/src/pwm/mod.rs | 32 | ||||
| -rw-r--r-- | embassy-stm32/src/time_driver.rs | 12 | ||||
| -rw-r--r-- | embassy-stm32/src/timer/mod.rs | 36 | ||||
| -rw-r--r-- | examples/stm32h7/src/bin/low_level_timer_api.rs | 23 |
4 files changed, 47 insertions, 56 deletions
diff --git a/embassy-stm32/src/pwm/mod.rs b/embassy-stm32/src/pwm/mod.rs index e8938ffae..c6edbc6c3 100644 --- a/embassy-stm32/src/pwm/mod.rs +++ b/embassy-stm32/src/pwm/mod.rs | |||
| @@ -99,7 +99,7 @@ macro_rules! impl_compare_capable_16bit { | |||
| 99 | mode: OutputCompareMode, | 99 | mode: OutputCompareMode, |
| 100 | ) { | 100 | ) { |
| 101 | use crate::timer::sealed::GeneralPurpose16bitInstance; | 101 | use crate::timer::sealed::GeneralPurpose16bitInstance; |
| 102 | let r = self.regs_gp16(); | 102 | let r = Self::regs_gp16(); |
| 103 | let raw_channel: usize = channel.raw(); | 103 | let raw_channel: usize = channel.raw(); |
| 104 | r.ccmr_output(raw_channel / 2) | 104 | r.ccmr_output(raw_channel / 2) |
| 105 | .modify(|w| w.set_ocm(raw_channel % 2, mode.into())); | 105 | .modify(|w| w.set_ocm(raw_channel % 2, mode.into())); |
| @@ -107,21 +107,21 @@ macro_rules! impl_compare_capable_16bit { | |||
| 107 | 107 | ||
| 108 | unsafe fn enable_channel(&mut self, channel: Channel, enable: bool) { | 108 | unsafe fn enable_channel(&mut self, channel: Channel, enable: bool) { |
| 109 | use crate::timer::sealed::GeneralPurpose16bitInstance; | 109 | use crate::timer::sealed::GeneralPurpose16bitInstance; |
| 110 | self.regs_gp16() | 110 | Self::regs_gp16() |
| 111 | .ccer() | 111 | .ccer() |
| 112 | .modify(|w| w.set_cce(channel.raw(), enable)); | 112 | .modify(|w| w.set_cce(channel.raw(), enable)); |
| 113 | } | 113 | } |
| 114 | 114 | ||
| 115 | unsafe fn set_compare_value(&mut self, channel: Channel, value: u16) { | 115 | unsafe fn set_compare_value(&mut self, channel: Channel, value: u16) { |
| 116 | use crate::timer::sealed::GeneralPurpose16bitInstance; | 116 | use crate::timer::sealed::GeneralPurpose16bitInstance; |
| 117 | self.regs_gp16() | 117 | Self::regs_gp16() |
| 118 | .ccr(channel.raw()) | 118 | .ccr(channel.raw()) |
| 119 | .modify(|w| w.set_ccr(value)); | 119 | .modify(|w| w.set_ccr(value)); |
| 120 | } | 120 | } |
| 121 | 121 | ||
| 122 | unsafe fn get_max_compare_value(&self) -> u16 { | 122 | unsafe fn get_max_compare_value(&self) -> u16 { |
| 123 | use crate::timer::sealed::GeneralPurpose16bitInstance; | 123 | use crate::timer::sealed::GeneralPurpose16bitInstance; |
| 124 | self.regs_gp16().arr().read().arr() | 124 | Self::regs_gp16().arr().read().arr() |
| 125 | } | 125 | } |
| 126 | } | 126 | } |
| 127 | }; | 127 | }; |
| @@ -136,7 +136,7 @@ foreach_interrupt! { | |||
| 136 | mode: OutputCompareMode, | 136 | mode: OutputCompareMode, |
| 137 | ) { | 137 | ) { |
| 138 | use crate::timer::sealed::GeneralPurpose16bitInstance; | 138 | use crate::timer::sealed::GeneralPurpose16bitInstance; |
| 139 | let r = self.regs_gp16(); | 139 | let r = Self::regs_gp16(); |
| 140 | let raw_channel: usize = channel.raw(); | 140 | let raw_channel: usize = channel.raw(); |
| 141 | r.ccmr_output(raw_channel / 2) | 141 | r.ccmr_output(raw_channel / 2) |
| 142 | .modify(|w| w.set_ocm(raw_channel % 2, mode.into())); | 142 | .modify(|w| w.set_ocm(raw_channel % 2, mode.into())); |
| @@ -144,21 +144,21 @@ foreach_interrupt! { | |||
| 144 | 144 | ||
| 145 | unsafe fn enable_channel(&mut self, channel: Channel, enable: bool) { | 145 | unsafe fn enable_channel(&mut self, channel: Channel, enable: bool) { |
| 146 | use crate::timer::sealed::GeneralPurpose16bitInstance; | 146 | use crate::timer::sealed::GeneralPurpose16bitInstance; |
| 147 | self.regs_gp16() | 147 | Self::regs_gp16() |
| 148 | .ccer() | 148 | .ccer() |
| 149 | .modify(|w| w.set_cce(channel.raw(), enable)); | 149 | .modify(|w| w.set_cce(channel.raw(), enable)); |
| 150 | } | 150 | } |
| 151 | 151 | ||
| 152 | unsafe fn set_compare_value(&mut self, channel: Channel, value: u16) { | 152 | unsafe fn set_compare_value(&mut self, channel: Channel, value: u16) { |
| 153 | use crate::timer::sealed::GeneralPurpose16bitInstance; | 153 | use crate::timer::sealed::GeneralPurpose16bitInstance; |
| 154 | self.regs_gp16() | 154 | Self::regs_gp16() |
| 155 | .ccr(channel.raw()) | 155 | .ccr(channel.raw()) |
| 156 | .modify(|w| w.set_ccr(value)); | 156 | .modify(|w| w.set_ccr(value)); |
| 157 | } | 157 | } |
| 158 | 158 | ||
| 159 | unsafe fn get_max_compare_value(&self) -> u16 { | 159 | unsafe fn get_max_compare_value(&self) -> u16 { |
| 160 | use crate::timer::sealed::GeneralPurpose16bitInstance; | 160 | use crate::timer::sealed::GeneralPurpose16bitInstance; |
| 161 | self.regs_gp16().arr().read().arr() | 161 | Self::regs_gp16().arr().read().arr() |
| 162 | } | 162 | } |
| 163 | } | 163 | } |
| 164 | 164 | ||
| @@ -177,22 +177,22 @@ foreach_interrupt! { | |||
| 177 | ) { | 177 | ) { |
| 178 | use crate::timer::sealed::GeneralPurpose32bitInstance; | 178 | use crate::timer::sealed::GeneralPurpose32bitInstance; |
| 179 | let raw_channel = channel.raw(); | 179 | let raw_channel = channel.raw(); |
| 180 | self.regs_gp32().ccmr_output(raw_channel / 2).modify(|w| w.set_ocm(raw_channel % 2, mode.into())); | 180 | Self::regs_gp32().ccmr_output(raw_channel / 2).modify(|w| w.set_ocm(raw_channel % 2, mode.into())); |
| 181 | } | 181 | } |
| 182 | 182 | ||
| 183 | unsafe fn enable_channel(&mut self, channel: Channel, enable: bool) { | 183 | unsafe fn enable_channel(&mut self, channel: Channel, enable: bool) { |
| 184 | use crate::timer::sealed::GeneralPurpose32bitInstance; | 184 | use crate::timer::sealed::GeneralPurpose32bitInstance; |
| 185 | self.regs_gp32().ccer().modify(|w| w.set_cce(channel.raw(), enable)); | 185 | Self::regs_gp32().ccer().modify(|w| w.set_cce(channel.raw(), enable)); |
| 186 | } | 186 | } |
| 187 | 187 | ||
| 188 | unsafe fn set_compare_value(&mut self, channel: Channel, value: u32) { | 188 | unsafe fn set_compare_value(&mut self, channel: Channel, value: u32) { |
| 189 | use crate::timer::sealed::GeneralPurpose32bitInstance; | 189 | use crate::timer::sealed::GeneralPurpose32bitInstance; |
| 190 | self.regs_gp32().ccr(channel.raw()).modify(|w| w.set_ccr(value)); | 190 | Self::regs_gp32().ccr(channel.raw()).modify(|w| w.set_ccr(value)); |
| 191 | } | 191 | } |
| 192 | 192 | ||
| 193 | unsafe fn get_max_compare_value(&self) -> u32 { | 193 | unsafe fn get_max_compare_value(&self) -> u32 { |
| 194 | use crate::timer::sealed::GeneralPurpose32bitInstance; | 194 | use crate::timer::sealed::GeneralPurpose32bitInstance; |
| 195 | self.regs_gp32().arr().read().arr() as u32 | 195 | Self::regs_gp32().arr().read().arr() as u32 |
| 196 | } | 196 | } |
| 197 | } | 197 | } |
| 198 | impl CaptureCompare16bitInstance for crate::peripherals::$inst { | 198 | impl CaptureCompare16bitInstance for crate::peripherals::$inst { |
| @@ -211,7 +211,7 @@ foreach_interrupt! { | |||
| 211 | mode: OutputCompareMode, | 211 | mode: OutputCompareMode, |
| 212 | ) { | 212 | ) { |
| 213 | use crate::timer::sealed::AdvancedControlInstance; | 213 | use crate::timer::sealed::AdvancedControlInstance; |
| 214 | let r = self.regs_advanced(); | 214 | let r = Self::regs_advanced(); |
| 215 | let raw_channel: usize = channel.raw(); | 215 | let raw_channel: usize = channel.raw(); |
| 216 | r.ccmr_output(raw_channel / 2) | 216 | r.ccmr_output(raw_channel / 2) |
| 217 | .modify(|w| w.set_ocm(raw_channel % 2, mode.into())); | 217 | .modify(|w| w.set_ocm(raw_channel % 2, mode.into())); |
| @@ -219,21 +219,21 @@ foreach_interrupt! { | |||
| 219 | 219 | ||
| 220 | unsafe fn enable_channel(&mut self, channel: Channel, enable: bool) { | 220 | unsafe fn enable_channel(&mut self, channel: Channel, enable: bool) { |
| 221 | use crate::timer::sealed::AdvancedControlInstance; | 221 | use crate::timer::sealed::AdvancedControlInstance; |
| 222 | self.regs_advanced() | 222 | Self::regs_advanced() |
| 223 | .ccer() | 223 | .ccer() |
| 224 | .modify(|w| w.set_cce(channel.raw(), enable)); | 224 | .modify(|w| w.set_cce(channel.raw(), enable)); |
| 225 | } | 225 | } |
| 226 | 226 | ||
| 227 | unsafe fn set_compare_value(&mut self, channel: Channel, value: u16) { | 227 | unsafe fn set_compare_value(&mut self, channel: Channel, value: u16) { |
| 228 | use crate::timer::sealed::AdvancedControlInstance; | 228 | use crate::timer::sealed::AdvancedControlInstance; |
| 229 | self.regs_advanced() | 229 | Self::regs_advanced() |
| 230 | .ccr(channel.raw()) | 230 | .ccr(channel.raw()) |
| 231 | .modify(|w| w.set_ccr(value)); | 231 | .modify(|w| w.set_ccr(value)); |
| 232 | } | 232 | } |
| 233 | 233 | ||
| 234 | unsafe fn get_max_compare_value(&self) -> u16 { | 234 | unsafe fn get_max_compare_value(&self) -> u16 { |
| 235 | use crate::timer::sealed::AdvancedControlInstance; | 235 | use crate::timer::sealed::AdvancedControlInstance; |
| 236 | self.regs_advanced().arr().read().arr() | 236 | Self::regs_advanced().arr().read().arr() |
| 237 | } | 237 | } |
| 238 | } | 238 | } |
| 239 | 239 | ||
diff --git a/embassy-stm32/src/time_driver.rs b/embassy-stm32/src/time_driver.rs index 009c62030..08796acd5 100644 --- a/embassy-stm32/src/time_driver.rs +++ b/embassy-stm32/src/time_driver.rs | |||
| @@ -103,7 +103,6 @@ impl AlarmState { | |||
| 103 | } | 103 | } |
| 104 | 104 | ||
| 105 | struct RtcDriver { | 105 | struct RtcDriver { |
| 106 | timer: T, | ||
| 107 | /// Number of 2^15 periods elapsed since boot. | 106 | /// Number of 2^15 periods elapsed since boot. |
| 108 | period: AtomicU32, | 107 | period: AtomicU32, |
| 109 | alarm_count: AtomicU8, | 108 | alarm_count: AtomicU8, |
| @@ -114,7 +113,6 @@ struct RtcDriver { | |||
| 114 | const ALARM_STATE_NEW: AlarmState = AlarmState::new(); | 113 | const ALARM_STATE_NEW: AlarmState = AlarmState::new(); |
| 115 | 114 | ||
| 116 | embassy::time_driver_impl!(static DRIVER: RtcDriver = RtcDriver { | 115 | embassy::time_driver_impl!(static DRIVER: RtcDriver = RtcDriver { |
| 117 | timer: unsafe { core::mem::transmute(()) }, // steal is not const | ||
| 118 | period: AtomicU32::new(0), | 116 | period: AtomicU32::new(0), |
| 119 | alarm_count: AtomicU8::new(0), | 117 | alarm_count: AtomicU8::new(0), |
| 120 | alarms: Mutex::const_new(CriticalSectionRawMutex::new(), [ALARM_STATE_NEW; ALARM_COUNT]), | 118 | alarms: Mutex::const_new(CriticalSectionRawMutex::new(), [ALARM_STATE_NEW; ALARM_COUNT]), |
| @@ -122,7 +120,7 @@ embassy::time_driver_impl!(static DRIVER: RtcDriver = RtcDriver { | |||
| 122 | 120 | ||
| 123 | impl RtcDriver { | 121 | impl RtcDriver { |
| 124 | fn init(&'static self) { | 122 | fn init(&'static self) { |
| 125 | let r = self.timer.regs_gp16(); | 123 | let r = T::regs_gp16(); |
| 126 | 124 | ||
| 127 | <T as RccPeripheral>::enable(); | 125 | <T as RccPeripheral>::enable(); |
| 128 | <T as RccPeripheral>::reset(); | 126 | <T as RccPeripheral>::reset(); |
| @@ -163,7 +161,7 @@ impl RtcDriver { | |||
| 163 | } | 161 | } |
| 164 | 162 | ||
| 165 | fn on_interrupt(&self) { | 163 | fn on_interrupt(&self) { |
| 166 | let r = self.timer.regs_gp16(); | 164 | let r = T::regs_gp16(); |
| 167 | 165 | ||
| 168 | // NOTE(unsafe) Use critical section to access the methods | 166 | // NOTE(unsafe) Use critical section to access the methods |
| 169 | // XXX: reduce the size of this critical section ? | 167 | // XXX: reduce the size of this critical section ? |
| @@ -194,7 +192,7 @@ impl RtcDriver { | |||
| 194 | } | 192 | } |
| 195 | 193 | ||
| 196 | fn next_period(&self) { | 194 | fn next_period(&self) { |
| 197 | let r = self.timer.regs_gp16(); | 195 | let r = T::regs_gp16(); |
| 198 | 196 | ||
| 199 | let period = self.period.fetch_add(1, Ordering::Relaxed) + 1; | 197 | let period = self.period.fetch_add(1, Ordering::Relaxed) + 1; |
| 200 | let t = (period as u64) << 15; | 198 | let t = (period as u64) << 15; |
| @@ -236,7 +234,7 @@ impl RtcDriver { | |||
| 236 | 234 | ||
| 237 | impl Driver for RtcDriver { | 235 | impl Driver for RtcDriver { |
| 238 | fn now(&self) -> u64 { | 236 | fn now(&self) -> u64 { |
| 239 | let r = self.timer.regs_gp16(); | 237 | let r = T::regs_gp16(); |
| 240 | 238 | ||
| 241 | let period = self.period.load(Ordering::Relaxed); | 239 | let period = self.period.load(Ordering::Relaxed); |
| 242 | compiler_fence(Ordering::Acquire); | 240 | compiler_fence(Ordering::Acquire); |
| @@ -273,7 +271,7 @@ impl Driver for RtcDriver { | |||
| 273 | 271 | ||
| 274 | fn set_alarm(&self, alarm: AlarmHandle, timestamp: u64) { | 272 | fn set_alarm(&self, alarm: AlarmHandle, timestamp: u64) { |
| 275 | critical_section::with(|cs| { | 273 | critical_section::with(|cs| { |
| 276 | let r = self.timer.regs_gp16(); | 274 | let r = T::regs_gp16(); |
| 277 | 275 | ||
| 278 | let n = alarm.id() as _; | 276 | let n = alarm.id() as _; |
| 279 | let alarm = self.get_alarm(cs, alarm); | 277 | let alarm = self.get_alarm(cs, alarm); |
diff --git a/embassy-stm32/src/timer/mod.rs b/embassy-stm32/src/timer/mod.rs index 4c1eb946b..f9fefdf73 100644 --- a/embassy-stm32/src/timer/mod.rs +++ b/embassy-stm32/src/timer/mod.rs | |||
| @@ -14,7 +14,7 @@ pub(crate) mod sealed { | |||
| 14 | pub trait Basic16bitInstance: RccPeripheral { | 14 | pub trait Basic16bitInstance: RccPeripheral { |
| 15 | type Interrupt: Interrupt; | 15 | type Interrupt: Interrupt; |
| 16 | 16 | ||
| 17 | fn regs(&self) -> crate::pac::timer::TimBasic; | 17 | fn regs() -> crate::pac::timer::TimBasic; |
| 18 | 18 | ||
| 19 | fn start(&mut self); | 19 | fn start(&mut self); |
| 20 | 20 | ||
| @@ -30,17 +30,17 @@ pub(crate) mod sealed { | |||
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | pub trait GeneralPurpose16bitInstance: Basic16bitInstance { | 32 | pub trait GeneralPurpose16bitInstance: Basic16bitInstance { |
| 33 | fn regs_gp16(&self) -> crate::pac::timer::TimGp16; | 33 | fn regs_gp16() -> crate::pac::timer::TimGp16; |
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | pub trait GeneralPurpose32bitInstance: GeneralPurpose16bitInstance { | 36 | pub trait GeneralPurpose32bitInstance: GeneralPurpose16bitInstance { |
| 37 | fn regs_gp32(&self) -> crate::pac::timer::TimGp32; | 37 | fn regs_gp32() -> crate::pac::timer::TimGp32; |
| 38 | 38 | ||
| 39 | fn set_frequency<F: Into<Hertz>>(&mut self, frequency: F); | 39 | fn set_frequency<F: Into<Hertz>>(&mut self, frequency: F); |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | pub trait AdvancedControlInstance: Basic16bitInstance { | 42 | pub trait AdvancedControlInstance: Basic16bitInstance { |
| 43 | fn regs_advanced(&self) -> crate::pac::timer::TimAdv; | 43 | fn regs_advanced() -> crate::pac::timer::TimAdv; |
| 44 | } | 44 | } |
| 45 | } | 45 | } |
| 46 | 46 | ||
| @@ -58,26 +58,25 @@ macro_rules! impl_basic_16bit_timer { | |||
| 58 | impl sealed::Basic16bitInstance for crate::peripherals::$inst { | 58 | impl sealed::Basic16bitInstance for crate::peripherals::$inst { |
| 59 | type Interrupt = crate::interrupt::$irq; | 59 | type Interrupt = crate::interrupt::$irq; |
| 60 | 60 | ||
| 61 | fn regs(&self) -> crate::pac::timer::TimBasic { | 61 | fn regs() -> crate::pac::timer::TimBasic { |
| 62 | crate::pac::timer::TimBasic(crate::pac::$inst.0) | 62 | crate::pac::timer::TimBasic(crate::pac::$inst.0) |
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | fn start(&mut self) { | 65 | fn start(&mut self) { |
| 66 | unsafe { | 66 | unsafe { |
| 67 | self.regs().cr1().modify(|r| r.set_cen(true)); | 67 | Self::regs().cr1().modify(|r| r.set_cen(true)); |
| 68 | } | 68 | } |
| 69 | } | 69 | } |
| 70 | 70 | ||
| 71 | fn stop(&mut self) { | 71 | fn stop(&mut self) { |
| 72 | let regs = self.regs(); | ||
| 73 | unsafe { | 72 | unsafe { |
| 74 | regs.cr1().modify(|r| r.set_cen(false)); | 73 | Self::regs().cr1().modify(|r| r.set_cen(false)); |
| 75 | } | 74 | } |
| 76 | } | 75 | } |
| 77 | 76 | ||
| 78 | fn reset(&mut self) { | 77 | fn reset(&mut self) { |
| 79 | unsafe { | 78 | unsafe { |
| 80 | self.regs().cnt().write(|r| r.set_cnt(0)); | 79 | Self::regs().cnt().write(|r| r.set_cnt(0)); |
| 81 | } | 80 | } |
| 82 | } | 81 | } |
| 83 | 82 | ||
| @@ -90,7 +89,7 @@ macro_rules! impl_basic_16bit_timer { | |||
| 90 | let arr: u16 = | 89 | let arr: u16 = |
| 91 | unwrap!((pclk_ticks_per_timer_period / (u32::from(psc) + 1)).try_into()); | 90 | unwrap!((pclk_ticks_per_timer_period / (u32::from(psc) + 1)).try_into()); |
| 92 | 91 | ||
| 93 | let regs = self.regs(); | 92 | let regs = Self::regs(); |
| 94 | unsafe { | 93 | unsafe { |
| 95 | regs.psc().write(|r| r.set_psc(psc)); | 94 | regs.psc().write(|r| r.set_psc(psc)); |
| 96 | regs.arr().write(|r| r.set_arr(arr)); | 95 | regs.arr().write(|r| r.set_arr(arr)); |
| @@ -102,10 +101,11 @@ macro_rules! impl_basic_16bit_timer { | |||
| 102 | } | 101 | } |
| 103 | 102 | ||
| 104 | fn clear_update_interrupt(&mut self) -> bool { | 103 | fn clear_update_interrupt(&mut self) -> bool { |
| 104 | let regs = Self::regs(); | ||
| 105 | unsafe { | 105 | unsafe { |
| 106 | let sr = self.regs().sr().read(); | 106 | let sr = regs.sr().read(); |
| 107 | if sr.uif() { | 107 | if sr.uif() { |
| 108 | self.regs().sr().modify(|r| { | 108 | regs.sr().modify(|r| { |
| 109 | r.set_uif(false); | 109 | r.set_uif(false); |
| 110 | }); | 110 | }); |
| 111 | true | 111 | true |
| @@ -117,7 +117,7 @@ macro_rules! impl_basic_16bit_timer { | |||
| 117 | 117 | ||
| 118 | fn enable_update_interrupt(&mut self, enable: bool) { | 118 | fn enable_update_interrupt(&mut self, enable: bool) { |
| 119 | unsafe { | 119 | unsafe { |
| 120 | self.regs().dier().write(|r| r.set_uie(enable)); | 120 | Self::regs().dier().write(|r| r.set_uie(enable)); |
| 121 | } | 121 | } |
| 122 | } | 122 | } |
| 123 | } | 123 | } |
| @@ -128,7 +128,7 @@ macro_rules! impl_basic_16bit_timer { | |||
| 128 | macro_rules! impl_32bit_timer { | 128 | macro_rules! impl_32bit_timer { |
| 129 | ($inst:ident) => { | 129 | ($inst:ident) => { |
| 130 | impl sealed::GeneralPurpose32bitInstance for crate::peripherals::$inst { | 130 | impl sealed::GeneralPurpose32bitInstance for crate::peripherals::$inst { |
| 131 | fn regs_gp32(&self) -> crate::pac::timer::TimGp32 { | 131 | fn regs_gp32() -> crate::pac::timer::TimGp32 { |
| 132 | crate::pac::$inst | 132 | crate::pac::$inst |
| 133 | } | 133 | } |
| 134 | 134 | ||
| @@ -141,7 +141,7 @@ macro_rules! impl_32bit_timer { | |||
| 141 | let arr: u32 = | 141 | let arr: u32 = |
| 142 | unwrap!(((pclk_ticks_per_timer_period / (psc as u64 + 1)).try_into())); | 142 | unwrap!(((pclk_ticks_per_timer_period / (psc as u64 + 1)).try_into())); |
| 143 | 143 | ||
| 144 | let regs = self.regs_gp32(); | 144 | let regs = Self::regs_gp32(); |
| 145 | unsafe { | 145 | unsafe { |
| 146 | regs.psc().write(|r| r.set_psc(psc)); | 146 | regs.psc().write(|r| r.set_psc(psc)); |
| 147 | regs.arr().write(|r| r.set_arr(arr)); | 147 | regs.arr().write(|r| r.set_arr(arr)); |
| @@ -169,7 +169,7 @@ foreach_interrupt! { | |||
| 169 | } | 169 | } |
| 170 | 170 | ||
| 171 | impl sealed::GeneralPurpose16bitInstance for crate::peripherals::$inst { | 171 | impl sealed::GeneralPurpose16bitInstance for crate::peripherals::$inst { |
| 172 | fn regs_gp16(&self) -> crate::pac::timer::TimGp16 { | 172 | fn regs_gp16() -> crate::pac::timer::TimGp16 { |
| 173 | crate::pac::$inst | 173 | crate::pac::$inst |
| 174 | } | 174 | } |
| 175 | } | 175 | } |
| @@ -185,7 +185,7 @@ foreach_interrupt! { | |||
| 185 | } | 185 | } |
| 186 | 186 | ||
| 187 | impl sealed::GeneralPurpose16bitInstance for crate::peripherals::$inst { | 187 | impl sealed::GeneralPurpose16bitInstance for crate::peripherals::$inst { |
| 188 | fn regs_gp16(&self) -> crate::pac::timer::TimGp16 { | 188 | fn regs_gp16() -> crate::pac::timer::TimGp16 { |
| 189 | crate::pac::timer::TimGp16(crate::pac::$inst.0) | 189 | crate::pac::timer::TimGp16(crate::pac::$inst.0) |
| 190 | } | 190 | } |
| 191 | } | 191 | } |
| @@ -206,7 +206,7 @@ foreach_interrupt! { | |||
| 206 | } | 206 | } |
| 207 | 207 | ||
| 208 | impl sealed::AdvancedControlInstance for crate::peripherals::$inst { | 208 | impl sealed::AdvancedControlInstance for crate::peripherals::$inst { |
| 209 | fn regs_advanced(&self) -> crate::pac::timer::TimAdv { | 209 | fn regs_advanced() -> crate::pac::timer::TimAdv { |
| 210 | crate::pac::$inst | 210 | crate::pac::$inst |
| 211 | } | 211 | } |
| 212 | } | 212 | } |
diff --git a/examples/stm32h7/src/bin/low_level_timer_api.rs b/examples/stm32h7/src/bin/low_level_timer_api.rs index 0c99b0941..3a47dc22b 100644 --- a/examples/stm32h7/src/bin/low_level_timer_api.rs +++ b/examples/stm32h7/src/bin/low_level_timer_api.rs | |||
| @@ -90,20 +90,16 @@ impl<'d, T: CaptureCompare32bitInstance> SimplePwm32<'d, T> { | |||
| 90 | this.inner.start(); | 90 | this.inner.start(); |
| 91 | 91 | ||
| 92 | unsafe { | 92 | unsafe { |
| 93 | this.inner | 93 | T::regs_gp32() |
| 94 | .regs_gp32() | ||
| 95 | .ccmr_output(0) | 94 | .ccmr_output(0) |
| 96 | .modify(|w| w.set_ocm(0, OutputCompareMode::PwmMode1.into())); | 95 | .modify(|w| w.set_ocm(0, OutputCompareMode::PwmMode1.into())); |
| 97 | this.inner | 96 | T::regs_gp32() |
| 98 | .regs_gp32() | ||
| 99 | .ccmr_output(0) | 97 | .ccmr_output(0) |
| 100 | .modify(|w| w.set_ocm(1, OutputCompareMode::PwmMode1.into())); | 98 | .modify(|w| w.set_ocm(1, OutputCompareMode::PwmMode1.into())); |
| 101 | this.inner | 99 | T::regs_gp32() |
| 102 | .regs_gp32() | ||
| 103 | .ccmr_output(1) | 100 | .ccmr_output(1) |
| 104 | .modify(|w| w.set_ocm(0, OutputCompareMode::PwmMode1.into())); | 101 | .modify(|w| w.set_ocm(0, OutputCompareMode::PwmMode1.into())); |
| 105 | this.inner | 102 | T::regs_gp32() |
| 106 | .regs_gp32() | ||
| 107 | .ccmr_output(1) | 103 | .ccmr_output(1) |
| 108 | .modify(|w| w.set_ocm(1, OutputCompareMode::PwmMode1.into())); | 104 | .modify(|w| w.set_ocm(1, OutputCompareMode::PwmMode1.into())); |
| 109 | } | 105 | } |
| @@ -112,8 +108,7 @@ impl<'d, T: CaptureCompare32bitInstance> SimplePwm32<'d, T> { | |||
| 112 | 108 | ||
| 113 | pub fn enable(&mut self, channel: Channel) { | 109 | pub fn enable(&mut self, channel: Channel) { |
| 114 | unsafe { | 110 | unsafe { |
| 115 | self.inner | 111 | T::regs_gp32() |
| 116 | .regs_gp32() | ||
| 117 | .ccer() | 112 | .ccer() |
| 118 | .modify(|w| w.set_cce(channel.raw(), true)); | 113 | .modify(|w| w.set_cce(channel.raw(), true)); |
| 119 | } | 114 | } |
| @@ -121,8 +116,7 @@ impl<'d, T: CaptureCompare32bitInstance> SimplePwm32<'d, T> { | |||
| 121 | 116 | ||
| 122 | pub fn disable(&mut self, channel: Channel) { | 117 | pub fn disable(&mut self, channel: Channel) { |
| 123 | unsafe { | 118 | unsafe { |
| 124 | self.inner | 119 | T::regs_gp32() |
| 125 | .regs_gp32() | ||
| 126 | .ccer() | 120 | .ccer() |
| 127 | .modify(|w| w.set_cce(channel.raw(), false)); | 121 | .modify(|w| w.set_cce(channel.raw(), false)); |
| 128 | } | 122 | } |
| @@ -136,14 +130,13 @@ impl<'d, T: CaptureCompare32bitInstance> SimplePwm32<'d, T> { | |||
| 136 | } | 130 | } |
| 137 | 131 | ||
| 138 | pub fn get_max_duty(&self) -> u32 { | 132 | pub fn get_max_duty(&self) -> u32 { |
| 139 | unsafe { self.inner.regs_gp32().arr().read().arr() } | 133 | unsafe { T::regs_gp32().arr().read().arr() } |
| 140 | } | 134 | } |
| 141 | 135 | ||
| 142 | pub fn set_duty(&mut self, channel: Channel, duty: u32) { | 136 | pub fn set_duty(&mut self, channel: Channel, duty: u32) { |
| 143 | defmt::assert!(duty < self.get_max_duty()); | 137 | defmt::assert!(duty < self.get_max_duty()); |
| 144 | unsafe { | 138 | unsafe { |
| 145 | self.inner | 139 | T::regs_gp32() |
| 146 | .regs_gp32() | ||
| 147 | .ccr(channel.raw()) | 140 | .ccr(channel.raw()) |
| 148 | .modify(|w| w.set_ccr(duty)) | 141 | .modify(|w| w.set_ccr(duty)) |
| 149 | } | 142 | } |
