aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-stm32/src/timer/input_capture.rs1
-rw-r--r--examples/stm32f4/Cargo.toml2
-rw-r--r--examples/stm32f4/src/bin/input_capture.rs29
3 files changed, 18 insertions, 14 deletions
diff --git a/embassy-stm32/src/timer/input_capture.rs b/embassy-stm32/src/timer/input_capture.rs
index 6401656c8..bf26cabc6 100644
--- a/embassy-stm32/src/timer/input_capture.rs
+++ b/embassy-stm32/src/timer/input_capture.rs
@@ -3,7 +3,6 @@
3use core::marker::PhantomData; 3use core::marker::PhantomData;
4 4
5use embassy_hal_internal::{into_ref, PeripheralRef}; 5use embassy_hal_internal::{into_ref, PeripheralRef};
6use embassy_sync::channel;
7 6
8use super::low_level::{CountingMode, InputCaptureMode, InputTISelection, Timer}; 7use super::low_level::{CountingMode, InputCaptureMode, InputTISelection, Timer};
9use super::{Channel, Channel1Pin, Channel2Pin, Channel3Pin, Channel4Pin, GeneralInstance4Channel}; 8use super::{Channel, Channel1Pin, Channel2Pin, Channel3Pin, Channel4Pin, GeneralInstance4Channel};
diff --git a/examples/stm32f4/Cargo.toml b/examples/stm32f4/Cargo.toml
index 64ac50818..5469f0cc6 100644
--- a/examples/stm32f4/Cargo.toml
+++ b/examples/stm32f4/Cargo.toml
@@ -6,7 +6,7 @@ license = "MIT OR Apache-2.0"
6 6
7[dependencies] 7[dependencies]
8# Change stm32f429zi to your chip name, if necessary. 8# Change stm32f429zi to your chip name, if necessary.
9embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32f429zi", "unstable-pac", "memory-x", "time-driver-any", "exti", "chrono"] } 9embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32f446re", "unstable-pac", "memory-x", "time-driver-any", "exti", "chrono"] }
10embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["defmt"] } 10embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["defmt"] }
11embassy-executor = { version = "0.5.0", path = "../../embassy-executor", features = ["task-arena-size-32768", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] } 11embassy-executor = { version = "0.5.0", path = "../../embassy-executor", features = ["task-arena-size-32768", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] }
12embassy-time = { version = "0.3.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } 12embassy-time = { version = "0.3.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] }
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}