aboutsummaryrefslogtreecommitdiff
path: root/examples/stm32h7/src/bin/low_level_timer_api.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/stm32h7/src/bin/low_level_timer_api.rs')
-rw-r--r--examples/stm32h7/src/bin/low_level_timer_api.rs24
1 files changed, 9 insertions, 15 deletions
diff --git a/examples/stm32h7/src/bin/low_level_timer_api.rs b/examples/stm32h7/src/bin/low_level_timer_api.rs
index fc19d84e4..d7c6da5bd 100644
--- a/examples/stm32h7/src/bin/low_level_timer_api.rs
+++ b/examples/stm32h7/src/bin/low_level_timer_api.rs
@@ -2,8 +2,6 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use core::marker::PhantomData;
6
7use defmt::*; 5use defmt::*;
8use embassy::executor::Spawner; 6use embassy::executor::Spawner;
9use embassy::time::{Duration, Timer}; 7use embassy::time::{Duration, Timer};
@@ -11,7 +9,7 @@ use embassy_stm32::gpio::low_level::AFType;
11use embassy_stm32::gpio::Speed; 9use embassy_stm32::gpio::Speed;
12use embassy_stm32::pwm::*; 10use embassy_stm32::pwm::*;
13use embassy_stm32::time::{khz, mhz, Hertz}; 11use embassy_stm32::time::{khz, mhz, Hertz};
14use embassy_stm32::{unborrow, Config, Peripherals, Unborrow}; 12use embassy_stm32::{into_ref, Config, Peripheral, PeripheralRef, Peripherals};
15use {defmt_rtt as _, panic_probe as _}; 13use {defmt_rtt as _, panic_probe as _};
16 14
17pub fn config() -> Config { 15pub fn config() -> Config {
@@ -49,20 +47,19 @@ async fn main(_spawner: Spawner, p: Peripherals) {
49 } 47 }
50} 48}
51pub struct SimplePwm32<'d, T: CaptureCompare32bitInstance> { 49pub struct SimplePwm32<'d, T: CaptureCompare32bitInstance> {
52 phantom: PhantomData<&'d mut T>, 50 inner: PeripheralRef<'d, T>,
53 inner: T,
54} 51}
55 52
56impl<'d, T: CaptureCompare32bitInstance> SimplePwm32<'d, T> { 53impl<'d, T: CaptureCompare32bitInstance> SimplePwm32<'d, T> {
57 pub fn new( 54 pub fn new(
58 tim: impl Unborrow<Target = T> + 'd, 55 tim: impl Peripheral<P = T> + 'd,
59 ch1: impl Unborrow<Target = impl Channel1Pin<T>> + 'd, 56 ch1: impl Peripheral<P = impl Channel1Pin<T>> + 'd,
60 ch2: impl Unborrow<Target = impl Channel2Pin<T>> + 'd, 57 ch2: impl Peripheral<P = impl Channel2Pin<T>> + 'd,
61 ch3: impl Unborrow<Target = impl Channel3Pin<T>> + 'd, 58 ch3: impl Peripheral<P = impl Channel3Pin<T>> + 'd,
62 ch4: impl Unborrow<Target = impl Channel4Pin<T>> + 'd, 59 ch4: impl Peripheral<P = impl Channel4Pin<T>> + 'd,
63 freq: Hertz, 60 freq: Hertz,
64 ) -> Self { 61 ) -> Self {
65 unborrow!(tim, ch1, ch2, ch3, ch4); 62 into_ref!(tim, ch1, ch2, ch3, ch4);
66 63
67 T::enable(); 64 T::enable();
68 <T as embassy_stm32::rcc::low_level::RccPeripheral>::reset(); 65 <T as embassy_stm32::rcc::low_level::RccPeripheral>::reset();
@@ -78,10 +75,7 @@ impl<'d, T: CaptureCompare32bitInstance> SimplePwm32<'d, T> {
78 ch4.set_as_af(ch1.af_num(), AFType::OutputPushPull); 75 ch4.set_as_af(ch1.af_num(), AFType::OutputPushPull);
79 } 76 }
80 77
81 let mut this = Self { 78 let mut this = Self { inner: tim };
82 inner: tim,
83 phantom: PhantomData,
84 };
85 79
86 this.set_freq(freq); 80 this.set_freq(freq);
87 this.inner.start(); 81 this.inner.start();