aboutsummaryrefslogtreecommitdiff
path: root/examples/stm32f4/src/bin/input_capture.rs
diff options
context:
space:
mode:
authorBruno Bousquet <[email protected]>2024-05-05 22:30:16 -0400
committerBruno Bousquet <[email protected]>2024-05-05 22:30:16 -0400
commit431a60ca6384a77243d33f5b1bbef878267bea49 (patch)
tree4358e4e9c5ff4d36e1d861d823b69feb66c5b5da /examples/stm32f4/src/bin/input_capture.rs
parentad66dc3aabe6ac11dd0f3aa4d9f403e3aac7e8f4 (diff)
formatting
Diffstat (limited to 'examples/stm32f4/src/bin/input_capture.rs')
-rw-r--r--examples/stm32f4/src/bin/input_capture.rs29
1 files changed, 17 insertions, 12 deletions
diff --git a/examples/stm32f4/src/bin/input_capture.rs b/examples/stm32f4/src/bin/input_capture.rs
index 202f363fc..714f043b6 100644
--- a/examples/stm32f4/src/bin/input_capture.rs
+++ b/examples/stm32f4/src/bin/input_capture.rs
@@ -3,17 +3,14 @@
3 3
4use defmt::*; 4use defmt::*;
5use embassy_executor::Spawner; 5use embassy_executor::Spawner;
6use embassy_stm32::{ 6use embassy_stm32::gpio::{Level, Output, Pull, Speed};
7 gpio::{self, Level, Output, Speed}, 7use embassy_stm32::time::khz;
8 time::Hertz, 8use embassy_stm32::timer::input_capture::{CapturePin, InputCapture};
9}; 9use embassy_stm32::timer::Channel;
10use embassy_time::Timer; 10use embassy_time::Timer;
11use {defmt_rtt as _, panic_probe as _}; 11use {defmt_rtt as _, panic_probe as _};
12 12
13use embassy_stm32::timer::{ 13/// Connect PB2 and PB10 with a 1k Ohm resistor
14 input_capture::{CapturePin, InputCapture},
15 Channel,
16};
17 14
18#[embassy_executor::main] 15#[embassy_executor::main]
19async fn main(_spawner: Spawner) { 16async fn main(_spawner: Spawner) {
@@ -22,9 +19,11 @@ async fn main(_spawner: Spawner) {
22 19
23 let mut led = Output::new(p.PB2, Level::High, Speed::Low); 20 let mut led = Output::new(p.PB2, Level::High, Speed::Low);
24 21
25 let ic = CapturePin::new_ch3(p.PB10, gpio::Pull::None); 22 let ch3 = CapturePin::new_ch3(p.PB10, Pull::None);
26 let drv = InputCapture::new(p.TIM2, None, None, Some(ic), None, Hertz::mhz(1), Default::default()); 23 let mut ic = InputCapture::new(p.TIM2, None, None, Some(ch3), None, khz(1000), Default::default());
27 let mut _last: u32; 24 ic.enable(Channel::Ch3);
25
26 let mut last = 0;
28 27
29 loop { 28 loop {
30 info!("high"); 29 info!("high");
@@ -34,6 +33,12 @@ async fn main(_spawner: Spawner) {
34 info!("low"); 33 info!("low");
35 led.set_low(); 34 led.set_low();
36 Timer::after_millis(300).await; 35 Timer::after_millis(300).await;
37 _last = drv.get_capture_value(Channel::Ch1); 36
37 // Check for input capture
38 let cap = ic.get_capture_value(Channel::Ch3);
39 if cap != last {
40 info!("New capture!");
41 last = cap;
42 }
38 } 43 }
39} 44}