diff options
| author | Bruno Bousquet <[email protected]> | 2024-05-05 21:58:54 -0400 |
|---|---|---|
| committer | Bruno Bousquet <[email protected]> | 2024-05-05 21:58:54 -0400 |
| commit | ad66dc3aabe6ac11dd0f3aa4d9f403e3aac7e8f4 (patch) | |
| tree | 2c62239324aefb1515ae122b16b9be4297e6c1a2 /examples/stm32f4/src/bin/input_capture.rs | |
| parent | 15c3ae8ef6abaf37704e3278a1de6b2ae259aa15 (diff) | |
create input_capture
Diffstat (limited to 'examples/stm32f4/src/bin/input_capture.rs')
| -rw-r--r-- | examples/stm32f4/src/bin/input_capture.rs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/examples/stm32f4/src/bin/input_capture.rs b/examples/stm32f4/src/bin/input_capture.rs new file mode 100644 index 000000000..202f363fc --- /dev/null +++ b/examples/stm32f4/src/bin/input_capture.rs | |||
| @@ -0,0 +1,39 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | |||
| 4 | use defmt::*; | ||
| 5 | use embassy_executor::Spawner; | ||
| 6 | use embassy_stm32::{ | ||
| 7 | gpio::{self, Level, Output, Speed}, | ||
| 8 | time::Hertz, | ||
| 9 | }; | ||
| 10 | use embassy_time::Timer; | ||
| 11 | use {defmt_rtt as _, panic_probe as _}; | ||
| 12 | |||
| 13 | use embassy_stm32::timer::{ | ||
| 14 | input_capture::{CapturePin, InputCapture}, | ||
| 15 | Channel, | ||
| 16 | }; | ||
| 17 | |||
| 18 | #[embassy_executor::main] | ||
| 19 | async fn main(_spawner: Spawner) { | ||
| 20 | let p = embassy_stm32::init(Default::default()); | ||
| 21 | info!("Hello World!"); | ||
| 22 | |||
| 23 | let mut led = Output::new(p.PB2, Level::High, Speed::Low); | ||
| 24 | |||
| 25 | let ic = CapturePin::new_ch3(p.PB10, gpio::Pull::None); | ||
| 26 | let drv = InputCapture::new(p.TIM2, None, None, Some(ic), None, Hertz::mhz(1), Default::default()); | ||
| 27 | let mut _last: u32; | ||
| 28 | |||
| 29 | loop { | ||
| 30 | info!("high"); | ||
| 31 | led.set_high(); | ||
| 32 | Timer::after_millis(300).await; | ||
| 33 | |||
| 34 | info!("low"); | ||
| 35 | led.set_low(); | ||
| 36 | Timer::after_millis(300).await; | ||
| 37 | _last = drv.get_capture_value(Channel::Ch1); | ||
| 38 | } | ||
| 39 | } | ||
