aboutsummaryrefslogtreecommitdiff
path: root/examples/stm32h7/src/bin/low_level_timer_api.rs
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2022-02-10 21:38:03 +0100
committerDario Nieuwenhuis <[email protected]>2022-02-10 21:38:03 +0100
commitb99ab3d5d9d8fdee135956dcbc2111b00abd1d72 (patch)
tree53f3723e24ba49b98f0a792aa9835141ef56729e /examples/stm32h7/src/bin/low_level_timer_api.rs
parent9d682aa1fae81d9bb56bb41304828144b9a0d4a7 (diff)
stm32: Add standard crate-wide macros for pin/dma traits, switch all drivers to use them.
Diffstat (limited to 'examples/stm32h7/src/bin/low_level_timer_api.rs')
-rw-r--r--examples/stm32h7/src/bin/low_level_timer_api.rs21
1 files changed, 13 insertions, 8 deletions
diff --git a/examples/stm32h7/src/bin/low_level_timer_api.rs b/examples/stm32h7/src/bin/low_level_timer_api.rs
index 1bf69104d..0c99b0941 100644
--- a/examples/stm32h7/src/bin/low_level_timer_api.rs
+++ b/examples/stm32h7/src/bin/low_level_timer_api.rs
@@ -10,9 +10,10 @@ use embassy::executor::Spawner;
10use embassy::time::{Duration, Timer}; 10use embassy::time::{Duration, Timer};
11use embassy::util::Unborrow; 11use embassy::util::Unborrow;
12use embassy_hal_common::unborrow; 12use embassy_hal_common::unborrow;
13use embassy_stm32::pwm::{pins::*, Channel, OutputCompareMode}; 13use embassy_stm32::gpio::low_level::AFType;
14use embassy_stm32::gpio::Speed;
15use embassy_stm32::pwm::*;
14use embassy_stm32::time::{Hertz, U32Ext}; 16use embassy_stm32::time::{Hertz, U32Ext};
15use embassy_stm32::timer::GeneralPurpose32bitInstance;
16use embassy_stm32::{Config, Peripherals}; 17use embassy_stm32::{Config, Peripherals};
17use example_common::*; 18use example_common::*;
18 19
@@ -50,12 +51,12 @@ async fn main(_spawner: Spawner, p: Peripherals) {
50 Timer::after(Duration::from_millis(300)).await; 51 Timer::after(Duration::from_millis(300)).await;
51 } 52 }
52} 53}
53pub struct SimplePwm32<'d, T: GeneralPurpose32bitInstance> { 54pub struct SimplePwm32<'d, T: CaptureCompare32bitInstance> {
54 phantom: PhantomData<&'d mut T>, 55 phantom: PhantomData<&'d mut T>,
55 inner: T, 56 inner: T,
56} 57}
57 58
58impl<'d, T: GeneralPurpose32bitInstance> SimplePwm32<'d, T> { 59impl<'d, T: CaptureCompare32bitInstance> SimplePwm32<'d, T> {
59 pub fn new<F: Into<Hertz>>( 60 pub fn new<F: Into<Hertz>>(
60 tim: impl Unborrow<Target = T> + 'd, 61 tim: impl Unborrow<Target = T> + 'd,
61 ch1: impl Unborrow<Target = impl Channel1Pin<T>> + 'd, 62 ch1: impl Unborrow<Target = impl Channel1Pin<T>> + 'd,
@@ -70,10 +71,14 @@ impl<'d, T: GeneralPurpose32bitInstance> SimplePwm32<'d, T> {
70 <T as embassy_stm32::rcc::low_level::RccPeripheral>::reset(); 71 <T as embassy_stm32::rcc::low_level::RccPeripheral>::reset();
71 72
72 unsafe { 73 unsafe {
73 ch1.configure(); 74 ch1.set_speed(Speed::VeryHigh);
74 ch2.configure(); 75 ch1.set_as_af(ch1.af_num(), AFType::OutputPushPull);
75 ch3.configure(); 76 ch2.set_speed(Speed::VeryHigh);
76 ch4.configure(); 77 ch2.set_as_af(ch1.af_num(), AFType::OutputPushPull);
78 ch3.set_speed(Speed::VeryHigh);
79 ch3.set_as_af(ch1.af_num(), AFType::OutputPushPull);
80 ch4.set_speed(Speed::VeryHigh);
81 ch4.set_as_af(ch1.af_num(), AFType::OutputPushPull);
77 } 82 }
78 83
79 let mut this = Self { 84 let mut this = Self {