diff options
| author | Bruno Bousquet <[email protected]> | 2024-05-05 22:30:16 -0400 |
|---|---|---|
| committer | Bruno Bousquet <[email protected]> | 2024-05-05 22:30:16 -0400 |
| commit | 431a60ca6384a77243d33f5b1bbef878267bea49 (patch) | |
| tree | 4358e4e9c5ff4d36e1d861d823b69feb66c5b5da /examples/stm32f4 | |
| parent | ad66dc3aabe6ac11dd0f3aa4d9f403e3aac7e8f4 (diff) | |
formatting
Diffstat (limited to 'examples/stm32f4')
| -rw-r--r-- | examples/stm32f4/Cargo.toml | 2 | ||||
| -rw-r--r-- | examples/stm32f4/src/bin/input_capture.rs | 29 |
2 files changed, 18 insertions, 13 deletions
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. |
| 9 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32f429zi", "unstable-pac", "memory-x", "time-driver-any", "exti", "chrono"] } | 9 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32f446re", "unstable-pac", "memory-x", "time-driver-any", "exti", "chrono"] } |
| 10 | embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["defmt"] } | 10 | embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["defmt"] } |
| 11 | embassy-executor = { version = "0.5.0", path = "../../embassy-executor", features = ["task-arena-size-32768", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] } | 11 | embassy-executor = { version = "0.5.0", path = "../../embassy-executor", features = ["task-arena-size-32768", "arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] } |
| 12 | embassy-time = { version = "0.3.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "tick-hz-32_768"] } | 12 | embassy-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 | ||
| 4 | use defmt::*; | 4 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::{ | 6 | use embassy_stm32::gpio::{Level, Output, Pull, Speed}; |
| 7 | gpio::{self, Level, Output, Speed}, | 7 | use embassy_stm32::time::khz; |
| 8 | time::Hertz, | 8 | use embassy_stm32::timer::input_capture::{CapturePin, InputCapture}; |
| 9 | }; | 9 | use embassy_stm32::timer::Channel; |
| 10 | use embassy_time::Timer; | 10 | use embassy_time::Timer; |
| 11 | use {defmt_rtt as _, panic_probe as _}; | 11 | use {defmt_rtt as _, panic_probe as _}; |
| 12 | 12 | ||
| 13 | use 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] |
| 19 | async fn main(_spawner: Spawner) { | 16 | async 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 | } |
