From 29d6fa0a4aa3203e95cf81ada366cb0ccf593af4 Mon Sep 17 00:00:00 2001 From: Bruno Bousquet <21108660+brunob45@users.noreply.github.com> Date: Sun, 5 May 2024 23:00:48 -0400 Subject: add get_input_interrupt --- examples/stm32f4/src/bin/input_capture.rs | 39 ++++++++++++++++++------------- 1 file changed, 23 insertions(+), 16 deletions(-) (limited to 'examples') diff --git a/examples/stm32f4/src/bin/input_capture.rs b/examples/stm32f4/src/bin/input_capture.rs index 714f043b6..17f65c6b9 100644 --- a/examples/stm32f4/src/bin/input_capture.rs +++ b/examples/stm32f4/src/bin/input_capture.rs @@ -4,6 +4,7 @@ use defmt::*; use embassy_executor::Spawner; use embassy_stm32::gpio::{Level, Output, Pull, Speed}; +use embassy_stm32::peripherals::PB2; use embassy_stm32::time::khz; use embassy_stm32::timer::input_capture::{CapturePin, InputCapture}; use embassy_stm32::timer::Channel; @@ -12,18 +13,9 @@ use {defmt_rtt as _, panic_probe as _}; /// Connect PB2 and PB10 with a 1k Ohm resistor -#[embassy_executor::main] -async fn main(_spawner: Spawner) { - let p = embassy_stm32::init(Default::default()); - info!("Hello World!"); - - let mut led = Output::new(p.PB2, Level::High, Speed::Low); - - 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; +#[embassy_executor::task] +async fn blinky(led: PB2) { + let mut led = Output::new(led, Level::High, Speed::Low); loop { info!("high"); @@ -33,12 +25,27 @@ async fn main(_spawner: Spawner) { info!("low"); led.set_low(); Timer::after_millis(300).await; + } +} +#[embassy_executor::main] +async fn main(spawner: Spawner) { + let p = embassy_stm32::init(Default::default()); + info!("Hello World!"); + + unwrap!(spawner.spawn(blinky(p.PB2))); + + 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); + + loop { // Check for input capture - let cap = ic.get_capture_value(Channel::Ch3); - if cap != last { - info!("New capture!"); - last = cap; + if ic.get_input_interrupt(Channel::Ch3) { + let capture_value = ic.get_capture_value(Channel::Ch3); + info!("New capture! {}", capture_value); } + // Wait a little bit + Timer::after_millis(1).await; } } -- cgit