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 /tests/stm32 | |
| parent | 7559f9e5834799b041d899767ef4305dcfdf0181 (diff) | |
time: Update examples, tests, and other code to use new Timer::after_x convenience methods
Diffstat (limited to 'tests/stm32')
| -rw-r--r-- | tests/stm32/src/bin/dac.rs | 6 | ||||
| -rw-r--r-- | tests/stm32/src/bin/rtc.rs | 4 | ||||
| -rw-r--r-- | tests/stm32/src/bin/stop.rs | 6 | ||||
| -rw-r--r-- | tests/stm32/src/bin/timer.rs | 4 | ||||
| -rw-r--r-- | tests/stm32/src/bin/usart_rx_ringbuffered.rs | 8 |
5 files changed, 14 insertions, 14 deletions
diff --git a/tests/stm32/src/bin/dac.rs b/tests/stm32/src/bin/dac.rs index fb7a84b1b..10e3c3e81 100644 --- a/tests/stm32/src/bin/dac.rs +++ b/tests/stm32/src/bin/dac.rs | |||
| @@ -12,7 +12,7 @@ use embassy_executor::Spawner; | |||
| 12 | use embassy_stm32::adc::Adc; | 12 | use embassy_stm32::adc::Adc; |
| 13 | use embassy_stm32::dac::{DacCh1, DacChannel, Value}; | 13 | use embassy_stm32::dac::{DacCh1, DacChannel, Value}; |
| 14 | use embassy_stm32::dma::NoDma; | 14 | use embassy_stm32::dma::NoDma; |
| 15 | use embassy_time::{Delay, Duration, Timer}; | 15 | use embassy_time::{Delay, Timer}; |
| 16 | use {defmt_rtt as _, panic_probe as _}; | 16 | use {defmt_rtt as _, panic_probe as _}; |
| 17 | 17 | ||
| 18 | #[embassy_executor::main] | 18 | #[embassy_executor::main] |
| @@ -38,7 +38,7 @@ async fn main(_spawner: Spawner) { | |||
| 38 | 38 | ||
| 39 | unwrap!(dac.set(Value::Bit8(0))); | 39 | unwrap!(dac.set(Value::Bit8(0))); |
| 40 | // Now wait a little to obtain a stable value | 40 | // Now wait a little to obtain a stable value |
| 41 | Timer::after(Duration::from_millis(30)).await; | 41 | Timer::after_millis(30).await; |
| 42 | let offset = adc.read(&mut unsafe { embassy_stm32::Peripherals::steal() }.PA4); | 42 | let offset = adc.read(&mut unsafe { embassy_stm32::Peripherals::steal() }.PA4); |
| 43 | 43 | ||
| 44 | for v in 0..=255 { | 44 | for v in 0..=255 { |
| @@ -47,7 +47,7 @@ async fn main(_spawner: Spawner) { | |||
| 47 | unwrap!(dac.set(Value::Bit8(dac_output_val))); | 47 | unwrap!(dac.set(Value::Bit8(dac_output_val))); |
| 48 | 48 | ||
| 49 | // Now wait a little to obtain a stable value | 49 | // Now wait a little to obtain a stable value |
| 50 | Timer::after(Duration::from_millis(30)).await; | 50 | Timer::after_millis(30).await; |
| 51 | 51 | ||
| 52 | // Need to steal the peripherals here because PA4 is obviously in use already | 52 | // Need to steal the peripherals here because PA4 is obviously in use already |
| 53 | let measured = adc.read(&mut unsafe { embassy_stm32::Peripherals::steal() }.PA4); | 53 | let measured = adc.read(&mut unsafe { embassy_stm32::Peripherals::steal() }.PA4); |
diff --git a/tests/stm32/src/bin/rtc.rs b/tests/stm32/src/bin/rtc.rs index 46fdbfaeb..64f1122a6 100644 --- a/tests/stm32/src/bin/rtc.rs +++ b/tests/stm32/src/bin/rtc.rs | |||
| @@ -12,7 +12,7 @@ use defmt::assert; | |||
| 12 | use embassy_executor::Spawner; | 12 | use embassy_executor::Spawner; |
| 13 | use embassy_stm32::rcc::LsConfig; | 13 | use embassy_stm32::rcc::LsConfig; |
| 14 | use embassy_stm32::rtc::{Rtc, RtcConfig}; | 14 | use embassy_stm32::rtc::{Rtc, RtcConfig}; |
| 15 | use embassy_time::{Duration, Timer}; | 15 | use embassy_time::Timer; |
| 16 | 16 | ||
| 17 | #[embassy_executor::main] | 17 | #[embassy_executor::main] |
| 18 | async fn main(_spawner: Spawner) { | 18 | async fn main(_spawner: Spawner) { |
| @@ -32,7 +32,7 @@ async fn main(_spawner: Spawner) { | |||
| 32 | rtc.set_datetime(now.into()).expect("datetime not set"); | 32 | rtc.set_datetime(now.into()).expect("datetime not set"); |
| 33 | 33 | ||
| 34 | info!("Waiting 5 seconds"); | 34 | info!("Waiting 5 seconds"); |
| 35 | Timer::after(Duration::from_millis(5000)).await; | 35 | Timer::after_millis(5000).await; |
| 36 | 36 | ||
| 37 | let then: NaiveDateTime = rtc.now().unwrap().into(); | 37 | let then: NaiveDateTime = rtc.now().unwrap().into(); |
| 38 | let seconds = (then - now).num_seconds(); | 38 | let seconds = (then - now).num_seconds(); |
diff --git a/tests/stm32/src/bin/stop.rs b/tests/stm32/src/bin/stop.rs index 929869bc9..f38924c90 100644 --- a/tests/stm32/src/bin/stop.rs +++ b/tests/stm32/src/bin/stop.rs | |||
| @@ -14,7 +14,7 @@ use embassy_stm32::low_power::{stop_with_rtc, Executor}; | |||
| 14 | use embassy_stm32::rcc::LsConfig; | 14 | use embassy_stm32::rcc::LsConfig; |
| 15 | use embassy_stm32::rtc::{Rtc, RtcConfig}; | 15 | use embassy_stm32::rtc::{Rtc, RtcConfig}; |
| 16 | use embassy_stm32::Config; | 16 | use embassy_stm32::Config; |
| 17 | use embassy_time::{Duration, Timer}; | 17 | use embassy_time::Timer; |
| 18 | use static_cell::make_static; | 18 | use static_cell::make_static; |
| 19 | 19 | ||
| 20 | #[entry] | 20 | #[entry] |
| @@ -28,7 +28,7 @@ fn main() -> ! { | |||
| 28 | async fn task_1() { | 28 | async fn task_1() { |
| 29 | for _ in 0..9 { | 29 | for _ in 0..9 { |
| 30 | info!("task 1: waiting for 500ms..."); | 30 | info!("task 1: waiting for 500ms..."); |
| 31 | Timer::after(Duration::from_millis(500)).await; | 31 | Timer::after_millis(500).await; |
| 32 | } | 32 | } |
| 33 | } | 33 | } |
| 34 | 34 | ||
| @@ -36,7 +36,7 @@ async fn task_1() { | |||
| 36 | async fn task_2() { | 36 | async fn task_2() { |
| 37 | for _ in 0..5 { | 37 | for _ in 0..5 { |
| 38 | info!("task 2: waiting for 1000ms..."); | 38 | info!("task 2: waiting for 1000ms..."); |
| 39 | Timer::after(Duration::from_millis(1000)).await; | 39 | Timer::after_millis(1000).await; |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | info!("Test OK"); | 42 | info!("Test OK"); |
diff --git a/tests/stm32/src/bin/timer.rs b/tests/stm32/src/bin/timer.rs index f8b453cda..4efeb0a49 100644 --- a/tests/stm32/src/bin/timer.rs +++ b/tests/stm32/src/bin/timer.rs | |||
| @@ -7,7 +7,7 @@ mod common; | |||
| 7 | use common::*; | 7 | use common::*; |
| 8 | use defmt::assert; | 8 | use defmt::assert; |
| 9 | use embassy_executor::Spawner; | 9 | use embassy_executor::Spawner; |
| 10 | use embassy_time::{Duration, Instant, Timer}; | 10 | use embassy_time::{Instant, Timer}; |
| 11 | 11 | ||
| 12 | #[embassy_executor::main] | 12 | #[embassy_executor::main] |
| 13 | async fn main(_spawner: Spawner) { | 13 | async fn main(_spawner: Spawner) { |
| @@ -15,7 +15,7 @@ async fn main(_spawner: Spawner) { | |||
| 15 | info!("Hello World!"); | 15 | info!("Hello World!"); |
| 16 | 16 | ||
| 17 | let start = Instant::now(); | 17 | let start = Instant::now(); |
| 18 | Timer::after(Duration::from_millis(100)).await; | 18 | Timer::after_millis(100).await; |
| 19 | let end = Instant::now(); | 19 | let end = Instant::now(); |
| 20 | let ms = (end - start).as_millis(); | 20 | let ms = (end - start).as_millis(); |
| 21 | info!("slept for {} ms", ms); | 21 | info!("slept for {} ms", ms); |
diff --git a/tests/stm32/src/bin/usart_rx_ringbuffered.rs b/tests/stm32/src/bin/usart_rx_ringbuffered.rs index 1ee7e596d..7e15f64b6 100644 --- a/tests/stm32/src/bin/usart_rx_ringbuffered.rs +++ b/tests/stm32/src/bin/usart_rx_ringbuffered.rs | |||
| @@ -10,7 +10,7 @@ use common::*; | |||
| 10 | use defmt::{assert_eq, panic}; | 10 | use defmt::{assert_eq, panic}; |
| 11 | use embassy_executor::Spawner; | 11 | use embassy_executor::Spawner; |
| 12 | use embassy_stm32::usart::{Config, DataBits, Parity, RingBufferedUartRx, StopBits, Uart, UartTx}; | 12 | use embassy_stm32::usart::{Config, DataBits, Parity, RingBufferedUartRx, StopBits, Uart, UartTx}; |
| 13 | use embassy_time::{Duration, Timer}; | 13 | use embassy_time::Timer; |
| 14 | use rand_chacha::ChaCha8Rng; | 14 | use rand_chacha::ChaCha8Rng; |
| 15 | use rand_core::{RngCore, SeedableRng}; | 15 | use rand_core::{RngCore, SeedableRng}; |
| 16 | 16 | ||
| @@ -54,7 +54,7 @@ async fn main(spawner: Spawner) { | |||
| 54 | #[embassy_executor::task] | 54 | #[embassy_executor::task] |
| 55 | async fn transmit_task(mut tx: UartTx<'static, peris::UART, peris::UART_TX_DMA>) { | 55 | async fn transmit_task(mut tx: UartTx<'static, peris::UART, peris::UART_TX_DMA>) { |
| 56 | // workaround https://github.com/embassy-rs/embassy/issues/1426 | 56 | // workaround https://github.com/embassy-rs/embassy/issues/1426 |
| 57 | Timer::after(Duration::from_millis(100) as _).await; | 57 | Timer::after_millis(100).await; |
| 58 | 58 | ||
| 59 | let mut rng = ChaCha8Rng::seed_from_u64(1337); | 59 | let mut rng = ChaCha8Rng::seed_from_u64(1337); |
| 60 | 60 | ||
| @@ -70,7 +70,7 @@ async fn transmit_task(mut tx: UartTx<'static, peris::UART, peris::UART_TX_DMA>) | |||
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | tx.write(&buf[..len]).await.unwrap(); | 72 | tx.write(&buf[..len]).await.unwrap(); |
| 73 | Timer::after(Duration::from_micros((rng.next_u32() % 1000) as _)).await; | 73 | Timer::after_micros((rng.next_u32() % 1000) as _).await; |
| 74 | } | 74 | } |
| 75 | } | 75 | } |
| 76 | 76 | ||
| @@ -98,7 +98,7 @@ async fn receive_task(mut rx: RingBufferedUartRx<'static, peris::UART, peris::UA | |||
| 98 | } | 98 | } |
| 99 | 99 | ||
| 100 | if received < max_len { | 100 | if received < max_len { |
| 101 | Timer::after(Duration::from_micros((rng.next_u32() % 1000) as _)).await; | 101 | Timer::after_micros((rng.next_u32() % 1000) as _).await; |
| 102 | } | 102 | } |
| 103 | 103 | ||
| 104 | i += received; | 104 | i += received; |
