aboutsummaryrefslogtreecommitdiff
path: root/examples/stm32f4/src
diff options
context:
space:
mode:
authorBruno Bousquet <[email protected]>2024-05-05 23:00:48 -0400
committerBruno Bousquet <[email protected]>2024-05-05 23:00:48 -0400
commit29d6fa0a4aa3203e95cf81ada366cb0ccf593af4 (patch)
tree9c94a5a69b04a099dd50449b6ab932424c146749 /examples/stm32f4/src
parent431a60ca6384a77243d33f5b1bbef878267bea49 (diff)
add get_input_interrupt
Diffstat (limited to 'examples/stm32f4/src')
-rw-r--r--examples/stm32f4/src/bin/input_capture.rs39
1 files changed, 23 insertions, 16 deletions
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 @@
4use defmt::*; 4use defmt::*;
5use embassy_executor::Spawner; 5use embassy_executor::Spawner;
6use embassy_stm32::gpio::{Level, Output, Pull, Speed}; 6use embassy_stm32::gpio::{Level, Output, Pull, Speed};
7use embassy_stm32::peripherals::PB2;
7use embassy_stm32::time::khz; 8use embassy_stm32::time::khz;
8use embassy_stm32::timer::input_capture::{CapturePin, InputCapture}; 9use embassy_stm32::timer::input_capture::{CapturePin, InputCapture};
9use embassy_stm32::timer::Channel; 10use embassy_stm32::timer::Channel;
@@ -12,18 +13,9 @@ use {defmt_rtt as _, panic_probe as _};
12 13
13/// Connect PB2 and PB10 with a 1k Ohm resistor 14/// Connect PB2 and PB10 with a 1k Ohm resistor
14 15
15#[embassy_executor::main] 16#[embassy_executor::task]
16async fn main(_spawner: Spawner) { 17async fn blinky(led: PB2) {
17 let p = embassy_stm32::init(Default::default()); 18 let mut led = Output::new(led, Level::High, Speed::Low);
18 info!("Hello World!");
19
20 let mut led = Output::new(p.PB2, Level::High, Speed::Low);
21
22 let ch3 = CapturePin::new_ch3(p.PB10, Pull::None);
23 let mut ic = InputCapture::new(p.TIM2, None, None, Some(ch3), None, khz(1000), Default::default());
24 ic.enable(Channel::Ch3);
25
26 let mut last = 0;
27 19
28 loop { 20 loop {
29 info!("high"); 21 info!("high");
@@ -33,12 +25,27 @@ async fn main(_spawner: Spawner) {
33 info!("low"); 25 info!("low");
34 led.set_low(); 26 led.set_low();
35 Timer::after_millis(300).await; 27 Timer::after_millis(300).await;
28 }
29}
36 30
31#[embassy_executor::main]
32async fn main(spawner: Spawner) {
33 let p = embassy_stm32::init(Default::default());
34 info!("Hello World!");
35
36 unwrap!(spawner.spawn(blinky(p.PB2)));
37
38 let ch3 = CapturePin::new_ch3(p.PB10, Pull::None);
39 let mut ic = InputCapture::new(p.TIM2, None, None, Some(ch3), None, khz(1000), Default::default());
40 ic.enable(Channel::Ch3);
41
42 loop {
37 // Check for input capture 43 // Check for input capture
38 let cap = ic.get_capture_value(Channel::Ch3); 44 if ic.get_input_interrupt(Channel::Ch3) {
39 if cap != last { 45 let capture_value = ic.get_capture_value(Channel::Ch3);
40 info!("New capture!"); 46 info!("New capture! {}", capture_value);
41 last = cap;
42 } 47 }
48 // Wait a little bit
49 Timer::after_millis(1).await;
43 } 50 }
44} 51}