Skip to content

Commit

Permalink
time: Update examples, tests, and other code to use new Timer::after_…
Browse files Browse the repository at this point in the history
…x convenience methods
  • Loading branch information
adamgreig committed Oct 15, 2023
1 parent 7559f9e commit 0621e95
Show file tree
Hide file tree
Showing 174 changed files with 496 additions and 501 deletions.
6 changes: 3 additions & 3 deletions cyw43/src/bus.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use embassy_futures::yield_now;
use embassy_time::{Duration, Timer};
use embassy_time::Timer;
use embedded_hal_1::digital::OutputPin;
use futures::FutureExt;

Expand Down Expand Up @@ -51,9 +51,9 @@ where
pub async fn init(&mut self) {
// Reset
self.pwr.set_low().unwrap();
Timer::after(Duration::from_millis(20)).await;
Timer::after_millis(20).await;
self.pwr.set_high().unwrap();
Timer::after(Duration::from_millis(250)).await;
Timer::after_millis(250).await;

while self
.read32_swapped(REG_BUS_TEST_RO)
Expand Down
24 changes: 12 additions & 12 deletions cyw43/src/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use core::cmp::{max, min};

use ch::driver::LinkState;
use embassy_net_driver_channel as ch;
use embassy_time::{Duration, Timer};
use embassy_time::Timer;

pub use crate::bus::SpiBusCyw43;
use crate::consts::*;
Expand Down Expand Up @@ -87,22 +87,22 @@ impl<'a> Control<'a> {
self.set_iovar("country", &country_info.to_bytes()).await;

// set country takes some time, next ioctls fail if we don't wait.
Timer::after(Duration::from_millis(100)).await;
Timer::after_millis(100).await;

// Set antenna to chip antenna
self.ioctl_set_u32(IOCTL_CMD_ANTDIV, 0, 0).await;

self.set_iovar_u32("bus:txglom", 0).await;
Timer::after(Duration::from_millis(100)).await;
Timer::after_millis(100).await;
//self.set_iovar_u32("apsta", 1).await; // this crashes, also we already did it before...??
//Timer::after(Duration::from_millis(100)).await;
//Timer::after_millis(100).await;
self.set_iovar_u32("ampdu_ba_wsize", 8).await;
Timer::after(Duration::from_millis(100)).await;
Timer::after_millis(100).await;
self.set_iovar_u32("ampdu_mpdu", 4).await;
Timer::after(Duration::from_millis(100)).await;
Timer::after_millis(100).await;
//self.set_iovar_u32("ampdu_rx_factor", 0).await; // this crashes

//Timer::after(Duration::from_millis(100)).await;
//Timer::after_millis(100).await;

// evts
let mut evts = EventMask {
Expand All @@ -121,17 +121,17 @@ impl<'a> Control<'a> {

self.set_iovar("bsscfg:event_msgs", &evts.to_bytes()).await;

Timer::after(Duration::from_millis(100)).await;
Timer::after_millis(100).await;

// set wifi up
self.up().await;

Timer::after(Duration::from_millis(100)).await;
Timer::after_millis(100).await;

self.ioctl_set_u32(110, 0, 1).await; // SET_GMODE = auto
self.ioctl_set_u32(142, 0, 0).await; // SET_BAND = any

Timer::after(Duration::from_millis(100)).await;
Timer::after_millis(100).await;

self.state_ch.set_ethernet_address(mac_addr);

Expand Down Expand Up @@ -185,7 +185,7 @@ impl<'a> Control<'a> {
self.set_iovar_u32x2("bsscfg:sup_wpa2_eapver", 0, 0xFFFF_FFFF).await;
self.set_iovar_u32x2("bsscfg:sup_wpa_tmo", 0, 2500).await;

Timer::after(Duration::from_millis(100)).await;
Timer::after_millis(100).await;

let mut pfi = PassphraseInfo {
len: passphrase.len() as _,
Expand Down Expand Up @@ -297,7 +297,7 @@ impl<'a> Control<'a> {
if security != Security::OPEN {
self.set_iovar_u32x2("bsscfg:wpa_auth", 0, 0x0084).await; // wpa_auth = WPA2_AUTH_PSK | WPA_AUTH_PSK

Timer::after(Duration::from_millis(100)).await;
Timer::after_millis(100).await;

// Set passphrase
let mut pfi = PassphraseInfo {
Expand Down
4 changes: 2 additions & 2 deletions cyw43/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,14 +555,14 @@ where

self.bus.bp_write8(base + AI_RESETCTRL_OFFSET, 0).await;

Timer::after(Duration::from_millis(1)).await;
Timer::after_millis(1).await;

self.bus
.bp_write8(base + AI_IOCTRL_OFFSET, AI_IOCTRL_BIT_CLOCK_EN)
.await;
let _ = self.bus.bp_read8(base + AI_IOCTRL_OFFSET).await;

Timer::after(Duration::from_millis(1)).await;
Timer::after_millis(1).await;
}

async fn core_is_up(&mut self, core: Core) -> bool {
Expand Down
8 changes: 2 additions & 6 deletions embassy-embedded-hal/src/shared_bus/asynch/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ where
#[cfg(not(feature = "time"))]
Operation::DelayUs(_) => return Err(SpiDeviceError::DelayUsNotSupported),
#[cfg(feature = "time")]
Operation::DelayUs(us) => {
embassy_time::Timer::after(embassy_time::Duration::from_micros(*us as _)).await
}
Operation::DelayUs(us) => embassy_time::Timer::after_micros(*us as _).await,
}
}
};
Expand Down Expand Up @@ -143,9 +141,7 @@ where
#[cfg(not(feature = "time"))]
Operation::DelayUs(_) => return Err(SpiDeviceError::DelayUsNotSupported),
#[cfg(feature = "time")]
Operation::DelayUs(us) => {
embassy_time::Timer::after(embassy_time::Duration::from_micros(*us as _)).await
}
Operation::DelayUs(us) => embassy_time::Timer::after_micros(*us as _).await,
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion embassy-lora/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ impl lorawan_device::async_device::radio::Timer for LoraTimer {
}

async fn delay_ms(&mut self, millis: u64) {
Timer::after(Duration::from_millis(millis)).await
Timer::after_millis(millis).await
}
}
6 changes: 3 additions & 3 deletions embassy-net-adin1110/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub use crc32::ETH_FCS;
use crc8::crc8;
use embassy_futures::select::{select, Either};
use embassy_net_driver_channel as ch;
use embassy_time::{Duration, Timer};
use embassy_time::Timer;
use embedded_hal_1::digital::OutputPin;
use embedded_hal_async::digital::Wait;
use embedded_hal_async::spi::{Error, Operation, SpiDevice};
Expand Down Expand Up @@ -609,12 +609,12 @@ pub async fn new<const N_RX: usize, const N_TX: usize, SPI: SpiDevice, INT: Wait
reset.set_low().unwrap();

// Wait t1: 20-43mS
Timer::after(Duration::from_millis(30)).await;
Timer::after_millis(30).await;

reset.set_high().unwrap();

// Wait t3: 50mS
Timer::after(Duration::from_millis(50)).await;
Timer::after_millis(50).await;

// Create device
let mut mac = ADIN1110::new(spi_dev, spi_crc, append_fcs_on_tx);
Expand Down
4 changes: 2 additions & 2 deletions embassy-net-esp-hosted/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ where
pub async fn run(mut self) -> ! {
debug!("resetting...");
self.reset.set_low().unwrap();
Timer::after(Duration::from_millis(100)).await;
Timer::after_millis(100).await;
self.reset.set_high().unwrap();
Timer::after(Duration::from_millis(1000)).await;
Timer::after_millis(1000).await;

let mut tx_buf = [0u8; MAX_SPI_BUFFER_SIZE];
let mut rx_buf = [0u8; MAX_SPI_BUFFER_SIZE];
Expand Down
6 changes: 3 additions & 3 deletions embassy-net-wiznet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ mod device;
use embassy_futures::select::{select, Either};
use embassy_net_driver_channel as ch;
use embassy_net_driver_channel::driver::LinkState;
use embassy_time::{Duration, Timer};
use embassy_time::Timer;
use embedded_hal::digital::OutputPin;
use embedded_hal_async::digital::Wait;
use embedded_hal_async::spi::SpiDevice;
Expand Down Expand Up @@ -95,12 +95,12 @@ pub async fn new<'a, const N_RX: usize, const N_TX: usize, C: Chip, SPI: SpiDevi
// Reset the chip.
reset.set_low().ok();
// Ensure the reset is registered.
Timer::after(Duration::from_millis(1)).await;
Timer::after_millis(1).await;
reset.set_high().ok();

// Wait for PLL lock. Some chips are slower than others.
// Slowest is w5100s which is 100ms, so let's just wait that.
Timer::after(Duration::from_millis(100)).await;
Timer::after_millis(100).await;

let mac = WiznetDevice::new(spi_dev, mac_addr).await.unwrap();

Expand Down
4 changes: 2 additions & 2 deletions embassy-rp/src/uart/buffered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use core::task::Poll;
use atomic_polyfill::{AtomicU8, Ordering};
use embassy_hal_internal::atomic_ring_buffer::RingBuffer;
use embassy_sync::waitqueue::AtomicWaker;
use embassy_time::{Duration, Timer};
use embassy_time::Timer;

use super::*;
use crate::clocks::clk_peri_freq;
Expand Down Expand Up @@ -435,7 +435,7 @@ impl<'d, T: Instance> BufferedUartTx<'d, T> {
Self::flush().await.unwrap();
while self.busy() {}
regs.uartlcr_h().write_set(|w| w.set_brk(true));
Timer::after(Duration::from_micros(wait_usecs)).await;
Timer::after_micros(wait_usecs).await;
regs.uartlcr_h().write_clear(|w| w.set_brk(true));
}
}
Expand Down
4 changes: 2 additions & 2 deletions embassy-rp/src/uart/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use atomic_polyfill::{AtomicU16, Ordering};
use embassy_futures::select::{select, Either};
use embassy_hal_internal::{into_ref, PeripheralRef};
use embassy_sync::waitqueue::AtomicWaker;
use embassy_time::{Duration, Timer};
use embassy_time::Timer;
use pac::uart::regs::Uartris;

use crate::clocks::clk_peri_freq;
Expand Down Expand Up @@ -187,7 +187,7 @@ impl<'d, T: Instance, M: Mode> UartTx<'d, T, M> {
self.blocking_flush().unwrap();
while self.busy() {}
regs.uartlcr_h().write_set(|w| w.set_brk(true));
Timer::after(Duration::from_micros(wait_usecs)).await;
Timer::after_micros(wait_usecs).await;
regs.uartlcr_h().write_clear(|w| w.set_brk(true));
}
}
Expand Down
4 changes: 2 additions & 2 deletions embassy-time/src/delay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ mod eha {

impl embedded_hal_async::delay::DelayUs for Delay {
async fn delay_us(&mut self, micros: u32) {
Timer::after(Duration::from_micros(micros as _)).await
Timer::after_micros(micros as _).await
}

async fn delay_ms(&mut self, millis: u32) {
Timer::after(Duration::from_millis(millis as _)).await
Timer::after_millis(millis as _).await
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions examples/boot/application/nrf/src/bin/b.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use embassy_executor::Spawner;
use embassy_nrf::gpio::{Level, Output, OutputDrive};
use embassy_time::{Duration, Timer};
use embassy_time::Timer;
use panic_reset as _;

#[embassy_executor::main]
Expand All @@ -19,8 +19,8 @@ async fn main(_spawner: Spawner) {

loop {
led.set_high();
Timer::after(Duration::from_millis(300)).await;
Timer::after_millis(300).await;
led.set_low();
Timer::after(Duration::from_millis(300)).await;
Timer::after_millis(300).await;
}
}
4 changes: 2 additions & 2 deletions examples/boot/application/rp/src/bin/a.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async fn main(_s: Spawner) {
let mut aligned = AlignedBuffer([0; 1]);
let mut updater = BlockingFirmwareUpdater::new(config, &mut aligned.0);

Timer::after(Duration::from_secs(5)).await;
Timer::after_secs(5).await;
watchdog.feed();
led.set_high();
let mut offset = 0;
Expand All @@ -61,7 +61,7 @@ async fn main(_s: Spawner) {
watchdog.feed();
defmt::info!("firmware written, marking update");
updater.mark_updated().unwrap();
Timer::after(Duration::from_secs(2)).await;
Timer::after_secs(2).await;
led.set_low();
defmt::info!("update marked, resetting");
cortex_m::peripheral::SCB::sys_reset();
Expand Down
6 changes: 3 additions & 3 deletions examples/boot/application/rp/src/bin/b.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use embassy_executor::Spawner;
use embassy_rp::gpio;
use embassy_time::{Duration, Timer};
use embassy_time::Timer;
use gpio::{Level, Output};
use {defmt_rtt as _, panic_reset as _};

Expand All @@ -15,9 +15,9 @@ async fn main(_s: Spawner) {

loop {
led.set_high();
Timer::after(Duration::from_millis(100)).await;
Timer::after_millis(100).await;

led.set_low();
Timer::after(Duration::from_millis(100)).await;
Timer::after_millis(100).await;
}
}
6 changes: 3 additions & 3 deletions examples/boot/application/stm32f3/src/bin/b.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use defmt_rtt::*;
use embassy_executor::Spawner;
use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_time::{Duration, Timer};
use embassy_time::Timer;
use panic_reset as _;

#[embassy_executor::main]
Expand All @@ -16,9 +16,9 @@ async fn main(_spawner: Spawner) {

loop {
led.set_high();
Timer::after(Duration::from_millis(500)).await;
Timer::after_millis(500).await;

led.set_low();
Timer::after(Duration::from_millis(500)).await;
Timer::after_millis(500).await;
}
}
8 changes: 4 additions & 4 deletions examples/boot/application/stm32f7/src/bin/b.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@
use defmt_rtt::*;
use embassy_executor::Spawner;
use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_time::{Duration, Timer};
use embassy_time::Timer;
use panic_reset as _;

#[embassy_executor::main]
async fn main(_spawner: Spawner) {
let p = embassy_stm32::init(Default::default());
Timer::after(Duration::from_millis(300)).await;
Timer::after_millis(300).await;
let mut led = Output::new(p.PB7, Level::High, Speed::Low);
led.set_high();

loop {
led.set_high();
Timer::after(Duration::from_millis(500)).await;
Timer::after_millis(500).await;

led.set_low();
Timer::after(Duration::from_millis(500)).await;
Timer::after_millis(500).await;
}
}
8 changes: 4 additions & 4 deletions examples/boot/application/stm32h7/src/bin/b.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@
use defmt_rtt::*;
use embassy_executor::Spawner;
use embassy_stm32::gpio::{Level, Output, Speed};
use embassy_time::{Duration, Timer};
use embassy_time::Timer;
use panic_reset as _;

#[embassy_executor::main]
async fn main(_spawner: Spawner) {
let p = embassy_stm32::init(Default::default());
Timer::after(Duration::from_millis(300)).await;
Timer::after_millis(300).await;
let mut led = Output::new(p.PB14, Level::High, Speed::Low);
led.set_high();

loop {
led.set_high();
Timer::after(Duration::from_millis(500)).await;
Timer::after_millis(500).await;

led.set_low();
Timer::after(Duration::from_millis(500)).await;
Timer::after_millis(500).await;
}
}
Loading

0 comments on commit 0621e95

Please sign in to comment.