diff options
| author | Adam Greig <[email protected]> | 2023-10-15 00:57:25 +0100 |
|---|---|---|
| committer | Adam Greig <[email protected]> | 2023-10-15 01:30:12 +0100 |
| commit | 0621e957a0ddc7010d46b3ea3ddc8b9852bc8333 (patch) | |
| tree | f6caefe939109e55a73e9141c736d2f6c20f51e8 /examples/stm32f4/src/bin | |
| parent | 7559f9e5834799b041d899767ef4305dcfdf0181 (diff) | |
time: Update examples, tests, and other code to use new Timer::after_x convenience methods
Diffstat (limited to 'examples/stm32f4/src/bin')
| -rw-r--r-- | examples/stm32f4/src/bin/adc.rs | 4 | ||||
| -rw-r--r-- | examples/stm32f4/src/bin/blinky.rs | 6 | ||||
| -rw-r--r-- | examples/stm32f4/src/bin/eth.rs | 6 | ||||
| -rw-r--r-- | examples/stm32f4/src/bin/flash_async.rs | 6 | ||||
| -rw-r--r-- | examples/stm32f4/src/bin/hello.rs | 4 | ||||
| -rw-r--r-- | examples/stm32f4/src/bin/mco.rs | 6 | ||||
| -rw-r--r-- | examples/stm32f4/src/bin/multiprio.rs | 8 | ||||
| -rw-r--r-- | examples/stm32f4/src/bin/pwm.rs | 10 | ||||
| -rw-r--r-- | examples/stm32f4/src/bin/pwm_complementary.rs | 10 | ||||
| -rw-r--r-- | examples/stm32f4/src/bin/rtc.rs | 4 | ||||
| -rw-r--r-- | examples/stm32f4/src/bin/wdt.rs | 6 |
11 files changed, 35 insertions, 35 deletions
diff --git a/examples/stm32f4/src/bin/adc.rs b/examples/stm32f4/src/bin/adc.rs index dd10385c4..f19328727 100644 --- a/examples/stm32f4/src/bin/adc.rs +++ b/examples/stm32f4/src/bin/adc.rs | |||
| @@ -6,7 +6,7 @@ use cortex_m::prelude::_embedded_hal_blocking_delay_DelayUs; | |||
| 6 | use defmt::*; | 6 | use defmt::*; |
| 7 | use embassy_executor::Spawner; | 7 | use embassy_executor::Spawner; |
| 8 | use embassy_stm32::adc::{Adc, Temperature, VrefInt}; | 8 | use embassy_stm32::adc::{Adc, Temperature, VrefInt}; |
| 9 | use embassy_time::{Delay, Duration, Timer}; | 9 | use embassy_time::{Delay, Timer}; |
| 10 | use {defmt_rtt as _, panic_probe as _}; | 10 | use {defmt_rtt as _, panic_probe as _}; |
| 11 | 11 | ||
| 12 | #[embassy_executor::main] | 12 | #[embassy_executor::main] |
| @@ -63,6 +63,6 @@ async fn main(_spawner: Spawner) { | |||
| 63 | let v = adc.read(&mut vrefint); | 63 | let v = adc.read(&mut vrefint); |
| 64 | info!("VrefInt: {}", v); | 64 | info!("VrefInt: {}", v); |
| 65 | 65 | ||
| 66 | Timer::after(Duration::from_millis(100)).await; | 66 | Timer::after_millis(100).await; |
| 67 | } | 67 | } |
| 68 | } | 68 | } |
diff --git a/examples/stm32f4/src/bin/blinky.rs b/examples/stm32f4/src/bin/blinky.rs index b27bee4ce..4bfc5a50d 100644 --- a/examples/stm32f4/src/bin/blinky.rs +++ b/examples/stm32f4/src/bin/blinky.rs | |||
| @@ -5,7 +5,7 @@ | |||
| 5 | use defmt::*; | 5 | use defmt::*; |
| 6 | use embassy_executor::Spawner; | 6 | use embassy_executor::Spawner; |
| 7 | use embassy_stm32::gpio::{Level, Output, Speed}; | 7 | use embassy_stm32::gpio::{Level, Output, Speed}; |
| 8 | use embassy_time::{Duration, Timer}; | 8 | use embassy_time::Timer; |
| 9 | use {defmt_rtt as _, panic_probe as _}; | 9 | use {defmt_rtt as _, panic_probe as _}; |
| 10 | 10 | ||
| 11 | #[embassy_executor::main] | 11 | #[embassy_executor::main] |
| @@ -18,10 +18,10 @@ async fn main(_spawner: Spawner) { | |||
| 18 | loop { | 18 | loop { |
| 19 | info!("high"); | 19 | info!("high"); |
| 20 | led.set_high(); | 20 | led.set_high(); |
| 21 | Timer::after(Duration::from_millis(300)).await; | 21 | Timer::after_millis(300).await; |
| 22 | 22 | ||
| 23 | info!("low"); | 23 | info!("low"); |
| 24 | led.set_low(); | 24 | led.set_low(); |
| 25 | Timer::after(Duration::from_millis(300)).await; | 25 | Timer::after_millis(300).await; |
| 26 | } | 26 | } |
| 27 | } | 27 | } |
diff --git a/examples/stm32f4/src/bin/eth.rs b/examples/stm32f4/src/bin/eth.rs index 6a1d4b088..ddf8596ae 100644 --- a/examples/stm32f4/src/bin/eth.rs +++ b/examples/stm32f4/src/bin/eth.rs | |||
| @@ -12,7 +12,7 @@ use embassy_stm32::peripherals::ETH; | |||
| 12 | use embassy_stm32::rng::Rng; | 12 | use embassy_stm32::rng::Rng; |
| 13 | use embassy_stm32::time::mhz; | 13 | use embassy_stm32::time::mhz; |
| 14 | use embassy_stm32::{bind_interrupts, eth, peripherals, rng, Config}; | 14 | use embassy_stm32::{bind_interrupts, eth, peripherals, rng, Config}; |
| 15 | use embassy_time::{Duration, Timer}; | 15 | use embassy_time::Timer; |
| 16 | use embedded_io_async::Write; | 16 | use embedded_io_async::Write; |
| 17 | use static_cell::make_static; | 17 | use static_cell::make_static; |
| 18 | use {defmt_rtt as _, panic_probe as _}; | 18 | use {defmt_rtt as _, panic_probe as _}; |
| @@ -99,7 +99,7 @@ async fn main(spawner: Spawner) -> ! { | |||
| 99 | let r = socket.connect(remote_endpoint).await; | 99 | let r = socket.connect(remote_endpoint).await; |
| 100 | if let Err(e) = r { | 100 | if let Err(e) = r { |
| 101 | info!("connect error: {:?}", e); | 101 | info!("connect error: {:?}", e); |
| 102 | Timer::after(Duration::from_secs(1)).await; | 102 | Timer::after_secs(1).await; |
| 103 | continue; | 103 | continue; |
| 104 | } | 104 | } |
| 105 | info!("connected!"); | 105 | info!("connected!"); |
| @@ -110,7 +110,7 @@ async fn main(spawner: Spawner) -> ! { | |||
| 110 | info!("write error: {:?}", e); | 110 | info!("write error: {:?}", e); |
| 111 | break; | 111 | break; |
| 112 | } | 112 | } |
| 113 | Timer::after(Duration::from_secs(1)).await; | 113 | Timer::after_secs(1).await; |
| 114 | } | 114 | } |
| 115 | } | 115 | } |
| 116 | } | 116 | } |
diff --git a/examples/stm32f4/src/bin/flash_async.rs b/examples/stm32f4/src/bin/flash_async.rs index 6c9689d9c..f0a65a725 100644 --- a/examples/stm32f4/src/bin/flash_async.rs +++ b/examples/stm32f4/src/bin/flash_async.rs | |||
| @@ -7,7 +7,7 @@ use embassy_executor::Spawner; | |||
| 7 | use embassy_stm32::bind_interrupts; | 7 | use embassy_stm32::bind_interrupts; |
| 8 | use embassy_stm32::flash::{Flash, InterruptHandler}; | 8 | use embassy_stm32::flash::{Flash, InterruptHandler}; |
| 9 | use embassy_stm32::gpio::{AnyPin, Level, Output, Pin, Speed}; | 9 | use embassy_stm32::gpio::{AnyPin, Level, Output, Pin, Speed}; |
| 10 | use embassy_time::{Duration, 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 | bind_interrupts!(struct Irqs { | 13 | bind_interrupts!(struct Irqs { |
| @@ -35,11 +35,11 @@ async fn blinky(p: AnyPin) { | |||
| 35 | loop { | 35 | loop { |
| 36 | info!("high"); | 36 | info!("high"); |
| 37 | led.set_high(); | 37 | led.set_high(); |
| 38 | Timer::after(Duration::from_millis(300)).await; | 38 | Timer::after_millis(300).await; |
| 39 | 39 | ||
| 40 | info!("low"); | 40 | info!("low"); |
| 41 | led.set_low(); | 41 | led.set_low(); |
| 42 | Timer::after(Duration::from_millis(300)).await; | 42 | Timer::after_millis(300).await; |
| 43 | } | 43 | } |
| 44 | } | 44 | } |
| 45 | 45 | ||
diff --git a/examples/stm32f4/src/bin/hello.rs b/examples/stm32f4/src/bin/hello.rs index c409703f5..27ee83aa5 100644 --- a/examples/stm32f4/src/bin/hello.rs +++ b/examples/stm32f4/src/bin/hello.rs | |||
| @@ -6,7 +6,7 @@ use defmt::info; | |||
| 6 | use embassy_executor::Spawner; | 6 | use embassy_executor::Spawner; |
| 7 | use embassy_stm32::time::Hertz; | 7 | use embassy_stm32::time::Hertz; |
| 8 | use embassy_stm32::Config; | 8 | use embassy_stm32::Config; |
| 9 | use embassy_time::{Duration, Timer}; | 9 | use embassy_time::Timer; |
| 10 | use {defmt_rtt as _, panic_probe as _}; | 10 | use {defmt_rtt as _, panic_probe as _}; |
| 11 | 11 | ||
| 12 | #[embassy_executor::main] | 12 | #[embassy_executor::main] |
| @@ -17,6 +17,6 @@ async fn main(_spawner: Spawner) -> ! { | |||
| 17 | 17 | ||
| 18 | loop { | 18 | loop { |
| 19 | info!("Hello World!"); | 19 | info!("Hello World!"); |
| 20 | Timer::after(Duration::from_secs(1)).await; | 20 | Timer::after_secs(1).await; |
| 21 | } | 21 | } |
| 22 | } | 22 | } |
diff --git a/examples/stm32f4/src/bin/mco.rs b/examples/stm32f4/src/bin/mco.rs index 5144a78c6..3315e7652 100644 --- a/examples/stm32f4/src/bin/mco.rs +++ b/examples/stm32f4/src/bin/mco.rs | |||
| @@ -6,7 +6,7 @@ use defmt::*; | |||
| 6 | use embassy_executor::Spawner; | 6 | use embassy_executor::Spawner; |
| 7 | use embassy_stm32::gpio::{Level, Output, Speed}; | 7 | use embassy_stm32::gpio::{Level, Output, Speed}; |
| 8 | use embassy_stm32::rcc::{Mco, Mco1Source, Mco2Source, McoPrescaler}; | 8 | use embassy_stm32::rcc::{Mco, Mco1Source, Mco2Source, McoPrescaler}; |
| 9 | use embassy_time::{Duration, Timer}; | 9 | use embassy_time::Timer; |
| 10 | use {defmt_rtt as _, panic_probe as _}; | 10 | use {defmt_rtt as _, panic_probe as _}; |
| 11 | 11 | ||
| 12 | #[embassy_executor::main] | 12 | #[embassy_executor::main] |
| @@ -21,10 +21,10 @@ async fn main(_spawner: Spawner) { | |||
| 21 | loop { | 21 | loop { |
| 22 | info!("high"); | 22 | info!("high"); |
| 23 | led.set_high(); | 23 | led.set_high(); |
| 24 | Timer::after(Duration::from_millis(300)).await; | 24 | Timer::after_millis(300).await; |
| 25 | 25 | ||
| 26 | info!("low"); | 26 | info!("low"); |
| 27 | led.set_low(); | 27 | led.set_low(); |
| 28 | Timer::after(Duration::from_millis(300)).await; | 28 | Timer::after_millis(300).await; |
| 29 | } | 29 | } |
| 30 | } | 30 | } |
diff --git a/examples/stm32f4/src/bin/multiprio.rs b/examples/stm32f4/src/bin/multiprio.rs index 80bf59deb..74f3bb1c5 100644 --- a/examples/stm32f4/src/bin/multiprio.rs +++ b/examples/stm32f4/src/bin/multiprio.rs | |||
| @@ -62,7 +62,7 @@ use defmt::*; | |||
| 62 | use embassy_executor::{Executor, InterruptExecutor}; | 62 | use embassy_executor::{Executor, InterruptExecutor}; |
| 63 | use embassy_stm32::interrupt; | 63 | use embassy_stm32::interrupt; |
| 64 | use embassy_stm32::interrupt::{InterruptExt, Priority}; | 64 | use embassy_stm32::interrupt::{InterruptExt, Priority}; |
| 65 | use embassy_time::{Duration, Instant, Timer}; | 65 | use embassy_time::{Instant, Timer}; |
| 66 | use static_cell::StaticCell; | 66 | use static_cell::StaticCell; |
| 67 | use {defmt_rtt as _, panic_probe as _}; | 67 | use {defmt_rtt as _, panic_probe as _}; |
| 68 | 68 | ||
| @@ -70,7 +70,7 @@ use {defmt_rtt as _, panic_probe as _}; | |||
| 70 | async fn run_high() { | 70 | async fn run_high() { |
| 71 | loop { | 71 | loop { |
| 72 | info!(" [high] tick!"); | 72 | info!(" [high] tick!"); |
| 73 | Timer::after(Duration::from_ticks(27374)).await; | 73 | Timer::after_ticks(27374).await; |
| 74 | } | 74 | } |
| 75 | } | 75 | } |
| 76 | 76 | ||
| @@ -87,7 +87,7 @@ async fn run_med() { | |||
| 87 | let ms = end.duration_since(start).as_ticks() / 33; | 87 | let ms = end.duration_since(start).as_ticks() / 33; |
| 88 | info!(" [med] done in {} ms", ms); | 88 | info!(" [med] done in {} ms", ms); |
| 89 | 89 | ||
| 90 | Timer::after(Duration::from_ticks(23421)).await; | 90 | Timer::after_ticks(23421).await; |
| 91 | } | 91 | } |
| 92 | } | 92 | } |
| 93 | 93 | ||
| @@ -104,7 +104,7 @@ async fn run_low() { | |||
| 104 | let ms = end.duration_since(start).as_ticks() / 33; | 104 | let ms = end.duration_since(start).as_ticks() / 33; |
| 105 | info!("[low] done in {} ms", ms); | 105 | info!("[low] done in {} ms", ms); |
| 106 | 106 | ||
| 107 | Timer::after(Duration::from_ticks(32983)).await; | 107 | Timer::after_ticks(32983).await; |
| 108 | } | 108 | } |
| 109 | } | 109 | } |
| 110 | 110 | ||
diff --git a/examples/stm32f4/src/bin/pwm.rs b/examples/stm32f4/src/bin/pwm.rs index 1013a844e..538427e89 100644 --- a/examples/stm32f4/src/bin/pwm.rs +++ b/examples/stm32f4/src/bin/pwm.rs | |||
| @@ -8,7 +8,7 @@ use embassy_stm32::gpio::OutputType; | |||
| 8 | use embassy_stm32::time::khz; | 8 | use embassy_stm32::time::khz; |
| 9 | use embassy_stm32::timer::simple_pwm::{PwmPin, SimplePwm}; | 9 | use embassy_stm32::timer::simple_pwm::{PwmPin, SimplePwm}; |
| 10 | use embassy_stm32::timer::Channel; | 10 | use embassy_stm32::timer::Channel; |
| 11 | use embassy_time::{Duration, Timer}; | 11 | use embassy_time::Timer; |
| 12 | use {defmt_rtt as _, panic_probe as _}; | 12 | use {defmt_rtt as _, panic_probe as _}; |
| 13 | 13 | ||
| 14 | #[embassy_executor::main] | 14 | #[embassy_executor::main] |
| @@ -26,12 +26,12 @@ async fn main(_spawner: Spawner) { | |||
| 26 | 26 | ||
| 27 | loop { | 27 | loop { |
| 28 | pwm.set_duty(Channel::Ch1, 0); | 28 | pwm.set_duty(Channel::Ch1, 0); |
| 29 | Timer::after(Duration::from_millis(300)).await; | 29 | Timer::after_millis(300).await; |
| 30 | pwm.set_duty(Channel::Ch1, max / 4); | 30 | pwm.set_duty(Channel::Ch1, max / 4); |
| 31 | Timer::after(Duration::from_millis(300)).await; | 31 | Timer::after_millis(300).await; |
| 32 | pwm.set_duty(Channel::Ch1, max / 2); | 32 | pwm.set_duty(Channel::Ch1, max / 2); |
| 33 | Timer::after(Duration::from_millis(300)).await; | 33 | Timer::after_millis(300).await; |
| 34 | pwm.set_duty(Channel::Ch1, max - 1); | 34 | pwm.set_duty(Channel::Ch1, max - 1); |
| 35 | Timer::after(Duration::from_millis(300)).await; | 35 | Timer::after_millis(300).await; |
| 36 | } | 36 | } |
| 37 | } | 37 | } |
diff --git a/examples/stm32f4/src/bin/pwm_complementary.rs b/examples/stm32f4/src/bin/pwm_complementary.rs index 83a3c7537..a8211f6e0 100644 --- a/examples/stm32f4/src/bin/pwm_complementary.rs +++ b/examples/stm32f4/src/bin/pwm_complementary.rs | |||
| @@ -9,7 +9,7 @@ use embassy_stm32::time::khz; | |||
| 9 | use embassy_stm32::timer::complementary_pwm::{ComplementaryPwm, ComplementaryPwmPin}; | 9 | use embassy_stm32::timer::complementary_pwm::{ComplementaryPwm, ComplementaryPwmPin}; |
| 10 | use embassy_stm32::timer::simple_pwm::PwmPin; | 10 | use embassy_stm32::timer::simple_pwm::PwmPin; |
| 11 | use embassy_stm32::timer::Channel; | 11 | use embassy_stm32::timer::Channel; |
| 12 | use embassy_time::{Duration, Timer}; | 12 | use embassy_time::Timer; |
| 13 | use {defmt_rtt as _, panic_probe as _}; | 13 | use {defmt_rtt as _, panic_probe as _}; |
| 14 | 14 | ||
| 15 | #[embassy_executor::main] | 15 | #[embassy_executor::main] |
| @@ -42,12 +42,12 @@ async fn main(_spawner: Spawner) { | |||
| 42 | 42 | ||
| 43 | loop { | 43 | loop { |
| 44 | pwm.set_duty(Channel::Ch1, 0); | 44 | pwm.set_duty(Channel::Ch1, 0); |
| 45 | Timer::after(Duration::from_millis(300)).await; | 45 | Timer::after_millis(300).await; |
| 46 | pwm.set_duty(Channel::Ch1, max / 4); | 46 | pwm.set_duty(Channel::Ch1, max / 4); |
| 47 | Timer::after(Duration::from_millis(300)).await; | 47 | Timer::after_millis(300).await; |
| 48 | pwm.set_duty(Channel::Ch1, max / 2); | 48 | pwm.set_duty(Channel::Ch1, max / 2); |
| 49 | Timer::after(Duration::from_millis(300)).await; | 49 | Timer::after_millis(300).await; |
| 50 | pwm.set_duty(Channel::Ch1, max - 1); | 50 | pwm.set_duty(Channel::Ch1, max - 1); |
| 51 | Timer::after(Duration::from_millis(300)).await; | 51 | Timer::after_millis(300).await; |
| 52 | } | 52 | } |
| 53 | } | 53 | } |
diff --git a/examples/stm32f4/src/bin/rtc.rs b/examples/stm32f4/src/bin/rtc.rs index e95ad5779..44b4303c0 100644 --- a/examples/stm32f4/src/bin/rtc.rs +++ b/examples/stm32f4/src/bin/rtc.rs | |||
| @@ -7,7 +7,7 @@ use defmt::*; | |||
| 7 | use embassy_executor::Spawner; | 7 | use embassy_executor::Spawner; |
| 8 | use embassy_stm32::rtc::{Rtc, RtcConfig}; | 8 | use embassy_stm32::rtc::{Rtc, RtcConfig}; |
| 9 | use embassy_stm32::Config; | 9 | use embassy_stm32::Config; |
| 10 | use embassy_time::{Duration, 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 | #[embassy_executor::main] | 13 | #[embassy_executor::main] |
| @@ -31,6 +31,6 @@ async fn main(_spawner: Spawner) { | |||
| 31 | 31 | ||
| 32 | info!("{}", now.timestamp()); | 32 | info!("{}", now.timestamp()); |
| 33 | 33 | ||
| 34 | Timer::after(Duration::from_millis(1000)).await; | 34 | Timer::after_millis(1000).await; |
| 35 | } | 35 | } |
| 36 | } | 36 | } |
diff --git a/examples/stm32f4/src/bin/wdt.rs b/examples/stm32f4/src/bin/wdt.rs index e5d122af7..0443b61c5 100644 --- a/examples/stm32f4/src/bin/wdt.rs +++ b/examples/stm32f4/src/bin/wdt.rs | |||
| @@ -6,7 +6,7 @@ use defmt::*; | |||
| 6 | use embassy_executor::Spawner; | 6 | use embassy_executor::Spawner; |
| 7 | use embassy_stm32::gpio::{Level, Output, Speed}; | 7 | use embassy_stm32::gpio::{Level, Output, Speed}; |
| 8 | use embassy_stm32::wdg::IndependentWatchdog; | 8 | use embassy_stm32::wdg::IndependentWatchdog; |
| 9 | use embassy_time::{Duration, Timer}; | 9 | use embassy_time::Timer; |
| 10 | use {defmt_rtt as _, panic_probe as _}; | 10 | use {defmt_rtt as _, panic_probe as _}; |
| 11 | 11 | ||
| 12 | #[embassy_executor::main] | 12 | #[embassy_executor::main] |
| @@ -24,11 +24,11 @@ async fn main(_spawner: Spawner) { | |||
| 24 | loop { | 24 | loop { |
| 25 | info!("high"); | 25 | info!("high"); |
| 26 | led.set_high(); | 26 | led.set_high(); |
| 27 | Timer::after(Duration::from_millis(300)).await; | 27 | Timer::after_millis(300).await; |
| 28 | 28 | ||
| 29 | info!("low"); | 29 | info!("low"); |
| 30 | led.set_low(); | 30 | led.set_low(); |
| 31 | Timer::after(Duration::from_millis(300)).await; | 31 | Timer::after_millis(300).await; |
| 32 | 32 | ||
| 33 | // Pet watchdog for 5 iterations and then stop. | 33 | // Pet watchdog for 5 iterations and then stop. |
| 34 | // MCU should restart in 1 second after the last pet. | 34 | // MCU should restart in 1 second after the last pet. |
