From 431a60ca6384a77243d33f5b1bbef878267bea49 Mon Sep 17 00:00:00 2001 From: Bruno Bousquet <21108660+brunob45@users.noreply.github.com> Date: Sun, 5 May 2024 22:30:16 -0400 Subject: formatting --- examples/stm32f4/src/bin/input_capture.rs | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'examples/stm32f4/src') 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 @@ use defmt::*; use embassy_executor::Spawner; -use embassy_stm32::{ - gpio::{self, Level, Output, Speed}, - time::Hertz, -}; +use embassy_stm32::gpio::{Level, Output, Pull, Speed}; +use embassy_stm32::time::khz; +use embassy_stm32::timer::input_capture::{CapturePin, InputCapture}; +use embassy_stm32::timer::Channel; use embassy_time::Timer; use {defmt_rtt as _, panic_probe as _}; -use embassy_stm32::timer::{ - input_capture::{CapturePin, InputCapture}, - Channel, -}; +/// Connect PB2 and PB10 with a 1k Ohm resistor #[embassy_executor::main] async fn main(_spawner: Spawner) { @@ -22,9 +19,11 @@ async fn main(_spawner: Spawner) { let mut led = Output::new(p.PB2, Level::High, Speed::Low); - let ic = CapturePin::new_ch3(p.PB10, gpio::Pull::None); - let drv = InputCapture::new(p.TIM2, None, None, Some(ic), None, Hertz::mhz(1), Default::default()); - let mut _last: u32; + let ch3 = CapturePin::new_ch3(p.PB10, Pull::None); + let mut ic = InputCapture::new(p.TIM2, None, None, Some(ch3), None, khz(1000), Default::default()); + ic.enable(Channel::Ch3); + + let mut last = 0; loop { info!("high"); @@ -34,6 +33,12 @@ async fn main(_spawner: Spawner) { info!("low"); led.set_low(); Timer::after_millis(300).await; - _last = drv.get_capture_value(Channel::Ch1); + + // Check for input capture + let cap = ic.get_capture_value(Channel::Ch3); + if cap != last { + info!("New capture!"); + last = cap; + } } } -- cgit