aboutsummaryrefslogtreecommitdiff
path: root/examples/stm32h7/src/bin/low_level_timer_api.rs
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2024-03-23 01:38:51 +0100
committerDario Nieuwenhuis <[email protected]>2024-03-23 01:38:51 +0100
commit2bca875b5f72578cbd20404010d174795d263313 (patch)
treea5d2175fdb8c7d10e298e5b5eaad70fe9301e5ee /examples/stm32h7/src/bin/low_level_timer_api.rs
parent389cbc0a77daea15decae706818f104d89446020 (diff)
stm32: use private_bounds for sealed traits.
Diffstat (limited to 'examples/stm32h7/src/bin/low_level_timer_api.rs')
-rw-r--r--examples/stm32h7/src/bin/low_level_timer_api.rs37
1 files changed, 25 insertions, 12 deletions
diff --git a/examples/stm32h7/src/bin/low_level_timer_api.rs b/examples/stm32h7/src/bin/low_level_timer_api.rs
index 780fbc6f0..a95b44b74 100644
--- a/examples/stm32h7/src/bin/low_level_timer_api.rs
+++ b/examples/stm32h7/src/bin/low_level_timer_api.rs
@@ -3,8 +3,7 @@
3 3
4use defmt::*; 4use defmt::*;
5use embassy_executor::Spawner; 5use embassy_executor::Spawner;
6use embassy_stm32::gpio::low_level::AFType; 6use embassy_stm32::gpio::{AFType, Flex, Pull, Speed};
7use embassy_stm32::gpio::Speed;
8use embassy_stm32::time::{khz, Hertz}; 7use embassy_stm32::time::{khz, Hertz};
9use embassy_stm32::timer::low_level::{OutputCompareMode, Timer as LLTimer}; 8use embassy_stm32::timer::low_level::{OutputCompareMode, Timer as LLTimer};
10use embassy_stm32::timer::{Channel, Channel1Pin, Channel2Pin, Channel3Pin, Channel4Pin, GeneralInstance32bit4Channel}; 9use embassy_stm32::timer::{Channel, Channel1Pin, Channel2Pin, Channel3Pin, Channel4Pin, GeneralInstance32bit4Channel};
@@ -59,6 +58,10 @@ async fn main(_spawner: Spawner) {
59} 58}
60pub struct SimplePwm32<'d, T: GeneralInstance32bit4Channel> { 59pub struct SimplePwm32<'d, T: GeneralInstance32bit4Channel> {
61 tim: LLTimer<'d, T>, 60 tim: LLTimer<'d, T>,
61 _ch1: Flex<'d>,
62 _ch2: Flex<'d>,
63 _ch3: Flex<'d>,
64 _ch4: Flex<'d>,
62} 65}
63 66
64impl<'d, T: GeneralInstance32bit4Channel> SimplePwm32<'d, T> { 67impl<'d, T: GeneralInstance32bit4Channel> SimplePwm32<'d, T> {
@@ -72,16 +75,26 @@ impl<'d, T: GeneralInstance32bit4Channel> SimplePwm32<'d, T> {
72 ) -> Self { 75 ) -> Self {
73 into_ref!(ch1, ch2, ch3, ch4); 76 into_ref!(ch1, ch2, ch3, ch4);
74 77
75 ch1.set_speed(Speed::VeryHigh); 78 let af1 = ch1.af_num();
76 ch1.set_as_af(ch1.af_num(), AFType::OutputPushPull); 79 let af2 = ch2.af_num();
77 ch2.set_speed(Speed::VeryHigh); 80 let af3 = ch3.af_num();
78 ch2.set_as_af(ch1.af_num(), AFType::OutputPushPull); 81 let af4 = ch4.af_num();
79 ch3.set_speed(Speed::VeryHigh); 82 let mut ch1 = Flex::new(ch1);
80 ch3.set_as_af(ch1.af_num(), AFType::OutputPushPull); 83 let mut ch2 = Flex::new(ch2);
81 ch4.set_speed(Speed::VeryHigh); 84 let mut ch3 = Flex::new(ch3);
82 ch4.set_as_af(ch1.af_num(), AFType::OutputPushPull); 85 let mut ch4 = Flex::new(ch4);
83 86 ch1.set_as_af_unchecked(af1, AFType::OutputPushPull, Pull::None, Speed::VeryHigh);
84 let mut this = Self { tim: LLTimer::new(tim) }; 87 ch2.set_as_af_unchecked(af2, AFType::OutputPushPull, Pull::None, Speed::VeryHigh);
88 ch3.set_as_af_unchecked(af3, AFType::OutputPushPull, Pull::None, Speed::VeryHigh);
89 ch4.set_as_af_unchecked(af4, AFType::OutputPushPull, Pull::None, Speed::VeryHigh);
90
91 let mut this = Self {
92 tim: LLTimer::new(tim),
93 _ch1: ch1,
94 _ch2: ch2,
95 _ch3: ch3,
96 _ch4: ch4,
97 };
85 98
86 this.set_frequency(freq); 99 this.set_frequency(freq);
87 this.tim.start(); 100 this.tim.start();