diff --git a/docs/modules/ROOT/examples/basic/src/main.rs b/docs/modules/ROOT/examples/basic/src/main.rs index 8394f73b..461741fd 100644 --- a/docs/modules/ROOT/examples/basic/src/main.rs +++ b/docs/modules/ROOT/examples/basic/src/main.rs @@ -2,18 +2,13 @@ #![no_main] #![feature(type_alias_impl_trait)] -use defmt_rtt as _; // global logger -use panic_probe as _; - use defmt::*; - use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; -use embassy_nrf::{ - gpio::{Level, Output, OutputDrive}, - peripherals::P0_13, - Peripherals, -}; +use embassy_nrf::gpio::{Level, Output, OutputDrive}; +use embassy_nrf::peripherals::P0_13; +use embassy_nrf::Peripherals; +use {defmt_rtt as _, panic_probe as _}; // global logger #[embassy::task] async fn blinker(mut led: Output<'static, P0_13>, interval: Duration) { diff --git a/docs/modules/ROOT/examples/layer-by-layer/blinky-async/src/main.rs b/docs/modules/ROOT/examples/layer-by-layer/blinky-async/src/main.rs index 35726be6..56bc698d 100644 --- a/docs/modules/ROOT/examples/layer-by-layer/blinky-async/src/main.rs +++ b/docs/modules/ROOT/examples/layer-by-layer/blinky-async/src/main.rs @@ -2,15 +2,11 @@ #![no_main] #![feature(type_alias_impl_trait)] -use defmt_rtt as _; -use panic_probe as _; - use embassy::executor::Spawner; -use embassy_stm32::{ - exti::ExtiInput, - gpio::{Input, Level, Output, Pull, Speed}, - Peripherals, -}; +use embassy_stm32::exti::ExtiInput; +use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; +use embassy_stm32::Peripherals; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_s: Spawner, p: Peripherals) { diff --git a/docs/modules/ROOT/examples/layer-by-layer/blinky-hal/src/main.rs b/docs/modules/ROOT/examples/layer-by-layer/blinky-hal/src/main.rs index 2064ea61..d0c9f490 100644 --- a/docs/modules/ROOT/examples/layer-by-layer/blinky-hal/src/main.rs +++ b/docs/modules/ROOT/examples/layer-by-layer/blinky-hal/src/main.rs @@ -2,10 +2,8 @@ #![no_main] use cortex_m_rt::entry; -use defmt_rtt as _; -use panic_probe as _; - use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; +use {defmt_rtt as _, panic_probe as _}; #[entry] fn main() -> ! { diff --git a/docs/modules/ROOT/examples/layer-by-layer/blinky-irq/src/main.rs b/docs/modules/ROOT/examples/layer-by-layer/blinky-irq/src/main.rs index 6a75384c..743d0c34 100644 --- a/docs/modules/ROOT/examples/layer-by-layer/blinky-irq/src/main.rs +++ b/docs/modules/ROOT/examples/layer-by-layer/blinky-irq/src/main.rs @@ -1,18 +1,15 @@ #![no_std] #![no_main] -use defmt_rtt as _; -use panic_probe as _; - use core::cell::RefCell; + use cortex_m::interrupt::Mutex; use cortex_m::peripheral::NVIC; use cortex_m_rt::entry; -use embassy_stm32::{ - gpio::{Input, Level, Output, Pin, Pull, Speed}, - interrupt, pac, - peripherals::{PB14, PC13}, -}; +use embassy_stm32::gpio::{Input, Level, Output, Pin, Pull, Speed}; +use embassy_stm32::peripherals::{PB14, PC13}; +use embassy_stm32::{interrupt, pac}; +use {defmt_rtt as _, panic_probe as _}; static BUTTON: Mutex>>> = Mutex::new(RefCell::new(None)); static LED: Mutex>>> = Mutex::new(RefCell::new(None)); diff --git a/docs/modules/ROOT/examples/layer-by-layer/blinky-pac/src/main.rs b/docs/modules/ROOT/examples/layer-by-layer/blinky-pac/src/main.rs index 239eac18..990d46cb 100644 --- a/docs/modules/ROOT/examples/layer-by-layer/blinky-pac/src/main.rs +++ b/docs/modules/ROOT/examples/layer-by-layer/blinky-pac/src/main.rs @@ -1,12 +1,8 @@ #![no_std] #![no_main] -use defmt_rtt as _; -use panic_probe as _; - -use stm32_metapac as pac; - use pac::gpio::vals; +use {defmt_rtt as _, panic_probe as _, stm32_metapac as pac}; #[cortex_m_rt::entry] fn main() -> ! { @@ -30,30 +26,18 @@ fn main() -> ! { let gpioc = pac::GPIOC; const BUTTON_PIN: usize = 13; unsafe { - gpioc - .pupdr() - .modify(|w| w.set_pupdr(BUTTON_PIN, vals::Pupdr::PULLUP)); - gpioc - .otyper() - .modify(|w| w.set_ot(BUTTON_PIN, vals::Ot::PUSHPULL)); - gpioc - .moder() - .modify(|w| w.set_moder(BUTTON_PIN, vals::Moder::INPUT)); + gpioc.pupdr().modify(|w| w.set_pupdr(BUTTON_PIN, vals::Pupdr::PULLUP)); + gpioc.otyper().modify(|w| w.set_ot(BUTTON_PIN, vals::Ot::PUSHPULL)); + gpioc.moder().modify(|w| w.set_moder(BUTTON_PIN, vals::Moder::INPUT)); } // Setup LED let gpiob = pac::GPIOB; const LED_PIN: usize = 14; unsafe { - gpiob - .pupdr() - .modify(|w| w.set_pupdr(LED_PIN, vals::Pupdr::FLOATING)); - gpiob - .otyper() - .modify(|w| w.set_ot(LED_PIN, vals::Ot::PUSHPULL)); - gpiob - .moder() - .modify(|w| w.set_moder(LED_PIN, vals::Moder::OUTPUT)); + gpiob.pupdr().modify(|w| w.set_pupdr(LED_PIN, vals::Pupdr::FLOATING)); + gpiob.otyper().modify(|w| w.set_ot(LED_PIN, vals::Ot::PUSHPULL)); + gpiob.moder().modify(|w| w.set_moder(LED_PIN, vals::Moder::OUTPUT)); } // Main loop diff --git a/embassy-boot/boot/src/lib.rs b/embassy-boot/boot/src/lib.rs index 87bb973a..b18c88a6 100644 --- a/embassy-boot/boot/src/lib.rs +++ b/embassy-boot/boot/src/lib.rs @@ -202,8 +202,7 @@ impl BootLoader { // Ensure we have enough progress pages to store copy progress assert!( self.active.len() / PAGE_SIZE - <= (self.state.len() - - <

::STATE as FlashConfig>::FLASH::WRITE_SIZE) + <= (self.state.len() - <

::STATE as FlashConfig>::FLASH::WRITE_SIZE) / <

::STATE as FlashConfig>::FLASH::WRITE_SIZE ); @@ -226,15 +225,12 @@ impl BootLoader { // Overwrite magic and reset progress let fstate = p.state().flash(); let aligned = Aligned( - [!P::STATE::ERASE_VALUE; - <

::STATE as FlashConfig>::FLASH::WRITE_SIZE], + [!P::STATE::ERASE_VALUE; <

::STATE as FlashConfig>::FLASH::WRITE_SIZE], ); fstate.write(self.state.from as u32, &aligned.0)?; fstate.erase(self.state.from as u32, self.state.to as u32)?; - let aligned = Aligned( - [BOOT_MAGIC; - <

::STATE as FlashConfig>::FLASH::WRITE_SIZE], - ); + let aligned = + Aligned([BOOT_MAGIC; <

::STATE as FlashConfig>::FLASH::WRITE_SIZE]); fstate.write(self.state.from as u32, &aligned.0)?; } } @@ -262,10 +258,7 @@ impl BootLoader { let flash = p.flash(); let mut aligned = Aligned([!P::ERASE_VALUE; P::FLASH::WRITE_SIZE]); for i in 0..max_index { - flash.read( - (self.state.from + write_size + i * write_size) as u32, - &mut aligned.0, - )?; + flash.read((self.state.from + write_size + i * write_size) as u32, &mut aligned.0)?; if aligned.0 == [P::ERASE_VALUE; P::FLASH::WRITE_SIZE] { return Ok(i); } @@ -311,9 +304,7 @@ impl BootLoader { offset += chunk.len(); } - p.active() - .flash() - .erase(to_page as u32, (to_page + PAGE_SIZE) as u32)?; + p.active().flash().erase(to_page as u32, (to_page + PAGE_SIZE) as u32)?; let mut offset = to_page; for chunk in buf.chunks(P::ACTIVE::BLOCK_SIZE) { @@ -343,9 +334,7 @@ impl BootLoader { offset += chunk.len(); } - p.dfu() - .flash() - .erase(to_page as u32, (to_page + PAGE_SIZE) as u32)?; + p.dfu().flash().erase(to_page as u32, (to_page + PAGE_SIZE) as u32)?; let mut offset = to_page; for chunk in buf.chunks(P::DFU::BLOCK_SIZE) { @@ -609,9 +598,7 @@ impl FirmwareUpdater { aligned[i] = 0; } flash.write(self.state.from as u32, aligned).await?; - flash - .erase(self.state.from as u32, self.state.to as u32) - .await?; + flash.erase(self.state.from as u32, self.state.to as u32).await?; for i in 0..aligned.len() { aligned[i] = magic; @@ -677,13 +664,15 @@ impl FirmwareUpdater { #[cfg(test)] mod tests { - use super::*; use core::convert::Infallible; use core::future::Future; + use embedded_storage::nor_flash::ErrorType; use embedded_storage_async::nor_flash::AsyncReadNorFlash; use futures::executor::block_on; + use super::*; + /* #[test] fn test_bad_magic() { @@ -810,11 +799,7 @@ mod tests { assert_eq!( State::Swap, bootloader - .prepare_boot(&mut MultiFlashProvider::new( - &mut active, - &mut state, - &mut dfu, - )) + .prepare_boot(&mut MultiFlashProvider::new(&mut active, &mut state, &mut dfu,)) .unwrap() ); @@ -858,11 +843,7 @@ mod tests { assert_eq!( State::Swap, bootloader - .prepare_boot(&mut MultiFlashProvider::new( - &mut active, - &mut state, - &mut dfu, - )) + .prepare_boot(&mut MultiFlashProvider::new(&mut active, &mut state, &mut dfu,)) .unwrap() ); @@ -876,9 +857,7 @@ mod tests { } } - struct MemFlash( - [u8; SIZE], - ); + struct MemFlash([u8; SIZE]); impl NorFlash for MemFlash @@ -889,12 +868,7 @@ mod tests { let from = from as usize; let to = to as usize; assert!(from % ERASE_SIZE == 0); - assert!( - to % ERASE_SIZE == 0, - "To: {}, erase size: {}", - to, - ERASE_SIZE - ); + assert!(to % ERASE_SIZE == 0, "To: {}, erase size: {}", to, ERASE_SIZE); for i in from..to { self.0[i] = 0xFF; } diff --git a/embassy-boot/nrf/src/lib.rs b/embassy-boot/nrf/src/lib.rs index 9f891887..2d6b837c 100644 --- a/embassy-boot/nrf/src/lib.rs +++ b/embassy-boot/nrf/src/lib.rs @@ -6,14 +6,10 @@ mod fmt; -pub use embassy_boot::{ - FirmwareUpdater, FlashConfig, FlashProvider, Partition, SingleFlashProvider, -}; -use embassy_nrf::{ - nvmc::{Nvmc, PAGE_SIZE}, - peripherals::WDT, - wdt, -}; +pub use embassy_boot::{FirmwareUpdater, FlashConfig, FlashProvider, Partition, SingleFlashProvider}; +use embassy_nrf::nvmc::{Nvmc, PAGE_SIZE}; +use embassy_nrf::peripherals::WDT; +use embassy_nrf::wdt; use embedded_storage::nor_flash::{ErrorType, NorFlash, ReadNorFlash}; pub struct BootLoader { @@ -95,9 +91,7 @@ impl BootLoader { let mut cmd = mbr::sd_mbr_command_t { command: mbr::NRF_MBR_COMMANDS_SD_MBR_COMMAND_IRQ_FORWARD_ADDRESS_SET, params: mbr::sd_mbr_command_t__bindgen_ty_1 { - irq_forward_address_set: mbr::sd_mbr_command_irq_forward_address_set_t { - address: addr, - }, + irq_forward_address_set: mbr::sd_mbr_command_irq_forward_address_set_t { address: addr }, }, }; let ret = mbr::sd_mbr_command(&mut cmd); diff --git a/embassy-boot/nrf/src/main.rs b/embassy-boot/nrf/src/main.rs index 0ccd3774..bc7e0755 100644 --- a/embassy-boot/nrf/src/main.rs +++ b/embassy-boot/nrf/src/main.rs @@ -2,10 +2,8 @@ #![no_main] use cortex_m_rt::{entry, exception}; - #[cfg(feature = "defmt")] use defmt_rtt as _; - use embassy_boot_nrf::*; use embassy_nrf::nvmc::Nvmc; diff --git a/embassy-boot/stm32/src/lib.rs b/embassy-boot/stm32/src/lib.rs index 8c6e6550..5a4f2d05 100644 --- a/embassy-boot/stm32/src/lib.rs +++ b/embassy-boot/stm32/src/lib.rs @@ -6,9 +6,7 @@ mod fmt; -pub use embassy_boot::{ - FirmwareUpdater, FlashConfig, FlashProvider, Partition, SingleFlashProvider, State, -}; +pub use embassy_boot::{FirmwareUpdater, FlashConfig, FlashProvider, Partition, SingleFlashProvider, State}; use embedded_storage::nor_flash::NorFlash; pub struct BootLoader { diff --git a/embassy-boot/stm32/src/main.rs b/embassy-boot/stm32/src/main.rs index d79b14c6..45c511ce 100644 --- a/embassy-boot/stm32/src/main.rs +++ b/embassy-boot/stm32/src/main.rs @@ -2,10 +2,8 @@ #![no_main] use cortex_m_rt::{entry, exception}; - #[cfg(feature = "defmt")] use defmt_rtt as _; - use embassy_boot_stm32::*; use embassy_stm32::flash::{Flash, ERASE_SIZE}; diff --git a/embassy-cortex-m/src/executor.rs b/embassy-cortex-m/src/executor.rs index 63a1519c..34f3ec23 100644 --- a/embassy-cortex-m/src/executor.rs +++ b/embassy-cortex-m/src/executor.rs @@ -1,9 +1,9 @@ use core::marker::PhantomData; -use crate::interrupt::{Interrupt, InterruptExt}; +pub use embassy::executor::Executor; use embassy::executor::{raw, SendSpawner}; -pub use embassy::executor::Executor; +use crate::interrupt::{Interrupt, InterruptExt}; fn pend_by_number(n: u16) { #[derive(Clone, Copy)] diff --git a/embassy-cortex-m/src/interrupt.rs b/embassy-cortex-m/src/interrupt.rs index df2aad0e..72686b40 100644 --- a/embassy-cortex-m/src/interrupt.rs +++ b/embassy-cortex-m/src/interrupt.rs @@ -1,9 +1,8 @@ +use core::{mem, ptr}; + use atomic_polyfill::{compiler_fence, AtomicPtr, Ordering}; -use core::mem; -use core::ptr; use cortex_m::peripheral::NVIC; use embassy_hal_common::Unborrow; - pub use embassy_macros::cortex_m_interrupt_take as take; /// Implementation detail, do not use outside embassy crates. diff --git a/embassy-cortex-m/src/peripheral.rs b/embassy-cortex-m/src/peripheral.rs index 40277691..5ff69083 100644 --- a/embassy-cortex-m/src/peripheral.rs +++ b/embassy-cortex-m/src/peripheral.rs @@ -1,5 +1,6 @@ use core::marker::PhantomData; use core::mem::MaybeUninit; + use cortex_m::peripheral::scb::VectActive; use cortex_m::peripheral::{NVIC, SCB}; @@ -53,13 +54,11 @@ impl<'a, S: PeripheralState> PeripheralMutex<'a, S> { /// Create a new `PeripheralMutex` wrapping `irq`, with `init` initializing the initial state. /// /// Registers `on_interrupt` as the `irq`'s handler, and enables it. - pub fn new( - irq: S::Interrupt, - storage: &'a mut StateStorage, - init: impl FnOnce() -> S, - ) -> Self { + pub fn new(irq: S::Interrupt, storage: &'a mut StateStorage, init: impl FnOnce() -> S) -> Self { if can_be_preempted(&irq) { - panic!("`PeripheralMutex` cannot be created in an interrupt with higher priority than the interrupt it wraps"); + panic!( + "`PeripheralMutex` cannot be created in an interrupt with higher priority than the interrupt it wraps" + ); } let state_ptr = storage.0.as_mut_ptr(); diff --git a/embassy-embedded-hal/src/adapter.rs b/embassy-embedded-hal/src/adapter.rs index 033efb7e..7d25d89f 100644 --- a/embassy-embedded-hal/src/adapter.rs +++ b/embassy-embedded-hal/src/adapter.rs @@ -1,6 +1,6 @@ use core::future::Future; -use embedded_hal_02::blocking; -use embedded_hal_02::serial; + +use embedded_hal_02::{blocking, serial}; /// BlockingAsync is a wrapper that implements async traits using blocking peripherals. This allows /// driver writers to depend on the async traits while still supporting embedded-hal peripheral implementations. @@ -25,9 +25,7 @@ impl BlockingAsync { impl embedded_hal_1::i2c::ErrorType for BlockingAsync where E: embedded_hal_1::i2c::Error + 'static, - T: blocking::i2c::WriteRead - + blocking::i2c::Read - + blocking::i2c::Write, + T: blocking::i2c::WriteRead + blocking::i2c::Read + blocking::i2c::Write, { type Error = E; } @@ -35,9 +33,7 @@ where impl embedded_hal_async::i2c::I2c for BlockingAsync where E: embedded_hal_1::i2c::Error + 'static, - T: blocking::i2c::WriteRead - + blocking::i2c::Read - + blocking::i2c::Write, + T: blocking::i2c::WriteRead + blocking::i2c::Read + blocking::i2c::Write, { type WriteFuture<'a> = impl Future> + 'a where Self: 'a; type ReadFuture<'a> = impl Future> + 'a where Self: 'a; @@ -51,12 +47,7 @@ where async move { self.wrapped.write(address, bytes) } } - fn write_read<'a>( - &'a mut self, - address: u8, - bytes: &'a [u8], - buffer: &'a mut [u8], - ) -> Self::WriteReadFuture<'a> { + fn write_read<'a>(&'a mut self, address: u8, bytes: &'a [u8], buffer: &'a mut [u8]) -> Self::WriteReadFuture<'a> { async move { self.wrapped.write_read(address, bytes, buffer) } } diff --git a/embassy-embedded-hal/src/shared_bus/i2c.rs b/embassy-embedded-hal/src/shared_bus/i2c.rs index 5a180e89..e8131288 100644 --- a/embassy-embedded-hal/src/shared_bus/i2c.rs +++ b/embassy-embedded-hal/src/shared_bus/i2c.rs @@ -22,7 +22,9 @@ //! let i2c_dev2 = I2cBusDevice::new(i2c_bus); //! let mpu = Mpu6050::new(i2c_dev2); //! ``` -use core::{fmt::Debug, future::Future}; +use core::fmt::Debug; +use core::future::Future; + use embassy::blocking_mutex::raw::RawMutex; use embassy::mutex::Mutex; use embedded_hal_async::i2c; @@ -70,9 +72,7 @@ where fn read<'a>(&'a mut self, address: u8, buffer: &'a mut [u8]) -> Self::ReadFuture<'a> { async move { let mut bus = self.bus.lock().await; - bus.read(address, buffer) - .await - .map_err(I2cBusDeviceError::I2c)?; + bus.read(address, buffer).await.map_err(I2cBusDeviceError::I2c)?; Ok(()) } } @@ -82,9 +82,7 @@ where fn write<'a>(&'a mut self, address: u8, bytes: &'a [u8]) -> Self::WriteFuture<'a> { async move { let mut bus = self.bus.lock().await; - bus.write(address, bytes) - .await - .map_err(I2cBusDeviceError::I2c)?; + bus.write(address, bytes).await.map_err(I2cBusDeviceError::I2c)?; Ok(()) } } diff --git a/embassy-embedded-hal/src/shared_bus/spi.rs b/embassy-embedded-hal/src/shared_bus/spi.rs index 3ec064ba..fd4b6d56 100644 --- a/embassy-embedded-hal/src/shared_bus/spi.rs +++ b/embassy-embedded-hal/src/shared_bus/spi.rs @@ -25,10 +25,11 @@ //! let spi_dev2 = SpiBusDevice::new(spi_bus, cs_pin2); //! let display2 = ST7735::new(spi_dev2, dc2, rst2, Default::default(), 160, 128); //! ``` -use core::{fmt::Debug, future::Future}; +use core::fmt::Debug; +use core::future::Future; + use embassy::blocking_mutex::raw::RawMutex; use embassy::mutex::Mutex; - use embedded_hal_1::digital::blocking::OutputPin; use embedded_hal_1::spi::ErrorType; use embedded_hal_async::spi; diff --git a/embassy-hal-common/src/drop.rs b/embassy-hal-common/src/drop.rs index 3a90dd50..6ef716f9 100644 --- a/embassy-hal-common/src/drop.rs +++ b/embassy-hal-common/src/drop.rs @@ -7,9 +7,7 @@ pub struct OnDrop { impl OnDrop { pub fn new(f: F) -> Self { - Self { - f: MaybeUninit::new(f), - } + Self { f: MaybeUninit::new(f) } } pub fn defuse(self) { diff --git a/embassy-hal-common/src/ratio.rs b/embassy-hal-common/src/ratio.rs index ce7e4b1b..9a8808a3 100644 --- a/embassy-hal-common/src/ratio.rs +++ b/embassy-hal-common/src/ratio.rs @@ -1,4 +1,5 @@ use core::ops::{Add, Div, Mul}; + use num_traits::{CheckedAdd, CheckedDiv, CheckedMul}; /// Represents the ratio between two numbers. diff --git a/embassy-lora/src/stm32wl/mod.rs b/embassy-lora/src/stm32wl/mod.rs index b5ce278d..5f3dc17a 100644 --- a/embassy-lora/src/stm32wl/mod.rs +++ b/embassy-lora/src/stm32wl/mod.rs @@ -1,25 +1,20 @@ //! A radio driver integration for the radio found on STM32WL family devices. use core::future::Future; use core::mem::MaybeUninit; + use embassy::channel::signal::Signal; use embassy_hal_common::unborrow; -use embassy_stm32::interrupt::InterruptExt; +use embassy_stm32::dma::NoDma; +use embassy_stm32::gpio::{AnyPin, Output}; +use embassy_stm32::interrupt::{InterruptExt, SUBGHZ_RADIO}; +use embassy_stm32::subghz::{ + CalibrateImage, CfgIrq, CodingRate, HeaderType, Irq, LoRaBandwidth, LoRaModParams, LoRaPacketParams, LoRaSyncWord, + Ocp, PaConfig, PaSel, PacketType, RampTime, RegMode, RfFreq, SpreadingFactor as SF, StandbyClk, Status, SubGhz, + TcxoMode, TcxoTrim, Timeout, TxParams, +}; use embassy_stm32::Unborrow; -use embassy_stm32::{ - dma::NoDma, - gpio::{AnyPin, Output}, - interrupt::SUBGHZ_RADIO, - subghz::{ - CalibrateImage, CfgIrq, CodingRate, HeaderType, Irq, LoRaBandwidth, LoRaModParams, - LoRaPacketParams, LoRaSyncWord, Ocp, PaConfig, PaSel, PacketType, RampTime, RegMode, - RfFreq, SpreadingFactor as SF, StandbyClk, Status, SubGhz, TcxoMode, TcxoTrim, Timeout, - TxParams, - }, -}; -use lorawan_device::async_device::{ - radio::{Bandwidth, PhyRxTx, RfConfig, RxQuality, SpreadingFactor, TxConfig}, - Timings, -}; +use lorawan_device::async_device::radio::{Bandwidth, PhyRxTx, RfConfig, RxQuality, SpreadingFactor, TxConfig}; +use lorawan_device::async_device::Timings; #[derive(Debug, Copy, Clone)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] @@ -98,9 +93,7 @@ impl<'a> StateInner<'a> { self.radio.set_standby(StandbyClk::Rc)?; let tcxo_mode = TcxoMode::new() .set_txco_trim(TcxoTrim::Volts1pt7) - .set_timeout(Timeout::from_duration_sat( - core::time::Duration::from_millis(40), - )); + .set_timeout(Timeout::from_duration_sat(core::time::Duration::from_millis(40))); self.radio.set_tcxo_mode(&tcxo_mode)?; self.radio.set_regulator_mode(RegMode::Ldo)?; @@ -109,21 +102,14 @@ impl<'a> StateInner<'a> { self.radio.set_buffer_base_address(0, 0)?; - self.radio.set_pa_config( - &PaConfig::new() - .set_pa_duty_cycle(0x1) - .set_hp_max(0x0) - .set_pa(PaSel::Lp), - )?; + self.radio + .set_pa_config(&PaConfig::new().set_pa_duty_cycle(0x1).set_hp_max(0x0).set_pa(PaSel::Lp))?; self.radio.set_pa_ocp(Ocp::Max140m)?; // let tx_params = TxParams::LP_14.set_ramp_time(RampTime::Micros40); - self.radio.set_tx_params( - &TxParams::new() - .set_ramp_time(RampTime::Micros40) - .set_power(0x0A), - )?; + self.radio + .set_tx_params(&TxParams::new().set_ramp_time(RampTime::Micros40).set_power(0x0A))?; self.radio.set_packet_type(PacketType::LoRa)?; self.radio.set_lora_sync_word(LoRaSyncWord::Public)?; @@ -193,19 +179,14 @@ impl<'a> StateInner<'a> { /// Perform a radio receive operation with the radio config and receive buffer. The receive buffer must /// be able to hold a single LoRaWAN packet. - async fn do_rx( - &mut self, - config: RfConfig, - buf: &mut [u8], - ) -> Result<(usize, RxQuality), RadioError> { + async fn do_rx(&mut self, config: RfConfig, buf: &mut [u8]) -> Result<(usize, RxQuality), RadioError> { assert!(buf.len() >= 255); trace!("RX START"); // trace!("Starting RX: {}", config); self.switch.set_rx(); self.configure()?; - self.radio - .set_rf_frequency(&RfFreq::from_frequency(config.frequency))?; + self.radio.set_rf_frequency(&RfFreq::from_frequency(config.frequency))?; let mod_params = LoRaModParams::new() .set_sf(convert_spreading_factor(config.spreading_factor)) @@ -315,16 +296,8 @@ pub struct RadioSwitch<'a> { } impl<'a> RadioSwitch<'a> { - pub fn new( - ctrl1: Output<'a, AnyPin>, - ctrl2: Output<'a, AnyPin>, - ctrl3: Output<'a, AnyPin>, - ) -> Self { - Self { - ctrl1, - ctrl2, - ctrl3, - } + pub fn new(ctrl1: Output<'a, AnyPin>, ctrl2: Output<'a, AnyPin>, ctrl3: Output<'a, AnyPin>) -> Self { + Self { ctrl1, ctrl2, ctrl3 } } pub(crate) fn set_rx(&mut self) { diff --git a/embassy-lora/src/sx127x/mod.rs b/embassy-lora/src/sx127x/mod.rs index c70f3358..f47a9eb5 100644 --- a/embassy-lora/src/sx127x/mod.rs +++ b/embassy-lora/src/sx127x/mod.rs @@ -1,11 +1,10 @@ use core::future::Future; + use embedded_hal::digital::v2::OutputPin; use embedded_hal_async::digital::Wait; use embedded_hal_async::spi::*; -use lorawan_device::async_device::{ - radio::{Bandwidth, PhyRxTx, RfConfig, RxQuality, SpreadingFactor, TxConfig}, - Timings, -}; +use lorawan_device::async_device::radio::{Bandwidth, PhyRxTx, RfConfig, RxQuality, SpreadingFactor, TxConfig}; +use lorawan_device::async_device::Timings; mod sx127x_lora; use sx127x_lora::{Error as RadioError, LoRa, RadioMode, IRQ}; diff --git a/embassy-lora/src/sx127x/sx127x_lora/mod.rs b/embassy-lora/src/sx127x/sx127x_lora/mod.rs index 62eaf0a9..8b937ec2 100644 --- a/embassy-lora/src/sx127x/sx127x_lora/mod.rs +++ b/embassy-lora/src/sx127x/sx127x_lora/mod.rs @@ -11,9 +11,8 @@ use embedded_hal::digital::v2::OutputPin; use embedded_hal_async::spi::SpiBus; mod register; -use self::register::PaConfig; -use self::register::Register; pub use self::register::IRQ; +use self::register::{PaConfig, Register}; /// Provides high-level access to Semtech SX1276/77/78/79 based boards connected to a Raspberry Pi pub struct LoRa { @@ -72,15 +71,11 @@ where let version = self.read_register(Register::RegVersion.addr()).await?; if version == VERSION_CHECK { self.set_mode(RadioMode::Sleep).await?; - self.write_register(Register::RegFifoTxBaseAddr.addr(), 0) - .await?; - self.write_register(Register::RegFifoRxBaseAddr.addr(), 0) - .await?; + self.write_register(Register::RegFifoTxBaseAddr.addr(), 0).await?; + self.write_register(Register::RegFifoRxBaseAddr.addr(), 0).await?; let lna = self.read_register(Register::RegLna.addr()).await?; - self.write_register(Register::RegLna.addr(), lna | 0x03) - .await?; - self.write_register(Register::RegModemConfig3.addr(), 0x04) - .await?; + self.write_register(Register::RegLna.addr(), lna | 0x03).await?; + self.write_register(Register::RegModemConfig3.addr(), 0x04).await?; self.set_tcxo(true).await?; self.set_mode(RadioMode::Stdby).await?; self.cs.set_high().map_err(CS)?; @@ -106,10 +101,7 @@ where .await } - pub async fn transmit_start( - &mut self, - buffer: &[u8], - ) -> Result<(), Error> { + pub async fn transmit_start(&mut self, buffer: &[u8]) -> Result<(), Error> { assert!(buffer.len() < 255); if self.transmitting().await? { //trace!("ALREADY TRANSMNITTING"); @@ -123,10 +115,8 @@ where } self.write_register(Register::RegIrqFlags.addr(), 0).await?; - self.write_register(Register::RegFifoAddrPtr.addr(), 0) - .await?; - self.write_register(Register::RegPayloadLength.addr(), 0) - .await?; + self.write_register(Register::RegFifoAddrPtr.addr(), 0).await?; + self.write_register(Register::RegPayloadLength.addr(), 0).await?; for byte in buffer.iter() { self.write_register(Register::RegFifo.addr(), *byte).await?; } @@ -138,10 +128,7 @@ where } pub async fn packet_ready(&mut self) -> Result> { - Ok(self - .read_register(Register::RegIrqFlags.addr()) - .await? - .get_bit(6)) + Ok(self.read_register(Register::RegIrqFlags.addr()).await?.get_bit(6)) } pub async fn irq_flags_mask(&mut self) -> Result> { @@ -159,37 +146,26 @@ where /// Returns the contents of the fifo as a fixed 255 u8 array. This should only be called is there is a /// new packet ready to be read. - pub async fn read_packet( - &mut self, - buffer: &mut [u8], - ) -> Result<(), Error> { + pub async fn read_packet(&mut self, buffer: &mut [u8]) -> Result<(), Error> { self.clear_irq().await?; let size = self.read_register(Register::RegRxNbBytes.addr()).await?; assert!(size as usize <= buffer.len()); - let fifo_addr = self - .read_register(Register::RegFifoRxCurrentAddr.addr()) - .await?; - self.write_register(Register::RegFifoAddrPtr.addr(), fifo_addr) - .await?; + let fifo_addr = self.read_register(Register::RegFifoRxCurrentAddr.addr()).await?; + self.write_register(Register::RegFifoAddrPtr.addr(), fifo_addr).await?; for i in 0..size { let byte = self.read_register(Register::RegFifo.addr()).await?; buffer[i as usize] = byte; } - self.write_register(Register::RegFifoAddrPtr.addr(), 0) - .await?; + self.write_register(Register::RegFifoAddrPtr.addr(), 0).await?; Ok(()) } /// Returns true if the radio is currently transmitting a packet. pub async fn transmitting(&mut self) -> Result> { - if (self.read_register(Register::RegOpMode.addr()).await?) & RadioMode::Tx.addr() - == RadioMode::Tx.addr() - { + if (self.read_register(Register::RegOpMode.addr()).await?) & RadioMode::Tx.addr() == RadioMode::Tx.addr() { Ok(true) } else { - if (self.read_register(Register::RegIrqFlags.addr()).await? & IRQ::IrqTxDoneMask.addr()) - == 1 - { + if (self.read_register(Register::RegIrqFlags.addr()).await? & IRQ::IrqTxDoneMask.addr()) == 1 { self.write_register(Register::RegIrqFlags.addr(), IRQ::IrqTxDoneMask.addr()) .await?; } @@ -200,8 +176,7 @@ where /// Clears the radio's IRQ registers. pub async fn clear_irq(&mut self) -> Result> { let irq_flags = self.read_register(Register::RegIrqFlags.addr()).await?; - self.write_register(Register::RegIrqFlags.addr(), 0xFF) - .await?; + self.write_register(Register::RegIrqFlags.addr(), 0xFF).await?; Ok(irq_flags) } @@ -243,11 +218,8 @@ where self.set_ocp(100).await?; } level -= 2; - self.write_register( - Register::RegPaConfig.addr(), - PaConfig::PaBoost.addr() | level as u8, - ) - .await + self.write_register(Register::RegPaConfig.addr(), PaConfig::PaBoost.addr() | level as u8) + .await } } @@ -269,10 +241,7 @@ where } /// Sets the state of the radio. Default mode after initiation is `Standby`. - pub async fn set_mode( - &mut self, - mode: RadioMode, - ) -> Result<(), Error> { + pub async fn set_mode(&mut self, mode: RadioMode) -> Result<(), Error> { if self.explicit_header { self.set_explicit_header_mode().await?; } else { @@ -289,25 +258,18 @@ where } pub async fn reset_payload_length(&mut self) -> Result<(), Error> { - self.write_register(Register::RegPayloadLength.addr(), 0xFF) - .await + self.write_register(Register::RegPayloadLength.addr(), 0xFF).await } /// Sets the frequency of the radio. Values are in megahertz. /// I.E. 915 MHz must be used for North America. Check regulation for your area. - pub async fn set_frequency( - &mut self, - freq: u32, - ) -> Result<(), Error> { + pub async fn set_frequency(&mut self, freq: u32) -> Result<(), Error> { const FREQ_STEP: f64 = 61.03515625; // calculate register values let frf = (freq as f64 / FREQ_STEP) as u32; // write registers - self.write_register( - Register::RegFrfMsb.addr(), - ((frf & 0x00FF_0000) >> 16) as u8, - ) - .await?; + self.write_register(Register::RegFrfMsb.addr(), ((frf & 0x00FF_0000) >> 16) as u8) + .await?; self.write_register(Register::RegFrfMid.addr(), ((frf & 0x0000_FF00) >> 8) as u8) .await?; self.write_register(Register::RegFrfLsb.addr(), (frf & 0x0000_00FF) as u8) @@ -335,10 +297,7 @@ where /// Sets the spreading factor of the radio. Supported values are between 6 and 12. /// If a spreading factor of 6 is set, implicit header mode must be used to transmit /// and receive packets. Default value is `7`. - pub async fn set_spreading_factor( - &mut self, - mut sf: u8, - ) -> Result<(), Error> { + pub async fn set_spreading_factor(&mut self, mut sf: u8) -> Result<(), Error> { if sf < 6 { sf = 6; } else if sf > 12 { @@ -346,13 +305,11 @@ where } if sf == 6 { - self.write_register(Register::RegDetectionOptimize.addr(), 0xc5) - .await?; + self.write_register(Register::RegDetectionOptimize.addr(), 0xc5).await?; self.write_register(Register::RegDetectionThreshold.addr(), 0x0c) .await?; } else { - self.write_register(Register::RegDetectionOptimize.addr(), 0xc3) - .await?; + self.write_register(Register::RegDetectionOptimize.addr(), 0xc3).await?; self.write_register(Register::RegDetectionThreshold.addr(), 0x0a) .await?; } @@ -364,16 +321,12 @@ where .await?; self.set_ldo_flag().await?; - self.write_register(Register::RegSymbTimeoutLsb.addr(), 0x05) - .await?; + self.write_register(Register::RegSymbTimeoutLsb.addr(), 0x05).await?; Ok(()) } - pub async fn set_tcxo( - &mut self, - external: bool, - ) -> Result<(), Error> { + pub async fn set_tcxo(&mut self, external: bool) -> Result<(), Error> { if external { self.write_register(Register::RegTcxo.addr(), 0x10).await } else { @@ -384,10 +337,7 @@ where /// Sets the signal bandwidth of the radio. Supported values are: `7800 Hz`, `10400 Hz`, /// `15600 Hz`, `20800 Hz`, `31250 Hz`,`41700 Hz` ,`62500 Hz`,`125000 Hz` and `250000 Hz` /// Default value is `125000 Hz` - pub async fn set_signal_bandwidth( - &mut self, - sbw: i64, - ) -> Result<(), Error> { + pub async fn set_signal_bandwidth(&mut self, sbw: i64) -> Result<(), Error> { let bw: i64 = match sbw { 7_800 => 0, 10_400 => 1, @@ -413,10 +363,7 @@ where /// Sets the coding rate of the radio with the numerator fixed at 4. Supported values /// are between `5` and `8`, these correspond to coding rates of `4/5` and `4/8`. /// Default value is `5`. - pub async fn set_coding_rate_4( - &mut self, - mut denominator: u8, - ) -> Result<(), Error> { + pub async fn set_coding_rate_4(&mut self, mut denominator: u8) -> Result<(), Error> { if denominator < 5 { denominator = 5; } else if denominator > 8 { @@ -424,23 +371,16 @@ where } let cr = denominator - 4; let modem_config_1 = self.read_register(Register::RegModemConfig1.addr()).await?; - self.write_register( - Register::RegModemConfig1.addr(), - (modem_config_1 & 0xf1) | (cr << 1), - ) - .await + self.write_register(Register::RegModemConfig1.addr(), (modem_config_1 & 0xf1) | (cr << 1)) + .await } /// Sets the preamble length of the radio. Values are between 6 and 65535. /// Default value is `8`. - pub async fn set_preamble_length( - &mut self, - length: i64, - ) -> Result<(), Error> { + pub async fn set_preamble_length(&mut self, length: i64) -> Result<(), Error> { self.write_register(Register::RegPreambleMsb.addr(), (length >> 8) as u8) .await?; - self.write_register(Register::RegPreambleLsb.addr(), length as u8) - .await + self.write_register(Register::RegPreambleLsb.addr(), length as u8).await } /// Enables are disables the radio's CRC check. Default value is `false`. @@ -456,20 +396,13 @@ where } /// Inverts the radio's IQ signals. Default value is `false`. - pub async fn set_invert_iq( - &mut self, - value: bool, - ) -> Result<(), Error> { + pub async fn set_invert_iq(&mut self, value: bool) -> Result<(), Error> { if value { - self.write_register(Register::RegInvertiq.addr(), 0x66) - .await?; - self.write_register(Register::RegInvertiq2.addr(), 0x19) - .await + self.write_register(Register::RegInvertiq.addr(), 0x66).await?; + self.write_register(Register::RegInvertiq2.addr(), 0x19).await } else { - self.write_register(Register::RegInvertiq.addr(), 0x27) - .await?; - self.write_register(Register::RegInvertiq2.addr(), 0x1d) - .await + self.write_register(Register::RegInvertiq.addr(), 0x27).await?; + self.write_register(Register::RegInvertiq2.addr(), 0x1d).await } } @@ -504,15 +437,11 @@ where /// Returns the signal to noise radio of the the last received packet. pub async fn get_packet_snr(&mut self) -> Result> { - Ok(f64::from( - self.read_register(Register::RegPktSnrValue.addr()).await?, - )) + Ok(f64::from(self.read_register(Register::RegPktSnrValue.addr()).await?)) } /// Returns the frequency error of the last received packet in Hz. - pub async fn get_packet_frequency_error( - &mut self, - ) -> Result> { + pub async fn get_packet_frequency_error(&mut self) -> Result> { let mut freq_error: i32; freq_error = i32::from(self.read_register(Register::RegFreqErrorMsb.addr()).await? & 0x7); freq_error <<= 8i64; @@ -537,29 +466,20 @@ where let mut config_3 = self.read_register(Register::RegModemConfig3.addr()).await?; config_3.set_bit(3, ldo_on); //config_3.set_bit(2, true); - self.write_register(Register::RegModemConfig3.addr(), config_3) - .await + self.write_register(Register::RegModemConfig3.addr(), config_3).await } async fn read_register(&mut self, reg: u8) -> Result> { let mut buffer = [reg & 0x7f, 0]; self.cs.set_low().map_err(CS)?; - let _ = self - .spi - .transfer(&mut buffer, &[reg & 0x7f, 0]) - .await - .map_err(SPI)?; + let _ = self.spi.transfer(&mut buffer, &[reg & 0x7f, 0]).await.map_err(SPI)?; self.cs.set_high().map_err(CS)?; Ok(buffer[1]) } - async fn write_register( - &mut self, - reg: u8, - byte: u8, - ) -> Result<(), Error> { + async fn write_register(&mut self, reg: u8, byte: u8) -> Result<(), Error> { self.cs.set_low().map_err(CS)?; let buffer = [reg | 0x80, byte]; self.spi.write(&buffer).await.map_err(SPI)?; @@ -576,8 +496,7 @@ where .set_bit(3, false) //Low freq registers .set_bits(0..2, 0b011); // Mode - self.write_register(Register::RegOpMode as u8, op_mode) - .await + self.write_register(Register::RegOpMode as u8, op_mode).await } pub async fn set_fsk_pa_ramp( @@ -590,8 +509,7 @@ where .set_bits(5..6, modulation_shaping as u8) .set_bits(0..3, ramp as u8); - self.write_register(Register::RegPaRamp as u8, pa_ramp) - .await + self.write_register(Register::RegPaRamp as u8, pa_ramp).await } pub async fn set_lora_pa_ramp(&mut self) -> Result<(), Error> { diff --git a/embassy-macros/src/lib.rs b/embassy-macros/src/lib.rs index 50f44243..ec8498f9 100644 --- a/embassy-macros/src/lib.rs +++ b/embassy-macros/src/lib.rs @@ -25,17 +25,13 @@ pub fn main(args: TokenStream, item: TokenStream) -> TokenStream { pub fn cortex_m_interrupt(args: TokenStream, item: TokenStream) -> TokenStream { let args = syn::parse_macro_input!(args as syn::AttributeArgs); let f = syn::parse_macro_input!(item as syn::ItemFn); - cortex_m_interrupt::run(args, f) - .unwrap_or_else(|x| x) - .into() + cortex_m_interrupt::run(args, f).unwrap_or_else(|x| x).into() } #[proc_macro] pub fn cortex_m_interrupt_declare(item: TokenStream) -> TokenStream { let name = syn::parse_macro_input!(item as syn::Ident); - cortex_m_interrupt_declare::run(name) - .unwrap_or_else(|x| x) - .into() + cortex_m_interrupt_declare::run(name).unwrap_or_else(|x| x).into() } /// # interrupt_take procedural macro @@ -46,7 +42,5 @@ pub fn cortex_m_interrupt_declare(item: TokenStream) -> TokenStream { #[proc_macro] pub fn cortex_m_interrupt_take(item: TokenStream) -> TokenStream { let name = syn::parse_macro_input!(item as syn::Ident); - cortex_m_interrupt_take::run(name) - .unwrap_or_else(|x| x) - .into() + cortex_m_interrupt_take::run(name).unwrap_or_else(|x| x).into() } diff --git a/embassy-macros/src/macros/cortex_m_interrupt.rs b/embassy-macros/src/macros/cortex_m_interrupt.rs index 32cc0e01..13af8ca0 100644 --- a/embassy-macros/src/macros/cortex_m_interrupt.rs +++ b/embassy-macros/src/macros/cortex_m_interrupt.rs @@ -1,9 +1,9 @@ +use std::iter; + use darling::FromMeta; use proc_macro2::TokenStream; use quote::quote; -use std::iter; -use syn::ReturnType; -use syn::{Type, Visibility}; +use syn::{ReturnType, Type, Visibility}; use crate::util::ctxt::Ctxt; diff --git a/embassy-macros/src/macros/main.rs b/embassy-macros/src/macros/main.rs index b7ce9dda..5638276b 100644 --- a/embassy-macros/src/macros/main.rs +++ b/embassy-macros/src/macros/main.rs @@ -81,14 +81,11 @@ pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result().unwrap()) - .unwrap_or_else(|| { - syn::Expr::Verbatim(quote! { - Default::default() - }) - }); + let config = args.config.map(|s| s.parse::().unwrap()).unwrap_or_else(|| { + syn::Expr::Verbatim(quote! { + Default::default() + }) + }); let (hal_setup, peris_arg) = match HAL { Some(hal) => { diff --git a/embassy-macros/src/macros/task.rs b/embassy-macros/src/macros/task.rs index e48de3d6..53c9af54 100644 --- a/embassy-macros/src/macros/task.rs +++ b/embassy-macros/src/macros/task.rs @@ -47,10 +47,7 @@ pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result { - ctxt.error_spanned_by( - arg, - "pattern matching in task arguments is not yet supported", - ); + ctxt.error_spanned_by(arg, "pattern matching in task arguments is not yet supported"); } }, } diff --git a/embassy-macros/src/util/ctxt.rs b/embassy-macros/src/util/ctxt.rs index d668ae78..74c872c3 100644 --- a/embassy-macros/src/util/ctxt.rs +++ b/embassy-macros/src/util/ctxt.rs @@ -1,11 +1,12 @@ // nifty utility borrowed from serde :) // https://github.com/serde-rs/serde/blob/master/serde_derive/src/internals/ctxt.rs -use proc_macro2::TokenStream; -use quote::{quote, ToTokens}; use std::cell::RefCell; use std::fmt::Display; use std::thread; + +use proc_macro2::TokenStream; +use quote::{quote, ToTokens}; use syn; /// A type to collect errors together and format them. diff --git a/embassy-net/src/device.rs b/embassy-net/src/device.rs index 99c6a221..c183bd58 100644 --- a/embassy-net/src/device.rs +++ b/embassy-net/src/device.rs @@ -1,6 +1,6 @@ use core::task::Waker; -use smoltcp::phy::Device as SmolDevice; -use smoltcp::phy::DeviceCapabilities; + +use smoltcp::phy::{Device as SmolDevice, DeviceCapabilities}; use smoltcp::time::Instant as SmolInstant; use crate::packet_pool::PacketBoxExt; diff --git a/embassy-net/src/lib.rs b/embassy-net/src/lib.rs index 243dfda8..1c5ba103 100644 --- a/embassy-net/src/lib.rs +++ b/embassy-net/src/lib.rs @@ -18,11 +18,9 @@ pub mod tcp; // smoltcp reexports pub use smoltcp::phy::{DeviceCapabilities, Medium}; -pub use smoltcp::time::Duration as SmolDuration; -pub use smoltcp::time::Instant as SmolInstant; +pub use smoltcp::time::{Duration as SmolDuration, Instant as SmolInstant}; #[cfg(feature = "medium-ethernet")] pub use smoltcp::wire::{EthernetAddress, HardwareAddress}; pub use smoltcp::wire::{IpAddress, IpCidr, Ipv4Address, Ipv4Cidr}; - #[cfg(feature = "proto-ipv6")] pub use smoltcp::wire::{Ipv6Address, Ipv6Cidr}; diff --git a/embassy-net/src/packet_pool.rs b/embassy-net/src/packet_pool.rs index 99311ae7..cb8a1316 100644 --- a/embassy-net/src/packet_pool.rs +++ b/embassy-net/src/packet_pool.rs @@ -1,6 +1,6 @@ -use as_slice::{AsMutSlice, AsSlice}; use core::ops::{Deref, DerefMut, Range}; +use as_slice::{AsMutSlice, AsSlice}; use atomic_pool::{pool, Box}; pub const MTU: usize = 1516; @@ -41,10 +41,7 @@ pub trait PacketBoxExt { impl PacketBoxExt for PacketBox { fn slice(self, range: Range) -> PacketBuf { - PacketBuf { - packet: self, - range, - } + PacketBuf { packet: self, range } } } diff --git a/embassy-net/src/stack.rs b/embassy-net/src/stack.rs index e28370df..f3b1ff9d 100644 --- a/embassy-net/src/stack.rs +++ b/embassy-net/src/stack.rs @@ -1,7 +1,7 @@ use core::cell::UnsafeCell; use core::future::Future; -use core::task::Context; -use core::task::Poll; +use core::task::{Context, Poll}; + use embassy::time::{Instant, Timer}; use embassy::waitqueue::WakerRegistration; use futures::future::poll_fn; @@ -9,19 +9,17 @@ use futures::pin_mut; use heapless::Vec; #[cfg(feature = "dhcpv4")] use smoltcp::iface::SocketHandle; -use smoltcp::iface::{Interface, InterfaceBuilder}; -use smoltcp::iface::{SocketSet, SocketStorage}; -#[cfg(feature = "dhcpv4")] -use smoltcp::socket::dhcpv4; -use smoltcp::time::Instant as SmolInstant; -use smoltcp::wire::{IpCidr, Ipv4Address, Ipv4Cidr}; - +use smoltcp::iface::{Interface, InterfaceBuilder, SocketSet, SocketStorage}; #[cfg(feature = "medium-ethernet")] use smoltcp::iface::{Neighbor, NeighborCache, Route, Routes}; #[cfg(feature = "medium-ethernet")] use smoltcp::phy::{Device as _, Medium}; +#[cfg(feature = "dhcpv4")] +use smoltcp::socket::dhcpv4; +use smoltcp::time::Instant as SmolInstant; #[cfg(feature = "medium-ethernet")] use smoltcp::wire::{EthernetAddress, HardwareAddress, IpAddress}; +use smoltcp::wire::{IpCidr, Ipv4Address, Ipv4Cidr}; use crate::device::{Device, DeviceAdapter, LinkState}; @@ -38,9 +36,7 @@ pub struct StackResources; NEIGHBOR], } -impl - StackResources -{ +impl StackResources { pub fn new() -> Self { Self { addresses: [IpCidr::new(Ipv4Address::UNSPECIFIED.into(), 32); ADDR], @@ -122,8 +118,7 @@ impl Stack { let sockets = SocketSet::new(&mut resources.sockets[..]); - let next_local_port = - (random_seed % (LOCAL_PORT_MAX - LOCAL_PORT_MIN) as u64) as u16 + LOCAL_PORT_MIN; + let next_local_port = (random_seed % (LOCAL_PORT_MAX - LOCAL_PORT_MIN) as u64) as u16 + LOCAL_PORT_MIN; let mut inner = Inner { device, @@ -194,11 +189,7 @@ impl SocketStack { #[allow(clippy::absurd_extreme_comparisons)] pub fn get_local_port(&mut self) -> u16 { let res = self.next_local_port; - self.next_local_port = if res >= LOCAL_PORT_MAX { - LOCAL_PORT_MIN - } else { - res + 1 - }; + self.next_local_port = if res >= LOCAL_PORT_MAX { LOCAL_PORT_MIN } else { res + 1 }; res } } @@ -217,10 +208,7 @@ impl Inner { if medium == Medium::Ethernet { if let Some(gateway) = config.gateway { debug!(" Default gateway: {}", gateway); - s.iface - .routes_mut() - .add_default_ipv4_route(gateway) - .unwrap(); + s.iface.routes_mut().add_default_ipv4_route(gateway).unwrap(); } else { debug!(" Default gateway: None"); s.iface.routes_mut().remove_default_ipv4_route(); @@ -259,10 +247,7 @@ impl Inner { s.waker.register(cx.waker()); let timestamp = instant_to_smoltcp(Instant::now()); - if s.iface - .poll(timestamp, &mut self.device, &mut s.sockets) - .is_err() - { + if s.iface.poll(timestamp, &mut self.device, &mut s.sockets).is_err() { // If poll() returns error, it may not be done yet, so poll again later. cx.waker().wake_by_ref(); return; diff --git a/embassy-net/src/tcp.rs b/embassy-net/src/tcp.rs index 35ecf1b0..c18391ac 100644 --- a/embassy-net/src/tcp.rs +++ b/embassy-net/src/tcp.rs @@ -2,17 +2,16 @@ use core::cell::UnsafeCell; use core::future::Future; use core::mem; use core::task::Poll; + use futures::future::poll_fn; use smoltcp::iface::{Interface, SocketHandle}; use smoltcp::socket::tcp; use smoltcp::time::Duration; -use smoltcp::wire::IpEndpoint; -use smoltcp::wire::IpListenEndpoint; - -use crate::stack::SocketStack; -use crate::Device; +use smoltcp::wire::{IpEndpoint, IpListenEndpoint}; use super::stack::Stack; +use crate::stack::SocketStack; +use crate::Device; #[derive(PartialEq, Eq, Clone, Copy, Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] @@ -57,11 +56,7 @@ pub struct TcpWriter<'a> { } impl<'a> TcpSocket<'a> { - pub fn new( - stack: &'a Stack, - rx_buffer: &'a mut [u8], - tx_buffer: &'a mut [u8], - ) -> Self { + pub fn new(stack: &'a Stack, rx_buffer: &'a mut [u8], tx_buffer: &'a mut [u8]) -> Self { // safety: not accessed reentrantly. let s = unsafe { &mut *stack.socket.get() }; let rx_buffer: &'static mut [u8] = unsafe { mem::transmute(rx_buffer) }; @@ -91,10 +86,7 @@ impl<'a> TcpSocket<'a> { let local_port = unsafe { &mut *self.io.stack.get() }.get_local_port(); // safety: not accessed reentrantly. - match unsafe { - self.io - .with_mut(|s, i| s.connect(i, remote_endpoint, local_port)) - } { + match unsafe { self.io.with_mut(|s, i| s.connect(i, remote_endpoint, local_port)) } { Ok(()) => {} Err(tcp::ConnectError::InvalidState) => return Err(ConnectError::InvalidState), Err(tcp::ConnectError::Unaddressable) => return Err(ConnectError::NoRoute), @@ -102,9 +94,7 @@ impl<'a> TcpSocket<'a> { futures::future::poll_fn(|cx| unsafe { self.io.with_mut(|s, _| match s.state() { - tcp::State::Closed | tcp::State::TimeWait => { - Poll::Ready(Err(ConnectError::ConnectionReset)) - } + tcp::State::Closed | tcp::State::TimeWait => Poll::Ready(Err(ConnectError::ConnectionReset)), tcp::State::Listen => unreachable!(), tcp::State::SynSent | tcp::State::SynReceived => { s.register_send_waker(cx.waker()); diff --git a/embassy-nrf/src/buffered_uarte.rs b/embassy-nrf/src/buffered_uarte.rs index ef3ccdc9..34f20efe 100644 --- a/embassy-nrf/src/buffered_uarte.rs +++ b/embassy-nrf/src/buffered_uarte.rs @@ -13,29 +13,27 @@ //! //! Please also see [crate::uarte] to understand when [BufferedUarte] should be used. -use crate::interrupt::InterruptExt; -use crate::Unborrow; use core::cmp::min; use core::future::Future; use core::marker::PhantomData; use core::sync::atomic::{compiler_fence, Ordering}; use core::task::Poll; + use embassy::waitqueue::WakerRegistration; use embassy_cortex_m::peripheral::{PeripheralMutex, PeripheralState, StateStorage}; use embassy_hal_common::ring_buffer::RingBuffer; use embassy_hal_common::{low_power_wait_until, unborrow}; use futures::future::poll_fn; - -use crate::gpio::Pin as GpioPin; -use crate::pac; -use crate::ppi::{AnyConfigurableChannel, ConfigurableChannel, Event, Ppi, Task}; -use crate::timer::Instance as TimerInstance; -use crate::timer::{Frequency, Timer}; -use crate::uarte::{apply_workaround_for_enable_anomaly, Config, Instance as UarteInstance}; - // Re-export SVD variants to allow user to directly set values pub use pac::uarte0::{baudrate::BAUDRATE_A as Baudrate, config::PARITY_A as Parity}; +use crate::gpio::Pin as GpioPin; +use crate::interrupt::InterruptExt; +use crate::ppi::{AnyConfigurableChannel, ConfigurableChannel, Event, Ppi, Task}; +use crate::timer::{Frequency, Instance as TimerInstance, Timer}; +use crate::uarte::{apply_workaround_for_enable_anomaly, Config, Instance as UarteInstance}; +use crate::{pac, Unborrow}; + #[derive(Copy, Clone, Debug, PartialEq)] enum RxState { Idle, @@ -234,9 +232,7 @@ impl<'d, U: UarteInstance, T: TimerInstance> embedded_io::asynch::Read for Buffe } } -impl<'d, U: UarteInstance, T: TimerInstance> embedded_io::asynch::BufRead - for BufferedUarte<'d, U, T> -{ +impl<'d, U: UarteInstance, T: TimerInstance> embedded_io::asynch::BufRead for BufferedUarte<'d, U, T> { type FillBufFuture<'a> = impl Future> where Self: 'a; @@ -276,9 +272,7 @@ impl<'d, U: UarteInstance, T: TimerInstance> embedded_io::asynch::BufRead } } -impl<'d, U: UarteInstance, T: TimerInstance> embedded_io::asynch::Write - for BufferedUarte<'d, U, T> -{ +impl<'d, U: UarteInstance, T: TimerInstance> embedded_io::asynch::Write for BufferedUarte<'d, U, T> { type WriteFuture<'a> = impl Future> where Self: 'a; diff --git a/embassy-nrf/src/chips/nrf52805.rs b/embassy-nrf/src/chips/nrf52805.rs index 31659859..8fca4da1 100644 --- a/embassy-nrf/src/chips/nrf52805.rs +++ b/embassy-nrf/src/chips/nrf52805.rs @@ -197,9 +197,10 @@ impl_saadc_input!(P0_04, ANALOGINPUT2); impl_saadc_input!(P0_05, ANALOGINPUT3); pub mod irqs { - use crate::pac::Interrupt as InterruptEnum; use embassy_macros::cortex_m_interrupt_declare as declare; + use crate::pac::Interrupt as InterruptEnum; + declare!(POWER_CLOCK); declare!(RADIO); declare!(UARTE0_UART0); diff --git a/embassy-nrf/src/chips/nrf52810.rs b/embassy-nrf/src/chips/nrf52810.rs index 195be51c..538a617d 100644 --- a/embassy-nrf/src/chips/nrf52810.rs +++ b/embassy-nrf/src/chips/nrf52810.rs @@ -218,9 +218,10 @@ impl_saadc_input!(P0_30, ANALOGINPUT6); impl_saadc_input!(P0_31, ANALOGINPUT7); pub mod irqs { - use crate::pac::Interrupt as InterruptEnum; use embassy_macros::cortex_m_interrupt_declare as declare; + use crate::pac::Interrupt as InterruptEnum; + declare!(POWER_CLOCK); declare!(RADIO); declare!(UARTE0_UART0); diff --git a/embassy-nrf/src/chips/nrf52811.rs b/embassy-nrf/src/chips/nrf52811.rs index 18f05405..808adf51 100644 --- a/embassy-nrf/src/chips/nrf52811.rs +++ b/embassy-nrf/src/chips/nrf52811.rs @@ -219,9 +219,10 @@ impl_saadc_input!(P0_30, ANALOGINPUT6); impl_saadc_input!(P0_31, ANALOGINPUT7); pub mod irqs { - use crate::pac::Interrupt as InterruptEnum; use embassy_macros::cortex_m_interrupt_declare as declare; + use crate::pac::Interrupt as InterruptEnum; + declare!(POWER_CLOCK); declare!(RADIO); declare!(UARTE0_UART0); diff --git a/embassy-nrf/src/chips/nrf52820.rs b/embassy-nrf/src/chips/nrf52820.rs index b4ad4c72..6be5bd36 100644 --- a/embassy-nrf/src/chips/nrf52820.rs +++ b/embassy-nrf/src/chips/nrf52820.rs @@ -211,9 +211,10 @@ impl_ppi_channel!(PPI_CH30, 30 => static); impl_ppi_channel!(PPI_CH31, 31 => static); pub mod irqs { - use crate::pac::Interrupt as InterruptEnum; use embassy_macros::cortex_m_interrupt_declare as declare; + use crate::pac::Interrupt as InterruptEnum; + declare!(POWER_CLOCK); declare!(RADIO); declare!(UARTE0_UART0); diff --git a/embassy-nrf/src/chips/nrf52832.rs b/embassy-nrf/src/chips/nrf52832.rs index d578519f..cdc644d6 100644 --- a/embassy-nrf/src/chips/nrf52832.rs +++ b/embassy-nrf/src/chips/nrf52832.rs @@ -235,9 +235,10 @@ impl_saadc_input!(P0_30, ANALOGINPUT6); impl_saadc_input!(P0_31, ANALOGINPUT7); pub mod irqs { - use crate::pac::Interrupt as InterruptEnum; use embassy_macros::cortex_m_interrupt_declare as declare; + use crate::pac::Interrupt as InterruptEnum; + declare!(POWER_CLOCK); declare!(RADIO); declare!(UARTE0_UART0); diff --git a/embassy-nrf/src/chips/nrf52833.rs b/embassy-nrf/src/chips/nrf52833.rs index 92f415a5..4c3c5574 100644 --- a/embassy-nrf/src/chips/nrf52833.rs +++ b/embassy-nrf/src/chips/nrf52833.rs @@ -278,9 +278,10 @@ impl_saadc_input!(P0_30, ANALOGINPUT6); impl_saadc_input!(P0_31, ANALOGINPUT7); pub mod irqs { - use crate::pac::Interrupt as InterruptEnum; use embassy_macros::cortex_m_interrupt_declare as declare; + use crate::pac::Interrupt as InterruptEnum; + declare!(POWER_CLOCK); declare!(RADIO); declare!(UARTE0_UART0); diff --git a/embassy-nrf/src/chips/nrf52840.rs b/embassy-nrf/src/chips/nrf52840.rs index e7a94b18..bdaeadb9 100644 --- a/embassy-nrf/src/chips/nrf52840.rs +++ b/embassy-nrf/src/chips/nrf52840.rs @@ -283,9 +283,10 @@ impl_saadc_input!(P0_30, ANALOGINPUT6); impl_saadc_input!(P0_31, ANALOGINPUT7); pub mod irqs { - use crate::pac::Interrupt as InterruptEnum; use embassy_macros::cortex_m_interrupt_declare as declare; + use crate::pac::Interrupt as InterruptEnum; + declare!(POWER_CLOCK); declare!(RADIO); declare!(UARTE0_UART0); diff --git a/embassy-nrf/src/chips/nrf5340_app.rs b/embassy-nrf/src/chips/nrf5340_app.rs index 13ed23cd..26dc56bd 100644 --- a/embassy-nrf/src/chips/nrf5340_app.rs +++ b/embassy-nrf/src/chips/nrf5340_app.rs @@ -468,9 +468,10 @@ impl_saadc_input!(P0_19, ANALOGINPUT6); impl_saadc_input!(P0_20, ANALOGINPUT7); pub mod irqs { - use crate::pac::Interrupt as InterruptEnum; use embassy_macros::cortex_m_interrupt_declare as declare; + use crate::pac::Interrupt as InterruptEnum; + declare!(FPU); declare!(CACHE); declare!(SPU); diff --git a/embassy-nrf/src/chips/nrf5340_net.rs b/embassy-nrf/src/chips/nrf5340_net.rs index a7e70cdc..e28cfe01 100644 --- a/embassy-nrf/src/chips/nrf5340_net.rs +++ b/embassy-nrf/src/chips/nrf5340_net.rs @@ -328,9 +328,10 @@ impl_ppi_channel!(PPI_CH30, 30 => configurable); impl_ppi_channel!(PPI_CH31, 31 => configurable); pub mod irqs { - use crate::pac::Interrupt as InterruptEnum; use embassy_macros::cortex_m_interrupt_declare as declare; + use crate::pac::Interrupt as InterruptEnum; + declare!(CLOCK_POWER); declare!(RADIO); declare!(RNG); diff --git a/embassy-nrf/src/chips/nrf9160.rs b/embassy-nrf/src/chips/nrf9160.rs index 57ff39b7..1a0bd10f 100644 --- a/embassy-nrf/src/chips/nrf9160.rs +++ b/embassy-nrf/src/chips/nrf9160.rs @@ -346,9 +346,10 @@ impl_saadc_input!(P0_19, ANALOGINPUT6); impl_saadc_input!(P0_20, ANALOGINPUT7); pub mod irqs { - use crate::pac::Interrupt as InterruptEnum; use embassy_macros::cortex_m_interrupt_declare as declare; + use crate::pac::Interrupt as InterruptEnum; + declare!(SPU); declare!(CLOCK_POWER); declare!(UARTE0_SPIM0_SPIS0_TWIM0_TWIS0); diff --git a/embassy-nrf/src/gpio.rs b/embassy-nrf/src/gpio.rs index a6c84621..e68b8874 100644 --- a/embassy-nrf/src/gpio.rs +++ b/embassy-nrf/src/gpio.rs @@ -4,15 +4,13 @@ use core::convert::Infallible; use core::hint::unreachable_unchecked; use core::marker::PhantomData; -use crate::Unborrow; use cfg_if::cfg_if; use embassy_hal_common::{unborrow, unsafe_impl_unborrow}; -use crate::pac; +use self::sealed::Pin as _; use crate::pac::p0 as gpio; use crate::pac::p0::pin_cnf::{DRIVE_A, PULL_A}; - -use self::sealed::Pin as _; +use crate::{pac, Unborrow}; /// A GPIO port with up to 32 pins. #[derive(Debug, Eq, PartialEq)] @@ -93,11 +91,7 @@ pub struct Output<'d, T: Pin> { } impl<'d, T: Pin> Output<'d, T> { - pub fn new( - pin: impl Unborrow + 'd, - initial_output: Level, - drive: OutputDrive, - ) -> Self { + pub fn new(pin: impl Unborrow + 'd, initial_output: Level, drive: OutputDrive) -> Self { let mut pin = Flex::new(pin); match initial_output { Level::High => pin.set_high(), diff --git a/embassy-nrf/src/gpiote.rs b/embassy-nrf/src/gpiote.rs index 05154623..d4e1cb35 100644 --- a/embassy-nrf/src/gpiote.rs +++ b/embassy-nrf/src/gpiote.rs @@ -1,17 +1,17 @@ -use crate::interrupt::{Interrupt, InterruptExt}; use core::convert::Infallible; use core::future::Future; use core::marker::PhantomData; use core::task::{Context, Poll}; + use embassy::waitqueue::AtomicWaker; use embassy_hal_common::unsafe_impl_unborrow; use futures::future::poll_fn; use crate::gpio::sealed::Pin as _; use crate::gpio::{AnyPin, Flex, Input, Output, Pin as GpioPin}; -use crate::pac; +use crate::interrupt::{Interrupt, InterruptExt}; use crate::ppi::{Event, Task}; -use crate::{interrupt, peripherals}; +use crate::{interrupt, pac, peripherals}; pub const CHANNEL_COUNT: usize = 8; @@ -468,9 +468,7 @@ mod eh1 { type Error = Infallible; } - impl<'d, C: Channel, T: GpioPin> embedded_hal_1::digital::blocking::InputPin - for InputChannel<'d, C, T> - { + impl<'d, C: Channel, T: GpioPin> embedded_hal_1::digital::blocking::InputPin for InputChannel<'d, C, T> { fn is_high(&self) -> Result { Ok(self.pin.is_high()) } diff --git a/embassy-nrf/src/lib.rs b/embassy-nrf/src/lib.rs index 6eaadfc6..1f1ffc99 100644 --- a/embassy-nrf/src/lib.rs +++ b/embassy-nrf/src/lib.rs @@ -35,10 +35,7 @@ //! mutable slices always reside in RAM. #![no_std] -#![cfg_attr( - feature = "nightly", - feature(generic_associated_types, type_alias_impl_trait) -)] +#![cfg_attr(feature = "nightly", feature(generic_associated_types, type_alias_impl_trait))] #[cfg(not(any( feature = "nrf51", @@ -115,9 +112,10 @@ mod chip; pub use chip::EASY_DMA_SIZE; pub mod interrupt { - pub use crate::chip::irqs::*; pub use cortex_m::interrupt::{CriticalSection, Mutex}; pub use embassy_cortex_m::interrupt::*; + + pub use crate::chip::irqs::*; } // Reexports @@ -126,7 +124,6 @@ pub mod interrupt { pub use chip::pac; #[cfg(not(feature = "unstable-pac"))] pub(crate) use chip::pac; - pub use chip::{peripherals, Peripherals}; pub use embassy_cortex_m::executor; pub use embassy_hal_common::{unborrow, Unborrow}; diff --git a/embassy-nrf/src/nvmc.rs b/embassy-nrf/src/nvmc.rs index 108a71d5..e350f8c9 100644 --- a/embassy-nrf/src/nvmc.rs +++ b/embassy-nrf/src/nvmc.rs @@ -1,17 +1,16 @@ //! Nvmcerature sensor interface. -use crate::pac; -use crate::peripherals::NVMC; - -use crate::Unborrow; use core::marker::PhantomData; -use core::ptr; -use core::slice; +use core::{ptr, slice}; + use embassy_hal_common::unborrow; use embedded_storage::nor_flash::{ ErrorType, MultiwriteNorFlash, NorFlash, NorFlashError, NorFlashErrorKind, ReadNorFlash, }; +use crate::peripherals::NVMC; +use crate::{pac, Unborrow}; + pub const PAGE_SIZE: usize = 4096; pub const FLASH_SIZE: usize = crate::chip::FLASH_SIZE; diff --git a/embassy-nrf/src/ppi/dppi.rs b/embassy-nrf/src/ppi/dppi.rs index 8609ef8d..d0bffb1e 100644 --- a/embassy-nrf/src/ppi/dppi.rs +++ b/embassy-nrf/src/ppi/dppi.rs @@ -1,11 +1,9 @@ use core::marker::PhantomData; -use crate::Unborrow; use embassy_hal_common::unborrow; -use crate::pac; - use super::{Channel, ConfigurableChannel, Event, Ppi, Task}; +use crate::{pac, Unborrow}; const DPPI_ENABLE_BIT: u32 = 0x8000_0000; const DPPI_CHANNEL_MASK: u32 = 0x0000_00FF; @@ -21,12 +19,7 @@ impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 1> { } impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 2> { - pub fn new_one_to_two( - ch: impl Unborrow + 'd, - event: Event, - task1: Task, - task2: Task, - ) -> Self { + pub fn new_one_to_two(ch: impl Unborrow + 'd, event: Event, task1: Task, task2: Task) -> Self { Ppi::new_many_to_many(ch, [event], [task1, task2]) } } @@ -64,9 +57,7 @@ impl<'d, C: ConfigurableChannel, const EVENT_COUNT: usize, const TASK_COUNT: usi } } -impl<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> - Ppi<'d, C, EVENT_COUNT, TASK_COUNT> -{ +impl<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> Ppi<'d, C, EVENT_COUNT, TASK_COUNT> { /// Enables the channel. pub fn enable(&mut self) { let n = self.ch.number(); @@ -80,9 +71,7 @@ impl<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> } } -impl<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> Drop - for Ppi<'d, C, EVENT_COUNT, TASK_COUNT> -{ +impl<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> Drop for Ppi<'d, C, EVENT_COUNT, TASK_COUNT> { fn drop(&mut self) { self.disable(); diff --git a/embassy-nrf/src/ppi/mod.rs b/embassy-nrf/src/ppi/mod.rs index faabbf7c..660db641 100644 --- a/embassy-nrf/src/ppi/mod.rs +++ b/embassy-nrf/src/ppi/mod.rs @@ -15,12 +15,13 @@ //! many tasks and events, but any single task or event can only be coupled with one channel. //! -use crate::peripherals; -use crate::Unborrow; use core::marker::PhantomData; use core::ptr::NonNull; + use embassy_hal_common::unsafe_impl_unborrow; +use crate::{peripherals, Unborrow}; + #[cfg(feature = "_dppi")] mod dppi; #[cfg(feature = "_ppi")] diff --git a/embassy-nrf/src/ppi/ppi.rs b/embassy-nrf/src/ppi/ppi.rs index d832d69e..e5c86d44 100644 --- a/embassy-nrf/src/ppi/ppi.rs +++ b/embassy-nrf/src/ppi/ppi.rs @@ -1,10 +1,9 @@ use core::marker::PhantomData; -use crate::Unborrow; use embassy_hal_common::unborrow; use super::{Channel, ConfigurableChannel, Event, Ppi, StaticChannel, Task}; -use crate::pac; +use crate::{pac, Unborrow}; impl Task { fn reg_val(&self) -> u32 { @@ -55,12 +54,7 @@ impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 1> { #[cfg(not(feature = "nrf51"))] // Not for nrf51 because of the fork task impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 2> { - pub fn new_one_to_two( - ch: impl Unborrow + 'd, - event: Event, - task1: Task, - task2: Task, - ) -> Self { + pub fn new_one_to_two(ch: impl Unborrow + 'd, event: Event, task1: Task, task2: Task) -> Self { unborrow!(ch); let r = regs(); @@ -76,9 +70,7 @@ impl<'d, C: ConfigurableChannel> Ppi<'d, C, 1, 2> { } } -impl<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> - Ppi<'d, C, EVENT_COUNT, TASK_COUNT> -{ +impl<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> Ppi<'d, C, EVENT_COUNT, TASK_COUNT> { /// Enables the channel. pub fn enable(&mut self) { let n = self.ch.number(); @@ -92,9 +84,7 @@ impl<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> } } -impl<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> Drop - for Ppi<'d, C, EVENT_COUNT, TASK_COUNT> -{ +impl<'d, C: Channel, const EVENT_COUNT: usize, const TASK_COUNT: usize> Drop for Ppi<'d, C, EVENT_COUNT, TASK_COUNT> { fn drop(&mut self) { self.disable(); diff --git a/embassy-nrf/src/pwm.rs b/embassy-nrf/src/pwm.rs index 3ed60ca0..9a78ff1f 100644 --- a/embassy-nrf/src/pwm.rs +++ b/embassy-nrf/src/pwm.rs @@ -1,16 +1,16 @@ #![macro_use] -use crate::Unborrow; use core::marker::PhantomData; use core::sync::atomic::{compiler_fence, Ordering}; + use embassy_hal_common::unborrow; use crate::gpio::sealed::Pin as _; use crate::gpio::{AnyPin, Pin as GpioPin, PselBits}; use crate::interrupt::Interrupt; -use crate::pac; use crate::ppi::{Event, Task}; use crate::util::slice_in_ram_or; +use crate::{pac, Unborrow}; /// SimplePwm is the traditional pwm interface you're probably used to, allowing /// to simply set a duty cycle across up to four channels. @@ -68,14 +68,7 @@ impl<'d, T: Instance> SequencePwm<'d, T> { config: Config, ) -> Result { unborrow!(ch0, ch1); - Self::new_inner( - pwm, - Some(ch0.degrade()), - Some(ch1.degrade()), - None, - None, - config, - ) + Self::new_inner(pwm, Some(ch0.degrade()), Some(ch1.degrade()), None, None, config) } /// Create a new 3-channel PWM @@ -171,10 +164,8 @@ impl<'d, T: Instance> SequencePwm<'d, T> { CounterMode::UpAndDown => w.updown().up_and_down(), CounterMode::Up => w.updown().up(), }); - r.prescaler - .write(|w| w.prescaler().bits(config.prescaler as u8)); - r.countertop - .write(|w| unsafe { w.countertop().bits(config.max_duty) }); + r.prescaler.write(|w| w.prescaler().bits(config.prescaler as u8)); + r.countertop.write(|w| unsafe { w.countertop().bits(config.max_duty) }); Ok(Self { phantom: PhantomData, @@ -391,9 +382,7 @@ impl<'d, 's, T: Instance> SingleSequencer<'d, 's, T> { pub fn start(&self, times: SingleSequenceMode) -> Result<(), Error> { let (start_seq, times) = match times { SingleSequenceMode::Times(n) if n == 1 => (StartSequence::One, SequenceMode::Loop(1)), - SingleSequenceMode::Times(n) if n & 1 == 1 => { - (StartSequence::One, SequenceMode::Loop((n / 2) + 1)) - } + SingleSequenceMode::Times(n) if n & 1 == 1 => (StartSequence::One, SequenceMode::Loop((n / 2) + 1)), SingleSequenceMode::Times(n) => (StartSequence::Zero, SequenceMode::Loop(n / 2)), SingleSequenceMode::Infinite => (StartSequence::Zero, SequenceMode::Infinite), }; @@ -424,11 +413,7 @@ pub struct Sequencer<'d, 's, T: Instance> { impl<'d, 's, T: Instance> Sequencer<'d, 's, T> { /// Create a new double sequence. In the absence of sequence 1, sequence 0 /// will be used twice in the one loop. - pub fn new( - pwm: &'s mut SequencePwm<'d, T>, - sequence0: Sequence<'s>, - sequence1: Option>, - ) -> Self { + pub fn new(pwm: &'s mut SequencePwm<'d, T>, sequence0: Sequence<'s>, sequence1: Option>) -> Self { Sequencer { _pwm: pwm, sequence0, @@ -457,42 +442,26 @@ impl<'d, 's, T: Instance> Sequencer<'d, 's, T> { let r = T::regs(); - r.seq0 - .refresh - .write(|w| unsafe { w.bits(sequence0.config.refresh) }); - r.seq0 - .enddelay - .write(|w| unsafe { w.bits(sequence0.config.end_delay) }); - r.seq0 - .ptr - .write(|w| unsafe { w.bits(sequence0.words.as_ptr() as u32) }); - r.seq0 - .cnt - .write(|w| unsafe { w.bits(sequence0.words.len() as u32) }); + r.seq0.refresh.write(|w| unsafe { w.bits(sequence0.config.refresh) }); + r.seq0.enddelay.write(|w| unsafe { w.bits(sequence0.config.end_delay) }); + r.seq0.ptr.write(|w| unsafe { w.bits(sequence0.words.as_ptr() as u32) }); + r.seq0.cnt.write(|w| unsafe { w.bits(sequence0.words.len() as u32) }); - r.seq1 - .refresh - .write(|w| unsafe { w.bits(alt_sequence.config.refresh) }); + r.seq1.refresh.write(|w| unsafe { w.bits(alt_sequence.config.refresh) }); r.seq1 .enddelay .write(|w| unsafe { w.bits(alt_sequence.config.end_delay) }); r.seq1 .ptr .write(|w| unsafe { w.bits(alt_sequence.words.as_ptr() as u32) }); - r.seq1 - .cnt - .write(|w| unsafe { w.bits(alt_sequence.words.len() as u32) }); + r.seq1.cnt.write(|w| unsafe { w.bits(alt_sequence.words.len() as u32) }); r.enable.write(|w| w.enable().enabled()); // defensive before seqstart compiler_fence(Ordering::SeqCst); - let seqstart_index = if start_seq == StartSequence::One { - 1 - } else { - 0 - }; + let seqstart_index = if start_seq == StartSequence::One { 1 } else { 0 }; match times { // just the one time, no loop count @@ -604,10 +573,7 @@ pub enum CounterMode { impl<'d, T: Instance> SimplePwm<'d, T> { /// Create a new 1-channel PWM #[allow(unused_unsafe)] - pub fn new_1ch( - pwm: impl Unborrow + 'd, - ch0: impl Unborrow + 'd, - ) -> Self { + pub fn new_1ch(pwm: impl Unborrow + 'd, ch0: impl Unborrow + 'd) -> Self { unborrow!(ch0); Self::new_inner(pwm, Some(ch0.degrade()), None, None, None) } @@ -632,13 +598,7 @@ impl<'d, T: Instance> SimplePwm<'d, T> { ch2: impl Unborrow + 'd, ) -> Self { unborrow!(ch0, ch1, ch2); - Self::new_inner( - pwm, - Some(ch0.degrade()), - Some(ch1.degrade()), - Some(ch2.degrade()), - None, - ) + Self::new_inner(pwm, Some(ch0.degrade()), Some(ch1.degrade()), Some(ch2.degrade()), None) } /// Create a new 4-channel PWM @@ -709,9 +669,7 @@ impl<'d, T: Instance> SimplePwm<'d, T> { // Enable r.enable.write(|w| w.enable().enabled()); - r.seq0 - .ptr - .write(|w| unsafe { w.bits((&pwm.duty).as_ptr() as u32) }); + r.seq0.ptr.write(|w| unsafe { w.bits((&pwm.duty).as_ptr() as u32) }); r.seq0.cnt.write(|w| unsafe { w.bits(4) }); r.seq0.refresh.write(|w| unsafe { w.bits(0) }); @@ -750,9 +708,7 @@ impl<'d, T: Instance> SimplePwm<'d, T> { self.duty[channel] = duty & 0x7FFF; // reload ptr in case self was moved - r.seq0 - .ptr - .write(|w| unsafe { w.bits((&self.duty).as_ptr() as u32) }); + r.seq0.ptr.write(|w| unsafe { w.bits((&self.duty).as_ptr() as u32) }); // defensive before seqstart compiler_fence(Ordering::SeqCst); diff --git a/embassy-nrf/src/qdec.rs b/embassy-nrf/src/qdec.rs index b230043b..e254328a 100644 --- a/embassy-nrf/src/qdec.rs +++ b/embassy-nrf/src/qdec.rs @@ -1,19 +1,18 @@ //! Quadrature decoder interface -use crate::gpio::sealed::Pin as _; -use crate::gpio::{AnyPin, Pin as GpioPin}; -use crate::interrupt; -use crate::pac; -use crate::peripherals::QDEC; - -use crate::interrupt::InterruptExt; -use crate::Unborrow; use core::marker::PhantomData; use core::task::Poll; + use embassy::waitqueue::AtomicWaker; use embassy_hal_common::unborrow; use futures::future::poll_fn; +use crate::gpio::sealed::Pin as _; +use crate::gpio::{AnyPin, Pin as GpioPin}; +use crate::interrupt::InterruptExt; +use crate::peripherals::QDEC; +use crate::{interrupt, pac, Unborrow}; + /// Quadrature decoder pub struct Qdec<'d> { phantom: PhantomData<&'d QDEC>, @@ -63,14 +62,7 @@ impl<'d> Qdec<'d> { config: Config, ) -> Self { unborrow!(a, b, led); - Self::new_inner( - qdec, - irq, - a.degrade(), - b.degrade(), - Some(led.degrade()), - config, - ) + Self::new_inner(qdec, irq, a.degrade(), b.degrade(), Some(led.degrade()), config) } fn new_inner( @@ -139,9 +131,7 @@ impl<'d> Qdec<'d> { }); irq.enable(); - Self { - phantom: PhantomData, - } + Self { phantom: PhantomData } } /// Perform an asynchronous read of the decoder. diff --git a/embassy-nrf/src/qspi.rs b/embassy-nrf/src/qspi.rs index adb0d838..92fa79b8 100644 --- a/embassy-nrf/src/qspi.rs +++ b/embassy-nrf/src/qspi.rs @@ -1,22 +1,20 @@ #![macro_use] -use crate::interrupt::{Interrupt, InterruptExt}; -use crate::Unborrow; use core::marker::PhantomData; use core::ptr; use core::task::Poll; + use embassy_hal_common::drop::DropBomb; use embassy_hal_common::unborrow; use futures::future::poll_fn; use crate::gpio::sealed::Pin as _; use crate::gpio::{self, Pin as GpioPin}; -use crate::pac; - -pub use crate::pac::qspi::ifconfig0::ADDRMODE_A as AddressMode; -pub use crate::pac::qspi::ifconfig0::PPSIZE_A as WritePageSize; -pub use crate::pac::qspi::ifconfig0::READOC_A as ReadOpcode; -pub use crate::pac::qspi::ifconfig0::WRITEOC_A as WriteOpcode; +use crate::interrupt::{Interrupt, InterruptExt}; +pub use crate::pac::qspi::ifconfig0::{ + ADDRMODE_A as AddressMode, PPSIZE_A as WritePageSize, READOC_A as ReadOpcode, WRITEOC_A as WriteOpcode, +}; +use crate::{pac, Unborrow}; // TODO // - config: @@ -168,12 +166,7 @@ impl<'d, T: Instance, const FLASH_SIZE: usize> Qspi<'d, T, FLASH_SIZE> { } } - pub async fn custom_instruction( - &mut self, - opcode: u8, - req: &[u8], - resp: &mut [u8], - ) -> Result<(), Error> { + pub async fn custom_instruction(&mut self, opcode: u8, req: &[u8], resp: &mut [u8]) -> Result<(), Error> { let bomb = DropBomb::new(); let len = core::cmp::max(req.len(), resp.len()) as u8; @@ -188,12 +181,7 @@ impl<'d, T: Instance, const FLASH_SIZE: usize> Qspi<'d, T, FLASH_SIZE> { Ok(()) } - pub fn blocking_custom_instruction( - &mut self, - opcode: u8, - req: &[u8], - resp: &mut [u8], - ) -> Result<(), Error> { + pub fn blocking_custom_instruction(&mut self, opcode: u8, req: &[u8], resp: &mut [u8]) -> Result<(), Error> { let len = core::cmp::max(req.len(), resp.len()) as u8; self.custom_instruction_start(opcode, req, len)?; @@ -292,15 +280,9 @@ impl<'d, T: Instance, const FLASH_SIZE: usize> Qspi<'d, T, FLASH_SIZE> { let r = T::regs(); - r.read - .src - .write(|w| unsafe { w.src().bits(address as u32) }); - r.read - .dst - .write(|w| unsafe { w.dst().bits(data.as_ptr() as u32) }); - r.read - .cnt - .write(|w| unsafe { w.cnt().bits(data.len() as u32) }); + r.read.src.write(|w| unsafe { w.src().bits(address as u32) }); + r.read.dst.write(|w| unsafe { w.dst().bits(data.as_ptr() as u32) }); + r.read.cnt.write(|w| unsafe { w.cnt().bits(data.len() as u32) }); r.events_ready.reset(); r.intenset.write(|w| w.ready().set()); @@ -322,15 +304,9 @@ impl<'d, T: Instance, const FLASH_SIZE: usize> Qspi<'d, T, FLASH_SIZE> { } let r = T::regs(); - r.write - .src - .write(|w| unsafe { w.src().bits(data.as_ptr() as u32) }); - r.write - .dst - .write(|w| unsafe { w.dst().bits(address as u32) }); - r.write - .cnt - .write(|w| unsafe { w.cnt().bits(data.len() as u32) }); + r.write.src.write(|w| unsafe { w.src().bits(data.as_ptr() as u32) }); + r.write.dst.write(|w| unsafe { w.dst().bits(address as u32) }); + r.write.cnt.write(|w| unsafe { w.cnt().bits(data.len() as u32) }); r.events_ready.reset(); r.intenset.write(|w| w.ready().set()); @@ -346,9 +322,7 @@ impl<'d, T: Instance, const FLASH_SIZE: usize> Qspi<'d, T, FLASH_SIZE> { } let r = T::regs(); - r.erase - .ptr - .write(|w| unsafe { w.ptr().bits(address as u32) }); + r.erase.ptr.write(|w| unsafe { w.ptr().bits(address as u32) }); r.erase.len.write(|w| w.len()._4kb()); r.events_ready.reset(); @@ -458,9 +432,7 @@ impl<'d, T: Instance, const FLASH_SIZE: usize> Drop for Qspi<'d, T, FLASH_SIZE> } } -use embedded_storage::nor_flash::{ - ErrorType, NorFlash, NorFlashError, NorFlashErrorKind, ReadNorFlash, -}; +use embedded_storage::nor_flash::{ErrorType, NorFlash, NorFlashError, NorFlashErrorKind, ReadNorFlash}; impl<'d, T: Instance, const FLASH_SIZE: usize> ErrorType for Qspi<'d, T, FLASH_SIZE> { type Error = Error; diff --git a/embassy-nrf/src/rng.rs b/embassy-nrf/src/rng.rs index 43cf805f..e68ed912 100644 --- a/embassy-nrf/src/rng.rs +++ b/embassy-nrf/src/rng.rs @@ -1,19 +1,16 @@ use core::marker::PhantomData; use core::ptr; -use core::sync::atomic::AtomicPtr; -use core::sync::atomic::Ordering; +use core::sync::atomic::{AtomicPtr, Ordering}; use core::task::Poll; -use crate::interrupt::InterruptExt; -use crate::Unborrow; use embassy::waitqueue::AtomicWaker; use embassy_hal_common::drop::OnDrop; use embassy_hal_common::unborrow; use futures::future::poll_fn; -use crate::interrupt; -use crate::pac; +use crate::interrupt::InterruptExt; use crate::peripherals::RNG; +use crate::{interrupt, pac, Unborrow}; impl RNG { fn regs() -> &'static pac::rng::RegisterBlock { @@ -48,10 +45,7 @@ impl<'d> Rng<'d> { /// e.g. using `mem::forget`. /// /// The synchronous API is safe. - pub fn new( - _rng: impl Unborrow + 'd, - irq: impl Unborrow + 'd, - ) -> Self { + pub fn new(_rng: impl Unborrow + 'd, irq: impl Unborrow + 'd) -> Self { unborrow!(irq); let this = Self { diff --git a/embassy-nrf/src/saadc.rs b/embassy-nrf/src/saadc.rs index 915115a1..7d39e33f 100644 --- a/embassy-nrf/src/saadc.rs +++ b/embassy-nrf/src/saadc.rs @@ -1,29 +1,23 @@ #![macro_use] -use crate::interrupt::InterruptExt; -use crate::Unborrow; use core::marker::PhantomData; use core::sync::atomic::{compiler_fence, Ordering}; use core::task::Poll; + use embassy::waitqueue::AtomicWaker; use embassy_hal_common::unborrow; use futures::future::poll_fn; - -use crate::interrupt; -use crate::ppi::{ConfigurableChannel, Event, Ppi, Task}; -use crate::timer::{Frequency, Instance as TimerInstance, Timer}; -use crate::{pac, peripherals}; - use pac::{saadc, SAADC}; - +use saadc::ch::config::{GAIN_A, REFSEL_A, RESP_A, TACQ_A}; // We treat the positive and negative channels with the same enum values to keep our type tidy and given they are the same pub(crate) use saadc::ch::pselp::PSELP_A as InputChannel; +use saadc::oversample::OVERSAMPLE_A; +use saadc::resolution::VAL_A; -use saadc::{ - ch::config::{GAIN_A, REFSEL_A, RESP_A, TACQ_A}, - oversample::OVERSAMPLE_A, - resolution::VAL_A, -}; +use crate::interrupt::InterruptExt; +use crate::ppi::{ConfigurableChannel, Event, Ppi, Task}; +use crate::timer::{Frequency, Instance as TimerInstance, Timer}; +use crate::{interrupt, pac, peripherals, Unborrow}; #[derive(Debug, Clone, Copy, PartialEq, Eq)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] @@ -178,23 +172,17 @@ impl<'d, const N: usize> Saadc<'d, N> { let r = unsafe { &*SAADC::ptr() }; - let Config { - resolution, - oversample, - } = config; + let Config { resolution, oversample } = config; // Configure channels r.enable.write(|w| w.enable().enabled()); r.resolution.write(|w| w.val().variant(resolution.into())); - r.oversample - .write(|w| w.oversample().variant(oversample.into())); + r.oversample.write(|w| w.oversample().variant(oversample.into())); for (i, cc) in channel_configs.iter().enumerate() { r.ch[i].pselp.write(|w| w.pselp().variant(cc.p_channel)); if let Some(n_channel) = cc.n_channel { - r.ch[i] - .pseln - .write(|w| unsafe { w.pseln().bits(n_channel as u8) }); + r.ch[i].pseln.write(|w| unsafe { w.pseln().bits(n_channel as u8) }); } r.ch[i].config.write(|w| { w.refsel().variant(cc.reference.into()); @@ -223,9 +211,7 @@ impl<'d, const N: usize> Saadc<'d, N> { irq.unpend(); irq.enable(); - Self { - phantom: PhantomData, - } + Self { phantom: PhantomData } } fn on_interrupt(_ctx: *mut ()) { @@ -285,12 +271,8 @@ impl<'d, const N: usize> Saadc<'d, N> { let r = Self::regs(); // Set up the DMA - r.result - .ptr - .write(|w| unsafe { w.ptr().bits(buf.as_mut_ptr() as u32) }); - r.result - .maxcnt - .write(|w| unsafe { w.maxcnt().bits(N as _) }); + r.result.ptr.write(|w| unsafe { w.ptr().bits(buf.as_mut_ptr() as u32) }); + r.result.maxcnt.write(|w| unsafe { w.maxcnt().bits(N as _) }); // Reset and enable the end event r.events_end.reset(); @@ -353,11 +335,8 @@ impl<'d, const N: usize> Saadc<'d, N> { // We want the task start to effectively short with the last one ending so // we don't miss any samples. It'd be great for the SAADC to offer a SHORTS // register instead, but it doesn't, so we must use PPI. - let mut start_ppi = Ppi::new_one_to_one( - ppi_ch1, - Event::from_reg(&r.events_end), - Task::from_reg(&r.tasks_start), - ); + let mut start_ppi = + Ppi::new_one_to_one(ppi_ch1, Event::from_reg(&r.events_end), Task::from_reg(&r.tasks_start)); start_ppi.enable(); let mut timer = Timer::new(timer); @@ -365,11 +344,7 @@ impl<'d, const N: usize> Saadc<'d, N> { timer.cc(0).write(sample_counter); timer.cc(0).short_compare_clear(); - let mut sample_ppi = Ppi::new_one_to_one( - ppi_ch2, - timer.cc(0).event_compare(), - Task::from_reg(&r.tasks_sample), - ); + let mut sample_ppi = Ppi::new_one_to_one(ppi_ch2, timer.cc(0).event_compare(), Task::from_reg(&r.tasks_sample)); timer.start(); @@ -417,9 +392,7 @@ impl<'d, const N: usize> Saadc<'d, N> { r.result .ptr .write(|w| unsafe { w.ptr().bits(bufs[0].as_mut_ptr() as u32) }); - r.result - .maxcnt - .write(|w| unsafe { w.maxcnt().bits((N0 * N) as _) }); + r.result.maxcnt.write(|w| unsafe { w.maxcnt().bits((N0 * N) as _) }); // Reset and enable the events r.events_end.reset(); @@ -500,8 +473,7 @@ impl<'d> Saadc<'d, 1> { ) where S: FnMut(&[[i16; 1]]) -> SamplerState, { - self.run_sampler(bufs, Some(sample_rate_divisor), || {}, sampler) - .await; + self.run_sampler(bufs, Some(sample_rate_divisor), || {}, sampler).await; } } diff --git a/embassy-nrf/src/spim.rs b/embassy-nrf/src/spim.rs index 7b28373d..efccfeca 100644 --- a/embassy-nrf/src/spim.rs +++ b/embassy-nrf/src/spim.rs @@ -1,23 +1,20 @@ #![macro_use] -use crate::interrupt::InterruptExt; -use crate::Unborrow; use core::marker::PhantomData; use core::sync::atomic::{compiler_fence, Ordering}; use core::task::Poll; + use embassy_hal_common::unborrow; +pub use embedded_hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3}; use futures::future::poll_fn; +pub use pac::spim0::frequency::FREQUENCY_A as Frequency; use crate::chip::FORCE_COPY_BUFFER_SIZE; use crate::gpio::sealed::Pin as _; -use crate::gpio::{self, AnyPin}; -use crate::gpio::{Pin as GpioPin, PselBits}; -use crate::interrupt::Interrupt; -use crate::util::{slice_ptr_parts, slice_ptr_parts_mut}; -use crate::{pac, util::slice_in_ram_or}; - -pub use embedded_hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3}; -pub use pac::spim0::frequency::FREQUENCY_A as Frequency; +use crate::gpio::{self, AnyPin, Pin as GpioPin, PselBits}; +use crate::interrupt::{Interrupt, InterruptExt}; +use crate::util::{slice_in_ram_or, slice_ptr_parts, slice_ptr_parts_mut}; +use crate::{pac, Unborrow}; #[derive(Debug, Clone, Copy, PartialEq, Eq)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] @@ -183,9 +180,7 @@ impl<'d, T: Instance> Spim<'d, T> { irq.unpend(); irq.enable(); - Self { - phantom: PhantomData, - } + Self { phantom: PhantomData } } fn on_interrupt(_: *mut ()) { @@ -295,11 +290,7 @@ impl<'d, T: Instance> Spim<'d, T> { } /// Same as [`blocking_transfer`](Spim::blocking_transfer) but will fail instead of copying data into RAM. Consult the module level documentation to learn more. - pub fn blocking_transfer_from_ram( - &mut self, - read: &mut [u8], - write: &[u8], - ) -> Result<(), Error> { + pub fn blocking_transfer_from_ram(&mut self, read: &mut [u8], write: &[u8]) -> Result<(), Error> { self.blocking_inner(read, write) } diff --git a/embassy-nrf/src/temp.rs b/embassy-nrf/src/temp.rs index e5e5f29a..43ba3e04 100644 --- a/embassy-nrf/src/temp.rs +++ b/embassy-nrf/src/temp.rs @@ -1,18 +1,18 @@ //! Temperature sensor interface. -use crate::interrupt; -use crate::pac; -use crate::peripherals::TEMP; - -use crate::interrupt::InterruptExt; -use crate::Unborrow; use core::marker::PhantomData; use core::task::Poll; + use embassy::waitqueue::AtomicWaker; -use embassy_hal_common::{drop::OnDrop, unborrow}; +use embassy_hal_common::drop::OnDrop; +use embassy_hal_common::unborrow; use fixed::types::I30F2; use futures::future::poll_fn; +use crate::interrupt::InterruptExt; +use crate::peripherals::TEMP; +use crate::{interrupt, pac, Unborrow}; + /// Integrated temperature sensor. pub struct Temp<'d> { _temp: PhantomData<&'d TEMP>, @@ -22,10 +22,7 @@ pub struct Temp<'d> { static WAKER: AtomicWaker = AtomicWaker::new(); impl<'d> Temp<'d> { - pub fn new( - _t: impl Unborrow + 'd, - irq: impl Unborrow + 'd, - ) -> Self { + pub fn new(_t: impl Unborrow + 'd, irq: impl Unborrow + 'd) -> Self { unborrow!(_t, irq); // Enable interrupt that signals temperature values diff --git a/embassy-nrf/src/time_driver.rs b/embassy-nrf/src/time_driver.rs index 8f175814..f7b3345b 100644 --- a/embassy-nrf/src/time_driver.rs +++ b/embassy-nrf/src/time_driver.rs @@ -1,14 +1,14 @@ -use crate::interrupt::{Interrupt, InterruptExt}; use core::cell::Cell; use core::sync::atomic::{compiler_fence, AtomicU32, AtomicU8, Ordering}; use core::{mem, ptr}; + use critical_section::CriticalSection; use embassy::blocking_mutex::raw::CriticalSectionRawMutex; use embassy::blocking_mutex::CriticalSectionMutex as Mutex; use embassy::time::driver::{AlarmHandle, Driver}; -use crate::interrupt; -use crate::pac; +use crate::interrupt::{Interrupt, InterruptExt}; +use crate::{interrupt, pac}; fn rtc() -> &'static pac::rtc0::RegisterBlock { unsafe { &*pac::RTC1::ptr() } @@ -220,15 +220,13 @@ impl Driver for RtcDriver { } unsafe fn allocate_alarm(&self) -> Option { - let id = self - .alarm_count - .fetch_update(Ordering::AcqRel, Ordering::Acquire, |x| { - if x < ALARM_COUNT as u8 { - Some(x + 1) - } else { - None - } - }); + let id = self.alarm_count.fetch_update(Ordering::AcqRel, Ordering::Acquire, |x| { + if x < ALARM_COUNT as u8 { + Some(x + 1) + } else { + None + } + }); match id { Ok(id) => Some(AlarmHandle::new(id)), diff --git a/embassy-nrf/src/timer.rs b/embassy-nrf/src/timer.rs index 588654f9..c8c36dfa 100644 --- a/embassy-nrf/src/timer.rs +++ b/embassy-nrf/src/timer.rs @@ -3,16 +3,14 @@ use core::marker::PhantomData; use core::task::Poll; -use crate::interrupt::Interrupt; -use crate::interrupt::InterruptExt; -use crate::Unborrow; use embassy::waitqueue::AtomicWaker; use embassy_hal_common::drop::OnDrop; use embassy_hal_common::unborrow; use futures::future::poll_fn; -use crate::pac; +use crate::interrupt::{Interrupt, InterruptExt}; use crate::ppi::{Event, Task}; +use crate::{pac, Unborrow}; pub(crate) mod sealed { @@ -131,9 +129,7 @@ impl<'d, T: Instance, I: TimerType> Timer<'d, T, I> { fn new_irqless(_timer: impl Unborrow + 'd) -> Self { let regs = T::regs(); - let mut this = Self { - phantom: PhantomData, - }; + let mut this = Self { phantom: PhantomData }; // Stop the timer before doing anything else, // since changing BITMODE while running can cause 'unpredictable behaviour' according to the specification. @@ -233,11 +229,7 @@ impl<'d, T: Instance, I: TimerType> Timer<'d, T, I> { /// Panics if `n` >= the number of CC registers this timer has (4 for a normal timer, 6 for an extended timer). pub fn cc(&mut self, n: usize) -> Cc { if n >= T::CCS { - panic!( - "Cannot get CC register {} of timer with {} CC registers.", - n, - T::CCS - ); + panic!("Cannot get CC register {} of timer with {} CC registers.", n, T::CCS); } Cc { n, diff --git a/embassy-nrf/src/twim.rs b/embassy-nrf/src/twim.rs index 2337ae21..c3921104 100644 --- a/embassy-nrf/src/twim.rs +++ b/embassy-nrf/src/twim.rs @@ -6,12 +6,12 @@ //! //! - nRF52832: Section 33 //! - nRF52840: Section 6.31 -use crate::interrupt::{Interrupt, InterruptExt}; -use crate::Unborrow; use core::future::Future; use core::marker::PhantomData; -use core::sync::atomic::{compiler_fence, Ordering::SeqCst}; +use core::sync::atomic::compiler_fence; +use core::sync::atomic::Ordering::SeqCst; use core::task::Poll; + #[cfg(feature = "time")] use embassy::time::{Duration, Instant}; use embassy::waitqueue::AtomicWaker; @@ -19,10 +19,10 @@ use embassy_hal_common::unborrow; use futures::future::poll_fn; use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE}; -use crate::gpio; use crate::gpio::Pin as GpioPin; -use crate::pac; +use crate::interrupt::{Interrupt, InterruptExt}; use crate::util::{slice_in_ram, slice_in_ram_or}; +use crate::{gpio, pac, Unborrow}; pub enum Frequency { #[doc = "26738688: 100 kbps"] @@ -134,9 +134,7 @@ impl<'d, T: Instance> Twim<'d, T> { irq.unpend(); irq.enable(); - Self { - phantom: PhantomData, - } + Self { phantom: PhantomData } } fn on_interrupt(_: *mut ()) { @@ -319,12 +317,7 @@ impl<'d, T: Instance> Twim<'d, T> { }) } - fn setup_write_from_ram( - &mut self, - address: u8, - buffer: &[u8], - inten: bool, - ) -> Result<(), Error> { + fn setup_write_from_ram(&mut self, address: u8, buffer: &[u8], inten: bool) -> Result<(), Error> { let r = T::regs(); compiler_fence(SeqCst); @@ -506,12 +499,7 @@ impl<'d, T: Instance> Twim<'d, T> { /// /// The buffers must have a length of at most 255 bytes on the nRF52832 /// and at most 65535 bytes on the nRF52840. - pub fn blocking_write_read( - &mut self, - address: u8, - wr_buffer: &[u8], - rd_buffer: &mut [u8], - ) -> Result<(), Error> { + pub fn blocking_write_read(&mut self, address: u8, wr_buffer: &[u8], rd_buffer: &mut [u8]) -> Result<(), Error> { self.setup_write_read(address, wr_buffer, rd_buffer, false)?; self.blocking_wait(); compiler_fence(SeqCst); @@ -543,12 +531,7 @@ impl<'d, T: Instance> Twim<'d, T> { /// /// See [`blocking_write`]. #[cfg(feature = "time")] - pub fn blocking_write_timeout( - &mut self, - address: u8, - buffer: &[u8], - timeout: Duration, - ) -> Result<(), Error> { + pub fn blocking_write_timeout(&mut self, address: u8, buffer: &[u8], timeout: Duration) -> Result<(), Error> { self.setup_write(address, buffer, false)?; self.blocking_wait_timeout(timeout)?; compiler_fence(SeqCst); @@ -578,12 +561,7 @@ impl<'d, T: Instance> Twim<'d, T> { /// The buffer must have a length of at most 255 bytes on the nRF52832 /// and at most 65535 bytes on the nRF52840. #[cfg(feature = "time")] - pub fn blocking_read_timeout( - &mut self, - address: u8, - buffer: &mut [u8], - timeout: Duration, - ) -> Result<(), Error> { + pub fn blocking_read_timeout(&mut self, address: u8, buffer: &mut [u8], timeout: Duration) -> Result<(), Error> { self.setup_read(address, buffer, false)?; self.blocking_wait_timeout(timeout)?; compiler_fence(SeqCst); @@ -662,12 +640,7 @@ impl<'d, T: Instance> Twim<'d, T> { Ok(()) } - pub async fn write_read( - &mut self, - address: u8, - wr_buffer: &[u8], - rd_buffer: &mut [u8], - ) -> Result<(), Error> { + pub async fn write_read(&mut self, address: u8, wr_buffer: &[u8], rd_buffer: &mut [u8]) -> Result<(), Error> { self.setup_write_read(address, wr_buffer, rd_buffer, true)?; self.async_wait().await; compiler_fence(SeqCst); @@ -786,12 +759,7 @@ mod eh02 { impl<'a, T: Instance> embedded_hal_02::blocking::i2c::WriteRead for Twim<'a, T> { type Error = Error; - fn write_read<'w>( - &mut self, - addr: u8, - bytes: &'w [u8], - buffer: &'w mut [u8], - ) -> Result<(), Error> { + fn write_read<'w>(&mut self, addr: u8, bytes: &'w [u8], buffer: &'w mut [u8]) -> Result<(), Error> { self.blocking_write_read(addr, bytes, buffer) } } @@ -809,12 +777,12 @@ mod eh1 { Self::Transmit => embedded_hal_1::i2c::ErrorKind::Other, Self::Receive => embedded_hal_1::i2c::ErrorKind::Other, Self::DMABufferNotInDataMemory => embedded_hal_1::i2c::ErrorKind::Other, - Self::AddressNack => embedded_hal_1::i2c::ErrorKind::NoAcknowledge( - embedded_hal_1::i2c::NoAcknowledgeSource::Address, - ), - Self::DataNack => embedded_hal_1::i2c::ErrorKind::NoAcknowledge( - embedded_hal_1::i2c::NoAcknowledgeSource::Data, - ), + Self::AddressNack => { + embedded_hal_1::i2c::ErrorKind::NoAcknowledge(embedded_hal_1::i2c::NoAcknowledgeSource::Address) + } + Self::DataNack => { + embedded_hal_1::i2c::ErrorKind::NoAcknowledge(embedded_hal_1::i2c::NoAcknowledgeSource::Data) + } Self::Overrun => embedded_hal_1::i2c::ErrorKind::Overrun, Self::Timeout => embedded_hal_1::i2c::ErrorKind::Other, } @@ -841,24 +809,14 @@ mod eh1 { todo!(); } - fn write_iter_read( - &mut self, - _address: u8, - _bytes: B, - _buffer: &mut [u8], - ) -> Result<(), Self::Error> + fn write_iter_read(&mut self, _address: u8, _bytes: B, _buffer: &mut [u8]) -> Result<(), Self::Error> where B: IntoIterator, { todo!(); } - fn write_read( - &mut self, - address: u8, - wr_buffer: &[u8], - rd_buffer: &mut [u8], - ) -> Result<(), Self::Error> { + fn write_read(&mut self, address: u8, wr_buffer: &[u8], rd_buffer: &mut [u8]) -> Result<(), Self::Error> { self.blocking_write_read(address, wr_buffer, rd_buffer) } @@ -870,11 +828,7 @@ mod eh1 { todo!(); } - fn transaction_iter<'a, O>( - &mut self, - _address: u8, - _operations: O, - ) -> Result<(), Self::Error> + fn transaction_iter<'a, O>(&mut self, _address: u8, _operations: O) -> Result<(), Self::Error> where O: IntoIterator>, { diff --git a/embassy-nrf/src/uarte.rs b/embassy-nrf/src/uarte.rs index 70dbfb08..50b34144 100644 --- a/embassy-nrf/src/uarte.rs +++ b/embassy-nrf/src/uarte.rs @@ -13,27 +13,24 @@ //! memory may be used given that buffers are passed in directly to its read and write //! methods. -use crate::interrupt::InterruptExt; -use crate::Unborrow; use core::marker::PhantomData; use core::sync::atomic::{compiler_fence, Ordering}; use core::task::Poll; + use embassy_hal_common::drop::OnDrop; use embassy_hal_common::unborrow; use futures::future::poll_fn; +// Re-export SVD variants to allow user to directly set values. +pub use pac::uarte0::{baudrate::BAUDRATE_A as Baudrate, config::PARITY_A as Parity}; use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE}; use crate::gpio::sealed::Pin as _; use crate::gpio::{self, AnyPin, Pin as GpioPin, PselBits}; -use crate::interrupt::Interrupt; -use crate::pac; +use crate::interrupt::{Interrupt, InterruptExt}; use crate::ppi::{AnyConfigurableChannel, ConfigurableChannel, Event, Ppi, Task}; -use crate::timer::Instance as TimerInstance; -use crate::timer::{Frequency, Timer}; +use crate::timer::{Frequency, Instance as TimerInstance, Timer}; use crate::util::slice_in_ram_or; - -// Re-export SVD variants to allow user to directly set values. -pub use pac::uarte0::{baudrate::BAUDRATE_A as Baudrate, config::PARITY_A as Parity}; +use crate::{pac, Unborrow}; #[non_exhaustive] pub struct Config { @@ -182,12 +179,8 @@ impl<'d, T: Instance> Uarte<'d, T> { Self { phantom: PhantomData, - tx: UarteTx { - phantom: PhantomData, - }, - rx: UarteRx { - phantom: PhantomData, - }, + tx: UarteTx { phantom: PhantomData }, + rx: UarteRx { phantom: PhantomData }, } } @@ -893,9 +886,7 @@ mod eh02 { } } - impl<'d, U: Instance, T: TimerInstance> embedded_hal_02::blocking::serial::Write - for UarteWithIdle<'d, U, T> - { + impl<'d, U: Instance, T: TimerInstance> embedded_hal_02::blocking::serial::Write for UarteWithIdle<'d, U, T> { type Error = Error; fn bwrite_all(&mut self, buffer: &[u8]) -> Result<(), Self::Error> { @@ -956,9 +947,7 @@ mod eh1 { type Error = Error; } - impl<'d, U: Instance, T: TimerInstance> embedded_hal_1::serial::ErrorType - for UarteWithIdle<'d, U, T> - { + impl<'d, U: Instance, T: TimerInstance> embedded_hal_1::serial::ErrorType for UarteWithIdle<'d, U, T> { type Error = Error; } } diff --git a/embassy-nrf/src/usb.rs b/embassy-nrf/src/usb.rs index d0223c4c..6c872581 100644 --- a/embassy-nrf/src/usb.rs +++ b/embassy-nrf/src/usb.rs @@ -1,25 +1,23 @@ #![macro_use] -use crate::interrupt::InterruptExt; -use crate::Unborrow; use core::marker::PhantomData; use core::mem::MaybeUninit; use core::sync::atomic::{compiler_fence, AtomicU32, Ordering}; use core::task::Poll; + use cortex_m::peripheral::NVIC; use embassy::waitqueue::AtomicWaker; use embassy_hal_common::unborrow; +pub use embassy_usb; use embassy_usb::driver::{self, EndpointError, Event, Unsupported}; use embassy_usb::types::{EndpointAddress, EndpointInfo, EndpointType, UsbDirection}; use futures::future::poll_fn; use futures::Future; - -pub use embassy_usb; use pac::usbd::RegisterBlock; -use crate::interrupt::Interrupt; -use crate::pac; +use crate::interrupt::{Interrupt, InterruptExt}; use crate::util::slice_in_ram; +use crate::{pac, Unborrow}; const NEW_AW: AtomicWaker = AtomicWaker::new(); static BUS_WAKER: AtomicWaker = NEW_AW; @@ -35,10 +33,7 @@ pub struct Driver<'d, T: Instance> { } impl<'d, T: Instance> Driver<'d, T> { - pub fn new( - _usb: impl Unborrow + 'd, - irq: impl Unborrow + 'd, - ) -> Self { + pub fn new(_usb: impl Unborrow + 'd, irq: impl Unborrow + 'd) -> Self { unborrow!(irq); irq.set_handler(Self::on_interrupt); irq.unpend(); @@ -143,9 +138,7 @@ impl<'d, T: Instance> driver::Driver<'d> for Driver<'d, T> { fn start(self, control_max_packet_size: u16) -> (Self::Bus, Self::ControlPipe) { ( - Bus { - phantom: PhantomData, - }, + Bus { phantom: PhantomData }, ControlPipe { _phantom: PhantomData, max_packet_size: control_max_packet_size, @@ -266,8 +259,7 @@ impl<'d, T: Instance> driver::Bus for Bus<'d, T> { let regs = T::regs(); unsafe { if ep_addr.index() == 0 { - regs.tasks_ep0stall - .write(|w| w.tasks_ep0stall().bit(stalled)); + regs.tasks_ep0stall.write(|w| w.tasks_ep0stall().bit(stalled)); } else { regs.epstall.write(|w| { w.ep().bits(ep_addr.index() as u8 & 0b111); @@ -370,8 +362,7 @@ impl<'d, T: Instance> driver::Bus for Bus<'d, T> { regs.eventcause.write(|w| w.usbwuallowed().set_bit()); regs.dpdmvalue.write(|w| w.state().resume()); - regs.tasks_dpdmdrive - .write(|w| w.tasks_dpdmdrive().set_bit()); + regs.tasks_dpdmdrive.write(|w| w.tasks_dpdmdrive().set_bit()); Poll::Ready(()) } else { @@ -520,11 +511,7 @@ unsafe fn read_dma(i: usize, buf: &mut [u8]) -> Result driver::EndpointOut for Endpoint<'d, T, Out> { let i = self.info.addr.index(); assert!(i != 0); - self.wait_data_ready() - .await - .map_err(|_| EndpointError::Disabled)?; + self.wait_data_ready().await.map_err(|_| EndpointError::Disabled)?; unsafe { read_dma::(i, buf) } } @@ -596,9 +581,7 @@ impl<'d, T: Instance> driver::EndpointIn for Endpoint<'d, T, In> { let i = self.info.addr.index(); assert!(i != 0); - self.wait_data_ready() - .await - .map_err(|_| EndpointError::Disabled)?; + self.wait_data_ready().await.map_err(|_| EndpointError::Disabled)?; unsafe { write_dma::(i, buf) } @@ -659,20 +642,14 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> { } } - fn data_out<'a>( - &'a mut self, - buf: &'a mut [u8], - _first: bool, - _last: bool, - ) -> Self::DataOutFuture<'a> { + fn data_out<'a>(&'a mut self, buf: &'a mut [u8], _first: bool, _last: bool) -> Self::DataOutFuture<'a> { async move { let regs = T::regs(); regs.events_ep0datadone.reset(); // This starts a RX on EP0. events_ep0datadone notifies when done. - regs.tasks_ep0rcvout - .write(|w| w.tasks_ep0rcvout().set_bit()); + regs.tasks_ep0rcvout.write(|w| w.tasks_ep0rcvout().set_bit()); // Wait until ready regs.intenset.write(|w| { @@ -701,12 +678,7 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> { } } - fn data_in<'a>( - &'a mut self, - buf: &'a [u8], - _first: bool, - last: bool, - ) -> Self::DataInFuture<'a> { + fn data_in<'a>(&'a mut self, buf: &'a [u8], _first: bool, last: bool) -> Self::DataInFuture<'a> { async move { let regs = T::regs(); regs.events_ep0datadone.reset(); @@ -745,8 +717,7 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> { fn accept<'a>(&'a mut self) -> Self::AcceptFuture<'a> { async move { let regs = T::regs(); - regs.tasks_ep0status - .write(|w| w.tasks_ep0status().bit(true)); + regs.tasks_ep0status.write(|w| w.tasks_ep0status().bit(true)); } } diff --git a/embassy-rp/src/clocks.rs b/embassy-rp/src/clocks.rs index 3082cd0d..3ad1e5d8 100644 --- a/embassy-rp/src/clocks.rs +++ b/embassy-rp/src/clocks.rs @@ -47,11 +47,9 @@ pub unsafe fn init() { start_xosc(); // Before we touch PLLs, switch sys and ref cleanly away from their aux sources. - c.clk_sys_ctrl() - .modify(|w| w.set_src(ClkSysCtrlSrc::CLK_REF)); + c.clk_sys_ctrl().modify(|w| w.set_src(ClkSysCtrlSrc::CLK_REF)); while c.clk_sys_selected().read() != 1 {} - c.clk_ref_ctrl() - .modify(|w| w.set_src(ClkRefCtrlSrc::ROSC_CLKSRC_PH)); + c.clk_ref_ctrl().modify(|w| w.set_src(ClkRefCtrlSrc::ROSC_CLKSRC_PH)); while c.clk_ref_selected().read() != 1 {} // Configure PLLs @@ -135,9 +133,7 @@ unsafe fn start_xosc() { .write(|w| w.set_freq_range(pac::xosc::vals::CtrlFreqRange::_1_15MHZ)); let startup_delay = (((XOSC_MHZ * 1_000_000) / 1000) + 128) / 256; - pac::XOSC - .startup() - .write(|w| w.set_delay(startup_delay as u16)); + pac::XOSC.startup().write(|w| w.set_delay(startup_delay as u16)); pac::XOSC.ctrl().write(|w| { w.set_freq_range(pac::xosc::vals::CtrlFreqRange::_1_15MHZ); w.set_enable(pac::xosc::vals::Enable::ENABLE); @@ -145,13 +141,7 @@ unsafe fn start_xosc() { while !pac::XOSC.status().read().stable() {} } -unsafe fn configure_pll( - p: pac::pll::Pll, - refdiv: u32, - vco_freq: u32, - post_div1: u8, - post_div2: u8, -) { +unsafe fn configure_pll(p: pac::pll::Pll, refdiv: u32, vco_freq: u32, post_div1: u8, post_div2: u8) { let ref_freq = XOSC_MHZ * 1_000_000 / refdiv; let fbdiv = vco_freq / ref_freq; diff --git a/embassy-rp/src/gpio.rs b/embassy-rp/src/gpio.rs index a2e1b3d7..ae771e84 100644 --- a/embassy-rp/src/gpio.rs +++ b/embassy-rp/src/gpio.rs @@ -1,13 +1,11 @@ use core::convert::Infallible; use core::marker::PhantomData; -use crate::pac; +use embassy_hal_common::{unborrow, unsafe_impl_unborrow}; + use crate::pac::common::{Reg, RW}; use crate::pac::SIO; -use crate::peripherals; - -use crate::Unborrow; -use embassy_hal_common::{unborrow, unsafe_impl_unborrow}; +use crate::{pac, peripherals, Unborrow}; /// Represents a digital input or output level. #[derive(Debug, Eq, PartialEq)] @@ -195,10 +193,7 @@ impl<'d, T: Pin> OutputOpenDrain<'d, T> { pub fn set_high(&mut self) { // For Open Drain High, disable the output pin. unsafe { - self.pin - .sio_oe() - .value_clr() - .write_value(1 << self.pin.pin()); + self.pin.sio_oe().value_clr().write_value(1 << self.pin.pin()); } } @@ -207,10 +202,7 @@ impl<'d, T: Pin> OutputOpenDrain<'d, T> { pub fn set_low(&mut self) { // For Open Drain Low, enable the output pin. unsafe { - self.pin - .sio_oe() - .value_set() - .write_value(1 << self.pin.pin()); + self.pin.sio_oe().value_set().write_value(1 << self.pin.pin()); } } diff --git a/embassy-rp/src/interrupt.rs b/embassy-rp/src/interrupt.rs index 04288269..d652a8c7 100644 --- a/embassy-rp/src/interrupt.rs +++ b/embassy-rp/src/interrupt.rs @@ -5,9 +5,9 @@ // Re-exports pub use embassy_cortex_m::interrupt::*; +use embassy_macros::cortex_m_interrupt_declare as declare; use crate::pac::Interrupt as InterruptEnum; -use embassy_macros::cortex_m_interrupt_declare as declare; declare!(TIMER_IRQ_0); declare!(TIMER_IRQ_1); declare!(TIMER_IRQ_2); diff --git a/embassy-rp/src/lib.rs b/embassy-rp/src/lib.rs index 72fe864b..90ef1b17 100644 --- a/embassy-rp/src/lib.rs +++ b/embassy-rp/src/lib.rs @@ -17,15 +17,14 @@ mod reset; // Reexports +pub use embassy_cortex_m::executor; +pub use embassy_hal_common::{unborrow, Unborrow}; +pub use embassy_macros::cortex_m_interrupt as interrupt; #[cfg(feature = "unstable-pac")] pub use rp2040_pac2 as pac; #[cfg(not(feature = "unstable-pac"))] pub(crate) use rp2040_pac2 as pac; -pub use embassy_cortex_m::executor; -pub use embassy_hal_common::{unborrow, Unborrow}; -pub use embassy_macros::cortex_m_interrupt as interrupt; - embassy_hal_common::peripherals! { PIN_0, PIN_1, diff --git a/embassy-rp/src/reset.rs b/embassy-rp/src/reset.rs index 914e6a69..edd47c22 100644 --- a/embassy-rp/src/reset.rs +++ b/embassy-rp/src/reset.rs @@ -1,7 +1,7 @@ -use crate::pac; - pub use pac::resets::regs::Peripherals; +use crate::pac; + pub const ALL_PERIPHERALS: Peripherals = Peripherals(0x01ffffff); pub unsafe fn reset(peris: Peripherals) { @@ -10,8 +10,6 @@ pub unsafe fn reset(peris: Peripherals) { pub unsafe fn unreset_wait(peris: Peripherals) { // TODO use the "atomic clear" register version - pac::RESETS - .reset() - .modify(|v| *v = Peripherals(v.0 & !peris.0)); + pac::RESETS.reset().modify(|v| *v = Peripherals(v.0 & !peris.0)); while ((!pac::RESETS.reset_done().read().0) & peris.0) != 0 {} } diff --git a/embassy-rp/src/spi.rs b/embassy-rp/src/spi.rs index 726c20a8..e988e41d 100644 --- a/embassy-rp/src/spi.rs +++ b/embassy-rp/src/spi.rs @@ -1,13 +1,11 @@ use core::marker::PhantomData; -use crate::Unborrow; use embassy_hal_common::unborrow; +pub use embedded_hal_02::spi::{Phase, Polarity}; use crate::gpio::sealed::Pin as _; use crate::gpio::{AnyPin, Pin as GpioPin}; -use crate::{pac, peripherals}; - -pub use embedded_hal_02::spi::{Phase, Polarity}; +use crate::{pac, peripherals, Unborrow}; #[derive(Debug, Clone, Copy, PartialEq, Eq)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] @@ -56,11 +54,7 @@ fn calc_prescs(freq: u32) -> (u8, u8) { } let presc = div_roundup(ratio, 256); - let postdiv = if presc == 1 { - ratio - } else { - div_roundup(ratio, presc) - }; + let postdiv = if presc == 1 { ratio } else { div_roundup(ratio, presc) }; ((presc * 2) as u8, (postdiv - 1) as u8) } @@ -91,14 +85,7 @@ impl<'d, T: Instance> Spi<'d, T> { config: Config, ) -> Self { unborrow!(clk, mosi); - Self::new_inner( - inner, - Some(clk.degrade()), - Some(mosi.degrade()), - None, - None, - config, - ) + Self::new_inner(inner, Some(clk.degrade()), Some(mosi.degrade()), None, None, config) } pub fn new_rxonly( @@ -108,14 +95,7 @@ impl<'d, T: Instance> Spi<'d, T> { config: Config, ) -> Self { unborrow!(clk, miso); - Self::new_inner( - inner, - Some(clk.degrade()), - None, - Some(miso.degrade()), - None, - config, - ) + Self::new_inner(inner, Some(clk.degrade()), None, Some(miso.degrade()), None, config) } fn new_inner( diff --git a/embassy-rp/src/timer.rs b/embassy-rp/src/timer.rs index c43e044f..6c4c258b 100644 --- a/embassy-rp/src/timer.rs +++ b/embassy-rp/src/timer.rs @@ -1,11 +1,12 @@ -use crate::interrupt::{Interrupt, InterruptExt}; -use atomic_polyfill::{AtomicU8, Ordering}; use core::cell::Cell; + +use atomic_polyfill::{AtomicU8, Ordering}; use critical_section::CriticalSection; use embassy::blocking_mutex::raw::CriticalSectionRawMutex; use embassy::blocking_mutex::Mutex; use embassy::time::driver::{AlarmHandle, Driver}; +use crate::interrupt::{Interrupt, InterruptExt}; use crate::{interrupt, pac}; struct AlarmState { @@ -45,15 +46,13 @@ impl Driver for TimerDriver { } unsafe fn allocate_alarm(&self) -> Option { - let id = self - .next_alarm - .fetch_update(Ordering::AcqRel, Ordering::Acquire, |x| { - if x < ALARM_COUNT as u8 { - Some(x + 1) - } else { - None - } - }); + let id = self.next_alarm.fetch_update(Ordering::AcqRel, Ordering::Acquire, |x| { + if x < ALARM_COUNT as u8 { + Some(x + 1) + } else { + None + } + }); match id { Ok(id) => Some(AlarmHandle::new(id)), diff --git a/embassy-rp/src/uart.rs b/embassy-rp/src/uart.rs index 1aa3c5a8..c95407b6 100644 --- a/embassy-rp/src/uart.rs +++ b/embassy-rp/src/uart.rs @@ -1,10 +1,9 @@ use core::marker::PhantomData; -use crate::Unborrow; use embassy_hal_common::unborrow; use gpio::Pin; -use crate::{gpio, pac, peripherals}; +use crate::{gpio, pac, peripherals, Unborrow}; #[non_exhaustive] pub struct Config { @@ -57,10 +56,8 @@ impl<'d, T: Instance> Uart<'d, T> { } // Load PL011's baud divisor registers - p.uartibrd() - .write_value(pac::uart::regs::Uartibrd(baud_ibrd)); - p.uartfbrd() - .write_value(pac::uart::regs::Uartfbrd(baud_fbrd)); + p.uartibrd().write_value(pac::uart::regs::Uartibrd(baud_ibrd)); + p.uartfbrd().write_value(pac::uart::regs::Uartfbrd(baud_fbrd)); p.uartlcr_h().write(|w| { w.set_wlen(config.data_bits - 5); diff --git a/embassy-stm32/build.rs b/embassy-stm32/build.rs index 42c88a26..3b4aa5df 100644 --- a/embassy-stm32/build.rs +++ b/embassy-stm32/build.rs @@ -1,10 +1,10 @@ +use std::collections::{HashMap, HashSet}; +use std::fmt::Write as _; +use std::path::PathBuf; +use std::{env, fs}; + use proc_macro2::TokenStream; use quote::{format_ident, quote}; -use std::collections::{HashMap, HashSet}; -use std::env; -use std::fmt::Write as _; -use std::fs; -use std::path::PathBuf; use stm32_metapac::metadata::METADATA; fn main() { @@ -116,10 +116,7 @@ fn main() { continue; } for irq in p.interrupts { - dma_irqs - .entry(irq.interrupt) - .or_default() - .push((p.name, irq.signal)); + dma_irqs.entry(irq.interrupt).or_default().push((p.name, irq.signal)); } } } @@ -128,9 +125,7 @@ fn main() { for (irq, channels) in dma_irqs { let irq = format_ident!("{}", irq); - let channels = channels - .iter() - .map(|(dma, ch)| format_ident!("{}_{}", dma, ch)); + let channels = channels.iter().map(|(dma, ch)| format_ident!("{}_{}", dma, ch)); g.extend(quote! { #[crate::interrupt] @@ -147,9 +142,7 @@ fn main() { for p in METADATA.peripherals { // generating RccPeripheral impl for H7 ADC3 would result in bad frequency - if !singletons.contains(&p.name.to_string()) - || (p.name == "ADC3" && METADATA.line.starts_with("STM32H7")) - { + if !singletons.contains(&p.name.to_string()) || (p.name == "ADC3" && METADATA.line.starts_with("STM32H7")) { continue; } @@ -568,12 +561,7 @@ fn main() { let mut pins_table: Vec> = Vec::new(); let mut dma_channels_table: Vec> = Vec::new(); - let gpio_base = METADATA - .peripherals - .iter() - .find(|p| p.name == "GPIOA") - .unwrap() - .address as u32; + let gpio_base = METADATA.peripherals.iter().find(|p| p.name == "GPIOA").unwrap().address as u32; let gpio_stride = 0x400; for p in METADATA.peripherals { @@ -618,11 +606,7 @@ fn main() { for ch in METADATA.dma_channels { let mut row = Vec::new(); - let dma_peri = METADATA - .peripherals - .iter() - .find(|p| p.name == ch.dma) - .unwrap(); + let dma_peri = METADATA.peripherals.iter().find(|p| p.name == ch.dma).unwrap(); let bi = dma_peri.registers.as_ref().unwrap(); let num; @@ -649,10 +633,7 @@ fn main() { row.push(num.to_string()); if let Some(dmamux) = &ch.dmamux { let dmamux_channel = ch.dmamux_channel.unwrap(); - row.push(format!( - "{{dmamux: {}, dmamux_channel: {}}}", - dmamux, dmamux_channel - )); + row.push(format!("{{dmamux: {}, dmamux_channel: {}}}", dmamux, dmamux_channel)); } else { row.push("{}".to_string()); } @@ -709,11 +690,7 @@ fn main() { }; if let Some(core) = core_name { - println!( - "cargo:rustc-cfg={}_{}", - &chip_name[..chip_name.len() - 2], - core - ); + println!("cargo:rustc-cfg={}_{}", &chip_name[..chip_name.len() - 2], core); } else { println!("cargo:rustc-cfg={}", &chip_name[..chip_name.len() - 2]); } diff --git a/embassy-stm32/src/adc/f1.rs b/embassy-stm32/src/adc/f1.rs index ecb68b1a..74cfac13 100644 --- a/embassy-stm32/src/adc/f1.rs +++ b/embassy-stm32/src/adc/f1.rs @@ -1,10 +1,12 @@ +use core::marker::PhantomData; + +use embassy_hal_common::unborrow; +use embedded_hal_02::blocking::delay::DelayUs; + use crate::adc::{AdcPin, Instance}; use crate::rcc::get_freqs; use crate::time::Hertz; use crate::Unborrow; -use core::marker::PhantomData; -use embassy_hal_common::unborrow; -use embedded_hal_02::blocking::delay::DelayUs; pub const VDDA_CALIB_MV: u32 = 3300; pub const ADC_MAX: u32 = (1 << 12) - 1; diff --git a/embassy-stm32/src/adc/v2.rs b/embassy-stm32/src/adc/v2.rs index cdb8dfe9..936a3556 100644 --- a/embassy-stm32/src/adc/v2.rs +++ b/embassy-stm32/src/adc/v2.rs @@ -1,9 +1,11 @@ +use core::marker::PhantomData; + +use embassy_hal_common::unborrow; +use embedded_hal_02::blocking::delay::DelayUs; + use crate::adc::{AdcPin, Instance}; use crate::time::Hertz; use crate::Unborrow; -use core::marker::PhantomData; -use embassy_hal_common::unborrow; -use embedded_hal_02::blocking::delay::DelayUs; pub const VDDA_CALIB_MV: u32 = 3000; @@ -132,9 +134,7 @@ impl Prescaler { 2..=3 => Self::Div4, 4..=5 => Self::Div6, 6..=7 => Self::Div8, - _ => panic!( - "Selected PCLK2 frequency is too high for ADC with largest possible prescaler." - ), + _ => panic!("Selected PCLK2 frequency is too high for ADC with largest possible prescaler."), } } @@ -165,9 +165,7 @@ where let presc = unsafe { Prescaler::from_pclk2(crate::rcc::get_freqs().apb2) }; unsafe { - T::common_regs() - .ccr() - .modify(|w| w.set_adcpre(presc.adcpre())); + T::common_regs().ccr().modify(|w| w.set_adcpre(presc.adcpre())); } unsafe { @@ -241,9 +239,7 @@ where pin.set_as_analog(); // Configure ADC - T::regs() - .cr1() - .modify(|reg| reg.set_res(self.resolution.res())); + T::regs().cr1().modify(|reg| reg.set_res(self.resolution.res())); // Select channel T::regs().sqr3().write(|reg| reg.set_sq(0, pin.channel())); diff --git a/embassy-stm32/src/adc/v3.rs b/embassy-stm32/src/adc/v3.rs index 875510b7..49d149b1 100644 --- a/embassy-stm32/src/adc/v3.rs +++ b/embassy-stm32/src/adc/v3.rs @@ -1,9 +1,11 @@ -use crate::adc::{AdcPin, Instance}; -use crate::Unborrow; use core::marker::PhantomData; + use embassy_hal_common::unborrow; use embedded_hal_02::blocking::delay::DelayUs; +use crate::adc::{AdcPin, Instance}; +use crate::Unborrow; + pub const VDDA_CALIB_MV: u32 = 3000; /// Sadly we cannot use `RccPeripheral::enable` since devices are quite inconsistent ADC clock @@ -369,13 +371,9 @@ impl<'d, T: Instance> Adc<'d, T> { // Configure ADC #[cfg(not(stm32g0))] - T::regs() - .cfgr() - .modify(|reg| reg.set_res(self.resolution.res())); + T::regs().cfgr().modify(|reg| reg.set_res(self.resolution.res())); #[cfg(stm32g0)] - T::regs() - .cfgr1() - .modify(|reg| reg.set_res(self.resolution.res())); + T::regs().cfgr1().modify(|reg| reg.set_res(self.resolution.res())); // Configure channel Self::set_channel_sample_time(pin.channel(), self.sample_time); @@ -384,9 +382,7 @@ impl<'d, T: Instance> Adc<'d, T> { #[cfg(not(stm32g0))] T::regs().sqr1().write(|reg| reg.set_sq(0, pin.channel())); #[cfg(stm32g0)] - T::regs() - .chselr() - .write(|reg| reg.set_chsel(pin.channel() as u32)); + T::regs().chselr().write(|reg| reg.set_chsel(pin.channel() as u32)); // Some models are affected by an erratum: // If we perform conversions slower than 1 kHz, the first read ADC value can be @@ -407,9 +403,7 @@ impl<'d, T: Instance> Adc<'d, T> { #[cfg(stm32g0)] unsafe fn set_channel_sample_time(_ch: u8, sample_time: SampleTime) { - T::regs() - .smpr() - .modify(|reg| reg.set_smp1(sample_time.sample_time())); + T::regs().smpr().modify(|reg| reg.set_smp1(sample_time.sample_time())); } #[cfg(not(stm32g0))] diff --git a/embassy-stm32/src/adc/v4.rs b/embassy-stm32/src/adc/v4.rs index 316e04e0..cdb79f51 100644 --- a/embassy-stm32/src/adc/v4.rs +++ b/embassy-stm32/src/adc/v4.rs @@ -1,16 +1,13 @@ use core::marker::PhantomData; -use crate::time::{Hertz, U32Ext}; -use crate::Unborrow; -use atomic_polyfill::AtomicU8; -use atomic_polyfill::Ordering; +use atomic_polyfill::{AtomicU8, Ordering}; use embedded_hal_02::blocking::delay::DelayUs; use pac::adc::vals::{Adcaldif, Boost, Difsel, Exten, Pcsel}; use pac::adccommon::vals::Presc; -use crate::pac; - use super::{AdcPin, Instance}; +use crate::time::{Hertz, U32Ext}; +use crate::{pac, Unborrow}; pub enum Resolution { SixteenBit, @@ -333,9 +330,7 @@ impl<'d, T: Instance + crate::rcc::RccPeripheral> Adc<'d, T> { let prescaler = Prescaler::from_ker_ck(T::frequency()); unsafe { - T::common_regs() - .ccr() - .modify(|w| w.set_presc(prescaler.presc())); + T::common_regs().ccr().modify(|w| w.set_presc(prescaler.presc())); } let frequency = Hertz(T::frequency().0 / prescaler.divisor()); @@ -509,9 +504,7 @@ impl<'d, T: Instance + crate::rcc::RccPeripheral> Adc<'d, T> { unsafe fn read_channel(&mut self, channel: u8) -> u16 { // Configure ADC - T::regs() - .cfgr() - .modify(|reg| reg.set_res(self.resolution.res())); + T::regs().cfgr().modify(|reg| reg.set_res(self.resolution.res())); // Configure channel Self::set_channel_sample_time(channel, self.sample_time); diff --git a/embassy-stm32/src/can/bxcan.rs b/embassy-stm32/src/can/bxcan.rs index 0922d4d6..b54fd3ff 100644 --- a/embassy-stm32/src/can/bxcan.rs +++ b/embassy-stm32/src/can/bxcan.rs @@ -1,13 +1,12 @@ use core::marker::PhantomData; use core::ops::{Deref, DerefMut}; -use crate::Unborrow; +pub use bxcan; use embassy_hal_common::unborrow; use crate::gpio::sealed::AFType; -use crate::{peripherals, rcc::RccPeripheral}; - -pub use bxcan; +use crate::rcc::RccPeripheral; +use crate::{peripherals, Unborrow}; pub struct Can<'d, T: Instance + bxcan::Instance> { phantom: PhantomData<&'d mut T>, diff --git a/embassy-stm32/src/crc/v1.rs b/embassy-stm32/src/crc/v1.rs index 1ab4530b..87133714 100644 --- a/embassy-stm32/src/crc/v1.rs +++ b/embassy-stm32/src/crc/v1.rs @@ -1,10 +1,11 @@ use core::marker::PhantomData; +use embassy_hal_common::unborrow; + use crate::pac::CRC as PAC_CRC; use crate::peripherals::CRC; use crate::rcc::sealed::RccPeripheral; use crate::Unborrow; -use embassy_hal_common::unborrow; pub struct Crc<'d> { _peripheral: CRC, diff --git a/embassy-stm32/src/crc/v2v3.rs b/embassy-stm32/src/crc/v2v3.rs index b6645c67..63f24e4e 100644 --- a/embassy-stm32/src/crc/v2v3.rs +++ b/embassy-stm32/src/crc/v2v3.rs @@ -1,11 +1,12 @@ use core::marker::PhantomData; +use embassy_hal_common::unborrow; + use crate::pac::crc::vals; use crate::pac::CRC as PAC_CRC; use crate::peripherals::CRC; use crate::rcc::sealed::RccPeripheral; use crate::Unborrow; -use embassy_hal_common::unborrow; pub struct Crc<'d> { _peripheral: CRC, diff --git a/embassy-stm32/src/dac/mod.rs b/embassy-stm32/src/dac/mod.rs index 1f6ba63d..f1cb452c 100644 --- a/embassy-stm32/src/dac/mod.rs +++ b/embassy-stm32/src/dac/mod.rs @@ -3,9 +3,10 @@ #[cfg_attr(dac_v1, path = "v1.rs")] #[cfg_attr(dac_v2, path = "v2.rs")] mod _version; -use crate::peripherals; pub use _version::*; +use crate::peripherals; + pub(crate) mod sealed { pub trait Instance { fn regs() -> &'static crate::pac::dac::Dac; diff --git a/embassy-stm32/src/dac/v2.rs b/embassy-stm32/src/dac/v2.rs index 0b421cc8..ba7856a5 100644 --- a/embassy-stm32/src/dac/v2.rs +++ b/embassy-stm32/src/dac/v2.rs @@ -1,8 +1,10 @@ +use core::marker::PhantomData; + +use embassy_hal_common::unborrow; + use crate::dac::{DacPin, Instance}; use crate::pac::dac; use crate::Unborrow; -use core::marker::PhantomData; -use embassy_hal_common::unborrow; #[derive(Debug, Copy, Clone, Eq, PartialEq)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] @@ -93,23 +95,14 @@ pub struct Dac<'d, T: Instance> { macro_rules! enable { ($enable_reg:ident, $enable_field:ident, $reset_reg:ident, $reset_field:ident) => { - crate::pac::RCC - .$enable_reg() - .modify(|w| w.$enable_field(true)); - crate::pac::RCC - .$reset_reg() - .modify(|w| w.$reset_field(true)); - crate::pac::RCC - .$reset_reg() - .modify(|w| w.$reset_field(false)); + crate::pac::RCC.$enable_reg().modify(|w| w.$enable_field(true)); + crate::pac::RCC.$reset_reg().modify(|w| w.$reset_field(true)); + crate::pac::RCC.$reset_reg().modify(|w| w.$reset_field(false)); }; } impl<'d, T: Instance> Dac<'d, T> { - pub fn new_1ch( - peri: impl Unborrow + 'd, - _ch1: impl Unborrow> + 'd, - ) -> Self { + pub fn new_1ch(peri: impl Unborrow + 'd, _ch1: impl Unborrow> + 'd) -> Self { unborrow!(peri); Self::new_inner(peri, 1) } diff --git a/embassy-stm32/src/dcmi.rs b/embassy-stm32/src/dcmi.rs index 8a28ca4b..f4ca93a7 100644 --- a/embassy-stm32/src/dcmi.rs +++ b/embassy-stm32/src/dcmi.rs @@ -1,13 +1,14 @@ use core::marker::PhantomData; use core::task::Poll; -use crate::interrupt::{Interrupt, InterruptExt}; -use crate::Unborrow; use embassy::waitqueue::AtomicWaker; use embassy_hal_common::unborrow; use futures::future::poll_fn; -use crate::gpio::{sealed::AFType, Speed}; +use crate::gpio::sealed::AFType; +use crate::gpio::Speed; +use crate::interrupt::{Interrupt, InterruptExt}; +use crate::Unborrow; /// The level on the VSync pin when the data is not valid on the parallel interface. #[derive(Clone, Copy, PartialEq)] @@ -466,14 +467,7 @@ where let src = r.dr().ptr() as *mut u32; unsafe { - channel.start_double_buffered_read( - request, - src, - m0ar, - m1ar, - chunk_size, - TransferOptions::default(), - ); + channel.start_double_buffered_read(request, src, m0ar, m1ar, chunk_size, TransferOptions::default()); } let mut last_chunk_set_for_transfer = false; diff --git a/embassy-stm32/src/dma/bdma.rs b/embassy-stm32/src/dma/bdma.rs index b17d2295..c87f3ac4 100644 --- a/embassy-stm32/src/dma/bdma.rs +++ b/embassy-stm32/src/dma/bdma.rs @@ -3,16 +3,15 @@ use core::sync::atomic::{fence, Ordering}; use core::task::Waker; -use crate::interrupt::{Interrupt, InterruptExt}; use embassy::waitqueue::AtomicWaker; +use super::{TransferOptions, Word, WordSize}; use crate::_generated::BDMA_CHANNEL_COUNT; use crate::dma::Request; +use crate::interrupt::{Interrupt, InterruptExt}; use crate::pac; use crate::pac::bdma::vals; -use super::{TransferOptions, Word, WordSize}; - impl From for vals::Size { fn from(raw: WordSize) -> Self { match raw { @@ -185,14 +184,8 @@ mod low_level_api { #[cfg(dmamux)] dmamux_regs: pac::dmamux::Dmamux, #[cfg(dmamux)] dmamux_ch_num: u8, ) { - assert!( - options.mburst == crate::dma::Burst::Single, - "Burst mode not supported" - ); - assert!( - options.pburst == crate::dma::Burst::Single, - "Burst mode not supported" - ); + assert!(options.mburst == crate::dma::Burst::Single, "Burst mode not supported"); + assert!(options.pburst == crate::dma::Burst::Single, "Burst mode not supported"); assert!( options.flow_ctrl == crate::dma::FlowControl::Dma, "Peripheral flow control not supported" @@ -206,10 +199,7 @@ mod low_level_api { super::super::dmamux::configure_dmamux(dmamux_regs, dmamux_ch_num, request); #[cfg(bdma_v2)] - critical_section::with(|_| { - dma.cselr() - .modify(|w| w.set_cs(channel_number as _, request)) - }); + critical_section::with(|_| dma.cselr().modify(|w| w.set_cs(channel_number as _, request))); // "Preceding reads and writes cannot be moved past subsequent writes." fence(Ordering::SeqCst); @@ -279,10 +269,7 @@ mod low_level_api { let cr = dma.ch(channel_num).cr(); if isr.teif(channel_num) { - panic!( - "DMA: error on BDMA@{:08x} channel {}", - dma.0 as u32, channel_num - ); + panic!("DMA: error on BDMA@{:08x} channel {}", dma.0 as u32, channel_num); } if isr.tcif(channel_num) && cr.read().tcie() { cr.write(|_| ()); // Disable channel interrupts with the default value. diff --git a/embassy-stm32/src/dma/dma.rs b/embassy-stm32/src/dma/dma.rs index 04cde7b4..e8e589de 100644 --- a/embassy-stm32/src/dma/dma.rs +++ b/embassy-stm32/src/dma/dma.rs @@ -1,15 +1,13 @@ use core::sync::atomic::{fence, Ordering}; use core::task::Waker; -use crate::interrupt::{Interrupt, InterruptExt}; use embassy::waitqueue::AtomicWaker; -use crate::_generated::DMA_CHANNEL_COUNT; -use crate::interrupt; -use crate::pac; -use crate::pac::dma::{regs, vals}; - use super::{Burst, FlowControl, Request, TransferOptions, Word, WordSize}; +use crate::_generated::DMA_CHANNEL_COUNT; +use crate::interrupt::{Interrupt, InterruptExt}; +use crate::pac::dma::{regs, vals}; +use crate::{interrupt, pac}; impl From for vals::Size { fn from(raw: WordSize) -> Self { @@ -407,10 +405,7 @@ mod low_level_api { let isr = dma.isr(channel_num / 4).read(); if isr.teif(channel_num % 4) { - panic!( - "DMA: error on DMA@{:08x} channel {}", - dma.0 as u32, channel_num - ); + panic!("DMA: error on DMA@{:08x} channel {}", dma.0 as u32, channel_num); } if isr.tcif(channel_num % 4) && cr.read().tcie() { @@ -418,8 +413,7 @@ mod low_level_api { cr.write(|_| ()); // Disable channel with the default value. } else { // for double buffered mode, clear TCIF flag but do not stop the transfer - dma.ifcr(channel_num / 4) - .write(|w| w.set_tcif(channel_num % 4, true)); + dma.ifcr(channel_num / 4).write(|w| w.set_tcif(channel_num % 4, true)); } STATE.channels[state_index].waker.wake(); } diff --git a/embassy-stm32/src/dma/dmamux.rs b/embassy-stm32/src/dma/dmamux.rs index c45bebe2..e9967e34 100644 --- a/embassy-stm32/src/dma/dmamux.rs +++ b/embassy-stm32/src/dma/dmamux.rs @@ -1,13 +1,8 @@ #![macro_use] -use crate::pac; -use crate::peripherals; +use crate::{pac, peripherals}; -pub(crate) unsafe fn configure_dmamux( - dmamux_regs: pac::dmamux::Dmamux, - dmamux_ch_num: u8, - request: u8, -) { +pub(crate) unsafe fn configure_dmamux(dmamux_regs: pac::dmamux::Dmamux, dmamux_ch_num: u8, request: u8) { let ch_mux_regs = dmamux_regs.ccr(dmamux_ch_num as _); ch_mux_regs.write(|reg| { reg.set_nbreq(0); diff --git a/embassy-stm32/src/dma/gpdma.rs b/embassy-stm32/src/dma/gpdma.rs index b054f95c..8e901d72 100644 --- a/embassy-stm32/src/dma/gpdma.rs +++ b/embassy-stm32/src/dma/gpdma.rs @@ -1,15 +1,13 @@ use core::sync::atomic::{fence, Ordering}; use core::task::Waker; -use crate::interrupt::{Interrupt, InterruptExt}; use embassy::waitqueue::AtomicWaker; -use crate::_generated::GPDMA_CHANNEL_COUNT; -use crate::interrupt; -use crate::pac; -use crate::pac::gpdma::{vals, Gpdma}; - use super::{Request, TransferOptions, Word, WordSize}; +use crate::_generated::GPDMA_CHANNEL_COUNT; +use crate::interrupt::{Interrupt, InterruptExt}; +use crate::pac::gpdma::{vals, Gpdma}; +use crate::{interrupt, pac}; impl From for vals::ChTr1Dw { fn from(raw: WordSize) -> Self { diff --git a/embassy-stm32/src/dma/mod.rs b/embassy-stm32/src/dma/mod.rs index 3a909778..87ac38ba 100644 --- a/embassy-stm32/src/dma/mod.rs +++ b/embassy-stm32/src/dma/mod.rs @@ -7,18 +7,18 @@ mod dmamux; #[cfg(gpdma)] mod gpdma; -#[cfg(dmamux)] -pub use dmamux::*; - -use crate::Unborrow; use core::future::Future; use core::marker::PhantomData; use core::mem; use core::pin::Pin; -use core::task::Waker; -use core::task::{Context, Poll}; +use core::task::{Context, Poll, Waker}; + +#[cfg(dmamux)] +pub use dmamux::*; use embassy_hal_common::unborrow; +use crate::Unborrow; + #[cfg(feature = "unstable-pac")] pub mod low_level { pub use super::transfers::*; @@ -249,15 +249,7 @@ mod transfers { ) -> impl Future + 'a { unborrow!(channel); - unsafe { - channel.start_write_repeated::( - request, - repeated, - count, - reg_addr, - Default::default(), - ) - }; + unsafe { channel.start_write_repeated::(request, repeated, count, reg_addr, Default::default()) }; Transfer::new(channel) } diff --git a/embassy-stm32/src/eth/generic_smi.rs b/embassy-stm32/src/eth/generic_smi.rs index 5a323bf5..96825604 100644 --- a/embassy-stm32/src/eth/generic_smi.rs +++ b/embassy-stm32/src/eth/generic_smi.rs @@ -51,10 +51,7 @@ unsafe impl PHY for GenericSMI { Self::smi_write_ext(sm, PHY_REG_WUCSR, 0); // Enable auto-negotiation - sm.smi_write( - PHY_REG_BCR, - PHY_REG_BCR_AN | PHY_REG_BCR_ANRST | PHY_REG_BCR_100M, - ); + sm.smi_write(PHY_REG_BCR, PHY_REG_BCR_AN | PHY_REG_BCR_ANRST | PHY_REG_BCR_100M); } fn poll_link(sm: &mut S) -> bool { diff --git a/embassy-stm32/src/eth/v1/mod.rs b/embassy-stm32/src/eth/v1/mod.rs index d2cfb17c..7985acc5 100644 --- a/embassy-stm32/src/eth/v1/mod.rs +++ b/embassy-stm32/src/eth/v1/mod.rs @@ -4,33 +4,30 @@ use core::marker::PhantomData; use core::sync::atomic::{fence, Ordering}; use core::task::Waker; -use crate::Unborrow; use embassy::waitqueue::AtomicWaker; use embassy_cortex_m::peripheral::{PeripheralMutex, PeripheralState, StateStorage}; use embassy_hal_common::unborrow; use embassy_net::{Device, DeviceCapabilities, LinkState, PacketBuf, MTU}; -use crate::gpio::sealed::Pin as __GpioPin; -use crate::gpio::{sealed::AFType, AnyPin, Speed}; +use crate::gpio::sealed::{AFType, Pin as __GpioPin}; +use crate::gpio::{AnyPin, Speed}; #[cfg(eth_v1a)] use crate::pac::AFIO; #[cfg(any(eth_v1b, eth_v1c))] use crate::pac::SYSCFG; use crate::pac::{ETH, RCC}; +use crate::Unborrow; mod descriptors; mod rx_desc; mod tx_desc; -use super::*; use descriptors::DescriptorRing; -use stm32_metapac::eth::vals::{ - Apcs, Cr, Dm, DmaomrSr, Fes, Ftf, Ifg, MbProgress, Mw, Pbl, Rsf, St, Tsf, -}; +use stm32_metapac::eth::vals::{Apcs, Cr, Dm, DmaomrSr, Fes, Ftf, Ifg, MbProgress, Mw, Pbl, Rsf, St, Tsf}; -pub struct State<'d, T: Instance, const TX: usize, const RX: usize>( - StateStorage>, -); +use super::*; + +pub struct State<'d, T: Instance, const TX: usize, const RX: usize>(StateStorage>); impl<'d, T: Instance, const TX: usize, const RX: usize> State<'d, T, TX, RX> { pub fn new() -> Self { Self(StateStorage::new()) @@ -300,9 +297,7 @@ unsafe impl<'d, T: Instance, P: PHY, const TX: usize, const RX: usize> StationMa } } -impl<'d, T: Instance, P: PHY, const TX: usize, const RX: usize> Device - for Ethernet<'d, T, P, TX, RX> -{ +impl<'d, T: Instance, P: PHY, const TX: usize, const RX: usize> Device for Ethernet<'d, T, P, TX, RX> { fn is_transmit_ready(&mut self) -> bool { self.state.with(|s| s.desc_ring.tx.available()) } @@ -339,9 +334,7 @@ impl<'d, T: Instance, P: PHY, const TX: usize, const RX: usize> Device } } -impl<'d, T: Instance, P: PHY, const TX: usize, const RX: usize> Drop - for Ethernet<'d, T, P, TX, RX> -{ +impl<'d, T: Instance, P: PHY, const TX: usize, const RX: usize> Drop for Ethernet<'d, T, P, TX, RX> { fn drop(&mut self) { // NOTE(unsafe) We have `&mut self` and the interrupt doesn't use this registers unsafe { diff --git a/embassy-stm32/src/eth/v1/rx_desc.rs b/embassy-stm32/src/eth/v1/rx_desc.rs index 6164f297..d482590a 100644 --- a/embassy-stm32/src/eth/v1/rx_desc.rs +++ b/embassy-stm32/src/eth/v1/rx_desc.rs @@ -59,8 +59,7 @@ impl RDes { // // Contains first buffer of packet AND contains last buf of // packet AND no errors - (self.rdes0.get() & (RXDESC_0_ES | RXDESC_0_FS | RXDESC_0_LS)) - == (RXDESC_0_FS | RXDESC_0_LS) + (self.rdes0.get() & (RXDESC_0_ES | RXDESC_0_FS | RXDESC_0_LS)) == (RXDESC_0_FS | RXDESC_0_LS) } /// Return true if this RDes is not currently owned by the DMA @@ -72,8 +71,7 @@ impl RDes { /// Configures the reception buffer address and length and passed descriptor ownership to the DMA #[inline(always)] pub fn set_ready(&mut self, buf_addr: u32, buf_len: usize) { - self.rdes1 - .set(self.rdes1.get() | (buf_len as u32) & RXDESC_1_RBS_MASK); + self.rdes1.set(self.rdes1.get() | (buf_len as u32) & RXDESC_1_RBS_MASK); self.rdes2.set(buf_addr); // "Preceding reads and writes cannot be moved past subsequent writes." @@ -220,11 +218,7 @@ impl RDesRing { // We already have fences in `set_owned`, which is called in `setup` // Start receive - unsafe { - ETH.ethernet_dma() - .dmaomr() - .modify(|w| w.set_sr(DmaomrSr::STARTED)) - }; + unsafe { ETH.ethernet_dma().dmaomr().modify(|w| w.set_sr(DmaomrSr::STARTED)) }; self.demand_poll(); } diff --git a/embassy-stm32/src/eth/v1/tx_desc.rs b/embassy-stm32/src/eth/v1/tx_desc.rs index f253ab19..f2889b55 100644 --- a/embassy-stm32/src/eth/v1/tx_desc.rs +++ b/embassy-stm32/src/eth/v1/tx_desc.rs @@ -100,8 +100,7 @@ impl TDes { // set up as a part fo the ring buffer - configures the tdes pub fn setup(&mut self, next: Option<&Self>) { // Defer this initialization to this function, so we can have `RingEntry` on bss. - self.tdes0 - .set(TXDESC_0_TCH | TXDESC_0_IOC | TXDESC_0_FS | TXDESC_0_LS); + self.tdes0.set(TXDESC_0_TCH | TXDESC_0_IOC | TXDESC_0_FS | TXDESC_0_LS); match next { Some(next) => self.set_buffer2(next as *const TDes as *const u8), None => { @@ -169,11 +168,7 @@ impl TDesRing { // volatiles // Start transmission - unsafe { - ETH.ethernet_dma() - .dmaomr() - .modify(|w| w.set_st(St::STARTED)) - }; + unsafe { ETH.ethernet_dma().dmaomr().modify(|w| w.set_st(St::STARTED)) }; } /// Return true if a TDes is available for use diff --git a/embassy-stm32/src/eth/v2/descriptors.rs b/embassy-stm32/src/eth/v2/descriptors.rs index 23b11857..c6c06a9c 100644 --- a/embassy-stm32/src/eth/v2/descriptors.rs +++ b/embassy-stm32/src/eth/v2/descriptors.rs @@ -101,11 +101,9 @@ impl TDesRing { unsafe { let dma = ETH.ethernet_dma(); - dma.dmactx_dlar() - .write(|w| w.0 = &self.td as *const _ as u32); + dma.dmactx_dlar().write(|w| w.0 = &self.td as *const _ as u32); dma.dmactx_rlr().write(|w| w.set_tdrl((N as u16) - 1)); - dma.dmactx_dtpr() - .write(|w| w.0 = &self.td[0] as *const _ as u32); + dma.dmactx_dtpr().write(|w| w.0 = &self.td[0] as *const _ as u32); } } @@ -127,8 +125,7 @@ impl TDesRing { // Read format td.tdes0.set(address); - td.tdes2 - .set(pkt_len as u32 & EMAC_TDES2_B1L | EMAC_TDES2_IOC); + td.tdes2.set(pkt_len as u32 & EMAC_TDES2_B1L | EMAC_TDES2_IOC); // FD: Contains first buffer of packet // LD: Contains last buffer of packet @@ -225,8 +222,7 @@ impl RDes { #[inline(always)] pub fn set_ready(&mut self, buf_addr: u32) { self.rdes0.set(buf_addr); - self.rdes3 - .set(EMAC_RDES3_BUF1V | EMAC_RDES3_IOC | EMAC_DES3_OWN); + self.rdes3.set(EMAC_RDES3_BUF1V | EMAC_RDES3_IOC | EMAC_DES3_OWN); } } diff --git a/embassy-stm32/src/eth/v2/mod.rs b/embassy-stm32/src/eth/v2/mod.rs index e438a7b5..2b1caf99 100644 --- a/embassy-stm32/src/eth/v2/mod.rs +++ b/embassy-stm32/src/eth/v2/mod.rs @@ -2,23 +2,22 @@ use core::marker::PhantomData; use core::sync::atomic::{fence, Ordering}; use core::task::Waker; -use crate::Unborrow; use embassy::waitqueue::AtomicWaker; use embassy_cortex_m::peripheral::{PeripheralMutex, PeripheralState, StateStorage}; use embassy_hal_common::unborrow; use embassy_net::{Device, DeviceCapabilities, LinkState, PacketBuf, MTU}; -use crate::gpio::sealed::Pin as _; -use crate::gpio::{sealed::AFType, AnyPin, Speed}; +use crate::gpio::sealed::{AFType, Pin as _}; +use crate::gpio::{AnyPin, Speed}; use crate::pac::{ETH, RCC, SYSCFG}; +use crate::Unborrow; mod descriptors; -use super::*; use descriptors::DescriptorRing; -pub struct State<'d, T: Instance, const TX: usize, const RX: usize>( - StateStorage>, -); +use super::*; + +pub struct State<'d, T: Instance, const TX: usize, const RX: usize>(StateStorage>); impl<'d, T: Instance, const TX: usize, const RX: usize> State<'d, T, TX, RX> { pub fn new() -> Self { Self(StateStorage::new()) @@ -234,9 +233,7 @@ unsafe impl<'d, T: Instance, P: PHY, const TX: usize, const RX: usize> StationMa } } -impl<'d, T: Instance, P: PHY, const TX: usize, const RX: usize> Device - for Ethernet<'d, T, P, TX, RX> -{ +impl<'d, T: Instance, P: PHY, const TX: usize, const RX: usize> Device for Ethernet<'d, T, P, TX, RX> { fn is_transmit_ready(&mut self) -> bool { self.state.with(|s| s.desc_ring.tx.available()) } @@ -273,9 +270,7 @@ impl<'d, T: Instance, P: PHY, const TX: usize, const RX: usize> Device } } -impl<'d, T: Instance, P: PHY, const TX: usize, const RX: usize> Drop - for Ethernet<'d, T, P, TX, RX> -{ +impl<'d, T: Instance, P: PHY, const TX: usize, const RX: usize> Drop for Ethernet<'d, T, P, TX, RX> { fn drop(&mut self) { // NOTE(unsafe) We have `&mut self` and the interrupt doesn't use this registers unsafe { diff --git a/embassy-stm32/src/exti.rs b/embassy-stm32/src/exti.rs index efe54e59..378665b7 100644 --- a/embassy-stm32/src/exti.rs +++ b/embassy-stm32/src/exti.rs @@ -1,17 +1,15 @@ -use crate::Unborrow; use core::future::Future; use core::marker::PhantomData; use core::pin::Pin; use core::task::{Context, Poll}; + use embassy::waitqueue::AtomicWaker; use embassy_hal_common::unsafe_impl_unborrow; use crate::gpio::{AnyPin, Input, Pin as GpioPin}; -use crate::interrupt; -use crate::pac; use crate::pac::exti::regs::Lines; use crate::pac::EXTI; -use crate::peripherals; +use crate::{interrupt, pac, peripherals, Unborrow}; const EXTI_COUNT: usize = 16; const NEW_AW: AtomicWaker = AtomicWaker::new(); @@ -130,9 +128,10 @@ impl<'d, T: GpioPin> ExtiInput<'d, T> { } mod eh02 { - use super::*; use core::convert::Infallible; + use super::*; + impl<'d, T: GpioPin> embedded_hal_02::digital::v2::InputPin for ExtiInput<'d, T> { type Error = Infallible; @@ -148,9 +147,10 @@ mod eh02 { #[cfg(feature = "unstable-traits")] mod eh1 { - use super::*; use core::convert::Infallible; + use super::*; + impl<'d, T: GpioPin> embedded_hal_1::digital::ErrorType for ExtiInput<'d, T> { type Error = Infallible; } @@ -212,9 +212,7 @@ impl<'a> ExtiInputFuture<'a> { fn new(pin: u8, port: u8, rising: bool, falling: bool) -> Self { critical_section::with(|_| unsafe { let pin = pin as usize; - exticr_regs() - .exticr(pin / 4) - .modify(|w| w.set_exti(pin % 4, port)); + exticr_regs().exticr(pin / 4).modify(|w| w.set_exti(pin % 4, port)); EXTI.rtsr(0).modify(|w| w.set_line(pin, rising)); EXTI.ftsr(0).modify(|w| w.set_line(pin, falling)); @@ -366,8 +364,7 @@ macro_rules! enable_irq { /// safety: must be called only once pub(crate) unsafe fn init() { - use crate::interrupt::Interrupt; - use crate::interrupt::InterruptExt; + use crate::interrupt::{Interrupt, InterruptExt}; foreach_exti_irq!(enable_irq); diff --git a/embassy-stm32/src/flash/f3.rs b/embassy-stm32/src/flash/f3.rs index a5dc8dd0..1cb08ee1 100644 --- a/embassy-stm32/src/flash/f3.rs +++ b/embassy-stm32/src/flash/f3.rs @@ -20,10 +20,7 @@ pub(crate) unsafe fn blocking_write(offset: u32, buf: &[u8]) -> Result<(), Error let mut ret: Result<(), Error> = Ok(()); let mut offset = offset; for chunk in buf.chunks(2) { - write_volatile( - offset as *mut u16, - u16::from_le_bytes(chunk[0..2].try_into().unwrap()), - ); + write_volatile(offset as *mut u16, u16::from_le_bytes(chunk[0..2].try_into().unwrap())); offset += chunk.len() as u32; ret = blocking_wait_ready(); diff --git a/embassy-stm32/src/flash/f7.rs b/embassy-stm32/src/flash/f7.rs index 16316fd9..6d47b78a 100644 --- a/embassy-stm32/src/flash/f7.rs +++ b/embassy-stm32/src/flash/f7.rs @@ -26,10 +26,7 @@ pub(crate) unsafe fn blocking_write(offset: u32, buf: &[u8]) -> Result<(), Error let mut offset = offset; for chunk in buf.chunks(super::WRITE_SIZE) { for val in chunk.chunks(4) { - write_volatile( - offset as *mut u32, - u32::from_le_bytes(val[0..4].try_into().unwrap()), - ); + write_volatile(offset as *mut u32, u32::from_le_bytes(val[0..4].try_into().unwrap())); offset += val.len() as u32; // prevents parallelism errors diff --git a/embassy-stm32/src/flash/h7.rs b/embassy-stm32/src/flash/h7.rs index afccffc4..7ce0ac77 100644 --- a/embassy-stm32/src/flash/h7.rs +++ b/embassy-stm32/src/flash/h7.rs @@ -28,8 +28,7 @@ pub(crate) unsafe fn unlock() { } pub(crate) unsafe fn blocking_write(offset: u32, buf: &[u8]) -> Result<(), Error> { - let bank = if !is_dual_bank() || (offset - super::FLASH_BASE as u32) < SECOND_BANK_OFFSET as u32 - { + let bank = if !is_dual_bank() || (offset - super::FLASH_BASE as u32) < SECOND_BANK_OFFSET as u32 { pac::FLASH.bank(0) } else { pac::FLASH.bank(1) @@ -46,10 +45,7 @@ pub(crate) unsafe fn blocking_write(offset: u32, buf: &[u8]) -> Result<(), Error 'outer: for chunk in buf.chunks(super::WRITE_SIZE) { for val in chunk.chunks(4) { trace!("Writing at {:x}", offset); - write_volatile( - offset as *mut u32, - u32::from_le_bytes(val[0..4].try_into().unwrap()), - ); + write_volatile(offset as *mut u32, u32::from_le_bytes(val[0..4].try_into().unwrap())); offset += val.len() as u32; ret = blocking_wait_ready(bank); diff --git a/embassy-stm32/src/flash/l.rs b/embassy-stm32/src/flash/l.rs index cad950e6..5048a331 100644 --- a/embassy-stm32/src/flash/l.rs +++ b/embassy-stm32/src/flash/l.rs @@ -42,10 +42,7 @@ pub(crate) unsafe fn blocking_write(offset: u32, buf: &[u8]) -> Result<(), Error let mut offset = offset; for chunk in buf.chunks(super::WRITE_SIZE) { for val in chunk.chunks(4) { - write_volatile( - offset as *mut u32, - u32::from_le_bytes(val[0..4].try_into().unwrap()), - ); + write_volatile(offset as *mut u32, u32::from_le_bytes(val[0..4].try_into().unwrap())); offset += val.len() as u32; } @@ -80,11 +77,7 @@ pub(crate) unsafe fn blocking_erase(from: u32, to: u32) -> Result<(), Error> { let idx = (page - super::FLASH_BASE as u32) / super::ERASE_SIZE as u32; #[cfg(flash_l4)] - let (idx, bank) = if idx > 255 { - (idx - 256, true) - } else { - (idx, false) - }; + let (idx, bank) = if idx > 255 { (idx - 256, true) } else { (idx, false) }; pac::FLASH.cr().modify(|w| { w.set_per(true); diff --git a/embassy-stm32/src/flash/mod.rs b/embassy-stm32/src/flash/mod.rs index 330e5142..31ca243a 100644 --- a/embassy-stm32/src/flash/mod.rs +++ b/embassy-stm32/src/flash/mod.rs @@ -1,17 +1,11 @@ +use core::marker::PhantomData; + +use embassy_hal_common::unborrow; +use embedded_storage::nor_flash::{ErrorType, NorFlash, NorFlashError, NorFlashErrorKind, ReadNorFlash}; + +pub use crate::pac::{ERASE_SIZE, ERASE_VALUE, FLASH_BASE, FLASH_SIZE, WRITE_SIZE}; use crate::peripherals::FLASH; use crate::Unborrow; -use core::marker::PhantomData; -use embassy_hal_common::unborrow; - -use embedded_storage::nor_flash::{ - ErrorType, NorFlash, NorFlashError, NorFlashErrorKind, ReadNorFlash, -}; - -pub use crate::pac::ERASE_SIZE; -pub use crate::pac::ERASE_VALUE; -pub use crate::pac::FLASH_BASE; -pub use crate::pac::FLASH_SIZE; -pub use crate::pac::WRITE_SIZE; const FLASH_END: usize = FLASH_BASE + FLASH_SIZE; #[cfg_attr(any(flash_wl, flash_wb, flash_l0, flash_l1, flash_l4), path = "l.rs")] diff --git a/embassy-stm32/src/fmc/mod.rs b/embassy-stm32/src/fmc/mod.rs index c227cfa1..4f8e467d 100644 --- a/embassy-stm32/src/fmc/mod.rs +++ b/embassy-stm32/src/fmc/mod.rs @@ -1,9 +1,10 @@ -use crate::Unborrow; use core::marker::PhantomData; + use embassy_hal_common::unborrow; use crate::gpio::sealed::AFType; use crate::gpio::{Pull, Speed}; +use crate::Unborrow; mod pins; pub use pins::*; diff --git a/embassy-stm32/src/gpio.rs b/embassy-stm32/src/gpio.rs index 31f22e21..6e445f8c 100644 --- a/embassy-stm32/src/gpio.rs +++ b/embassy-stm32/src/gpio.rs @@ -1,12 +1,11 @@ #![macro_use] -use crate::Unborrow; use core::convert::Infallible; use core::marker::PhantomData; + use embassy_hal_common::{unborrow, unsafe_impl_unborrow}; -use crate::pac; use crate::pac::gpio::{self, vals}; -use crate::peripherals; +use crate::{pac, peripherals, Unborrow}; /// Pull setting for an input. #[derive(Debug, Eq, PartialEq)] @@ -138,8 +137,7 @@ impl<'d, T: Pin> Drop for Input<'d, T> { #[cfg(gpio_v1)] { let crlh = if n < 8 { 0 } else { 1 }; - r.cr(crlh) - .modify(|w| w.set_cnf_in(n % 8, vals::CnfIn::FLOATING)); + r.cr(crlh).modify(|w| w.set_cnf_in(n % 8, vals::CnfIn::FLOATING)); } #[cfg(gpio_v2)] r.pupdr().modify(|w| w.set_pupdr(n, vals::Pupdr::FLOATING)); @@ -264,12 +262,7 @@ pub struct OutputOpenDrain<'d, T: Pin> { impl<'d, T: Pin> OutputOpenDrain<'d, T> { #[inline] - pub fn new( - pin: impl Unborrow + 'd, - initial_output: Level, - speed: Speed, - pull: Pull, - ) -> Self { + pub fn new(pin: impl Unborrow + 'd, initial_output: Level, speed: Speed, pull: Pull) -> Self { unborrow!(pin); match initial_output { @@ -289,8 +282,7 @@ impl<'d, T: Pin> OutputOpenDrain<'d, T> { Pull::None => {} } r.cr(crlh).modify(|w| w.set_mode(n % 8, speed.into())); - r.cr(crlh) - .modify(|w| w.set_cnf_out(n % 8, vals::CnfOut::OPENDRAIN)); + r.cr(crlh).modify(|w| w.set_cnf_out(n % 8, vals::CnfOut::OPENDRAIN)); } #[cfg(gpio_v2)] { @@ -480,18 +472,12 @@ pub(crate) mod sealed { block.afr(pin / 8).modify(|w| w.set_afr(pin % 8, af_num)); match af_type { AFType::Input => {} - AFType::OutputPushPull => { - block.otyper().modify(|w| w.set_ot(pin, vals::Ot::PUSHPULL)) - } - AFType::OutputOpenDrain => block - .otyper() - .modify(|w| w.set_ot(pin, vals::Ot::OPENDRAIN)), + AFType::OutputPushPull => block.otyper().modify(|w| w.set_ot(pin, vals::Ot::PUSHPULL)), + AFType::OutputOpenDrain => block.otyper().modify(|w| w.set_ot(pin, vals::Ot::OPENDRAIN)), } block.pupdr().modify(|w| w.set_pupdr(pin, pull.into())); - block - .moder() - .modify(|w| w.set_moder(pin, vals::Moder::ALTERNATE)); + block.moder().modify(|w| w.set_moder(pin, vals::Moder::ALTERNATE)); } #[inline] @@ -507,9 +493,7 @@ pub(crate) mod sealed { }); } #[cfg(gpio_v2)] - block - .moder() - .modify(|w| w.set_moder(pin, vals::Moder::ANALOG)); + block.moder().modify(|w| w.set_moder(pin, vals::Moder::ANALOG)); } /// Set the pin as "disconnected", ie doing nothing and consuming the lowest @@ -535,9 +519,7 @@ pub(crate) mod sealed { } #[cfg(gpio_v2)] - self.block() - .ospeedr() - .modify(|w| w.set_ospeedr(pin, speed.into())); + self.block().ospeedr().modify(|w| w.set_ospeedr(pin, speed.into())); } } } @@ -623,10 +605,9 @@ pub(crate) unsafe fn init() { } mod eh02 { + use embedded_hal_02::digital::v2::{InputPin, OutputPin, StatefulOutputPin, ToggleableOutputPin}; + use super::*; - use embedded_hal_02::digital::v2::{ - InputPin, OutputPin, StatefulOutputPin, ToggleableOutputPin, - }; impl<'d, T: Pin> InputPin for Input<'d, T> { type Error = Infallible; @@ -715,12 +696,11 @@ mod eh02 { #[cfg(feature = "unstable-traits")] mod eh1 { - use super::*; - use embedded_hal_1::digital::blocking::{ - InputPin, OutputPin, StatefulOutputPin, ToggleableOutputPin, - }; + use embedded_hal_1::digital::blocking::{InputPin, OutputPin, StatefulOutputPin, ToggleableOutputPin}; use embedded_hal_1::digital::ErrorType; + use super::*; + impl<'d, T: Pin> ErrorType for Input<'d, T> { type Error = Infallible; } diff --git a/embassy-stm32/src/i2c/mod.rs b/embassy-stm32/src/i2c/mod.rs index 54f8d193..9d314f41 100644 --- a/embassy-stm32/src/i2c/mod.rs +++ b/embassy-stm32/src/i2c/mod.rs @@ -5,9 +5,10 @@ use crate::interrupt::Interrupt; #[cfg_attr(i2c_v1, path = "v1.rs")] #[cfg_attr(i2c_v2, path = "v2.rs")] mod _version; -use crate::peripherals; pub use _version::*; +use crate::peripherals; + #[derive(Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum Error { diff --git a/embassy-stm32/src/i2c/v1.rs b/embassy-stm32/src/i2c/v1.rs index 77acc387..87a4f969 100644 --- a/embassy-stm32/src/i2c/v1.rs +++ b/embassy-stm32/src/i2c/v1.rs @@ -1,11 +1,12 @@ -use crate::Unborrow; use core::marker::PhantomData; + use embassy_hal_common::unborrow; use crate::gpio::sealed::AFType; use crate::i2c::{Error, Instance, SclPin, SdaPin}; use crate::pac::i2c; use crate::time::Hertz; +use crate::Unborrow; pub struct State {} @@ -68,9 +69,7 @@ impl<'d, T: Instance> I2c<'d, T> { }); } - Self { - phantom: PhantomData, - } + Self { phantom: PhantomData } } unsafe fn check_and_clear_error_flags(&self) -> Result { @@ -249,12 +248,7 @@ impl<'d, T: Instance> I2c<'d, T> { Ok(()) } - pub fn blocking_write_read( - &mut self, - addr: u8, - bytes: &[u8], - buffer: &mut [u8], - ) -> Result<(), Error> { + pub fn blocking_write_read(&mut self, addr: u8, bytes: &[u8], buffer: &mut [u8]) -> Result<(), Error> { unsafe { self.write_bytes(addr, bytes)? }; self.blocking_read(addr, buffer)?; diff --git a/embassy-stm32/src/i2c/v2.rs b/embassy-stm32/src/i2c/v2.rs index 4d4840a0..1a085e78 100644 --- a/embassy-stm32/src/i2c/v2.rs +++ b/embassy-stm32/src/i2c/v2.rs @@ -2,8 +2,6 @@ use core::cmp; use core::marker::PhantomData; use core::task::Poll; -use crate::interrupt::InterruptExt; -use crate::Unborrow; use atomic_polyfill::{AtomicUsize, Ordering}; use embassy::waitqueue::AtomicWaker; use embassy_hal_common::drop::OnDrop; @@ -13,8 +11,10 @@ use futures::future::poll_fn; use crate::dma::NoDma; use crate::gpio::sealed::AFType; use crate::i2c::{Error, Instance, SclPin, SdaPin}; +use crate::interrupt::InterruptExt; use crate::pac::i2c; use crate::time::Hertz; +use crate::Unborrow; pub struct State { waker: AtomicWaker, @@ -277,12 +277,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { } } - fn read_internal( - &mut self, - address: u8, - buffer: &mut [u8], - restart: bool, - ) -> Result<(), Error> { + fn read_internal(&mut self, address: u8, buffer: &mut [u8], restart: bool) -> Result<(), Error> { let completed_chunks = buffer.len() / 255; let total_chunks = if completed_chunks * 255 == buffer.len() { completed_chunks @@ -335,12 +330,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { // ST SAD+W // NOTE(unsafe) We have &mut self unsafe { - Self::master_write( - address, - bytes.len().min(255), - Stop::Software, - last_chunk_idx != 0, - ); + Self::master_write(address, bytes.len().min(255), Stop::Software, last_chunk_idx != 0); } for (number, chunk) in bytes.chunks(255).enumerate() { @@ -467,12 +457,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { Ok(()) } - async fn read_dma_internal( - &mut self, - address: u8, - buffer: &mut [u8], - restart: bool, - ) -> Result<(), Error> + async fn read_dma_internal(&mut self, address: u8, buffer: &mut [u8], restart: bool) -> Result<(), Error> where RXDMA: crate::i2c::RxDma, { @@ -513,13 +498,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { // NOTE(unsafe) self.rx_dma does not fiddle with the i2c registers unsafe { - Self::master_read( - address, - total_len.min(255), - Stop::Software, - total_chunks != 1, - restart, - ); + Self::master_read(address, total_len.min(255), Stop::Software, total_chunks != 1, restart); } poll_fn(|cx| { @@ -597,12 +576,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { } } - pub async fn write_read( - &mut self, - address: u8, - bytes: &[u8], - buffer: &mut [u8], - ) -> Result<(), Error> + pub async fn write_read(&mut self, address: u8, bytes: &[u8], buffer: &mut [u8]) -> Result<(), Error> where TXDMA: super::TxDma, RXDMA: super::RxDma, @@ -634,12 +608,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { self.write_internal(address, bytes, true) } - pub fn blocking_write_read( - &mut self, - address: u8, - bytes: &[u8], - buffer: &mut [u8], - ) -> Result<(), Error> { + pub fn blocking_write_read(&mut self, address: u8, bytes: &[u8], buffer: &mut [u8]) -> Result<(), Error> { self.write_internal(address, bytes, false)?; self.read_internal(address, buffer, true) // Automatic Stop @@ -675,10 +644,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { if idx != 0 { // NOTE(unsafe) We have &mut self unsafe { - Self::master_continue( - slice_len.min(255), - (idx != last_slice_index) || (slice_len > 255), - ); + Self::master_continue(slice_len.min(255), (idx != last_slice_index) || (slice_len > 255)); } } @@ -686,10 +652,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> { if number != 0 { // NOTE(unsafe) We have &mut self unsafe { - Self::master_continue( - chunk.len(), - (number != last_chunk_idx) || (idx != last_slice_index), - ); + Self::master_continue(chunk.len(), (number != last_chunk_idx) || (idx != last_slice_index)); } } @@ -737,12 +700,7 @@ mod eh02 { impl<'d, T: Instance> embedded_hal_02::blocking::i2c::WriteRead for I2c<'d, T> { type Error = Error; - fn write_read( - &mut self, - address: u8, - bytes: &[u8], - buffer: &mut [u8], - ) -> Result<(), Self::Error> { + fn write_read(&mut self, address: u8, bytes: &[u8], buffer: &mut [u8]) -> Result<(), Self::Error> { self.blocking_write_read(address, bytes, buffer) } } @@ -794,10 +752,7 @@ impl Timings { // For the standard-mode configuration method, we must have a ratio of 4 // or higher - assert!( - ratio >= 4, - "The I2C PCLK must be at least 4 times the bus frequency!" - ); + assert!(ratio >= 4, "The I2C PCLK must be at least 4 times the bus frequency!"); let (presc_reg, scll, sclh, sdadel, scldel) = if freq > 100_000 { // Fast-mode (Fm) or Fast-mode Plus (Fm+) @@ -831,13 +786,7 @@ impl Timings { (sdadel, scldel) }; - ( - presc_reg, - scll as u8, - sclh as u8, - sdadel as u8, - scldel as u8, - ) + (presc_reg, scll as u8, sclh as u8, sdadel as u8, scldel as u8) } else { // Standard-mode (Sm) // here we pick SCLL = SCLH @@ -855,21 +804,12 @@ impl Timings { let scll = sclh; // Speed check - assert!( - sclh < 256, - "The I2C PCLK is too fast for this bus frequency!" - ); + assert!(sclh < 256, "The I2C PCLK is too fast for this bus frequency!"); let sdadel = i2cclk / 2_000_000 / presc; let scldel = i2cclk / 500_000 / presc - 1; - ( - presc_reg, - scll as u8, - sclh as u8, - sdadel as u8, - scldel as u8, - ) + (presc_reg, scll as u8, sclh as u8, sdadel as u8, scldel as u8) }; // Sanity check @@ -900,9 +840,9 @@ mod eh1 { match *self { Self::Bus => embedded_hal_1::i2c::ErrorKind::Bus, Self::Arbitration => embedded_hal_1::i2c::ErrorKind::ArbitrationLoss, - Self::Nack => embedded_hal_1::i2c::ErrorKind::NoAcknowledge( - embedded_hal_1::i2c::NoAcknowledgeSource::Unknown, - ), + Self::Nack => { + embedded_hal_1::i2c::ErrorKind::NoAcknowledge(embedded_hal_1::i2c::NoAcknowledgeSource::Unknown) + } Self::Timeout => embedded_hal_1::i2c::ErrorKind::Other, Self::Crc => embedded_hal_1::i2c::ErrorKind::Other, Self::Overrun => embedded_hal_1::i2c::ErrorKind::Overrun, @@ -911,9 +851,7 @@ mod eh1 { } } - impl<'d, T: Instance, TXDMA: TxDma, RXDMA: RxDma> embedded_hal_1::i2c::ErrorType - for I2c<'d, T, TXDMA, RXDMA> - { + impl<'d, T: Instance, TXDMA: TxDma, RXDMA: RxDma> embedded_hal_1::i2c::ErrorType for I2c<'d, T, TXDMA, RXDMA> { type Error = Error; } } diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs index b795352c..717ebb95 100644 --- a/embassy-stm32/src/lib.rs +++ b/embassy-stm32/src/lib.rs @@ -1,8 +1,5 @@ #![no_std] -#![cfg_attr( - feature = "nightly", - feature(generic_associated_types, type_alias_impl_trait) -)] +#![cfg_attr(feature = "nightly", feature(generic_associated_types, type_alias_impl_trait))] // This must go FIRST so that all the other modules see its macros. pub mod fmt; @@ -42,9 +39,7 @@ pub mod i2c; #[cfg(crc)] pub mod crc; -#[cfg(any( - flash_l0, flash_l1, flash_wl, flash_wb, flash_l4, flash_f3, flash_f7, flash_h7 -))] +#[cfg(any(flash_l0, flash_l1, flash_wl, flash_wb, flash_l4, flash_f3, flash_f7, flash_h7))] pub mod flash; pub mod pwm; #[cfg(rng)] @@ -77,7 +72,6 @@ pub use _generated::{peripherals, Peripherals}; pub use embassy_cortex_m::executor; pub use embassy_hal_common::{unborrow, Unborrow}; pub use embassy_macros::cortex_m_interrupt as interrupt; - #[cfg(feature = "unstable-pac")] pub use stm32_metapac as pac; #[cfg(not(feature = "unstable-pac"))] @@ -114,8 +108,8 @@ pub fn init(config: Config) -> Peripherals { cr.set_dbg_standby(true); } #[cfg(any( - dbgmcu_f1, dbgmcu_f2, dbgmcu_f3, dbgmcu_f4, dbgmcu_f7, dbgmcu_g4, dbgmcu_f7, - dbgmcu_l0, dbgmcu_l1, dbgmcu_l4, dbgmcu_wb, dbgmcu_wl + dbgmcu_f1, dbgmcu_f2, dbgmcu_f3, dbgmcu_f4, dbgmcu_f7, dbgmcu_g4, dbgmcu_f7, dbgmcu_l0, dbgmcu_l1, + dbgmcu_l4, dbgmcu_wb, dbgmcu_wl ))] { cr.set_dbg_sleep(true); diff --git a/embassy-stm32/src/pwm/mod.rs b/embassy-stm32/src/pwm/mod.rs index c6edbc6c..bd835856 100644 --- a/embassy-stm32/src/pwm/mod.rs +++ b/embassy-stm32/src/pwm/mod.rs @@ -64,9 +64,7 @@ pub(crate) mod sealed { unsafe fn get_max_compare_value(&self) -> u16; } - pub trait CaptureCompare32bitInstance: - crate::timer::sealed::GeneralPurpose32bitInstance - { + pub trait CaptureCompare32bitInstance: crate::timer::sealed::GeneralPurpose32bitInstance { unsafe fn set_output_compare_mode(&mut self, channel: Channel, mode: OutputCompareMode); unsafe fn enable_channel(&mut self, channel: Channel, enable: bool); @@ -82,10 +80,7 @@ pub trait CaptureCompare16bitInstance: { } pub trait CaptureCompare32bitInstance: - sealed::CaptureCompare32bitInstance - + CaptureCompare16bitInstance - + crate::timer::GeneralPurpose32bitInstance - + 'static + sealed::CaptureCompare32bitInstance + CaptureCompare16bitInstance + crate::timer::GeneralPurpose32bitInstance + 'static { } @@ -93,11 +88,7 @@ pub trait CaptureCompare32bitInstance: macro_rules! impl_compare_capable_16bit { ($inst:ident) => { impl crate::pwm::sealed::CaptureCompare16bitInstance for crate::peripherals::$inst { - unsafe fn set_output_compare_mode( - &mut self, - channel: crate::pwm::Channel, - mode: OutputCompareMode, - ) { + unsafe fn set_output_compare_mode(&mut self, channel: crate::pwm::Channel, mode: OutputCompareMode) { use crate::timer::sealed::GeneralPurpose16bitInstance; let r = Self::regs_gp16(); let raw_channel: usize = channel.raw(); @@ -114,9 +105,7 @@ macro_rules! impl_compare_capable_16bit { unsafe fn set_compare_value(&mut self, channel: Channel, value: u16) { use crate::timer::sealed::GeneralPurpose16bitInstance; - Self::regs_gp16() - .ccr(channel.raw()) - .modify(|w| w.set_ccr(value)); + Self::regs_gp16().ccr(channel.raw()).modify(|w| w.set_ccr(value)); } unsafe fn get_max_compare_value(&self) -> u16 { diff --git a/embassy-stm32/src/pwm/simple_pwm.rs b/embassy-stm32/src/pwm/simple_pwm.rs index 990f5bda..a475f3f7 100644 --- a/embassy-stm32/src/pwm/simple_pwm.rs +++ b/embassy-stm32/src/pwm/simple_pwm.rs @@ -1,11 +1,12 @@ -use crate::Unborrow; use core::marker::PhantomData; + use embassy_hal_common::unborrow; use super::*; #[allow(unused_imports)] use crate::gpio::sealed::{AFType, Pin}; use crate::time::Hertz; +use crate::Unborrow; pub struct SimplePwm<'d, T> { phantom: PhantomData<&'d mut T>, @@ -74,11 +75,7 @@ impl<'d, T: CaptureCompare16bitInstance> SimplePwm<'d, T> { }) } - fn new_inner>( - tim: impl Unborrow + 'd, - freq: F, - configure_pins: impl FnOnce(), - ) -> Self { + fn new_inner>(tim: impl Unborrow + 'd, freq: F, configure_pins: impl FnOnce()) -> Self { unborrow!(tim); T::enable(); diff --git a/embassy-stm32/src/rcc/f0.rs b/embassy-stm32/src/rcc/f0.rs index 427c958f..10b075da 100644 --- a/embassy-stm32/src/rcc/f0.rs +++ b/embassy-stm32/src/rcc/f0.rs @@ -1,9 +1,8 @@ +use super::{set_freqs, Clocks}; use crate::pac::rcc::vals::{Hpre, Pllmul, Pllsrc, Ppre, Sw, Usbsw}; use crate::pac::{FLASH, RCC}; use crate::time::Hertz; -use super::{set_freqs, Clocks}; - const HSI: u32 = 8_000_000; /// Configuration of the clocks @@ -112,8 +111,7 @@ pub(crate) unsafe fn init(config: Config) { while !RCC.cr2().read().hsi48rdy() {} if pllmul_bits.is_some() { - RCC.cfgr() - .modify(|w| w.set_pllsrc(Pllsrc::HSI48_DIV_PREDIV)) + RCC.cfgr().modify(|w| w.set_pllsrc(Pllsrc::HSI48_DIV_PREDIV)) } } _ => { diff --git a/embassy-stm32/src/rcc/f2.rs b/embassy-stm32/src/rcc/f2.rs index 7e5992bb..65fa78f8 100644 --- a/embassy-stm32/src/rcc/f2.rs +++ b/embassy-stm32/src/rcc/f2.rs @@ -436,9 +436,7 @@ pub(crate) unsafe fn init(config: Config) { let pll_clocks = config.pll.clocks(pll_src_freq); assert!(Hertz(950_000) <= pll_clocks.in_freq && pll_clocks.in_freq <= Hertz(2_100_000)); assert!(Hertz(192_000_000) <= pll_clocks.vco_freq && pll_clocks.vco_freq <= Hertz(432_000_000)); - assert!( - Hertz(24_000_000) <= pll_clocks.main_freq && pll_clocks.main_freq <= Hertz(120_000_000) - ); + assert!(Hertz(24_000_000) <= pll_clocks.main_freq && pll_clocks.main_freq <= Hertz(120_000_000)); // USB actually requires == 48 MHz, but other PLL48 peripherals are fine with <= 48MHz assert!(pll_clocks.pll48_freq <= Hertz(48_000_000)); diff --git a/embassy-stm32/src/rcc/f4.rs b/embassy-stm32/src/rcc/f4.rs index 22a2e9ad..21f3ad15 100644 --- a/embassy-stm32/src/rcc/f4.rs +++ b/embassy-stm32/src/rcc/f4.rs @@ -20,18 +20,12 @@ pub struct Config { pub pll48: bool, } -unsafe fn setup_pll( - pllsrcclk: u32, - use_hse: bool, - pllsysclk: Option, - pll48clk: bool, -) -> PllResults { +unsafe fn setup_pll(pllsrcclk: u32, use_hse: bool, pllsysclk: Option, pll48clk: bool) -> PllResults { use crate::pac::rcc::vals::{Pllp, Pllsrc}; let sysclk = pllsysclk.unwrap_or(pllsrcclk); if pllsysclk.is_none() && !pll48clk { - RCC.pllcfgr() - .modify(|w| w.set_pllsrc(Pllsrc(use_hse as u8))); + RCC.pllcfgr().modify(|w| w.set_pllsrc(Pllsrc(use_hse as u8))); return PllResults { use_pll: false, @@ -47,11 +41,7 @@ unsafe fn setup_pll( // Sysclk output divisor must be one of 2, 4, 6 or 8 let sysclk_div = core::cmp::min(8, (432_000_000 / sysclk) & !1); - let target_freq = if pll48clk { - 48_000_000 - } else { - sysclk * sysclk_div - }; + let target_freq = if pll48clk { 48_000_000 } else { sysclk * sysclk_div }; // Find the lowest pllm value that minimize the difference between // target frequency and the real vco_out frequency. @@ -135,11 +125,7 @@ pub(crate) unsafe fn init(config: Config) { assert!((max::PLL_48_CLK as i32 - freq as i32).abs() <= max::PLL_48_TOLERANCE as i32); } - let sysclk = if sysclk_on_pll { - unwrap!(plls.pllsysclk) - } else { - sysclk - }; + let sysclk = if sysclk_on_pll { unwrap!(plls.pllsysclk) } else { sysclk }; // AHB prescaler let hclk = config.hclk.map(|h| h.0).unwrap_or(sysclk); @@ -269,9 +255,7 @@ mod max { pub(crate) const SYSCLK_MAX: u32 = 168_000_000; #[cfg(any(stm32f410, stm32f411, stm32f412, stm32f413, stm32f423,))] pub(crate) const SYSCLK_MAX: u32 = 100_000_000; - #[cfg(any( - stm32f427, stm32f429, stm32f437, stm32f439, stm32f446, stm32f469, stm32f479, - ))] + #[cfg(any(stm32f427, stm32f429, stm32f437, stm32f439, stm32f446, stm32f469, stm32f479,))] pub(crate) const SYSCLK_MAX: u32 = 180_000_000; pub(crate) const HCLK_OVERDRIVE_FREQUENCY: u32 = 168_000_000; diff --git a/embassy-stm32/src/rcc/f7.rs b/embassy-stm32/src/rcc/f7.rs index f45a725c..d98aa401 100644 --- a/embassy-stm32/src/rcc/f7.rs +++ b/embassy-stm32/src/rcc/f7.rs @@ -21,18 +21,12 @@ pub struct Config { pub pll48: bool, } -unsafe fn setup_pll( - pllsrcclk: u32, - use_hse: bool, - pllsysclk: Option, - pll48clk: bool, -) -> PllResults { +unsafe fn setup_pll(pllsrcclk: u32, use_hse: bool, pllsysclk: Option, pll48clk: bool) -> PllResults { use crate::pac::rcc::vals::{Pllp, Pllsrc}; let sysclk = pllsysclk.unwrap_or(pllsrcclk); if pllsysclk.is_none() && !pll48clk { - RCC.pllcfgr() - .modify(|w| w.set_pllsrc(Pllsrc(use_hse as u8))); + RCC.pllcfgr().modify(|w| w.set_pllsrc(Pllsrc(use_hse as u8))); return PllResults { use_pll: false, @@ -48,11 +42,7 @@ unsafe fn setup_pll( // Sysclk output divisor must be one of 2, 4, 6 or 8 let sysclk_div = core::cmp::min(8, (432_000_000 / sysclk) & !1); - let target_freq = if pll48clk { - 48_000_000 - } else { - sysclk * sysclk_div - }; + let target_freq = if pll48clk { 48_000_000 } else { sysclk * sysclk_div }; // Find the lowest pllm value that minimize the difference between // target frequency and the real vco_out frequency. @@ -146,11 +136,7 @@ pub(crate) unsafe fn init(config: Config) { assert!((max::PLL_48_CLK as i32 - freq as i32).abs() <= max::PLL_48_TOLERANCE as i32); } - let sysclk = if sysclk_on_pll { - unwrap!(plls.pllsysclk) - } else { - sysclk - }; + let sysclk = if sysclk_on_pll { unwrap!(plls.pllsysclk) } else { sysclk }; // AHB prescaler let hclk = config.hclk.map(|h| h.0).unwrap_or(sysclk); diff --git a/embassy-stm32/src/rcc/g0.rs b/embassy-stm32/src/rcc/g0.rs index be049729..36b49c71 100644 --- a/embassy-stm32/src/rcc/g0.rs +++ b/embassy-stm32/src/rcc/g0.rs @@ -2,8 +2,7 @@ use crate::pac::flash::vals::Latency; use crate::pac::rcc::vals::{self, Hpre, Hsidiv, Ppre, Sw}; use crate::pac::{FLASH, PWR, RCC}; use crate::rcc::{set_freqs, Clocks}; -use crate::time::Hertz; -use crate::time::U32Ext; +use crate::time::{Hertz, U32Ext}; /// HSI speed pub const HSI_FREQ: u32 = 16_000_000; diff --git a/embassy-stm32/src/rcc/g4.rs b/embassy-stm32/src/rcc/g4.rs index ce8cca45..2b8c2b57 100644 --- a/embassy-stm32/src/rcc/g4.rs +++ b/embassy-stm32/src/rcc/g4.rs @@ -1,7 +1,6 @@ use crate::pac::{PWR, RCC}; use crate::rcc::{set_freqs, Clocks}; -use crate::time::Hertz; -use crate::time::U32Ext; +use crate::time::{Hertz, U32Ext}; /// HSI speed pub const HSI_FREQ: u32 = 16_000_000; diff --git a/embassy-stm32/src/rcc/h7.rs b/embassy-stm32/src/rcc/h7.rs index 0cd89645..4fa01ade 100644 --- a/embassy-stm32/src/rcc/h7.rs +++ b/embassy-stm32/src/rcc/h7.rs @@ -1,19 +1,16 @@ use core::marker::PhantomData; -use crate::Unborrow; use embassy_hal_common::unborrow; +pub use pll::PllConfig; use stm32_metapac::rcc::vals::{Mco1, Mco2}; use crate::gpio::sealed::AFType; use crate::gpio::Speed; -use crate::pac::rcc::vals::Timpre; -use crate::pac::rcc::vals::{Adcsel, Ckpersel, Dppre, Hpre, Hsidiv, Pllsrc, Sw}; +use crate::pac::rcc::vals::{Adcsel, Ckpersel, Dppre, Hpre, Hsidiv, Pllsrc, Sw, Timpre}; use crate::pac::{PWR, RCC, SYSCFG}; -use crate::peripherals; use crate::rcc::{set_freqs, Clocks}; use crate::time::Hertz; - -pub use pll::PllConfig; +use crate::{peripherals, Unborrow}; const HSI: Hertz = Hertz(64_000_000); const CSI: Hertz = Hertz(4_000_000); @@ -181,8 +178,10 @@ fn sys_ck_setup(config: &mut Config, srcclk: Hertz) -> (Hertz, bool) { // Therefore we must use pll1_p_ck let pll1_p_ck = match config.pll1.p_ck { Some(p_ck) => { - assert!(p_ck == sys_ck, - "Error: Cannot set pll1_p_ck independently as it must be used to generate sys_ck"); + assert!( + p_ck == sys_ck, + "Error: Cannot set pll1_p_ck independently as it must be used to generate sys_ck" + ); Some(p_ck) } None => Some(sys_ck), @@ -392,9 +391,7 @@ impl<'d, T: McoInstance> Mco<'d, T> { pin.set_speed(Speed::VeryHigh); }); - Self { - phantom: PhantomData, - } + Self { phantom: PhantomData } } } @@ -538,33 +535,19 @@ pub(crate) unsafe fn init(mut config: Config) { // Timer prescaler selection let timpre = Timpre::DEFAULTX2; - let requested_pclk1 = config - .pclk1 - .map(|v| v.0) - .unwrap_or_else(|| pclk_max.min(rcc_hclk / 2)); + let requested_pclk1 = config.pclk1.map(|v| v.0).unwrap_or_else(|| pclk_max.min(rcc_hclk / 2)); let (rcc_pclk1, ppre1_bits, ppre1, rcc_timerx_ker_ck) = ppre_calculate(requested_pclk1, rcc_hclk, pclk_max, Some(timpre)); - let requested_pclk2 = config - .pclk2 - .map(|v| v.0) - .unwrap_or_else(|| pclk_max.min(rcc_hclk / 2)); + let requested_pclk2 = config.pclk2.map(|v| v.0).unwrap_or_else(|| pclk_max.min(rcc_hclk / 2)); let (rcc_pclk2, ppre2_bits, ppre2, rcc_timery_ker_ck) = ppre_calculate(requested_pclk2, rcc_hclk, pclk_max, Some(timpre)); - let requested_pclk3 = config - .pclk3 - .map(|v| v.0) - .unwrap_or_else(|| pclk_max.min(rcc_hclk / 2)); - let (rcc_pclk3, ppre3_bits, ppre3, _) = - ppre_calculate(requested_pclk3, rcc_hclk, pclk_max, None); + let requested_pclk3 = config.pclk3.map(|v| v.0).unwrap_or_else(|| pclk_max.min(rcc_hclk / 2)); + let (rcc_pclk3, ppre3_bits, ppre3, _) = ppre_calculate(requested_pclk3, rcc_hclk, pclk_max, None); - let requested_pclk4 = config - .pclk4 - .map(|v| v.0) - .unwrap_or_else(|| pclk_max.min(rcc_hclk / 2)); - let (rcc_pclk4, ppre4_bits, ppre4, _) = - ppre_calculate(requested_pclk4, rcc_hclk, pclk_max, None); + let requested_pclk4 = config.pclk4.map(|v| v.0).unwrap_or_else(|| pclk_max.min(rcc_hclk / 2)); + let (rcc_pclk4, ppre4_bits, ppre4, _) = ppre_calculate(requested_pclk4, rcc_hclk, pclk_max, None); flash_setup(rcc_aclk, pwr_vos); @@ -593,11 +576,7 @@ pub(crate) unsafe fn init(mut config: Config) { None => None, }; - let pllsrc = if config.hse.is_some() { - Pllsrc::HSE - } else { - Pllsrc::HSI - }; + let pllsrc = if config.hse.is_some() { Pllsrc::HSE } else { Pllsrc::HSI }; RCC.pllckselr().modify(|w| w.set_pllsrc(pllsrc)); let enable_pll = |pll| { @@ -640,8 +619,7 @@ pub(crate) unsafe fn init(mut config: Config) { RCC.d1ccipr().modify(|w| w.set_ckpersel(ckpersel)); // ADC clock MUX - RCC.d3ccipr() - .modify(|w| w.set_adcsel(config.adc_clock_source.adcsel())); + RCC.d3ccipr().modify(|w| w.set_adcsel(config.adc_clock_source.adcsel())); let adc_ker_ck = match config.adc_clock_source { AdcClockSource::Pll2PCk => pll2_p_ck.map(Hertz), @@ -823,15 +801,13 @@ mod pll { let pll_x_n = vco_ck_target / ref_x_ck; assert!(pll_x_n >= 4); assert!(pll_x_n <= 512); - RCC.plldivr(plln) - .modify(|w| w.set_divn1((pll_x_n - 1) as u16)); + RCC.plldivr(plln).modify(|w| w.set_divn1((pll_x_n - 1) as u16)); // No FRACN RCC.pllcfgr().modify(|w| w.set_pllfracen(plln, false)); let vco_ck = ref_x_ck * pll_x_n; - RCC.plldivr(plln) - .modify(|w| w.set_divp1(Divp((pll_x_p - 1) as u8))); + RCC.plldivr(plln).modify(|w| w.set_divp1(Divp((pll_x_p - 1) as u8))); RCC.pllcfgr().modify(|w| w.set_divpen(plln, true)); // Calulate additional output dividers diff --git a/embassy-stm32/src/rcc/l0.rs b/embassy-stm32/src/rcc/l0.rs index 69279117..2e23833c 100644 --- a/embassy-stm32/src/rcc/l0.rs +++ b/embassy-stm32/src/rcc/l0.rs @@ -3,8 +3,7 @@ use crate::pac::RCC; #[cfg(crs)] use crate::pac::{CRS, SYSCFG}; use crate::rcc::{set_freqs, Clocks}; -use crate::time::Hertz; -use crate::time::U32Ext; +use crate::time::{Hertz, U32Ext}; /// HSI16 speed pub const HSI16_FREQ: u32 = 16_000_000; diff --git a/embassy-stm32/src/rcc/l1.rs b/embassy-stm32/src/rcc/l1.rs index dfcbd4f2..80290632 100644 --- a/embassy-stm32/src/rcc/l1.rs +++ b/embassy-stm32/src/rcc/l1.rs @@ -1,8 +1,7 @@ use crate::pac::rcc::vals::{Hpre, Msirange, Plldiv, Pllmul, Pllsrc, Ppre, Sw}; use crate::pac::{FLASH, RCC}; use crate::rcc::{set_freqs, Clocks}; -use crate::time::Hertz; -use crate::time::U32Ext; +use crate::time::{Hertz, U32Ext}; /// HSI speed pub const HSI_FREQ: u32 = 16_000_000; diff --git a/embassy-stm32/src/rcc/l4.rs b/embassy-stm32/src/rcc/l4.rs index 3b84fb9b..1905039b 100644 --- a/embassy-stm32/src/rcc/l4.rs +++ b/embassy-stm32/src/rcc/l4.rs @@ -1,8 +1,7 @@ use crate::pac::rcc::vals::{Hpre, Msirange, Pllsrc, Ppre, Sw}; use crate::pac::{FLASH, RCC}; use crate::rcc::{set_freqs, Clocks}; -use crate::time::Hertz; -use crate::time::U32Ext; +use crate::time::{Hertz, U32Ext}; /// HSI16 speed pub const HSI16_FREQ: u32 = 16_000_000; diff --git a/embassy-stm32/src/rcc/l5.rs b/embassy-stm32/src/rcc/l5.rs index 4419f3d3..48d12a89 100644 --- a/embassy-stm32/src/rcc/l5.rs +++ b/embassy-stm32/src/rcc/l5.rs @@ -3,8 +3,7 @@ use stm32_metapac::PWR; use crate::pac::rcc::vals::{Hpre, Msirange, Pllsrc, Ppre, Sw}; use crate::pac::{FLASH, RCC}; use crate::rcc::{set_freqs, Clocks}; -use crate::time::Hertz; -use crate::time::U32Ext; +use crate::time::{Hertz, U32Ext}; /// HSI16 speed pub const HSI16_FREQ: u32 = 16_000_000; @@ -297,8 +296,7 @@ impl Default for Config { } pub(crate) unsafe fn init(config: Config) { - PWR.cr1() - .modify(|w| w.set_vos(stm32_metapac::pwr::vals::Vos::RANGE0)); + PWR.cr1().modify(|w| w.set_vos(stm32_metapac::pwr::vals::Vos::RANGE0)); let (sys_clk, sw) = match config.mux { ClockSrc::MSI(range) => { // Enable MSI diff --git a/embassy-stm32/src/rcc/mod.rs b/embassy-stm32/src/rcc/mod.rs index 959e5926..866b1ffc 100644 --- a/embassy-stm32/src/rcc/mod.rs +++ b/embassy-stm32/src/rcc/mod.rs @@ -1,8 +1,9 @@ #![macro_use] -use crate::time::Hertz; use core::mem::MaybeUninit; +use crate::time::Hertz; + #[cfg_attr(rcc_f0, path = "f0.rs")] #[cfg_attr(any(rcc_f1, rcc_f1cl), path = "f1.rs")] #[cfg_attr(rcc_f2, path = "f2.rs")] @@ -41,13 +42,11 @@ pub struct Clocks { // AHB pub ahb1: Hertz, #[cfg(any( - rcc_l4, rcc_l5, rcc_f2, rcc_f4, rcc_f410, rcc_f7, rcc_h7, rcc_h7ab, rcc_g4, rcc_u5, rcc_wb, - rcc_wl5, rcc_wle + rcc_l4, rcc_l5, rcc_f2, rcc_f4, rcc_f410, rcc_f7, rcc_h7, rcc_h7ab, rcc_g4, rcc_u5, rcc_wb, rcc_wl5, rcc_wle ))] pub ahb2: Hertz, #[cfg(any( - rcc_l4, rcc_l5, rcc_f2, rcc_f4, rcc_f410, rcc_f7, rcc_h7, rcc_h7ab, rcc_u5, rcc_wb, - rcc_wl5, rcc_wle + rcc_l4, rcc_l5, rcc_f2, rcc_f4, rcc_f410, rcc_f7, rcc_h7, rcc_h7ab, rcc_u5, rcc_wb, rcc_wl5, rcc_wle ))] pub ahb3: Hertz, #[cfg(any(rcc_h7, rcc_h7ab))] diff --git a/embassy-stm32/src/rcc/u5.rs b/embassy-stm32/src/rcc/u5.rs index ac1cd06c..74d3a11e 100644 --- a/embassy-stm32/src/rcc/u5.rs +++ b/embassy-stm32/src/rcc/u5.rs @@ -1,7 +1,8 @@ +use stm32_metapac::rcc::vals::{Hpre, Msirange, Msirgsel, Pllm, Pllsrc, Ppre, Sw}; + use crate::pac::{FLASH, RCC}; use crate::rcc::{set_freqs, Clocks}; use crate::time::{Hertz, U32Ext}; -use stm32_metapac::rcc::vals::{Hpre, Msirange, Msirgsel, Pllm, Pllsrc, Ppre, Sw}; /// HSI16 speed pub const HSI16_FREQ: u32 = 16_000_000; diff --git a/embassy-stm32/src/rcc/wb.rs b/embassy-stm32/src/rcc/wb.rs index eae7c946..d950e28f 100644 --- a/embassy-stm32/src/rcc/wb.rs +++ b/embassy-stm32/src/rcc/wb.rs @@ -1,7 +1,6 @@ use crate::pac::RCC; use crate::rcc::{set_freqs, Clocks}; -use crate::time::Hertz; -use crate::time::U32Ext; +use crate::time::{Hertz, U32Ext}; /// Most of clock setup is copied from stm32l0xx-hal, and adopted to the generated PAC, /// and with the addition of the init function to configure a system clock. diff --git a/embassy-stm32/src/rng.rs b/embassy-stm32/src/rng.rs index e74b6623..5b3558c9 100644 --- a/embassy-stm32/src/rng.rs +++ b/embassy-stm32/src/rng.rs @@ -1,15 +1,14 @@ #![macro_use] -use crate::Unborrow; use core::marker::PhantomData; use core::task::Poll; + use embassy::waitqueue::AtomicWaker; use embassy_hal_common::unborrow; use futures::future::poll_fn; use rand_core::{CryptoRng, RngCore}; -use crate::pac; -use crate::peripherals; +use crate::{pac, peripherals, Unborrow}; pub(crate) static RNG_WAKER: AtomicWaker = AtomicWaker::new(); diff --git a/embassy-stm32/src/sdmmc/mod.rs b/embassy-stm32/src/sdmmc/mod.rs index a7290e74..1ebf91b3 100644 --- a/embassy-stm32/src/sdmmc/mod.rs +++ b/embassy-stm32/src/sdmmc/mod.rs @@ -4,8 +4,6 @@ use core::default::Default; use core::marker::PhantomData; use core::task::Poll; -use crate::interrupt::InterruptExt; -use crate::Unborrow; use embassy::waitqueue::AtomicWaker; use embassy_hal_common::drop::OnDrop; use embassy_hal_common::unborrow; @@ -15,11 +13,11 @@ use sdio_host::{BusWidth, CardCapacity, CardStatus, CurrentState, SDStatus, CID, use crate::dma::NoDma; use crate::gpio::sealed::AFType; use crate::gpio::{Pull, Speed}; -use crate::interrupt::Interrupt; +use crate::interrupt::{Interrupt, InterruptExt}; use crate::pac::sdmmc::Sdmmc as RegBlock; -use crate::peripherals; use crate::rcc::RccPeripheral; use crate::time::Hertz; +use crate::{peripherals, Unborrow}; /// The signalling scheme used on the SDMMC bus #[non_exhaustive] @@ -283,11 +281,7 @@ impl<'d, T: Instance, P: Pins, Dma: SdmmcDma> Sdmmc<'d, T, P, Dma> { } #[inline(always)] - pub async fn read_block( - &mut self, - block_idx: u32, - buffer: &mut DataBlock, - ) -> Result<(), Error> { + pub async fn read_block(&mut self, block_idx: u32, buffer: &mut DataBlock) -> Result<(), Error> { let card_capacity = self.card()?.card_type; let inner = T::inner(); let state = T::state(); @@ -475,8 +469,7 @@ impl SdmmcInner { self.select_card(Some(&card))?; - self.get_scr(&mut card, waker_reg, data_transfer_timeout, dma) - .await?; + self.get_scr(&mut card, waker_reg, data_transfer_timeout, dma).await?; // Set bus width let (width, acmd_arg) = match bus_width { @@ -515,12 +508,7 @@ impl SdmmcInner { if freq.0 > 25_000_000 { // Switch to SDR25 *signalling = self - .switch_signalling_mode( - Signalling::SDR25, - waker_reg, - data_transfer_timeout, - dma, - ) + .switch_signalling_mode(Signalling::SDR25, waker_reg, data_transfer_timeout, dma) .await?; if *signalling == Signalling::SDR25 { @@ -562,13 +550,7 @@ impl SdmmcInner { let on_drop = OnDrop::new(|| unsafe { self.on_drop() }); unsafe { - self.prepare_datapath_read( - buffer as *mut [u32; 128], - 512, - 9, - data_transfer_timeout, - dma, - ); + self.prepare_datapath_read(buffer as *mut [u32; 128], 512, 9, data_transfer_timeout, dma); self.data_interrupts(true); } self.cmd(Cmd::read_single_block(address), true)?; @@ -617,13 +599,7 @@ impl SdmmcInner { let on_drop = OnDrop::new(|| unsafe { self.on_drop() }); unsafe { - self.prepare_datapath_write( - buffer as *const [u32; 128], - 512, - 9, - data_transfer_timeout, - dma, - ); + self.prepare_datapath_write(buffer as *const [u32; 128], 512, 9, data_transfer_timeout, dma); self.data_interrupts(true); } self.cmd(Cmd::write_single_block(address), true)?; @@ -654,10 +630,7 @@ impl SdmmcInner { // Try to read card status (ACMD13) while timeout > 0 { - match self - .read_sd_status(card, waker_reg, data_transfer_timeout, dma) - .await - { + match self.read_sd_status(card, waker_reg, data_transfer_timeout, dma).await { Ok(_) => return Ok(()), Err(Error::Timeout) => (), // Try again Err(e) => return Err(e), @@ -732,8 +705,7 @@ impl SdmmcInner { // NOTE(unsafe) We have exclusive access to the regisers - regs.dtimer() - .write(|w| w.set_datatime(data_transfer_timeout)); + regs.dtimer().write(|w| w.set_datatime(data_transfer_timeout)); regs.dlenr().write(|w| w.set_datalength(length_bytes)); cfg_if::cfg_if! { @@ -781,8 +753,7 @@ impl SdmmcInner { // NOTE(unsafe) We have exclusive access to the regisers - regs.dtimer() - .write(|w| w.set_datatime(data_transfer_timeout)); + regs.dtimer().write(|w| w.set_datatime(data_transfer_timeout)); regs.dlenr().write(|w| w.set_datalength(length_bytes)); cfg_if::cfg_if! { @@ -824,13 +795,7 @@ impl SdmmcInner { } /// Sets the CLKDIV field in CLKCR. Updates clock field in self - fn clkcr_set_clkdiv( - &self, - freq: u32, - width: BusWidth, - ker_ck: Hertz, - clock: &mut Hertz, - ) -> Result<(), Error> { + fn clkcr_set_clkdiv(&self, freq: u32, width: BusWidth, ker_ck: Hertz, clock: &mut Hertz) -> Result<(), Error> { let regs = self.0; let (clkdiv, new_clock) = clk_div(ker_ck, freq)?; @@ -882,13 +847,7 @@ impl SdmmcInner { let on_drop = OnDrop::new(|| unsafe { self.on_drop() }); unsafe { - self.prepare_datapath_read( - &mut status as *mut [u32; 16], - 64, - 6, - data_transfer_timeout, - dma, - ); + self.prepare_datapath_read(&mut status as *mut [u32; 16], 64, 6, data_transfer_timeout, dma); self.data_interrupts(true); } self.cmd(Cmd::cmd6(set_function), true)?; // CMD6 @@ -970,13 +929,7 @@ impl SdmmcInner { let on_drop = OnDrop::new(|| unsafe { self.on_drop() }); unsafe { - self.prepare_datapath_read( - &mut status as *mut [u32; 16], - 64, - 6, - data_transfer_timeout, - dma, - ); + self.prepare_datapath_read(&mut status as *mut [u32; 16], 64, 6, data_transfer_timeout, dma); self.data_interrupts(true); } self.cmd(Cmd::card_status(0), true)?; @@ -1473,10 +1426,12 @@ foreach_peripheral!( #[cfg(feature = "sdmmc-rs")] mod sdmmc_rs { - use super::*; use core::future::Future; + use embedded_sdmmc::{Block, BlockCount, BlockDevice, BlockIdx}; + use super::*; + impl<'d, T: Instance, P: Pins> BlockDevice for Sdmmc<'d, T, P> { type Error = Error; type ReadFuture<'a> @@ -1506,13 +1461,7 @@ mod sdmmc_rs { // NOTE(unsafe) Block uses align(4) let buf = unsafe { &mut *(block as *mut [u8; 512] as *mut [u32; 128]) }; inner - .read_block( - address, - buf, - card_capacity, - state, - self.config.data_transfer_timeout, - ) + .read_block(address, buf, card_capacity, state, self.config.data_transfer_timeout) .await?; address += 1; } @@ -1520,11 +1469,7 @@ mod sdmmc_rs { } } - fn write<'a>( - &'a mut self, - blocks: &'a [Block], - start_block_idx: BlockIdx, - ) -> Self::WriteFuture<'a> { + fn write<'a>(&'a mut self, blocks: &'a [Block], start_block_idx: BlockIdx) -> Self::WriteFuture<'a> { async move { let card = self.card.as_mut().ok_or(Error::NoCard)?; let inner = T::inner(); diff --git a/embassy-stm32/src/spi/mod.rs b/embassy-stm32/src/spi/mod.rs index 3cdc87c7..7c142e50 100644 --- a/embassy-stm32/src/spi/mod.rs +++ b/embassy-stm32/src/spi/mod.rs @@ -1,22 +1,20 @@ #![macro_use] -use crate::Unborrow; use core::marker::PhantomData; use core::ptr; + use embassy_hal_common::unborrow; +pub use embedded_hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3}; use futures::future::join; use self::sealed::WordSize; use crate::dma::{slice_ptr_parts, NoDma, Transfer}; use crate::gpio::sealed::{AFType, Pin as _}; use crate::gpio::AnyPin; -use crate::pac::spi::Spi as Regs; -use crate::pac::spi::{regs, vals}; -use crate::peripherals; +use crate::pac::spi::{regs, vals, Spi as Regs}; use crate::rcc::RccPeripheral; use crate::time::Hertz; - -pub use embedded_hal_02::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3}; +use crate::{peripherals, Unborrow}; #[derive(Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] @@ -423,10 +421,7 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { let tx_request = self.txdma.request(); let tx_dst = T::REGS.tx_ptr(); - unsafe { - self.txdma - .start_write(tx_request, data, tx_dst, Default::default()) - } + unsafe { self.txdma.start_write(tx_request, data, tx_dst, Default::default()) } let tx_f = Transfer::new(&mut self.txdma); unsafe { @@ -472,22 +467,13 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { let rx_request = self.rxdma.request(); let rx_src = T::REGS.rx_ptr(); - unsafe { - self.rxdma - .start_read(rx_request, rx_src, data, Default::default()) - }; + unsafe { self.rxdma.start_read(rx_request, rx_src, data, Default::default()) }; let rx_f = Transfer::new(&mut self.rxdma); let tx_request = self.txdma.request(); let tx_dst = T::REGS.tx_ptr(); let clock_byte = 0x00u8; - let tx_f = crate::dma::write_repeated( - &mut self.txdma, - tx_request, - clock_byte, - clock_byte_count, - tx_dst, - ); + let tx_f = crate::dma::write_repeated(&mut self.txdma, tx_request, clock_byte, clock_byte_count, tx_dst); unsafe { set_txdmaen(T::REGS, true); @@ -507,11 +493,7 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { Ok(()) } - async fn transfer_inner( - &mut self, - read: *mut [W], - write: *const [W], - ) -> Result<(), Error> + async fn transfer_inner(&mut self, read: *mut [W], write: *const [W]) -> Result<(), Error> where Tx: TxDma, Rx: RxDma, @@ -537,18 +519,12 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { let rx_request = self.rxdma.request(); let rx_src = T::REGS.rx_ptr(); - unsafe { - self.rxdma - .start_read(rx_request, rx_src, read, Default::default()) - }; + unsafe { self.rxdma.start_read(rx_request, rx_src, read, Default::default()) }; let rx_f = Transfer::new(&mut self.rxdma); let tx_request = self.txdma.request(); let tx_dst = T::REGS.tx_ptr(); - unsafe { - self.txdma - .start_write(tx_request, write, tx_dst, Default::default()) - } + unsafe { self.txdma.start_write(tx_request, write, tx_dst, Default::default()) } let tx_f = Transfer::new(&mut self.txdma); unsafe { @@ -835,9 +811,7 @@ mod eh02 { // some marker traits. For details, see https://github.com/rust-embedded/embedded-hal/pull/289 macro_rules! impl_blocking { ($w:ident) => { - impl<'d, T: Instance> embedded_hal_02::blocking::spi::Write<$w> - for Spi<'d, T, NoDma, NoDma> - { + impl<'d, T: Instance> embedded_hal_02::blocking::spi::Write<$w> for Spi<'d, T, NoDma, NoDma> { type Error = Error; fn write(&mut self, words: &[$w]) -> Result<(), Self::Error> { @@ -845,9 +819,7 @@ mod eh02 { } } - impl<'d, T: Instance> embedded_hal_02::blocking::spi::Transfer<$w> - for Spi<'d, T, NoDma, NoDma> - { + impl<'d, T: Instance> embedded_hal_02::blocking::spi::Transfer<$w> for Spi<'d, T, NoDma, NoDma> { type Error = Error; fn transfer<'w>(&mut self, words: &'w mut [$w]) -> Result<&'w [$w], Self::Error> { @@ -876,25 +848,19 @@ mod eh1 { } } - impl<'d, T: Instance, W: Word> embedded_hal_1::spi::blocking::SpiBusRead - for Spi<'d, T, NoDma, NoDma> - { + impl<'d, T: Instance, W: Word> embedded_hal_1::spi::blocking::SpiBusRead for Spi<'d, T, NoDma, NoDma> { fn read(&mut self, words: &mut [W]) -> Result<(), Self::Error> { self.blocking_read(words) } } - impl<'d, T: Instance, W: Word> embedded_hal_1::spi::blocking::SpiBusWrite - for Spi<'d, T, NoDma, NoDma> - { + impl<'d, T: Instance, W: Word> embedded_hal_1::spi::blocking::SpiBusWrite for Spi<'d, T, NoDma, NoDma> { fn write(&mut self, words: &[W]) -> Result<(), Self::Error> { self.blocking_write(words) } } - impl<'d, T: Instance, W: Word> embedded_hal_1::spi::blocking::SpiBus - for Spi<'d, T, NoDma, NoDma> - { + impl<'d, T: Instance, W: Word> embedded_hal_1::spi::blocking::SpiBus for Spi<'d, T, NoDma, NoDma> { fn transfer(&mut self, read: &mut [W], write: &[W]) -> Result<(), Self::Error> { self.blocking_transfer(read, write) } diff --git a/embassy-stm32/src/subghz/mod.rs b/embassy-stm32/src/subghz/mod.rs index 6736324c..3b64932f 100644 --- a/embassy-stm32/src/subghz/mod.rs +++ b/embassy-stm32/src/subghz/mod.rs @@ -43,19 +43,20 @@ mod value_error; pub use bit_sync::BitSync; pub use cad_params::{CadParams, ExitMode, NbCadSymbol}; pub use calibrate::{Calibrate, CalibrateImage}; +use embassy_hal_common::ratio::Ratio; pub use fallback_mode::FallbackMode; pub use hse_trim::HseTrim; pub use irq::{CfgIrq, Irq, IrqLine}; pub use lora_sync_word::LoRaSyncWord; -pub use mod_params::BpskModParams; -pub use mod_params::{CodingRate, LoRaBandwidth, LoRaModParams, SpreadingFactor}; -pub use mod_params::{FskBandwidth, FskBitrate, FskFdev, FskModParams, FskPulseShape}; +pub use mod_params::{ + BpskModParams, CodingRate, FskBandwidth, FskBitrate, FskFdev, FskModParams, FskPulseShape, LoRaBandwidth, + LoRaModParams, SpreadingFactor, +}; pub use ocp::Ocp; pub use op_error::OpError; pub use pa_config::{PaConfig, PaSel}; pub use packet_params::{ - AddrComp, BpskPacketParams, CrcType, GenericPacketParams, HeaderType, LoRaPacketParams, - PreambleDetection, + AddrComp, BpskPacketParams, CrcType, GenericPacketParams, HeaderType, LoRaPacketParams, PreambleDetection, }; pub use packet_status::{FskPacketStatus, LoRaPacketStatus}; pub use packet_type::PacketType; @@ -75,17 +76,12 @@ pub use timeout::Timeout; pub use tx_params::{RampTime, TxParams}; pub use value_error::ValueError; -use embassy_hal_common::ratio::Ratio; - -use crate::Unborrow; -use crate::{ - dma::NoDma, - pac, - peripherals::SUBGHZSPI, - rcc::sealed::RccPeripheral, - spi::{BitOrder, Config as SpiConfig, MisoPin, MosiPin, SckPin, Spi, MODE_0}, - time::Hertz, -}; +use crate::dma::NoDma; +use crate::peripherals::SUBGHZSPI; +use crate::rcc::sealed::RccPeripheral; +use crate::spi::{BitOrder, Config as SpiConfig, MisoPin, MosiPin, SckPin, Spi, MODE_0}; +use crate::time::Hertz; +use crate::{pac, Unborrow}; /// Passthrough for SPI errors (for now) pub type Error = crate::spi::Error; @@ -105,8 +101,7 @@ impl Nss { fn clear() { let pwr = pac::PWR; unsafe { - pwr.subghzspicr() - .modify(|w| w.set_nss(pac::pwr::vals::Nss::LOW)); + pwr.subghzspicr().modify(|w| w.set_nss(pac::pwr::vals::Nss::LOW)); } } @@ -115,8 +110,7 @@ impl Nss { fn set() { let pwr = pac::PWR; unsafe { - pwr.subghzspicr() - .modify(|w| w.set_nss(pac::pwr::vals::Nss::HIGH)); + pwr.subghzspicr().modify(|w| w.set_nss(pac::pwr::vals::Nss::HIGH)); } } } @@ -286,8 +280,7 @@ impl<'d> SubGhz<'d, NoDma, NoDma> { self.poll_not_busy(); { let _nss: Nss = Nss::new(); - self.spi - .blocking_write(&[OpCode::WriteBuffer as u8, offset])?; + self.spi.blocking_write(&[OpCode::WriteBuffer as u8, offset])?; self.spi.blocking_write(data)?; } self.poll_not_busy(); @@ -305,8 +298,7 @@ impl<'d> SubGhz<'d, NoDma, NoDma> { self.poll_not_busy(); { let _nss: Nss = Nss::new(); - self.spi - .blocking_write(&[OpCode::ReadBuffer as u8, offset])?; + self.spi.blocking_write(&[OpCode::ReadBuffer as u8, offset])?; self.spi.blocking_transfer_in_place(&mut status_buf)?; self.spi.blocking_transfer_in_place(buf)?; } @@ -678,10 +670,7 @@ impl<'d> SubGhz<'d, NoDma, NoDma> { /// # Ok::<(), embassy_stm32::subghz::Error>(()) /// ``` pub fn set_rx_timeout_stop(&mut self, rx_timeout_stop: RxTimeoutStop) -> Result<(), Error> { - self.write(&[ - OpCode::SetStopRxTimerOnPreamble.into(), - rx_timeout_stop.into(), - ]) + self.write(&[OpCode::SetStopRxTimerOnPreamble.into(), rx_timeout_stop.into()]) } /// Put the radio in non-continuous RX mode. @@ -730,11 +719,7 @@ impl<'d> SubGhz<'d, NoDma, NoDma> { /// [`RxDone`]: crate::subghz::Irq::RxDone /// [`set_rf_frequency`]: crate::subghz::SubGhz::set_rf_frequency /// [`set_standby`]: crate::subghz::SubGhz::set_standby - pub fn set_rx_duty_cycle( - &mut self, - rx_period: Timeout, - sleep_period: Timeout, - ) -> Result<(), Error> { + pub fn set_rx_duty_cycle(&mut self, rx_period: Timeout, sleep_period: Timeout) -> Result<(), Error> { let rx_period_bits: u32 = rx_period.into_bits(); let sleep_period_bits: u32 = sleep_period.into_bits(); self.write(&[ @@ -1288,9 +1273,7 @@ impl<'d> SubGhz<'d, NoDma, NoDma> { /// # Ok::<(), embassy_stm32::subghz::Error>(()) /// ``` pub fn lora_packet_status(&mut self) -> Result { - Ok(LoRaPacketStatus::from( - self.read_n(OpCode::GetPacketStatus)?, - )) + Ok(LoRaPacketStatus::from(self.read_n(OpCode::GetPacketStatus)?)) } /// Get the instantaneous signal strength during packet reception. diff --git a/embassy-stm32/src/subghz/pa_config.rs b/embassy-stm32/src/subghz/pa_config.rs index 8da4ba40..9833368c 100644 --- a/embassy-stm32/src/subghz/pa_config.rs +++ b/embassy-stm32/src/subghz/pa_config.rs @@ -13,58 +13,37 @@ impl PaConfig { /// Optimal settings for +15dBm output power with the low-power PA. /// /// This must be used with [`TxParams::LP_15`](super::TxParams::LP_15). - pub const LP_15: PaConfig = PaConfig::new() - .set_pa_duty_cycle(0x6) - .set_hp_max(0x0) - .set_pa(PaSel::Lp); + pub const LP_15: PaConfig = PaConfig::new().set_pa_duty_cycle(0x6).set_hp_max(0x0).set_pa(PaSel::Lp); /// Optimal settings for +14dBm output power with the low-power PA. /// /// This must be used with [`TxParams::LP_14`](super::TxParams::LP_14). - pub const LP_14: PaConfig = PaConfig::new() - .set_pa_duty_cycle(0x4) - .set_hp_max(0x0) - .set_pa(PaSel::Lp); + pub const LP_14: PaConfig = PaConfig::new().set_pa_duty_cycle(0x4).set_hp_max(0x0).set_pa(PaSel::Lp); /// Optimal settings for +10dBm output power with the low-power PA. /// /// This must be used with [`TxParams::LP_10`](super::TxParams::LP_10). - pub const LP_10: PaConfig = PaConfig::new() - .set_pa_duty_cycle(0x1) - .set_hp_max(0x0) - .set_pa(PaSel::Lp); + pub const LP_10: PaConfig = PaConfig::new().set_pa_duty_cycle(0x1).set_hp_max(0x0).set_pa(PaSel::Lp); /// Optimal settings for +22dBm output power with the high-power PA. /// /// This must be used with [`TxParams::HP`](super::TxParams::HP). - pub const HP_22: PaConfig = PaConfig::new() - .set_pa_duty_cycle(0x4) - .set_hp_max(0x7) - .set_pa(PaSel::Hp); + pub const HP_22: PaConfig = PaConfig::new().set_pa_duty_cycle(0x4).set_hp_max(0x7).set_pa(PaSel::Hp); /// Optimal settings for +20dBm output power with the high-power PA. /// /// This must be used with [`TxParams::HP`](super::TxParams::HP). - pub const HP_20: PaConfig = PaConfig::new() - .set_pa_duty_cycle(0x3) - .set_hp_max(0x5) - .set_pa(PaSel::Hp); + pub const HP_20: PaConfig = PaConfig::new().set_pa_duty_cycle(0x3).set_hp_max(0x5).set_pa(PaSel::Hp); /// Optimal settings for +17dBm output power with the high-power PA. /// /// This must be used with [`TxParams::HP`](super::TxParams::HP). - pub const HP_17: PaConfig = PaConfig::new() - .set_pa_duty_cycle(0x2) - .set_hp_max(0x3) - .set_pa(PaSel::Hp); + pub const HP_17: PaConfig = PaConfig::new().set_pa_duty_cycle(0x2).set_hp_max(0x3).set_pa(PaSel::Hp); /// Optimal settings for +14dBm output power with the high-power PA. /// /// This must be used with [`TxParams::HP`](super::TxParams::HP). - pub const HP_14: PaConfig = PaConfig::new() - .set_pa_duty_cycle(0x2) - .set_hp_max(0x2) - .set_pa(PaSel::Hp); + pub const HP_14: PaConfig = PaConfig::new().set_pa_duty_cycle(0x2).set_hp_max(0x2).set_pa(PaSel::Hp); /// Create a new `PaConfig` struct. /// diff --git a/embassy-stm32/src/subghz/packet_params.rs b/embassy-stm32/src/subghz/packet_params.rs index ae84ea26..60b13ba4 100644 --- a/embassy-stm32/src/subghz/packet_params.rs +++ b/embassy-stm32/src/subghz/packet_params.rs @@ -147,10 +147,7 @@ impl GenericPacketParams { /// # assert_eq!(PKT_PARAMS.as_slice()[3], 0x4); /// ``` #[must_use = "set_preamble_detection returns a modified GenericPacketParams"] - pub const fn set_preamble_detection( - mut self, - pb_det: PreambleDetection, - ) -> GenericPacketParams { + pub const fn set_preamble_detection(mut self, pb_det: PreambleDetection) -> GenericPacketParams { self.buf[3] = pb_det as u8; self } diff --git a/embassy-stm32/src/subghz/packet_status.rs b/embassy-stm32/src/subghz/packet_status.rs index 46eded6f..a4e348d9 100644 --- a/embassy-stm32/src/subghz/packet_status.rs +++ b/embassy-stm32/src/subghz/packet_status.rs @@ -1,6 +1,4 @@ -use super::Ratio; - -use super::Status; +use super::{Ratio, Status}; /// (G)FSK packet status. /// diff --git a/embassy-stm32/src/subghz/rf_frequency.rs b/embassy-stm32/src/subghz/rf_frequency.rs index 54c03dcd..520dc89d 100644 --- a/embassy-stm32/src/subghz/rf_frequency.rs +++ b/embassy-stm32/src/subghz/rf_frequency.rs @@ -89,10 +89,7 @@ impl RfFreq { // Get the frequency bit value. const fn as_bits(&self) -> u32 { - ((self.buf[1] as u32) << 24) - | ((self.buf[2] as u32) << 16) - | ((self.buf[3] as u32) << 8) - | (self.buf[4] as u32) + ((self.buf[1] as u32) << 24) | ((self.buf[2] as u32) << 16) | ((self.buf[3] as u32) << 8) | (self.buf[4] as u32) } /// Get the actual frequency. diff --git a/embassy-stm32/src/subghz/sleep_cfg.rs b/embassy-stm32/src/subghz/sleep_cfg.rs index 3fdcc713..2d2fe0c9 100644 --- a/embassy-stm32/src/subghz/sleep_cfg.rs +++ b/embassy-stm32/src/subghz/sleep_cfg.rs @@ -49,9 +49,7 @@ impl SleepCfg { /// # assert_eq!(u8::from(SLEEP_CFG), 0b101); /// ``` pub const fn new() -> SleepCfg { - SleepCfg(0) - .set_startup(Startup::Warm) - .set_rtc_wakeup_en(true) + SleepCfg(0).set_startup(Startup::Warm).set_rtc_wakeup_en(true) } /// Set the startup mode. diff --git a/embassy-stm32/src/subghz/status.rs b/embassy-stm32/src/subghz/status.rs index ae50c519..10a212b9 100644 --- a/embassy-stm32/src/subghz/status.rs +++ b/embassy-stm32/src/subghz/status.rs @@ -192,11 +192,6 @@ impl core::fmt::Display for Status { #[cfg(feature = "defmt")] impl defmt::Format for Status { fn format(&self, fmt: defmt::Formatter) { - defmt::write!( - fmt, - "Status {{ mode: {}, cmd: {} }}", - self.mode(), - self.cmd() - ) + defmt::write!(fmt, "Status {{ mode: {}, cmd: {} }}", self.mode(), self.cmd()) } } diff --git a/embassy-stm32/src/subghz/timeout.rs b/embassy-stm32/src/subghz/timeout.rs index 580d0a64..2a0f5b85 100644 --- a/embassy-stm32/src/subghz/timeout.rs +++ b/embassy-stm32/src/subghz/timeout.rs @@ -145,8 +145,7 @@ impl Timeout { // `core::Duration` were not `const fn`, which leads to the hacks // you see here. let nanos: u128 = duration.as_nanos(); - const UPPER_LIMIT: u128 = - Timeout::MAX.as_nanos() as u128 + (Timeout::RESOLUTION_NANOS as u128) / 2; + const UPPER_LIMIT: u128 = Timeout::MAX.as_nanos() as u128 + (Timeout::RESOLUTION_NANOS as u128) / 2; const LOWER_LIMIT: u128 = (((Timeout::RESOLUTION_NANOS as u128) + 1) / 2) as u128; if nanos > UPPER_LIMIT { @@ -420,15 +419,13 @@ impl From for embassy::time::Duration { #[cfg(test)] mod tests { - use super::{Timeout, ValueError}; use core::time::Duration; + use super::{Timeout, ValueError}; + #[test] fn saturate() { - assert_eq!( - Timeout::from_duration_sat(Duration::from_secs(u64::MAX)), - Timeout::MAX - ); + assert_eq!(Timeout::from_duration_sat(Duration::from_secs(u64::MAX)), Timeout::MAX); } #[test] @@ -455,10 +452,7 @@ mod tests { #[test] fn upper_limit() { let high: Duration = Timeout::MAX.as_duration() + Timeout::RESOLUTION / 2; - assert_eq!( - Timeout::from_duration(high), - Ok(Timeout::from_raw(0xFFFFFF)) - ); + assert_eq!(Timeout::from_duration(high), Ok(Timeout::from_raw(0xFFFFFF))); let too_high: Duration = high + Duration::from_nanos(1); assert_eq!( diff --git a/embassy-stm32/src/time_driver.rs b/embassy-stm32/src/time_driver.rs index b63ed5bd..38a4adc1 100644 --- a/embassy-stm32/src/time_driver.rs +++ b/embassy-stm32/src/time_driver.rs @@ -1,22 +1,20 @@ -use crate::interrupt::InterruptExt; -use atomic_polyfill::{AtomicU32, AtomicU8}; use core::cell::Cell; use core::convert::TryInto; use core::sync::atomic::{compiler_fence, Ordering}; use core::{mem, ptr}; + +use atomic_polyfill::{AtomicU32, AtomicU8}; use embassy::blocking_mutex::raw::CriticalSectionRawMutex; use embassy::blocking_mutex::Mutex; use embassy::time::driver::{AlarmHandle, Driver}; use embassy::time::TICKS_PER_SECOND; use stm32_metapac::timer::regs; -use crate::interrupt; -use crate::interrupt::CriticalSection; +use crate::interrupt::{CriticalSection, InterruptExt}; use crate::pac::timer::vals; -use crate::peripherals; use crate::rcc::sealed::RccPeripheral; -use crate::timer::sealed::Basic16bitInstance as BasicInstance; -use crate::timer::sealed::GeneralPurpose16bitInstance as Instance; +use crate::timer::sealed::{Basic16bitInstance as BasicInstance, GeneralPurpose16bitInstance as Instance}; +use crate::{interrupt, peripherals}; #[cfg(not(any(time_driver_tim12, time_driver_tim15)))] const ALARM_COUNT: usize = 3; @@ -271,15 +269,13 @@ impl Driver for RtcDriver { } unsafe fn allocate_alarm(&self) -> Option { - let id = self - .alarm_count - .fetch_update(Ordering::AcqRel, Ordering::Acquire, |x| { - if x < ALARM_COUNT as u8 { - Some(x + 1) - } else { - None - } - }); + let id = self.alarm_count.fetch_update(Ordering::AcqRel, Ordering::Acquire, |x| { + if x < ALARM_COUNT as u8 { + Some(x + 1) + } else { + None + } + }); match id { Ok(id) => Some(AlarmHandle::new(id)), diff --git a/embassy-stm32/src/timer/mod.rs b/embassy-stm32/src/timer/mod.rs index 3cc6298b..9067fa46 100644 --- a/embassy-stm32/src/timer/mod.rs +++ b/embassy-stm32/src/timer/mod.rs @@ -1,9 +1,10 @@ -use crate::interrupt::Interrupt; - -use crate::rcc::{sealed::RccPeripheral as __RccPeri, RccPeripheral}; -use crate::time::Hertz; use stm32_metapac::timer::vals; +use crate::interrupt::Interrupt; +use crate::rcc::sealed::RccPeripheral as __RccPeri; +use crate::rcc::RccPeripheral; +use crate::time::Hertz; + #[cfg(feature = "unstable-pac")] pub mod low_level { pub use super::sealed::*; @@ -86,8 +87,7 @@ macro_rules! impl_basic_16bit_timer { let timer_f = Self::frequency().0; let pclk_ticks_per_timer_period = timer_f / f; let psc: u16 = unwrap!(((pclk_ticks_per_timer_period - 1) / (1 << 16)).try_into()); - let arr: u16 = - unwrap!((pclk_ticks_per_timer_period / (u32::from(psc) + 1)).try_into()); + let arr: u16 = unwrap!((pclk_ticks_per_timer_period / (u32::from(psc) + 1)).try_into()); let regs = Self::regs(); unsafe { @@ -138,8 +138,7 @@ macro_rules! impl_32bit_timer { let timer_f = Self::frequency().0; let pclk_ticks_per_timer_period = (timer_f / f) as u64; let psc: u16 = unwrap!(((pclk_ticks_per_timer_period - 1) / (1 << 32)).try_into()); - let arr: u32 = - unwrap!(((pclk_ticks_per_timer_period / (psc as u64 + 1)).try_into())); + let arr: u32 = unwrap!(((pclk_ticks_per_timer_period / (psc as u64 + 1)).try_into())); let regs = Self::regs_gp32(); unsafe { diff --git a/embassy-stm32/src/usart/buffered.rs b/embassy-stm32/src/usart/buffered.rs index e2c9f780..c4703cff 100644 --- a/embassy-stm32/src/usart/buffered.rs +++ b/embassy-stm32/src/usart/buffered.rs @@ -1,6 +1,7 @@ -use atomic_polyfill::{compiler_fence, Ordering}; use core::future::Future; use core::task::Poll; + +use atomic_polyfill::{compiler_fence, Ordering}; use embassy::waitqueue::WakerRegistration; use embassy_cortex_m::peripheral::{PeripheralMutex, PeripheralState, StateStorage}; use embassy_hal_common::ring_buffer::RingBuffer; diff --git a/embassy-stm32/src/usart/mod.rs b/embassy-stm32/src/usart/mod.rs index 2acec874..a893e4b8 100644 --- a/embassy-stm32/src/usart/mod.rs +++ b/embassy-stm32/src/usart/mod.rs @@ -1,15 +1,15 @@ #![macro_use] -use crate::interrupt::Interrupt; -use crate::Unborrow; use core::marker::PhantomData; + use embassy_hal_common::unborrow; use crate::dma::NoDma; use crate::gpio::sealed::AFType; +use crate::interrupt::Interrupt; use crate::pac::usart::{regs, vals}; -use crate::peripherals; use crate::rcc::RccPeripheral; +use crate::{peripherals, Unborrow}; #[derive(Clone, Copy, PartialEq, Eq, Debug)] pub enum DataBits { @@ -314,18 +314,14 @@ mod eh02 { } } - impl<'d, T: Instance, TxDma, RxDma> embedded_hal_02::serial::Read - for Uart<'d, T, TxDma, RxDma> - { + impl<'d, T: Instance, TxDma, RxDma> embedded_hal_02::serial::Read for Uart<'d, T, TxDma, RxDma> { type Error = Error; fn read(&mut self) -> Result> { embedded_hal_02::serial::Read::read(&mut self.rx) } } - impl<'d, T: Instance, TxDma, RxDma> embedded_hal_02::blocking::serial::Write - for Uart<'d, T, TxDma, RxDma> - { + impl<'d, T: Instance, TxDma, RxDma> embedded_hal_02::blocking::serial::Write for Uart<'d, T, TxDma, RxDma> { type Error = Error; fn bwrite_all(&mut self, buffer: &[u8]) -> Result<(), Self::Error> { self.blocking_write(buffer) @@ -351,9 +347,7 @@ mod eh1 { } } - impl<'d, T: Instance, TxDma, RxDma> embedded_hal_1::serial::ErrorType - for Uart<'d, T, TxDma, RxDma> - { + impl<'d, T: Instance, TxDma, RxDma> embedded_hal_1::serial::ErrorType for Uart<'d, T, TxDma, RxDma> { type Error = Error; } diff --git a/embassy-stm32/src/usb/mod.rs b/embassy-stm32/src/usb/mod.rs index 65451917..fbd1fa82 100644 --- a/embassy-stm32/src/usb/mod.rs +++ b/embassy-stm32/src/usb/mod.rs @@ -1,5 +1,4 @@ use crate::interrupt::Interrupt; - use crate::rcc::RccPeripheral; #[cfg(feature = "nightly")] diff --git a/embassy-stm32/src/usb/usb.rs b/embassy-stm32/src/usb/usb.rs index eaf24f8a..10eb94e6 100644 --- a/embassy-stm32/src/usb/usb.rs +++ b/embassy-stm32/src/usb/usb.rs @@ -1,11 +1,10 @@ #![macro_use] -use crate::interrupt::InterruptExt; -use crate::Unborrow; -use atomic_polyfill::{AtomicBool, AtomicU8}; use core::marker::PhantomData; use core::sync::atomic::Ordering; use core::task::Poll; + +use atomic_polyfill::{AtomicBool, AtomicU8}; use embassy::time::{block_for, Duration}; use embassy::waitqueue::AtomicWaker; use embassy_hal_common::unborrow; @@ -16,12 +15,12 @@ use futures::Future; use pac::common::{Reg, RW}; use pac::usb::vals::{EpType, Stat}; +use super::{DmPin, DpPin, Instance}; use crate::gpio::sealed::AFType; -use crate::pac; +use crate::interrupt::InterruptExt; use crate::pac::usb::regs; use crate::rcc::sealed::RccPeripheral; - -use super::{DmPin, DpPin, Instance}; +use crate::{pac, Unborrow}; const EP_COUNT: usize = 8; @@ -105,11 +104,7 @@ impl EndpointBuffer { if i * 2 + 1 < buf.len() { val |= (buf[i * 2 + 1] as u16) << 8; } - unsafe { - T::regs() - .ep_mem(self.addr as usize / 2 + i) - .write_value(val) - }; + unsafe { T::regs().ep_mem(self.addr as usize / 2 + i).write_value(val) }; } } } @@ -146,9 +141,7 @@ impl<'d, T: Instance> Driver<'d, T> { unsafe { crate::peripherals::PWR::enable(); - pac::PWR - .cr2() - .modify(|w| w.set_usv(pac::pwr::vals::Usv::VALID)); + pac::PWR.cr2().modify(|w| w.set_usv(pac::pwr::vals::Usv::VALID)); } unsafe { @@ -857,12 +850,7 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> { } } - fn data_out<'a>( - &'a mut self, - buf: &'a mut [u8], - first: bool, - last: bool, - ) -> Self::DataOutFuture<'a> { + fn data_out<'a>(&'a mut self, buf: &'a mut [u8], first: bool, last: bool) -> Self::DataOutFuture<'a> { async move { let regs = T::regs(); diff --git a/embassy-stm32/src/usb_otg.rs b/embassy-stm32/src/usb_otg.rs index 0f732965..58175413 100644 --- a/embassy-stm32/src/usb_otg.rs +++ b/embassy-stm32/src/usb_otg.rs @@ -1,9 +1,10 @@ -use crate::Unborrow; use core::marker::PhantomData; + use embassy_hal_common::unborrow; use crate::gpio::sealed::AFType; -use crate::{peripherals, rcc::RccPeripheral}; +use crate::rcc::RccPeripheral; +use crate::{peripherals, Unborrow}; macro_rules! config_ulpi_pins { ($($pin:ident),*) => { @@ -76,8 +77,8 @@ impl<'d, T: Instance> UsbOtg<'d, T> { ulpi_d7: impl Unborrow> + 'd, ) -> Self { config_ulpi_pins!( - ulpi_clk, ulpi_dir, ulpi_nxt, ulpi_stp, ulpi_d0, ulpi_d1, ulpi_d2, ulpi_d3, ulpi_d4, - ulpi_d5, ulpi_d6, ulpi_d7 + ulpi_clk, ulpi_dir, ulpi_nxt, ulpi_stp, ulpi_d0, ulpi_d1, ulpi_d2, ulpi_d3, ulpi_d4, ulpi_d5, ulpi_d6, + ulpi_d7 ); Self { diff --git a/embassy-usb-hid/src/lib.rs b/embassy-usb-hid/src/lib.rs index a75cb8c3..b87f5748 100644 --- a/embassy-usb-hid/src/lib.rs +++ b/embassy-usb-hid/src/lib.rs @@ -12,13 +12,9 @@ use core::ops::Range; use core::sync::atomic::{AtomicUsize, Ordering}; use embassy::time::Duration; -use embassy_usb::driver::EndpointOut; -use embassy_usb::{ - control::{ControlHandler, InResponse, OutResponse, Request, RequestType}, - driver::{Driver, Endpoint, EndpointError, EndpointIn}, - Builder, -}; - +use embassy_usb::control::{ControlHandler, InResponse, OutResponse, Request, RequestType}; +use embassy_usb::driver::{Driver, Endpoint, EndpointError, EndpointIn, EndpointOut}; +use embassy_usb::Builder; #[cfg(feature = "usbd-hid")] use ssmarshal::serialize; #[cfg(feature = "usbd-hid")] @@ -145,9 +141,7 @@ fn build<'d, D: Driver<'d>>( (ep_out, ep_in, &state.out_report_offset) } -impl<'d, D: Driver<'d>, const READ_N: usize, const WRITE_N: usize> - HidReaderWriter<'d, D, READ_N, WRITE_N> -{ +impl<'d, D: Driver<'d>, const READ_N: usize, const WRITE_N: usize> HidReaderWriter<'d, D, READ_N, WRITE_N> { /// Creates a new HidReaderWriter. /// /// This will allocate one IN and one OUT endpoints. If you only need writing (sending) @@ -178,10 +172,7 @@ impl<'d, D: Driver<'d>, const READ_N: usize, const WRITE_N: usize> /// Writes an input report by serializing the given report structure. #[cfg(feature = "usbd-hid")] - pub async fn write_serialize( - &mut self, - r: &IR, - ) -> Result<(), EndpointError> { + pub async fn write_serialize(&mut self, r: &IR) -> Result<(), EndpointError> { self.writer.write_serialize(r).await } @@ -250,10 +241,7 @@ impl<'d, D: Driver<'d>, const N: usize> HidWriter<'d, D, N> { /// Writes an input report by serializing the given report structure. #[cfg(feature = "usbd-hid")] - pub async fn write_serialize( - &mut self, - r: &IR, - ) -> Result<(), EndpointError> { + pub async fn write_serialize(&mut self, r: &IR) -> Result<(), EndpointError> { let mut buf: [u8; N] = [0; N]; let size = match serialize(&mut buf, r) { Ok(size) => size, @@ -298,8 +286,12 @@ impl<'d, D: Driver<'d>, const N: usize> HidReader<'d, D, N> { match self.read(&mut buf).await { Ok(len) => { let id = if use_report_ids { buf[0] } else { 0 }; - handler.set_report(ReportId::Out(id), &buf[..len]); } - Err(ReadError::BufferOverflow) => warn!("Host sent output report larger than the configured maximum output report length ({})", N), + handler.set_report(ReportId::Out(id), &buf[..len]); + } + Err(ReadError::BufferOverflow) => warn!( + "Host sent output report larger than the configured maximum output report length ({})", + N + ), Err(ReadError::Disabled) => self.ep_out.wait_enabled().await, Err(ReadError::Sync(_)) => unreachable!(), } diff --git a/embassy-usb-ncm/src/lib.rs b/embassy-usb-ncm/src/lib.rs index 70870d51..e796af28 100644 --- a/embassy-usb-ncm/src/lib.rs +++ b/embassy-usb-ncm/src/lib.rs @@ -5,9 +5,11 @@ pub(crate) mod fmt; use core::intrinsics::copy_nonoverlapping; use core::mem::{size_of, MaybeUninit}; + use embassy_usb::control::{self, ControlHandler, InResponse, OutResponse, Request}; -use embassy_usb::driver::{Endpoint, EndpointError, EndpointIn, EndpointOut}; -use embassy_usb::{driver::Driver, types::*, Builder}; +use embassy_usb::driver::{Driver, Endpoint, EndpointError, EndpointIn, EndpointOut}; +use embassy_usb::types::*; +use embassy_usb::Builder; /// This should be used as `device_class` when building the `UsbDevice`. pub const USB_CLASS_CDC: u8 = 0x02; @@ -358,9 +360,7 @@ impl<'d, D: Driver<'d>> Sender<'d, D> { // First packet is not full, just send it. // No need to send ZLP because it's short for sure. buf[OUT_HEADER_LEN..][..data.len()].copy_from_slice(data); - self.write_ep - .write(&buf[..OUT_HEADER_LEN + data.len()]) - .await?; + self.write_ep.write(&buf[..OUT_HEADER_LEN + data.len()]).await?; } else { let (d1, d2) = data.split_at(MAX_PACKET_SIZE - OUT_HEADER_LEN); diff --git a/embassy-usb-serial/src/lib.rs b/embassy-usb-serial/src/lib.rs index 4587bf71..4d981e3f 100644 --- a/embassy-usb-serial/src/lib.rs +++ b/embassy-usb-serial/src/lib.rs @@ -8,10 +8,12 @@ pub(crate) mod fmt; use core::cell::Cell; use core::mem::{self, MaybeUninit}; use core::sync::atomic::{AtomicBool, Ordering}; + use embassy::blocking_mutex::CriticalSectionMutex; use embassy_usb::control::{self, ControlHandler, InResponse, OutResponse, Request}; -use embassy_usb::driver::{Endpoint, EndpointError, EndpointIn, EndpointOut}; -use embassy_usb::{driver::Driver, types::*, Builder}; +use embassy_usb::driver::{Driver, Endpoint, EndpointError, EndpointIn, EndpointOut}; +use embassy_usb::types::*; +use embassy_usb::Builder; /// This should be used as `device_class` when building the `UsbDevice`. pub const USB_CLASS_CDC: u8 = 0x02; @@ -162,14 +164,8 @@ impl<'d> ControlHandler for Control<'d> { impl<'d, D: Driver<'d>> CdcAcmClass<'d, D> { /// Creates a new CdcAcmClass with the provided UsbBus and max_packet_size in bytes. For /// full-speed devices, max_packet_size has to be one of 8, 16, 32 or 64. - pub fn new( - builder: &mut Builder<'d, D>, - state: &'d mut State<'d>, - max_packet_size: u16, - ) -> Self { - let control = state.control.write(Control { - shared: &state.shared, - }); + pub fn new(builder: &mut Builder<'d, D>, state: &'d mut State<'d>, max_packet_size: u16) -> Self { + let control = state.control.write(Control { shared: &state.shared }); let control_shared = &state.shared; diff --git a/embassy-usb/src/builder.rs b/embassy-usb/src/builder.rs index 09904949..1ca24cc0 100644 --- a/embassy-usb/src/builder.rs +++ b/embassy-usb/src/builder.rs @@ -1,14 +1,11 @@ use heapless::Vec; -use crate::{Interface, STRING_INDEX_CUSTOM_START}; - use super::control::ControlHandler; use super::descriptor::{BosWriter, DescriptorWriter}; use super::driver::{Driver, Endpoint}; use super::types::*; -use super::DeviceStateHandler; -use super::UsbDevice; -use super::MAX_INTERFACE_COUNT; +use super::{DeviceStateHandler, UsbDevice, MAX_INTERFACE_COUNT}; +use crate::{Interface, STRING_INDEX_CUSTOM_START}; #[derive(Debug, Copy, Clone)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] @@ -151,9 +148,7 @@ impl<'d, D: Driver<'d>> Builder<'d, D> { ) -> Self { // Magic values specified in USB-IF ECN on IADs. if config.composite_with_iads - && (config.device_class != 0xEF - || config.device_sub_class != 0x02 - || config.device_protocol != 0x01) + && (config.device_class != 0xEF || config.device_sub_class != 0x02 || config.device_protocol != 0x01) { panic!("if composite_with_iads is set, you must set device_class = 0xEF, device_sub_class = 0x02, device_protocol = 0x01"); } @@ -218,12 +213,7 @@ impl<'d, D: Driver<'d>> Builder<'d, D> { /// with the given class/subclass/protocol, associating all the child interfaces. /// /// If it's not set, no IAD descriptor is added. - pub fn function( - &mut self, - class: u8, - subclass: u8, - protocol: u8, - ) -> FunctionBuilder<'_, 'd, D> { + pub fn function(&mut self, class: u8, subclass: u8, protocol: u8) -> FunctionBuilder<'_, 'd, D> { let iface_count_index = if self.config.composite_with_iads { self.config_descriptor.iad( InterfaceNumber::new(self.interfaces.len() as _), @@ -315,24 +305,14 @@ impl<'a, 'd, D: Driver<'d>> InterfaceBuilder<'a, 'd, D> { /// Alternate setting numbers are guaranteed to be allocated consecutively, starting from 0. /// /// The first alternate setting, with number 0, is the default one. - pub fn alt_setting( - &mut self, - class: u8, - subclass: u8, - protocol: u8, - ) -> InterfaceAltBuilder<'_, 'd, D> { + pub fn alt_setting(&mut self, class: u8, subclass: u8, protocol: u8) -> InterfaceAltBuilder<'_, 'd, D> { let number = self.next_alt_setting_number; self.next_alt_setting_number += 1; self.builder.interfaces[self.interface_number.0 as usize].num_alt_settings += 1; - self.builder.config_descriptor.interface_alt( - self.interface_number, - number, - class, - subclass, - protocol, - None, - ); + self.builder + .config_descriptor + .interface_alt(self.interface_number, number, class, subclass, protocol, None); InterfaceAltBuilder { builder: self.builder, @@ -365,17 +345,10 @@ impl<'a, 'd, D: Driver<'d>> InterfaceAltBuilder<'a, 'd, D> { /// Descriptors are written in the order builder functions are called. Note that some /// classes care about the order. pub fn descriptor(&mut self, descriptor_type: u8, descriptor: &[u8]) { - self.builder - .config_descriptor - .write(descriptor_type, descriptor) + self.builder.config_descriptor.write(descriptor_type, descriptor) } - fn endpoint_in( - &mut self, - ep_type: EndpointType, - max_packet_size: u16, - interval: u8, - ) -> D::EndpointIn { + fn endpoint_in(&mut self, ep_type: EndpointType, max_packet_size: u16, interval: u8) -> D::EndpointIn { let ep = self .builder .driver @@ -387,12 +360,7 @@ impl<'a, 'd, D: Driver<'d>> InterfaceAltBuilder<'a, 'd, D> { ep } - fn endpoint_out( - &mut self, - ep_type: EndpointType, - max_packet_size: u16, - interval: u8, - ) -> D::EndpointOut { + fn endpoint_out(&mut self, ep_type: EndpointType, max_packet_size: u16, interval: u8) -> D::EndpointOut { let ep = self .builder .driver diff --git a/embassy-usb/src/descriptor.rs b/embassy-usb/src/descriptor.rs index 7f23fd92..b94a4b16 100644 --- a/embassy-usb/src/descriptor.rs +++ b/embassy-usb/src/descriptor.rs @@ -1,5 +1,6 @@ use super::builder::Config; -use super::{types::*, CONFIGURATION_VALUE}; +use super::types::*; +use super::CONFIGURATION_VALUE; /// Standard descriptor types #[allow(missing_docs)] @@ -113,11 +114,7 @@ impl<'a> DescriptorWriter<'a> { CONFIGURATION_VALUE, // bConfigurationValue 0, // iConfiguration 0x80 | if config.self_powered { 0x40 } else { 0x00 } - | if config.supports_remote_wakeup { - 0x20 - } else { - 0x00 - }, // bmAttributes + | if config.supports_remote_wakeup { 0x20 } else { 0x00 }, // bmAttributes (config.max_power / 2) as u8, // bMaxPower ], ) diff --git a/embassy-usb/src/driver.rs b/embassy-usb/src/driver.rs index 0680df7a..bfe44d62 100644 --- a/embassy-usb/src/driver.rs +++ b/embassy-usb/src/driver.rs @@ -161,18 +161,12 @@ pub trait ControlPipe { /// /// Must be called after `setup()` for requests with `direction` of `Out` /// and `length` greater than zero. - fn data_out<'a>( - &'a mut self, - buf: &'a mut [u8], - first: bool, - last: bool, - ) -> Self::DataOutFuture<'a>; + fn data_out<'a>(&'a mut self, buf: &'a mut [u8], first: bool, last: bool) -> Self::DataOutFuture<'a>; /// Sends a DATA IN packet with `data` in response to a control read request. /// /// If `last_packet` is true, the STATUS packet will be ACKed following the transfer of `data`. - fn data_in<'a>(&'a mut self, data: &'a [u8], first: bool, last: bool) - -> Self::DataInFuture<'a>; + fn data_in<'a>(&'a mut self, data: &'a [u8], first: bool, last: bool) -> Self::DataInFuture<'a>; /// Accepts a control request. /// diff --git a/embassy-usb/src/lib.rs b/embassy-usb/src/lib.rs index b691bf11..f2577d4f 100644 --- a/embassy-usb/src/lib.rs +++ b/embassy-usb/src/lib.rs @@ -15,16 +15,13 @@ pub mod types; use embassy::util::{select, Either}; use heapless::Vec; -use crate::descriptor_reader::foreach_endpoint; -use crate::driver::ControlPipe; - +pub use self::builder::{Builder, Config}; use self::control::*; use self::descriptor::*; use self::driver::{Bus, Driver, Event}; use self::types::*; - -pub use self::builder::Builder; -pub use self::builder::Config; +use crate::descriptor_reader::foreach_endpoint; +use crate::driver::ControlPipe; /// The global state of the USB device. /// @@ -418,10 +415,8 @@ impl<'d, D: Driver<'d>> Inner<'d, D> { // Enable all endpoints of selected alt settings. foreach_endpoint(self.config_descriptor, |ep| { let iface = &self.interfaces[ep.interface as usize]; - self.bus.endpoint_set_enabled( - ep.ep_address, - iface.current_alt_setting == ep.interface_alt, - ); + self.bus + .endpoint_set_enabled(ep.ep_address, iface.current_alt_setting == ep.interface_alt); }) .unwrap(); @@ -474,10 +469,8 @@ impl<'d, D: Driver<'d>> Inner<'d, D> { // Enable/disable EPs of this interface as needed. foreach_endpoint(self.config_descriptor, |ep| { if ep.interface == req.index as u8 { - self.bus.endpoint_set_enabled( - ep.ep_address, - iface.current_alt_setting == ep.interface_alt, - ); + self.bus + .endpoint_set_enabled(ep.ep_address, iface.current_alt_setting == ep.interface_alt); } }) .unwrap(); diff --git a/embassy/src/blocking_mutex/mod.rs b/embassy/src/blocking_mutex/mod.rs index 859eca07..eb3cd939 100644 --- a/embassy/src/blocking_mutex/mod.rs +++ b/embassy/src/blocking_mutex/mod.rs @@ -2,9 +2,10 @@ pub mod raw; -use self::raw::RawMutex; use core::cell::UnsafeCell; +use self::raw::RawMutex; + /// Any object implementing this trait guarantees exclusive access to the data contained /// within the mutex for the duration of the lock. /// Adapted from . diff --git a/embassy/src/blocking_mutex/raw.rs b/embassy/src/blocking_mutex/raw.rs index ebeb6dcc..f9d249b0 100644 --- a/embassy/src/blocking_mutex/raw.rs +++ b/embassy/src/blocking_mutex/raw.rs @@ -14,9 +14,7 @@ unsafe impl Sync for CriticalSectionRawMutex {} impl CriticalSectionRawMutex { pub const fn new() -> Self { - Self { - _phantom: PhantomData, - } + Self { _phantom: PhantomData } } } @@ -38,9 +36,7 @@ unsafe impl Send for NoopRawMutex {} impl NoopRawMutex { pub const fn new() -> Self { - Self { - _phantom: PhantomData, - } + Self { _phantom: PhantomData } } } @@ -66,19 +62,14 @@ mod thread_mode { impl ThreadModeRawMutex { pub const fn new() -> Self { - Self { - _phantom: PhantomData, - } + Self { _phantom: PhantomData } } } impl RawMutex for ThreadModeRawMutex { const INIT: Self = Self::new(); fn lock(&self, f: impl FnOnce() -> R) -> R { - assert!( - in_thread_mode(), - "ThreadModeMutex can only be locked from thread mode." - ); + assert!(in_thread_mode(), "ThreadModeMutex can only be locked from thread mode."); f() } @@ -104,8 +95,7 @@ mod thread_mode { return Some("main") == std::thread::current().name(); #[cfg(not(feature = "std"))] - return cortex_m::peripheral::SCB::vect_active() - == cortex_m::peripheral::scb::VectActive::ThreadMode; + return cortex_m::peripheral::SCB::vect_active() == cortex_m::peripheral::scb::VectActive::ThreadMode; } } #[cfg(any(cortex_m, feature = "std"))] diff --git a/embassy/src/channel/mpmc.rs b/embassy/src/channel/mpmc.rs index 2377a966..48056cd8 100644 --- a/embassy/src/channel/mpmc.rs +++ b/embassy/src/channel/mpmc.rs @@ -20,8 +20,7 @@ use core::cell::RefCell; use core::pin::Pin; -use core::task::Context; -use core::task::Poll; +use core::task::{Context, Poll}; use futures::Future; use heapless::Deque; @@ -44,9 +43,7 @@ where M: RawMutex, { fn clone(&self) -> Self { - Sender { - channel: self.channel, - } + Sender { channel: self.channel } } } @@ -77,9 +74,7 @@ pub struct DynamicSender<'ch, T> { impl<'ch, T> Clone for DynamicSender<'ch, T> { fn clone(&self) -> Self { - DynamicSender { - channel: self.channel, - } + DynamicSender { channel: self.channel } } } @@ -125,9 +120,7 @@ where M: RawMutex, { fn clone(&self) -> Self { - Receiver { - channel: self.channel, - } + Receiver { channel: self.channel } } } @@ -158,9 +151,7 @@ pub struct DynamicReceiver<'ch, T> { impl<'ch, T> Clone for DynamicReceiver<'ch, T> { fn clone(&self) -> Self { - DynamicReceiver { - channel: self.channel, - } + DynamicReceiver { channel: self.channel } } } @@ -169,9 +160,7 @@ impl<'ch, T> DynamicReceiver<'ch, T> { /// /// See [`Channel::recv()`]. pub fn recv(&self) -> DynamicRecvFuture<'_, T> { - DynamicRecvFuture { - channel: self.channel, - } + DynamicRecvFuture { channel: self.channel } } /// Attempt to immediately receive the next value. @@ -282,11 +271,7 @@ impl<'ch, T> Future for DynamicSendFuture<'ch, T> { impl<'ch, T> Unpin for DynamicSendFuture<'ch, T> {} trait DynamicChannel { - fn try_send_with_context( - &self, - message: T, - cx: Option<&mut Context<'_>>, - ) -> Result<(), TrySendError>; + fn try_send_with_context(&self, message: T, cx: Option<&mut Context<'_>>) -> Result<(), TrySendError>; fn try_recv_with_context(&self, cx: Option<&mut Context<'_>>) -> Result; } @@ -346,11 +331,7 @@ impl ChannelState { self.try_send_with_context(message, None) } - fn try_send_with_context( - &mut self, - message: T, - cx: Option<&mut Context<'_>>, - ) -> Result<(), TrySendError> { + fn try_send_with_context(&mut self, message: T, cx: Option<&mut Context<'_>>) -> Result<(), TrySendError> { match self.queue.push_back(message) { Ok(()) => { self.receiver_waker.wake(); @@ -425,11 +406,7 @@ where self.lock(|c| c.try_recv_with_context(cx)) } - fn try_send_with_context( - &self, - m: T, - cx: Option<&mut Context<'_>>, - ) -> Result<(), TrySendError> { + fn try_send_with_context(&self, m: T, cx: Option<&mut Context<'_>>) -> Result<(), TrySendError> { self.lock(|c| c.try_send_with_context(m, cx)) } @@ -491,11 +468,7 @@ impl DynamicChannel for Channel where M: RawMutex, { - fn try_send_with_context( - &self, - m: T, - cx: Option<&mut Context<'_>>, - ) -> Result<(), TrySendError> { + fn try_send_with_context(&self, m: T, cx: Option<&mut Context<'_>>) -> Result<(), TrySendError> { Channel::try_send_with_context(self, m, cx) } @@ -512,11 +485,10 @@ mod tests { use futures_executor::ThreadPool; use futures_timer::Delay; + use super::*; use crate::blocking_mutex::raw::{CriticalSectionRawMutex, NoopRawMutex}; use crate::util::Forever; - use super::*; - fn capacity(c: &ChannelState) -> usize { c.queue.capacity() - c.queue.len() } diff --git a/embassy/src/executor/arch/wasm.rs b/embassy/src/executor/arch/wasm.rs index f069ebc3..9d5aa31e 100644 --- a/embassy/src/executor/arch/wasm.rs +++ b/embassy/src/executor/arch/wasm.rs @@ -1,11 +1,11 @@ use core::marker::PhantomData; + use js_sys::Promise; use wasm_bindgen::prelude::*; -use super::{ - raw::{self, util::UninitCell}, - Spawner, -}; +use super::raw::util::UninitCell; +use super::raw::{self}; +use super::Spawner; /// WASM executor, wasm_bindgen to schedule tasks on the JS event loop. pub struct Executor { diff --git a/embassy/src/executor/raw/mod.rs b/embassy/src/executor/raw/mod.rs index 5034c0d6..09429c19 100644 --- a/embassy/src/executor/raw/mod.rs +++ b/embassy/src/executor/raw/mod.rs @@ -13,25 +13,25 @@ mod timer_queue; pub(crate) mod util; mod waker; -use atomic_polyfill::{AtomicU32, Ordering}; use core::cell::Cell; use core::future::Future; use core::pin::Pin; use core::ptr::NonNull; use core::task::{Context, Poll}; use core::{mem, ptr}; + +use atomic_polyfill::{AtomicU32, Ordering}; use critical_section::CriticalSection; use self::run_queue::{RunQueue, RunQueueItem}; use self::util::UninitCell; +pub use self::waker::task_from_waker; use super::SpawnToken; #[cfg(feature = "time")] use crate::time::driver::{self, AlarmHandle}; #[cfg(feature = "time")] use crate::time::Instant; -pub use self::waker::task_from_waker; - /// Task is spawned (has a future) pub(crate) const STATE_SPAWNED: u32 = 1 << 0; /// Task is in the executor run queue @@ -97,8 +97,7 @@ impl TaskHeader { } // Mark it as scheduled - self.state - .store(state | STATE_RUN_QUEUED, Ordering::Relaxed); + self.state.store(state | STATE_RUN_QUEUED, Ordering::Relaxed); // We have just marked the task as scheduled, so enqueue it. let executor = &*self.executor.get(); diff --git a/embassy/src/executor/raw/run_queue.rs b/embassy/src/executor/raw/run_queue.rs index 7aa2079f..31615da7 100644 --- a/embassy/src/executor/raw/run_queue.rs +++ b/embassy/src/executor/raw/run_queue.rs @@ -1,6 +1,7 @@ -use atomic_polyfill::{AtomicPtr, Ordering}; use core::ptr; use core::ptr::NonNull; + +use atomic_polyfill::{AtomicPtr, Ordering}; use critical_section::CriticalSection; use super::TaskHeader; @@ -63,10 +64,7 @@ impl RunQueue { while let Some(task) = NonNull::new(ptr) { // If the task re-enqueues itself, the `next` pointer will get overwritten. // Therefore, first read the next pointer, and only then process the task. - let next = unsafe { task.as_ref() } - .run_queue_item - .next - .load(Ordering::Relaxed); + let next = unsafe { task.as_ref() }.run_queue_item.next.load(Ordering::Relaxed); on_task(task); diff --git a/embassy/src/executor/raw/timer_queue.rs b/embassy/src/executor/raw/timer_queue.rs index e96910bb..62fcfc53 100644 --- a/embassy/src/executor/raw/timer_queue.rs +++ b/embassy/src/executor/raw/timer_queue.rs @@ -1,9 +1,10 @@ -use atomic_polyfill::Ordering; use core::cell::Cell; use core::cmp::min; use core::ptr; use core::ptr::NonNull; +use atomic_polyfill::Ordering; + use super::{TaskHeader, STATE_TIMER_QUEUED}; use crate::time::Instant; @@ -54,11 +55,7 @@ impl TimerQueue { res } - pub(crate) unsafe fn dequeue_expired( - &self, - now: Instant, - on_task: impl Fn(NonNull), - ) { + pub(crate) unsafe fn dequeue_expired(&self, now: Instant, on_task: impl Fn(NonNull)) { self.retain(|p| { let task = p.as_ref(); if task.expires_at.get() <= now { diff --git a/embassy/src/executor/spawner.rs b/embassy/src/executor/spawner.rs index 73c1f786..884db6b5 100644 --- a/embassy/src/executor/spawner.rs +++ b/embassy/src/executor/spawner.rs @@ -2,6 +2,7 @@ use core::marker::PhantomData; use core::mem; use core::ptr::NonNull; use core::task::Poll; + use futures::future::poll_fn; use super::raw; diff --git a/embassy/src/lib.rs b/embassy/src/lib.rs index 5cfd18db..1b6ff2d4 100644 --- a/embassy/src/lib.rs +++ b/embassy/src/lib.rs @@ -1,8 +1,5 @@ #![cfg_attr(not(any(feature = "std", feature = "wasm")), no_std)] -#![cfg_attr( - feature = "nightly", - feature(generic_associated_types, type_alias_impl_trait) -)] +#![cfg_attr(feature = "nightly", feature(generic_associated_types, type_alias_impl_trait))] #![allow(clippy::new_without_default)] // This mod MUST go first, so that the others see its macros. diff --git a/embassy/src/mutex.rs b/embassy/src/mutex.rs index 27353bd4..7b6bcb14 100644 --- a/embassy/src/mutex.rs +++ b/embassy/src/mutex.rs @@ -7,6 +7,7 @@ use core::cell::{RefCell, UnsafeCell}; use core::ops::{Deref, DerefMut}; use core::task::Poll; + use futures::future::poll_fn; use crate::blocking_mutex::raw::RawMutex; diff --git a/embassy/src/time/delay.rs b/embassy/src/time/delay.rs index 06ed8ec4..83a895e9 100644 --- a/embassy/src/time/delay.rs +++ b/embassy/src/time/delay.rs @@ -56,9 +56,10 @@ cfg_if::cfg_if! { } mod eh02 { - use super::*; use embedded_hal_02::blocking::delay::{DelayMs, DelayUs}; + use super::*; + impl DelayMs for Delay { fn delay_ms(&mut self, ms: u8) { block_for(Duration::from_millis(ms as u64)) diff --git a/embassy/src/time/driver_std.rs b/embassy/src/time/driver_std.rs index 0b5c6f85..cb66f7c1 100644 --- a/embassy/src/time/driver_std.rs +++ b/embassy/src/time/driver_std.rs @@ -1,11 +1,10 @@ -use atomic_polyfill::{AtomicU8, Ordering}; use std::cell::UnsafeCell; -use std::mem; use std::mem::MaybeUninit; use std::sync::{Condvar, Mutex, Once}; -use std::time::Duration as StdDuration; -use std::time::Instant as StdInstant; -use std::{ptr, thread}; +use std::time::{Duration as StdDuration, Instant as StdInstant}; +use std::{mem, ptr, thread}; + +use atomic_polyfill::{AtomicU8, Ordering}; use crate::time::driver::{AlarmHandle, Driver}; @@ -106,15 +105,13 @@ impl Driver for TimeDriver { } unsafe fn allocate_alarm(&self) -> Option { - let id = self - .alarm_count - .fetch_update(Ordering::AcqRel, Ordering::Acquire, |x| { - if x < ALARM_COUNT as u8 { - Some(x + 1) - } else { - None - } - }); + let id = self.alarm_count.fetch_update(Ordering::AcqRel, Ordering::Acquire, |x| { + if x < ALARM_COUNT as u8 { + Some(x + 1) + } else { + None + } + }); match id { Ok(id) => Some(AlarmHandle::new(id)), diff --git a/embassy/src/time/driver_wasm.rs b/embassy/src/time/driver_wasm.rs index 0a927082..5f585a19 100644 --- a/embassy/src/time/driver_wasm.rs +++ b/embassy/src/time/driver_wasm.rs @@ -1,8 +1,9 @@ -use atomic_polyfill::{AtomicU8, Ordering}; use std::cell::UnsafeCell; use std::mem::MaybeUninit; use std::ptr; use std::sync::{Mutex, Once}; + +use atomic_polyfill::{AtomicU8, Ordering}; use wasm_bindgen::prelude::*; use wasm_timer::Instant as StdInstant; @@ -66,15 +67,13 @@ impl Driver for TimeDriver { } unsafe fn allocate_alarm(&self) -> Option { - let id = self - .alarm_count - .fetch_update(Ordering::AcqRel, Ordering::Acquire, |x| { - if x < ALARM_COUNT as u8 { - Some(x + 1) - } else { - None - } - }); + let id = self.alarm_count.fetch_update(Ordering::AcqRel, Ordering::Acquire, |x| { + if x < ALARM_COUNT as u8 { + Some(x + 1) + } else { + None + } + }); match id { Ok(id) => Some(AlarmHandle::new(id)), diff --git a/embassy/src/time/duration.rs b/embassy/src/time/duration.rs index 47b413f4..d35c2b65 100644 --- a/embassy/src/time/duration.rs +++ b/embassy/src/time/duration.rs @@ -65,30 +65,22 @@ impl Duration { /// Adds one Duration to another, returning a new Duration or None in the event of an overflow. pub fn checked_add(self, rhs: Duration) -> Option { - self.ticks - .checked_add(rhs.ticks) - .map(|ticks| Duration { ticks }) + self.ticks.checked_add(rhs.ticks).map(|ticks| Duration { ticks }) } /// Subtracts one Duration to another, returning a new Duration or None in the event of an overflow. pub fn checked_sub(self, rhs: Duration) -> Option { - self.ticks - .checked_sub(rhs.ticks) - .map(|ticks| Duration { ticks }) + self.ticks.checked_sub(rhs.ticks).map(|ticks| Duration { ticks }) } /// Multiplies one Duration by a scalar u32, returning a new Duration or None in the event of an overflow. pub fn checked_mul(self, rhs: u32) -> Option { - self.ticks - .checked_mul(rhs as _) - .map(|ticks| Duration { ticks }) + self.ticks.checked_mul(rhs as _).map(|ticks| Duration { ticks }) } /// Divides one Duration a scalar u32, returning a new Duration or None in the event of an overflow. pub fn checked_div(self, rhs: u32) -> Option { - self.ticks - .checked_div(rhs as _) - .map(|ticks| Duration { ticks }) + self.ticks.checked_div(rhs as _).map(|ticks| Duration { ticks }) } } @@ -96,8 +88,7 @@ impl Add for Duration { type Output = Duration; fn add(self, rhs: Duration) -> Duration { - self.checked_add(rhs) - .expect("overflow when adding durations") + self.checked_add(rhs).expect("overflow when adding durations") } } @@ -111,8 +102,7 @@ impl Sub for Duration { type Output = Duration; fn sub(self, rhs: Duration) -> Duration { - self.checked_sub(rhs) - .expect("overflow when subtracting durations") + self.checked_sub(rhs).expect("overflow when subtracting durations") } } diff --git a/embassy/src/time/instant.rs b/embassy/src/time/instant.rs index 71adbeb3..6a4925f4 100644 --- a/embassy/src/time/instant.rs +++ b/embassy/src/time/instant.rs @@ -18,9 +18,7 @@ impl Instant { /// Returns an Instant representing the current time. pub fn now() -> Instant { - Instant { - ticks: driver::now(), - } + Instant { ticks: driver::now() } } /// Create an Instant from a tick count since system boot. @@ -107,16 +105,12 @@ impl Instant { /// Adds one Duration to self, returning a new `Instant` or None in the event of an overflow. pub fn checked_add(&self, duration: Duration) -> Option { - self.ticks - .checked_add(duration.ticks) - .map(|ticks| Instant { ticks }) + self.ticks.checked_add(duration.ticks).map(|ticks| Instant { ticks }) } /// Subtracts one Duration to self, returning a new `Instant` or None in the event of an overflow. pub fn checked_sub(&self, duration: Duration) -> Option { - self.ticks - .checked_sub(duration.ticks) - .map(|ticks| Instant { ticks }) + self.ticks.checked_sub(duration.ticks).map(|ticks| Instant { ticks }) } } diff --git a/embassy/src/time/timer.rs b/embassy/src/time/timer.rs index 1b3832f3..2194a4b1 100644 --- a/embassy/src/time/timer.rs +++ b/embassy/src/time/timer.rs @@ -1,7 +1,9 @@ use core::future::Future; use core::pin::Pin; use core::task::{Context, Poll}; -use futures::{future::select, future::Either, pin_mut, Stream}; + +use futures::future::{select, Either}; +use futures::{pin_mut, Stream}; use crate::executor::raw; use crate::time::{Duration, Instant}; @@ -128,10 +130,7 @@ impl Ticker { /// Creates a new ticker that ticks at the specified duration interval. pub fn every(duration: Duration) -> Self { let expires_at = Instant::now() + duration; - Self { - expires_at, - duration, - } + Self { expires_at, duration } } } diff --git a/embassy/src/waitqueue/waker.rs b/embassy/src/waitqueue/waker.rs index 9eddbdaa..1ac6054f 100644 --- a/embassy/src/waitqueue/waker.rs +++ b/embassy/src/waitqueue/waker.rs @@ -1,7 +1,8 @@ -use atomic_polyfill::{compiler_fence, AtomicPtr, Ordering}; use core::ptr::{self, NonNull}; use core::task::Waker; +use atomic_polyfill::{compiler_fence, AtomicPtr, Ordering}; + use crate::executor::raw::{task_from_waker, wake_task, TaskHeader}; /// Utility struct to register and wake a waker. diff --git a/examples/boot/nrf/src/bin/a.rs b/examples/boot/nrf/src/bin/a.rs index d45d0ff3..0b9715e4 100644 --- a/examples/boot/nrf/src/bin/a.rs +++ b/examples/boot/nrf/src/bin/a.rs @@ -6,12 +6,9 @@ use embassy_boot_nrf::FirmwareUpdater; use embassy_embedded_hal::adapter::BlockingAsync; -use embassy_nrf::{ - gpio::{Input, Pull}, - gpio::{Level, Output, OutputDrive}, - nvmc::Nvmc, - Peripherals, -}; +use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pull}; +use embassy_nrf::nvmc::Nvmc; +use embassy_nrf::Peripherals; use panic_reset as _; static APP_B: &[u8] = include_bytes!("../../b.bin"); @@ -35,10 +32,7 @@ async fn main(_s: embassy::executor::Spawner, p: Peripherals) { for chunk in APP_B.chunks(4096) { let mut buf: [u8; 4096] = [0; 4096]; buf[..chunk.len()].copy_from_slice(chunk); - updater - .write_firmware(offset, &buf, &mut nvmc, 4096) - .await - .unwrap(); + updater.write_firmware(offset, &buf, &mut nvmc, 4096).await.unwrap(); offset += chunk.len(); } updater.update(&mut nvmc).await.unwrap(); diff --git a/examples/boot/nrf/src/bin/b.rs b/examples/boot/nrf/src/bin/b.rs index 18bb6330..a06c20f8 100644 --- a/examples/boot/nrf/src/bin/b.rs +++ b/examples/boot/nrf/src/bin/b.rs @@ -5,11 +5,8 @@ #![feature(type_alias_impl_trait)] use embassy::time::{Duration, Timer}; -use embassy_nrf::{ - gpio::{Level, Output, OutputDrive}, - Peripherals, -}; - +use embassy_nrf::gpio::{Level, Output, OutputDrive}; +use embassy_nrf::Peripherals; use panic_reset as _; #[embassy::main] diff --git a/examples/boot/stm32f3/src/bin/a.rs b/examples/boot/stm32f3/src/bin/a.rs index 9ad79838..4ff18d7c 100644 --- a/examples/boot/stm32f3/src/bin/a.rs +++ b/examples/boot/stm32f3/src/bin/a.rs @@ -2,6 +2,8 @@ #![no_main] #![feature(type_alias_impl_trait)] +#[cfg(feature = "defmt-rtt")] +use defmt_rtt::*; use embassy_boot_stm32::FirmwareUpdater; use embassy_embedded_hal::adapter::BlockingAsync; use embassy_stm32::exti::ExtiInput; @@ -10,9 +12,6 @@ use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; use embassy_stm32::Peripherals; use panic_reset as _; -#[cfg(feature = "defmt-rtt")] -use defmt_rtt::*; - static APP_B: &[u8] = include_bytes!("../../b.bin"); #[embassy::main] @@ -32,10 +31,7 @@ async fn main(_s: embassy::executor::Spawner, p: Peripherals) { for chunk in APP_B.chunks(2048) { let mut buf: [u8; 2048] = [0; 2048]; buf[..chunk.len()].copy_from_slice(chunk); - updater - .write_firmware(offset, &buf, &mut flash, 2048) - .await - .unwrap(); + updater.write_firmware(offset, &buf, &mut flash, 2048).await.unwrap(); offset += chunk.len(); } updater.update(&mut flash).await.unwrap(); diff --git a/examples/boot/stm32f3/src/bin/b.rs b/examples/boot/stm32f3/src/bin/b.rs index 81427598..4487e586 100644 --- a/examples/boot/stm32f3/src/bin/b.rs +++ b/examples/boot/stm32f3/src/bin/b.rs @@ -2,15 +2,14 @@ #![no_main] #![feature(type_alias_impl_trait)] +#[cfg(feature = "defmt-rtt")] +use defmt_rtt::*; use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; use embassy_stm32::gpio::{Level, Output, Speed}; use embassy_stm32::Peripherals; use panic_reset as _; -#[cfg(feature = "defmt-rtt")] -use defmt_rtt::*; - #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { let mut led = Output::new(p.PA5, Level::High, Speed::Low); diff --git a/examples/boot/stm32f7/src/bin/a.rs b/examples/boot/stm32f7/src/bin/a.rs index b4f49d57..9c7921a1 100644 --- a/examples/boot/stm32f7/src/bin/a.rs +++ b/examples/boot/stm32f7/src/bin/a.rs @@ -2,6 +2,8 @@ #![no_main] #![feature(type_alias_impl_trait)] +#[cfg(feature = "defmt-rtt")] +use defmt_rtt::*; use embassy_boot_stm32::FirmwareUpdater; use embassy_embedded_hal::adapter::BlockingAsync; use embassy_stm32::exti::ExtiInput; @@ -10,9 +12,6 @@ use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; use embassy_stm32::Peripherals; use panic_reset as _; -#[cfg(feature = "defmt-rtt")] -use defmt_rtt::*; - static APP_B: &[u8] = include_bytes!("../../b.bin"); #[embassy::main] @@ -32,10 +31,7 @@ async fn main(_s: embassy::executor::Spawner, p: Peripherals) { let mut buf: [u8; 256 * 1024] = [0; 256 * 1024]; for chunk in APP_B.chunks(256 * 1024) { buf[..chunk.len()].copy_from_slice(chunk); - updater - .write_firmware(offset, &buf, &mut flash, 2048) - .await - .unwrap(); + updater.write_firmware(offset, &buf, &mut flash, 2048).await.unwrap(); offset += chunk.len(); } updater.update(&mut flash).await.unwrap(); diff --git a/examples/boot/stm32f7/src/bin/b.rs b/examples/boot/stm32f7/src/bin/b.rs index ed37137f..aa05bbcd 100644 --- a/examples/boot/stm32f7/src/bin/b.rs +++ b/examples/boot/stm32f7/src/bin/b.rs @@ -2,15 +2,14 @@ #![no_main] #![feature(type_alias_impl_trait)] +#[cfg(feature = "defmt-rtt")] +use defmt_rtt::*; use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; use embassy_stm32::gpio::{Level, Output, Speed}; use embassy_stm32::Peripherals; use panic_reset as _; -#[cfg(feature = "defmt-rtt")] -use defmt_rtt::*; - #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { Timer::after(Duration::from_millis(300)).await; diff --git a/examples/boot/stm32h7/src/bin/a.rs b/examples/boot/stm32h7/src/bin/a.rs index 1d196e8a..704979db 100644 --- a/examples/boot/stm32h7/src/bin/a.rs +++ b/examples/boot/stm32h7/src/bin/a.rs @@ -2,6 +2,8 @@ #![no_main] #![feature(type_alias_impl_trait)] +#[cfg(feature = "defmt-rtt")] +use defmt_rtt::*; use embassy_boot_stm32::FirmwareUpdater; use embassy_embedded_hal::adapter::BlockingAsync; use embassy_stm32::exti::ExtiInput; @@ -10,9 +12,6 @@ use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; use embassy_stm32::Peripherals; use panic_reset as _; -#[cfg(feature = "defmt-rtt")] -use defmt_rtt::*; - static APP_B: &[u8] = include_bytes!("../../b.bin"); #[embassy::main] @@ -32,10 +31,7 @@ async fn main(_s: embassy::executor::Spawner, p: Peripherals) { let mut buf: [u8; 128 * 1024] = [0; 128 * 1024]; for chunk in APP_B.chunks(128 * 1024) { buf[..chunk.len()].copy_from_slice(chunk); - updater - .write_firmware(offset, &buf, &mut flash, 2048) - .await - .unwrap(); + updater.write_firmware(offset, &buf, &mut flash, 2048).await.unwrap(); offset += chunk.len(); } updater.update(&mut flash).await.unwrap(); diff --git a/examples/boot/stm32h7/src/bin/b.rs b/examples/boot/stm32h7/src/bin/b.rs index 233b93e1..ea014025 100644 --- a/examples/boot/stm32h7/src/bin/b.rs +++ b/examples/boot/stm32h7/src/bin/b.rs @@ -2,15 +2,14 @@ #![no_main] #![feature(type_alias_impl_trait)] +#[cfg(feature = "defmt-rtt")] +use defmt_rtt::*; use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; use embassy_stm32::gpio::{Level, Output, Speed}; use embassy_stm32::Peripherals; use panic_reset as _; -#[cfg(feature = "defmt-rtt")] -use defmt_rtt::*; - #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { Timer::after(Duration::from_millis(300)).await; diff --git a/examples/boot/stm32l0/src/bin/a.rs b/examples/boot/stm32l0/src/bin/a.rs index d4b252bf..ce620347 100644 --- a/examples/boot/stm32l0/src/bin/a.rs +++ b/examples/boot/stm32l0/src/bin/a.rs @@ -2,6 +2,8 @@ #![no_main] #![feature(type_alias_impl_trait)] +#[cfg(feature = "defmt-rtt")] +use defmt_rtt::*; use embassy::time::{Duration, Timer}; use embassy_boot_stm32::FirmwareUpdater; use embassy_embedded_hal::adapter::BlockingAsync; @@ -11,9 +13,6 @@ use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; use embassy_stm32::Peripherals; use panic_reset as _; -#[cfg(feature = "defmt-rtt")] -use defmt_rtt::*; - static APP_B: &[u8] = include_bytes!("../../b.bin"); #[embassy::main] @@ -34,10 +33,7 @@ async fn main(_s: embassy::executor::Spawner, p: Peripherals) { for chunk in APP_B.chunks(128) { let mut buf: [u8; 128] = [0; 128]; buf[..chunk.len()].copy_from_slice(chunk); - updater - .write_firmware(offset, &buf, &mut flash, 128) - .await - .unwrap(); + updater.write_firmware(offset, &buf, &mut flash, 128).await.unwrap(); offset += chunk.len(); } diff --git a/examples/boot/stm32l0/src/bin/b.rs b/examples/boot/stm32l0/src/bin/b.rs index ed774fd7..0b585a14 100644 --- a/examples/boot/stm32l0/src/bin/b.rs +++ b/examples/boot/stm32l0/src/bin/b.rs @@ -2,15 +2,14 @@ #![no_main] #![feature(type_alias_impl_trait)] +#[cfg(feature = "defmt-rtt")] +use defmt_rtt::*; use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; use embassy_stm32::gpio::{Level, Output, Speed}; use embassy_stm32::Peripherals; use panic_reset as _; -#[cfg(feature = "defmt-rtt")] -use defmt_rtt::*; - #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { let mut led = Output::new(p.PB6, Level::High, Speed::Low); diff --git a/examples/boot/stm32l1/src/bin/a.rs b/examples/boot/stm32l1/src/bin/a.rs index d4b252bf..ce620347 100644 --- a/examples/boot/stm32l1/src/bin/a.rs +++ b/examples/boot/stm32l1/src/bin/a.rs @@ -2,6 +2,8 @@ #![no_main] #![feature(type_alias_impl_trait)] +#[cfg(feature = "defmt-rtt")] +use defmt_rtt::*; use embassy::time::{Duration, Timer}; use embassy_boot_stm32::FirmwareUpdater; use embassy_embedded_hal::adapter::BlockingAsync; @@ -11,9 +13,6 @@ use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; use embassy_stm32::Peripherals; use panic_reset as _; -#[cfg(feature = "defmt-rtt")] -use defmt_rtt::*; - static APP_B: &[u8] = include_bytes!("../../b.bin"); #[embassy::main] @@ -34,10 +33,7 @@ async fn main(_s: embassy::executor::Spawner, p: Peripherals) { for chunk in APP_B.chunks(128) { let mut buf: [u8; 128] = [0; 128]; buf[..chunk.len()].copy_from_slice(chunk); - updater - .write_firmware(offset, &buf, &mut flash, 128) - .await - .unwrap(); + updater.write_firmware(offset, &buf, &mut flash, 128).await.unwrap(); offset += chunk.len(); } diff --git a/examples/boot/stm32l1/src/bin/b.rs b/examples/boot/stm32l1/src/bin/b.rs index ed774fd7..0b585a14 100644 --- a/examples/boot/stm32l1/src/bin/b.rs +++ b/examples/boot/stm32l1/src/bin/b.rs @@ -2,15 +2,14 @@ #![no_main] #![feature(type_alias_impl_trait)] +#[cfg(feature = "defmt-rtt")] +use defmt_rtt::*; use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; use embassy_stm32::gpio::{Level, Output, Speed}; use embassy_stm32::Peripherals; use panic_reset as _; -#[cfg(feature = "defmt-rtt")] -use defmt_rtt::*; - #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { let mut led = Output::new(p.PB6, Level::High, Speed::Low); diff --git a/examples/boot/stm32l4/src/bin/a.rs b/examples/boot/stm32l4/src/bin/a.rs index 23b1d98b..bf609935 100644 --- a/examples/boot/stm32l4/src/bin/a.rs +++ b/examples/boot/stm32l4/src/bin/a.rs @@ -2,6 +2,8 @@ #![no_main] #![feature(type_alias_impl_trait)] +#[cfg(feature = "defmt-rtt")] +use defmt_rtt::*; use embassy_boot_stm32::FirmwareUpdater; use embassy_embedded_hal::adapter::BlockingAsync; use embassy_stm32::exti::ExtiInput; @@ -10,9 +12,6 @@ use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; use embassy_stm32::Peripherals; use panic_reset as _; -#[cfg(feature = "defmt-rtt")] -use defmt_rtt::*; - static APP_B: &[u8] = include_bytes!("../../b.bin"); #[embassy::main] @@ -32,10 +31,7 @@ async fn main(_s: embassy::executor::Spawner, p: Peripherals) { for chunk in APP_B.chunks(2048) { let mut buf: [u8; 2048] = [0; 2048]; buf[..chunk.len()].copy_from_slice(chunk); - updater - .write_firmware(offset, &buf, &mut flash, 2048) - .await - .unwrap(); + updater.write_firmware(offset, &buf, &mut flash, 2048).await.unwrap(); offset += chunk.len(); } updater.update(&mut flash).await.unwrap(); diff --git a/examples/boot/stm32l4/src/bin/b.rs b/examples/boot/stm32l4/src/bin/b.rs index 81427598..4487e586 100644 --- a/examples/boot/stm32l4/src/bin/b.rs +++ b/examples/boot/stm32l4/src/bin/b.rs @@ -2,15 +2,14 @@ #![no_main] #![feature(type_alias_impl_trait)] +#[cfg(feature = "defmt-rtt")] +use defmt_rtt::*; use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; use embassy_stm32::gpio::{Level, Output, Speed}; use embassy_stm32::Peripherals; use panic_reset as _; -#[cfg(feature = "defmt-rtt")] -use defmt_rtt::*; - #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { let mut led = Output::new(p.PA5, Level::High, Speed::Low); diff --git a/examples/boot/stm32wl/src/bin/a.rs b/examples/boot/stm32wl/src/bin/a.rs index 1089eff1..dc1eb9be 100644 --- a/examples/boot/stm32wl/src/bin/a.rs +++ b/examples/boot/stm32wl/src/bin/a.rs @@ -2,6 +2,8 @@ #![no_main] #![feature(type_alias_impl_trait)] +#[cfg(feature = "defmt-rtt")] +use defmt_rtt::*; use embassy_boot_stm32::FirmwareUpdater; use embassy_embedded_hal::adapter::BlockingAsync; use embassy_stm32::exti::ExtiInput; @@ -10,9 +12,6 @@ use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; use embassy_stm32::Peripherals; use panic_reset as _; -#[cfg(feature = "defmt-rtt")] -use defmt_rtt::*; - static APP_B: &[u8] = include_bytes!("../../b.bin"); #[embassy::main] @@ -34,10 +33,7 @@ async fn main(_s: embassy::executor::Spawner, p: Peripherals) { let mut buf: [u8; 2048] = [0; 2048]; buf[..chunk.len()].copy_from_slice(chunk); // defmt::info!("Writing chunk at 0x{:x}", offset); - updater - .write_firmware(offset, &buf, &mut flash, 2048) - .await - .unwrap(); + updater.write_firmware(offset, &buf, &mut flash, 2048).await.unwrap(); offset += chunk.len(); } updater.update(&mut flash).await.unwrap(); diff --git a/examples/boot/stm32wl/src/bin/b.rs b/examples/boot/stm32wl/src/bin/b.rs index ffe15b66..f2344bd5 100644 --- a/examples/boot/stm32wl/src/bin/b.rs +++ b/examples/boot/stm32wl/src/bin/b.rs @@ -2,15 +2,14 @@ #![no_main] #![feature(type_alias_impl_trait)] +#[cfg(feature = "defmt-rtt")] +use defmt_rtt::*; use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; use embassy_stm32::gpio::{Level, Output, Speed}; use embassy_stm32::Peripherals; use panic_reset as _; -#[cfg(feature = "defmt-rtt")] -use defmt_rtt::*; - #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { let mut led = Output::new(p.PB15, Level::High, Speed::Low); diff --git a/examples/nrf/src/bin/awaitable_timer.rs b/examples/nrf/src/bin/awaitable_timer.rs index 810b4bd6..34a657cb 100644 --- a/examples/nrf/src/bin/awaitable_timer.rs +++ b/examples/nrf/src/bin/awaitable_timer.rs @@ -4,12 +4,9 @@ use defmt::info; use embassy::executor::Spawner; -use embassy_nrf::interrupt; use embassy_nrf::timer::Timer; -use embassy_nrf::Peripherals; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use embassy_nrf::{interrupt, Peripherals}; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/nrf/src/bin/blinky.rs b/examples/nrf/src/bin/blinky.rs index 4828b08f..23d16f79 100644 --- a/examples/nrf/src/bin/blinky.rs +++ b/examples/nrf/src/bin/blinky.rs @@ -6,9 +6,7 @@ use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; use embassy_nrf::gpio::{Level, Output, OutputDrive}; use embassy_nrf::Peripherals; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/nrf/src/bin/buffered_uart.rs b/examples/nrf/src/bin/buffered_uart.rs index 782c3949..18dd698b 100644 --- a/examples/nrf/src/bin/buffered_uart.rs +++ b/examples/nrf/src/bin/buffered_uart.rs @@ -4,13 +4,11 @@ use defmt::*; use embassy::executor::Spawner; -use embassy_nrf::buffered_uarte::State; -use embassy_nrf::{buffered_uarte::BufferedUarte, interrupt, uarte, Peripherals}; +use embassy_nrf::buffered_uarte::{BufferedUarte, State}; +use embassy_nrf::{interrupt, uarte, Peripherals}; use embedded_io::asynch::{BufRead, Write}; use futures::pin_mut; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/nrf/src/bin/channel.rs b/examples/nrf/src/bin/channel.rs index 12b46358..c57b91a4 100644 --- a/examples/nrf/src/bin/channel.rs +++ b/examples/nrf/src/bin/channel.rs @@ -9,9 +9,7 @@ use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; use embassy_nrf::gpio::{Level, Output, OutputDrive}; use embassy_nrf::Peripherals; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; enum LedState { On, diff --git a/examples/nrf/src/bin/channel_sender_receiver.rs b/examples/nrf/src/bin/channel_sender_receiver.rs index 1742dcc9..847ce238 100644 --- a/examples/nrf/src/bin/channel_sender_receiver.rs +++ b/examples/nrf/src/bin/channel_sender_receiver.rs @@ -10,9 +10,7 @@ use embassy::time::{Duration, Timer}; use embassy::util::Forever; use embassy_nrf::gpio::{AnyPin, Level, Output, OutputDrive, Pin}; use embassy_nrf::Peripherals; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; enum LedState { On, diff --git a/examples/nrf/src/bin/executor_fairness_test.rs b/examples/nrf/src/bin/executor_fairness_test.rs index 7a356d14..5a422151 100644 --- a/examples/nrf/src/bin/executor_fairness_test.rs +++ b/examples/nrf/src/bin/executor_fairness_test.rs @@ -3,13 +3,12 @@ #![feature(type_alias_impl_trait)] use core::task::Poll; + use defmt::{info, unwrap}; use embassy::executor::Spawner; use embassy::time::{Duration, Instant, Timer}; use embassy_nrf::Peripherals; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::task] async fn run1() { diff --git a/examples/nrf/src/bin/gpiote_channel.rs b/examples/nrf/src/bin/gpiote_channel.rs index 339f779f..ad8f37c6 100644 --- a/examples/nrf/src/bin/gpiote_channel.rs +++ b/examples/nrf/src/bin/gpiote_channel.rs @@ -7,9 +7,7 @@ use embassy::executor::Spawner; use embassy_nrf::gpio::{Input, Pull}; use embassy_nrf::gpiote::{InputChannel, InputChannelPolarity}; use embassy_nrf::Peripherals; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/nrf/src/bin/gpiote_port.rs b/examples/nrf/src/bin/gpiote_port.rs index dc6bd301..30b87b3a 100644 --- a/examples/nrf/src/bin/gpiote_port.rs +++ b/examples/nrf/src/bin/gpiote_port.rs @@ -6,9 +6,7 @@ use defmt::{info, unwrap}; use embassy::executor::Spawner; use embassy_nrf::gpio::{AnyPin, Input, Pin as _, Pull}; use embassy_nrf::Peripherals; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::task(pool_size = 4)] async fn button_task(n: usize, mut pin: Input<'static, AnyPin>) { diff --git a/examples/nrf/src/bin/multiprio.rs b/examples/nrf/src/bin/multiprio.rs index abda18aa..1a4598e2 100644 --- a/examples/nrf/src/bin/multiprio.rs +++ b/examples/nrf/src/bin/multiprio.rs @@ -64,9 +64,7 @@ use embassy::util::Forever; use embassy_nrf::executor::{Executor, InterruptExecutor}; use embassy_nrf::interrupt; use embassy_nrf::interrupt::InterruptExt; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::task] async fn run_high() { diff --git a/examples/nrf/src/bin/mutex.rs b/examples/nrf/src/bin/mutex.rs index db1b72f6..92e01976 100644 --- a/examples/nrf/src/bin/mutex.rs +++ b/examples/nrf/src/bin/mutex.rs @@ -8,9 +8,7 @@ use embassy::executor::Spawner; use embassy::mutex::Mutex; use embassy::time::{Duration, Timer}; use embassy_nrf::Peripherals; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; static MUTEX: Mutex = Mutex::new(0); diff --git a/examples/nrf/src/bin/nvmc.rs b/examples/nrf/src/bin/nvmc.rs index 7a57399f..b55ef1f6 100644 --- a/examples/nrf/src/bin/nvmc.rs +++ b/examples/nrf/src/bin/nvmc.rs @@ -8,9 +8,7 @@ use embassy::time::{Duration, Timer}; use embassy_nrf::nvmc::Nvmc; use embassy_nrf::Peripherals; use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/nrf/src/bin/ppi.rs b/examples/nrf/src/bin/ppi.rs index 3c9a8148..004a1bfa 100644 --- a/examples/nrf/src/bin/ppi.rs +++ b/examples/nrf/src/bin/ppi.rs @@ -3,6 +3,7 @@ #![feature(type_alias_impl_trait)] use core::future::pending; + use defmt::info; use embassy::executor::Spawner; use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pull}; @@ -10,9 +11,7 @@ use embassy_nrf::gpiote::{self, InputChannel, InputChannelPolarity}; use embassy_nrf::ppi::Ppi; use embassy_nrf::Peripherals; use gpiote::{OutputChannel, OutputChannelPolarity}; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { @@ -60,12 +59,7 @@ async fn main(_spawner: Spawner, p: Peripherals) { let mut ppi = Ppi::new_one_to_one(p.PPI_CH2, button3.event_in(), led1.task_set()); ppi.enable(); - let mut ppi = Ppi::new_one_to_two( - p.PPI_CH3, - button4.event_in(), - led1.task_out(), - led2.task_out(), - ); + let mut ppi = Ppi::new_one_to_two(p.PPI_CH3, button4.event_in(), led1.task_out(), led2.task_out()); ppi.enable(); info!("PPI setup!"); diff --git a/examples/nrf/src/bin/pwm.rs b/examples/nrf/src/bin/pwm.rs index 7939e79e..aec5dd73 100644 --- a/examples/nrf/src/bin/pwm.rs +++ b/examples/nrf/src/bin/pwm.rs @@ -7,81 +7,67 @@ use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; use embassy_nrf::pwm::{Prescaler, SimplePwm}; use embassy_nrf::Peripherals; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; // for i in range(1024): print(int((math.sin(i/512*math.pi)*0.4+0.5)**2*32767), ', ', end='') static DUTY: [u16; 1024] = [ - 8191, 8272, 8353, 8434, 8516, 8598, 8681, 8764, 8847, 8931, 9015, 9099, 9184, 9269, 9354, 9440, - 9526, 9613, 9700, 9787, 9874, 9962, 10050, 10139, 10227, 10316, 10406, 10495, 10585, 10675, - 10766, 10857, 10948, 11039, 11131, 11223, 11315, 11407, 11500, 11592, 11685, 11779, 11872, - 11966, 12060, 12154, 12248, 12343, 12438, 12533, 12628, 12723, 12818, 12914, 13010, 13106, - 13202, 13298, 13394, 13491, 13587, 13684, 13781, 13878, 13975, 14072, 14169, 14266, 14364, - 14461, 14558, 14656, 14754, 14851, 14949, 15046, 15144, 15242, 15339, 15437, 15535, 15632, - 15730, 15828, 15925, 16023, 16120, 16218, 16315, 16412, 16510, 16607, 16704, 16801, 16898, - 16995, 17091, 17188, 17284, 17380, 17477, 17572, 17668, 17764, 17859, 17955, 18050, 18145, - 18239, 18334, 18428, 18522, 18616, 18710, 18803, 18896, 18989, 19082, 19174, 19266, 19358, - 19449, 19540, 19631, 19722, 19812, 19902, 19991, 20081, 20169, 20258, 20346, 20434, 20521, - 20608, 20695, 20781, 20867, 20952, 21037, 21122, 21206, 21290, 21373, 21456, 21538, 21620, - 21701, 21782, 21863, 21943, 22022, 22101, 22179, 22257, 22335, 22412, 22488, 22564, 22639, - 22714, 22788, 22861, 22934, 23007, 23079, 23150, 23220, 23290, 23360, 23429, 23497, 23564, - 23631, 23698, 23763, 23828, 23892, 23956, 24019, 24081, 24143, 24204, 24264, 24324, 24383, - 24441, 24499, 24555, 24611, 24667, 24721, 24775, 24828, 24881, 24933, 24983, 25034, 25083, - 25132, 25180, 25227, 25273, 25319, 25363, 25407, 25451, 25493, 25535, 25575, 25615, 25655, - 25693, 25731, 25767, 25803, 25838, 25873, 25906, 25939, 25971, 26002, 26032, 26061, 26089, - 26117, 26144, 26170, 26195, 26219, 26242, 26264, 26286, 26307, 26327, 26346, 26364, 26381, - 26397, 26413, 26427, 26441, 26454, 26466, 26477, 26487, 26496, 26505, 26512, 26519, 26525, - 26530, 26534, 26537, 26539, 26540, 26541, 26540, 26539, 26537, 26534, 26530, 26525, 26519, - 26512, 26505, 26496, 26487, 26477, 26466, 26454, 26441, 26427, 26413, 26397, 26381, 26364, - 26346, 26327, 26307, 26286, 26264, 26242, 26219, 26195, 26170, 26144, 26117, 26089, 26061, - 26032, 26002, 25971, 25939, 25906, 25873, 25838, 25803, 25767, 25731, 25693, 25655, 25615, - 25575, 25535, 25493, 25451, 25407, 25363, 25319, 25273, 25227, 25180, 25132, 25083, 25034, - 24983, 24933, 24881, 24828, 24775, 24721, 24667, 24611, 24555, 24499, 24441, 24383, 24324, - 24264, 24204, 24143, 24081, 24019, 23956, 23892, 23828, 23763, 23698, 23631, 23564, 23497, - 23429, 23360, 23290, 23220, 23150, 23079, 23007, 22934, 22861, 22788, 22714, 22639, 22564, - 22488, 22412, 22335, 22257, 22179, 22101, 22022, 21943, 21863, 21782, 21701, 21620, 21538, - 21456, 21373, 21290, 21206, 21122, 21037, 20952, 20867, 20781, 20695, 20608, 20521, 20434, - 20346, 20258, 20169, 20081, 19991, 19902, 19812, 19722, 19631, 19540, 19449, 19358, 19266, - 19174, 19082, 18989, 18896, 18803, 18710, 18616, 18522, 18428, 18334, 18239, 18145, 18050, - 17955, 17859, 17764, 17668, 17572, 17477, 17380, 17284, 17188, 17091, 16995, 16898, 16801, - 16704, 16607, 16510, 16412, 16315, 16218, 16120, 16023, 15925, 15828, 15730, 15632, 15535, - 15437, 15339, 15242, 15144, 15046, 14949, 14851, 14754, 14656, 14558, 14461, 14364, 14266, - 14169, 14072, 13975, 13878, 13781, 13684, 13587, 13491, 13394, 13298, 13202, 13106, 13010, - 12914, 12818, 12723, 12628, 12533, 12438, 12343, 12248, 12154, 12060, 11966, 11872, 11779, - 11685, 11592, 11500, 11407, 11315, 11223, 11131, 11039, 10948, 10857, 10766, 10675, 10585, - 10495, 10406, 10316, 10227, 10139, 10050, 9962, 9874, 9787, 9700, 9613, 9526, 9440, 9354, 9269, - 9184, 9099, 9015, 8931, 8847, 8764, 8681, 8598, 8516, 8434, 8353, 8272, 8191, 8111, 8031, 7952, - 7873, 7794, 7716, 7638, 7561, 7484, 7407, 7331, 7255, 7180, 7105, 7031, 6957, 6883, 6810, 6738, - 6665, 6594, 6522, 6451, 6381, 6311, 6241, 6172, 6104, 6036, 5968, 5901, 5834, 5767, 5702, 5636, - 5571, 5507, 5443, 5379, 5316, 5253, 5191, 5130, 5068, 5008, 4947, 4888, 4828, 4769, 4711, 4653, - 4596, 4539, 4482, 4426, 4371, 4316, 4261, 4207, 4153, 4100, 4047, 3995, 3943, 3892, 3841, 3791, - 3741, 3691, 3642, 3594, 3546, 3498, 3451, 3404, 3358, 3312, 3267, 3222, 3178, 3134, 3090, 3047, - 3005, 2962, 2921, 2879, 2839, 2798, 2758, 2719, 2680, 2641, 2603, 2565, 2528, 2491, 2454, 2418, - 2382, 2347, 2312, 2278, 2244, 2210, 2177, 2144, 2112, 2080, 2048, 2017, 1986, 1956, 1926, 1896, - 1867, 1838, 1810, 1781, 1754, 1726, 1699, 1673, 1646, 1620, 1595, 1570, 1545, 1520, 1496, 1472, - 1449, 1426, 1403, 1380, 1358, 1336, 1315, 1294, 1273, 1252, 1232, 1212, 1192, 1173, 1154, 1135, - 1117, 1099, 1081, 1063, 1046, 1029, 1012, 996, 980, 964, 948, 933, 918, 903, 888, 874, 860, - 846, 833, 819, 806, 793, 781, 768, 756, 744, 733, 721, 710, 699, 688, 677, 667, 657, 647, 637, - 627, 618, 609, 599, 591, 582, 574, 565, 557, 549, 541, 534, 526, 519, 512, 505, 498, 492, 485, - 479, 473, 467, 461, 455, 450, 444, 439, 434, 429, 424, 419, 415, 410, 406, 402, 398, 394, 390, - 386, 383, 379, 376, 373, 370, 367, 364, 361, 359, 356, 354, 351, 349, 347, 345, 343, 342, 340, - 338, 337, 336, 334, 333, 332, 331, 330, 330, 329, 328, 328, 328, 327, 327, 327, 327, 327, 328, - 328, 328, 329, 330, 330, 331, 332, 333, 334, 336, 337, 338, 340, 342, 343, 345, 347, 349, 351, - 354, 356, 359, 361, 364, 367, 370, 373, 376, 379, 383, 386, 390, 394, 398, 402, 406, 410, 415, - 419, 424, 429, 434, 439, 444, 450, 455, 461, 467, 473, 479, 485, 492, 498, 505, 512, 519, 526, - 534, 541, 549, 557, 565, 574, 582, 591, 599, 609, 618, 627, 637, 647, 657, 667, 677, 688, 699, - 710, 721, 733, 744, 756, 768, 781, 793, 806, 819, 833, 846, 860, 874, 888, 903, 918, 933, 948, - 964, 980, 996, 1012, 1029, 1046, 1063, 1081, 1099, 1117, 1135, 1154, 1173, 1192, 1212, 1232, - 1252, 1273, 1294, 1315, 1336, 1358, 1380, 1403, 1426, 1449, 1472, 1496, 1520, 1545, 1570, 1595, - 1620, 1646, 1673, 1699, 1726, 1754, 1781, 1810, 1838, 1867, 1896, 1926, 1956, 1986, 2017, 2048, - 2080, 2112, 2144, 2177, 2210, 2244, 2278, 2312, 2347, 2382, 2418, 2454, 2491, 2528, 2565, 2603, - 2641, 2680, 2719, 2758, 2798, 2839, 2879, 2921, 2962, 3005, 3047, 3090, 3134, 3178, 3222, 3267, - 3312, 3358, 3404, 3451, 3498, 3546, 3594, 3642, 3691, 3741, 3791, 3841, 3892, 3943, 3995, 4047, - 4100, 4153, 4207, 4261, 4316, 4371, 4426, 4482, 4539, 4596, 4653, 4711, 4769, 4828, 4888, 4947, - 5008, 5068, 5130, 5191, 5253, 5316, 5379, 5443, 5507, 5571, 5636, 5702, 5767, 5834, 5901, 5968, - 6036, 6104, 6172, 6241, 6311, 6381, 6451, 6522, 6594, 6665, 6738, 6810, 6883, 6957, 7031, 7105, - 7180, 7255, 7331, 7407, 7484, 7561, 7638, 7716, 7794, 7873, 7952, 8031, 8111, + 8191, 8272, 8353, 8434, 8516, 8598, 8681, 8764, 8847, 8931, 9015, 9099, 9184, 9269, 9354, 9440, 9526, 9613, 9700, + 9787, 9874, 9962, 10050, 10139, 10227, 10316, 10406, 10495, 10585, 10675, 10766, 10857, 10948, 11039, 11131, 11223, + 11315, 11407, 11500, 11592, 11685, 11779, 11872, 11966, 12060, 12154, 12248, 12343, 12438, 12533, 12628, 12723, + 12818, 12914, 13010, 13106, 13202, 13298, 13394, 13491, 13587, 13684, 13781, 13878, 13975, 14072, 14169, 14266, + 14364, 14461, 14558, 14656, 14754, 14851, 14949, 15046, 15144, 15242, 15339, 15437, 15535, 15632, 15730, 15828, + 15925, 16023, 16120, 16218, 16315, 16412, 16510, 16607, 16704, 16801, 16898, 16995, 17091, 17188, 17284, 17380, + 17477, 17572, 17668, 17764, 17859, 17955, 18050, 18145, 18239, 18334, 18428, 18522, 18616, 18710, 18803, 18896, + 18989, 19082, 19174, 19266, 19358, 19449, 19540, 19631, 19722, 19812, 19902, 19991, 20081, 20169, 20258, 20346, + 20434, 20521, 20608, 20695, 20781, 20867, 20952, 21037, 21122, 21206, 21290, 21373, 21456, 21538, 21620, 21701, + 21782, 21863, 21943, 22022, 22101, 22179, 22257, 22335, 22412, 22488, 22564, 22639, 22714, 22788, 22861, 22934, + 23007, 23079, 23150, 23220, 23290, 23360, 23429, 23497, 23564, 23631, 23698, 23763, 23828, 23892, 23956, 24019, + 24081, 24143, 24204, 24264, 24324, 24383, 24441, 24499, 24555, 24611, 24667, 24721, 24775, 24828, 24881, 24933, + 24983, 25034, 25083, 25132, 25180, 25227, 25273, 25319, 25363, 25407, 25451, 25493, 25535, 25575, 25615, 25655, + 25693, 25731, 25767, 25803, 25838, 25873, 25906, 25939, 25971, 26002, 26032, 26061, 26089, 26117, 26144, 26170, + 26195, 26219, 26242, 26264, 26286, 26307, 26327, 26346, 26364, 26381, 26397, 26413, 26427, 26441, 26454, 26466, + 26477, 26487, 26496, 26505, 26512, 26519, 26525, 26530, 26534, 26537, 26539, 26540, 26541, 26540, 26539, 26537, + 26534, 26530, 26525, 26519, 26512, 26505, 26496, 26487, 26477, 26466, 26454, 26441, 26427, 26413, 26397, 26381, + 26364, 26346, 26327, 26307, 26286, 26264, 26242, 26219, 26195, 26170, 26144, 26117, 26089, 26061, 26032, 26002, + 25971, 25939, 25906, 25873, 25838, 25803, 25767, 25731, 25693, 25655, 25615, 25575, 25535, 25493, 25451, 25407, + 25363, 25319, 25273, 25227, 25180, 25132, 25083, 25034, 24983, 24933, 24881, 24828, 24775, 24721, 24667, 24611, + 24555, 24499, 24441, 24383, 24324, 24264, 24204, 24143, 24081, 24019, 23956, 23892, 23828, 23763, 23698, 23631, + 23564, 23497, 23429, 23360, 23290, 23220, 23150, 23079, 23007, 22934, 22861, 22788, 22714, 22639, 22564, 22488, + 22412, 22335, 22257, 22179, 22101, 22022, 21943, 21863, 21782, 21701, 21620, 21538, 21456, 21373, 21290, 21206, + 21122, 21037, 20952, 20867, 20781, 20695, 20608, 20521, 20434, 20346, 20258, 20169, 20081, 19991, 19902, 19812, + 19722, 19631, 19540, 19449, 19358, 19266, 19174, 19082, 18989, 18896, 18803, 18710, 18616, 18522, 18428, 18334, + 18239, 18145, 18050, 17955, 17859, 17764, 17668, 17572, 17477, 17380, 17284, 17188, 17091, 16995, 16898, 16801, + 16704, 16607, 16510, 16412, 16315, 16218, 16120, 16023, 15925, 15828, 15730, 15632, 15535, 15437, 15339, 15242, + 15144, 15046, 14949, 14851, 14754, 14656, 14558, 14461, 14364, 14266, 14169, 14072, 13975, 13878, 13781, 13684, + 13587, 13491, 13394, 13298, 13202, 13106, 13010, 12914, 12818, 12723, 12628, 12533, 12438, 12343, 12248, 12154, + 12060, 11966, 11872, 11779, 11685, 11592, 11500, 11407, 11315, 11223, 11131, 11039, 10948, 10857, 10766, 10675, + 10585, 10495, 10406, 10316, 10227, 10139, 10050, 9962, 9874, 9787, 9700, 9613, 9526, 9440, 9354, 9269, 9184, 9099, + 9015, 8931, 8847, 8764, 8681, 8598, 8516, 8434, 8353, 8272, 8191, 8111, 8031, 7952, 7873, 7794, 7716, 7638, 7561, + 7484, 7407, 7331, 7255, 7180, 7105, 7031, 6957, 6883, 6810, 6738, 6665, 6594, 6522, 6451, 6381, 6311, 6241, 6172, + 6104, 6036, 5968, 5901, 5834, 5767, 5702, 5636, 5571, 5507, 5443, 5379, 5316, 5253, 5191, 5130, 5068, 5008, 4947, + 4888, 4828, 4769, 4711, 4653, 4596, 4539, 4482, 4426, 4371, 4316, 4261, 4207, 4153, 4100, 4047, 3995, 3943, 3892, + 3841, 3791, 3741, 3691, 3642, 3594, 3546, 3498, 3451, 3404, 3358, 3312, 3267, 3222, 3178, 3134, 3090, 3047, 3005, + 2962, 2921, 2879, 2839, 2798, 2758, 2719, 2680, 2641, 2603, 2565, 2528, 2491, 2454, 2418, 2382, 2347, 2312, 2278, + 2244, 2210, 2177, 2144, 2112, 2080, 2048, 2017, 1986, 1956, 1926, 1896, 1867, 1838, 1810, 1781, 1754, 1726, 1699, + 1673, 1646, 1620, 1595, 1570, 1545, 1520, 1496, 1472, 1449, 1426, 1403, 1380, 1358, 1336, 1315, 1294, 1273, 1252, + 1232, 1212, 1192, 1173, 1154, 1135, 1117, 1099, 1081, 1063, 1046, 1029, 1012, 996, 980, 964, 948, 933, 918, 903, + 888, 874, 860, 846, 833, 819, 806, 793, 781, 768, 756, 744, 733, 721, 710, 699, 688, 677, 667, 657, 647, 637, 627, + 618, 609, 599, 591, 582, 574, 565, 557, 549, 541, 534, 526, 519, 512, 505, 498, 492, 485, 479, 473, 467, 461, 455, + 450, 444, 439, 434, 429, 424, 419, 415, 410, 406, 402, 398, 394, 390, 386, 383, 379, 376, 373, 370, 367, 364, 361, + 359, 356, 354, 351, 349, 347, 345, 343, 342, 340, 338, 337, 336, 334, 333, 332, 331, 330, 330, 329, 328, 328, 328, + 327, 327, 327, 327, 327, 328, 328, 328, 329, 330, 330, 331, 332, 333, 334, 336, 337, 338, 340, 342, 343, 345, 347, + 349, 351, 354, 356, 359, 361, 364, 367, 370, 373, 376, 379, 383, 386, 390, 394, 398, 402, 406, 410, 415, 419, 424, + 429, 434, 439, 444, 450, 455, 461, 467, 473, 479, 485, 492, 498, 505, 512, 519, 526, 534, 541, 549, 557, 565, 574, + 582, 591, 599, 609, 618, 627, 637, 647, 657, 667, 677, 688, 699, 710, 721, 733, 744, 756, 768, 781, 793, 806, 819, + 833, 846, 860, 874, 888, 903, 918, 933, 948, 964, 980, 996, 1012, 1029, 1046, 1063, 1081, 1099, 1117, 1135, 1154, + 1173, 1192, 1212, 1232, 1252, 1273, 1294, 1315, 1336, 1358, 1380, 1403, 1426, 1449, 1472, 1496, 1520, 1545, 1570, + 1595, 1620, 1646, 1673, 1699, 1726, 1754, 1781, 1810, 1838, 1867, 1896, 1926, 1956, 1986, 2017, 2048, 2080, 2112, + 2144, 2177, 2210, 2244, 2278, 2312, 2347, 2382, 2418, 2454, 2491, 2528, 2565, 2603, 2641, 2680, 2719, 2758, 2798, + 2839, 2879, 2921, 2962, 3005, 3047, 3090, 3134, 3178, 3222, 3267, 3312, 3358, 3404, 3451, 3498, 3546, 3594, 3642, + 3691, 3741, 3791, 3841, 3892, 3943, 3995, 4047, 4100, 4153, 4207, 4261, 4316, 4371, 4426, 4482, 4539, 4596, 4653, + 4711, 4769, 4828, 4888, 4947, 5008, 5068, 5130, 5191, 5253, 5316, 5379, 5443, 5507, 5571, 5636, 5702, 5767, 5834, + 5901, 5968, 6036, 6104, 6172, 6241, 6311, 6381, 6451, 6522, 6594, 6665, 6738, 6810, 6883, 6957, 7031, 7105, 7180, + 7255, 7331, 7407, 7484, 7561, 7638, 7716, 7794, 7873, 7952, 8031, 8111, ]; #[embassy::main] diff --git a/examples/nrf/src/bin/pwm_double_sequence.rs b/examples/nrf/src/bin/pwm_double_sequence.rs index 6fc42921..facafa77 100644 --- a/examples/nrf/src/bin/pwm_double_sequence.rs +++ b/examples/nrf/src/bin/pwm_double_sequence.rs @@ -6,13 +6,10 @@ use defmt::*; use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; use embassy_nrf::pwm::{ - Config, Prescaler, Sequence, SequenceConfig, SequenceMode, SequencePwm, Sequencer, - StartSequence, + Config, Prescaler, Sequence, SequenceConfig, SequenceMode, SequencePwm, Sequencer, StartSequence, }; use embassy_nrf::Peripherals; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/nrf/src/bin/pwm_sequence.rs b/examples/nrf/src/bin/pwm_sequence.rs index 3b2919ba..b7cb385c 100644 --- a/examples/nrf/src/bin/pwm_sequence.rs +++ b/examples/nrf/src/bin/pwm_sequence.rs @@ -5,13 +5,9 @@ use defmt::*; use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; -use embassy_nrf::pwm::{ - Config, Prescaler, SequenceConfig, SequencePwm, SingleSequenceMode, SingleSequencer, -}; +use embassy_nrf::pwm::{Config, Prescaler, SequenceConfig, SequencePwm, SingleSequenceMode, SingleSequencer}; use embassy_nrf::Peripherals; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/nrf/src/bin/pwm_sequence_ppi.rs b/examples/nrf/src/bin/pwm_sequence_ppi.rs index 1f3662c6..7d020e48 100644 --- a/examples/nrf/src/bin/pwm_sequence_ppi.rs +++ b/examples/nrf/src/bin/pwm_sequence_ppi.rs @@ -4,18 +4,15 @@ #![feature(array_from_fn)] use core::future::pending; + use defmt::*; use embassy::executor::Spawner; use embassy_nrf::gpio::{Input, Pull}; use embassy_nrf::gpiote::{InputChannel, InputChannelPolarity}; use embassy_nrf::ppi::Ppi; -use embassy_nrf::pwm::{ - Config, Prescaler, SequenceConfig, SequencePwm, SingleSequenceMode, SingleSequencer, -}; +use embassy_nrf::pwm::{Config, Prescaler, SequenceConfig, SequencePwm, SingleSequenceMode, SingleSequencer}; use embassy_nrf::Peripherals; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/nrf/src/bin/pwm_sequence_ws2812b.rs b/examples/nrf/src/bin/pwm_sequence_ws2812b.rs index 8bfe1d50..0dee8c94 100644 --- a/examples/nrf/src/bin/pwm_sequence_ws2812b.rs +++ b/examples/nrf/src/bin/pwm_sequence_ws2812b.rs @@ -6,13 +6,10 @@ use defmt::*; use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; use embassy_nrf::pwm::{ - Config, Prescaler, SequenceConfig, SequenceLoad, SequencePwm, SingleSequenceMode, - SingleSequencer, + Config, Prescaler, SequenceConfig, SequenceLoad, SequencePwm, SingleSequenceMode, SingleSequencer, }; use embassy_nrf::Peripherals; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; // WS2812B LED light demonstration. Drives just one light. // The following reference on WS2812B may be of use: diff --git a/examples/nrf/src/bin/pwm_servo.rs b/examples/nrf/src/bin/pwm_servo.rs index 40863bf3..71a90a94 100644 --- a/examples/nrf/src/bin/pwm_servo.rs +++ b/examples/nrf/src/bin/pwm_servo.rs @@ -7,9 +7,7 @@ use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; use embassy_nrf::pwm::{Prescaler, SimplePwm}; use embassy_nrf::Peripherals; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/nrf/src/bin/qdec.rs b/examples/nrf/src/bin/qdec.rs index bf5b1146..9529c7bb 100644 --- a/examples/nrf/src/bin/qdec.rs +++ b/examples/nrf/src/bin/qdec.rs @@ -4,14 +4,9 @@ use defmt::info; use embassy::executor::Spawner; -use embassy_nrf::{ - interrupt, - qdec::{self, Qdec}, - Peripherals, -}; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use embassy_nrf::qdec::{self, Qdec}; +use embassy_nrf::{interrupt, Peripherals}; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/nrf/src/bin/qspi.rs b/examples/nrf/src/bin/qspi.rs index 8673b796..96c90f9c 100644 --- a/examples/nrf/src/bin/qspi.rs +++ b/examples/nrf/src/bin/qspi.rs @@ -4,11 +4,8 @@ use defmt::{assert_eq, info, unwrap}; use embassy::executor::Spawner; -use embassy_nrf::Peripherals; -use embassy_nrf::{interrupt, qspi}; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use embassy_nrf::{interrupt, qspi, Peripherals}; +use {defmt_rtt as _, panic_probe as _}; const PAGE_SIZE: usize = 4096; diff --git a/examples/nrf/src/bin/qspi_lowpower.rs b/examples/nrf/src/bin/qspi_lowpower.rs index 255ce5d5..ce2e40b2 100644 --- a/examples/nrf/src/bin/qspi_lowpower.rs +++ b/examples/nrf/src/bin/qspi_lowpower.rs @@ -3,14 +3,12 @@ #![feature(type_alias_impl_trait)] use core::mem; + use defmt::{info, unwrap}; use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; -use embassy_nrf::Peripherals; -use embassy_nrf::{interrupt, qspi}; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use embassy_nrf::{interrupt, qspi, Peripherals}; +use {defmt_rtt as _, panic_probe as _}; // Workaround for alignment requirements. // Nicer API will probably come in the future. diff --git a/examples/nrf/src/bin/raw_spawn.rs b/examples/nrf/src/bin/raw_spawn.rs index 1d9d3ed5..d564b6b2 100644 --- a/examples/nrf/src/bin/raw_spawn.rs +++ b/examples/nrf/src/bin/raw_spawn.rs @@ -2,15 +2,14 @@ #![no_main] use core::mem; + use cortex_m_rt::entry; use defmt::{info, unwrap}; use embassy::executor::raw::TaskStorage; use embassy::executor::Executor; use embassy::time::{Duration, Timer}; use embassy::util::Forever; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; async fn run1() { loop { diff --git a/examples/nrf/src/bin/rng.rs b/examples/nrf/src/bin/rng.rs index 4b4b3a19..08d3abe1 100644 --- a/examples/nrf/src/bin/rng.rs +++ b/examples/nrf/src/bin/rng.rs @@ -3,13 +3,10 @@ #![feature(type_alias_impl_trait)] use embassy::executor::Spawner; -use embassy_nrf::interrupt; use embassy_nrf::rng::Rng; -use embassy_nrf::Peripherals; +use embassy_nrf::{interrupt, Peripherals}; use rand::Rng as _; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { @@ -27,12 +24,6 @@ async fn main(_spawner: Spawner, p: Peripherals) { rng.fill_bytes(&mut bytes).await; let zero_count: u32 = bytes.iter().fold(0, |acc, val| acc + val.count_zeros()); let one_count: u32 = bytes.iter().fold(0, |acc, val| acc + val.count_ones()); - defmt::info!( - "Chance of zero: {}%", - zero_count * 100 / (bytes.len() as u32 * 8) - ); - defmt::info!( - "Chance of one: {}%", - one_count * 100 / (bytes.len() as u32 * 8) - ); + defmt::info!("Chance of zero: {}%", zero_count * 100 / (bytes.len() as u32 * 8)); + defmt::info!("Chance of one: {}%", one_count * 100 / (bytes.len() as u32 * 8)); } diff --git a/examples/nrf/src/bin/saadc.rs b/examples/nrf/src/bin/saadc.rs index 5835be31..cb928978 100644 --- a/examples/nrf/src/bin/saadc.rs +++ b/examples/nrf/src/bin/saadc.rs @@ -7,9 +7,7 @@ use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; use embassy_nrf::saadc::{ChannelConfig, Config, Saadc}; use embassy_nrf::{interrupt, Peripherals}; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, mut p: Peripherals) { diff --git a/examples/nrf/src/bin/saadc_continuous.rs b/examples/nrf/src/bin/saadc_continuous.rs index 5e357f79..234294ea 100644 --- a/examples/nrf/src/bin/saadc_continuous.rs +++ b/examples/nrf/src/bin/saadc_continuous.rs @@ -8,9 +8,7 @@ use embassy::time::Duration; use embassy_nrf::saadc::{ChannelConfig, Config, Saadc, SamplerState}; use embassy_nrf::timer::Frequency; use embassy_nrf::{interrupt, Peripherals}; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; // Demonstrates both continuous sampling and scanning multiple channels driven by a PPI linked timer diff --git a/examples/nrf/src/bin/self_spawn.rs b/examples/nrf/src/bin/self_spawn.rs index 35e73a8d..4b8ac04b 100644 --- a/examples/nrf/src/bin/self_spawn.rs +++ b/examples/nrf/src/bin/self_spawn.rs @@ -6,9 +6,7 @@ use defmt::{info, unwrap}; use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; use embassy_nrf::Peripherals; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::task(pool_size = 2)] async fn my_task(spawner: Spawner, n: u32) { diff --git a/examples/nrf/src/bin/self_spawn_current_executor.rs b/examples/nrf/src/bin/self_spawn_current_executor.rs index 4850d295..3c3379ce 100644 --- a/examples/nrf/src/bin/self_spawn_current_executor.rs +++ b/examples/nrf/src/bin/self_spawn_current_executor.rs @@ -6,9 +6,7 @@ use defmt::{info, unwrap}; use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; use embassy_nrf::Peripherals; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::task(pool_size = 2)] async fn my_task(n: u32) { diff --git a/examples/nrf/src/bin/spim.rs b/examples/nrf/src/bin/spim.rs index f2a4ab38..62040168 100644 --- a/examples/nrf/src/bin/spim.rs +++ b/examples/nrf/src/bin/spim.rs @@ -5,11 +5,8 @@ use defmt::{info, unwrap}; use embassy::executor::Spawner; use embassy_nrf::gpio::{Level, Output, OutputDrive}; -use embassy_nrf::Peripherals; -use embassy_nrf::{interrupt, spim}; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use embassy_nrf::{interrupt, spim, Peripherals}; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/nrf/src/bin/temp.rs b/examples/nrf/src/bin/temp.rs index aa807910..939cb39e 100644 --- a/examples/nrf/src/bin/temp.rs +++ b/examples/nrf/src/bin/temp.rs @@ -5,10 +5,9 @@ use defmt::info; use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; -use embassy_nrf::{interrupt, temp::Temp, Peripherals}; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use embassy_nrf::temp::Temp; +use embassy_nrf::{interrupt, Peripherals}; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/nrf/src/bin/timer.rs b/examples/nrf/src/bin/timer.rs index ff8ee9a8..64376dd7 100644 --- a/examples/nrf/src/bin/timer.rs +++ b/examples/nrf/src/bin/timer.rs @@ -6,9 +6,7 @@ use defmt::{info, unwrap}; use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; use embassy_nrf::Peripherals; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::task] async fn run1() { diff --git a/examples/nrf/src/bin/twim.rs b/examples/nrf/src/bin/twim.rs index 08c61415..fb8372a1 100644 --- a/examples/nrf/src/bin/twim.rs +++ b/examples/nrf/src/bin/twim.rs @@ -10,9 +10,7 @@ use defmt::*; use embassy::executor::Spawner; use embassy_nrf::twim::{self, Twim}; use embassy_nrf::{interrupt, Peripherals}; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; const ADDRESS: u8 = 0x50; diff --git a/examples/nrf/src/bin/twim_lowpower.rs b/examples/nrf/src/bin/twim_lowpower.rs index 45b347ea..c9c2d503 100644 --- a/examples/nrf/src/bin/twim_lowpower.rs +++ b/examples/nrf/src/bin/twim_lowpower.rs @@ -9,14 +9,13 @@ #![feature(type_alias_impl_trait)] use core::mem; + use defmt::*; use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; use embassy_nrf::twim::{self, Twim}; use embassy_nrf::{interrupt, Peripherals}; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; const ADDRESS: u8 = 0x50; diff --git a/examples/nrf/src/bin/uart.rs b/examples/nrf/src/bin/uart.rs index 91f7f4fd..c8c4a67a 100644 --- a/examples/nrf/src/bin/uart.rs +++ b/examples/nrf/src/bin/uart.rs @@ -5,9 +5,7 @@ use defmt::*; use embassy::executor::Spawner; use embassy_nrf::{interrupt, uarte, Peripherals}; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/nrf/src/bin/uart_idle.rs b/examples/nrf/src/bin/uart_idle.rs index 89336faa..6679b28d 100644 --- a/examples/nrf/src/bin/uart_idle.rs +++ b/examples/nrf/src/bin/uart_idle.rs @@ -5,9 +5,7 @@ use defmt::*; use embassy::executor::Spawner; use embassy_nrf::{interrupt, uarte, Peripherals}; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { @@ -16,9 +14,7 @@ async fn main(_spawner: Spawner, p: Peripherals) { config.baudrate = uarte::Baudrate::BAUD115200; let irq = interrupt::take!(UARTE0_UART0); - let mut uart = uarte::UarteWithIdle::new( - p.UARTE0, p.TIMER0, p.PPI_CH0, p.PPI_CH1, irq, p.P0_08, p.P0_06, config, - ); + let mut uart = uarte::UarteWithIdle::new(p.UARTE0, p.TIMER0, p.PPI_CH0, p.PPI_CH1, irq, p.P0_08, p.P0_06, config); info!("uarte initialized!"); diff --git a/examples/nrf/src/bin/uart_split.rs b/examples/nrf/src/bin/uart_split.rs index 958cfeba..1ffb6370 100644 --- a/examples/nrf/src/bin/uart_split.rs +++ b/examples/nrf/src/bin/uart_split.rs @@ -9,9 +9,7 @@ use embassy::executor::Spawner; use embassy_nrf::peripherals::UARTE0; use embassy_nrf::uarte::UarteRx; use embassy_nrf::{interrupt, uarte, Peripherals}; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; static CHANNEL: Channel = Channel::new(); diff --git a/examples/nrf/src/bin/usb_ethernet.rs b/examples/nrf/src/bin/usb_ethernet.rs index 3d85d22b..a20321fe 100644 --- a/examples/nrf/src/bin/usb_ethernet.rs +++ b/examples/nrf/src/bin/usb_ethernet.rs @@ -6,6 +6,7 @@ use core::mem; use core::sync::atomic::{AtomicBool, Ordering}; use core::task::Waker; + use defmt::*; use embassy::blocking_mutex::raw::ThreadModeRawMutex; use embassy::channel::mpmc::Channel; @@ -13,18 +14,13 @@ use embassy::executor::Spawner; use embassy::util::Forever; use embassy_net::tcp::TcpSocket; use embassy_net::{PacketBox, PacketBoxExt, PacketBuf, Stack, StackResources}; -use embassy_nrf::pac; use embassy_nrf::rng::Rng; use embassy_nrf::usb::Driver; -use embassy_nrf::Peripherals; -use embassy_nrf::{interrupt, peripherals}; +use embassy_nrf::{interrupt, pac, peripherals, Peripherals}; use embassy_usb::{Builder, Config, UsbDevice}; use embassy_usb_ncm::{CdcNcmClass, Receiver, Sender, State}; - -use defmt_rtt as _; use embedded_io::asynch::{Read, Write}; -// global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; type MyDriver = Driver<'static, peripherals::USBD>; @@ -180,9 +176,7 @@ async fn main(spawner: Spawner, p: Peripherals) { let seed = u64::from_le_bytes(seed); // Init network stack - let device = Device { - mac_addr: our_mac_addr, - }; + let device = Device { mac_addr: our_mac_addr }; let stack = &*forever!(Stack::new( device, config, diff --git a/examples/nrf/src/bin/usb_hid_keyboard.rs b/examples/nrf/src/bin/usb_hid_keyboard.rs index 98e7dd69..97ec861d 100644 --- a/examples/nrf/src/bin/usb_hid_keyboard.rs +++ b/examples/nrf/src/bin/usb_hid_keyboard.rs @@ -5,25 +5,22 @@ use core::mem; use core::sync::atomic::{AtomicBool, Ordering}; + use defmt::*; use embassy::channel::signal::Signal; use embassy::executor::Spawner; use embassy::time::Duration; use embassy::util::{select, select3, Either, Either3}; use embassy_nrf::gpio::{Input, Pin, Pull}; -use embassy_nrf::interrupt; use embassy_nrf::interrupt::InterruptExt; -use embassy_nrf::pac; use embassy_nrf::usb::Driver; -use embassy_nrf::Peripherals; +use embassy_nrf::{interrupt, pac, Peripherals}; use embassy_usb::control::OutResponse; use embassy_usb::{Builder, Config, DeviceStateHandler}; use embassy_usb_hid::{HidReaderWriter, ReportId, RequestHandler, State}; use futures::future::join; use usbd_hid::descriptor::{KeyboardReport, SerializedDescriptor}; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; static ENABLE_USB: Signal = Signal::new(); static SUSPENDED: AtomicBool = AtomicBool::new(false); @@ -182,9 +179,7 @@ async fn main(_spawner: Spawner, p: Peripherals) { power_irq.unpend(); power_irq.enable(); - power - .intenset - .write(|w| w.usbdetected().set().usbremoved().set()); + power.intenset.write(|w| w.usbdetected().set().usbremoved().set()); // Run everything concurrently. // If we had made everything `'static` above instead, we could do this using separate tasks instead. @@ -260,9 +255,7 @@ impl DeviceStateHandler for MyDeviceStateHandler { fn configured(&self, configured: bool) { self.configured.store(configured, Ordering::Relaxed); if configured { - info!( - "Device configured, it may now draw up to the configured current limit from Vbus." - ) + info!("Device configured, it may now draw up to the configured current limit from Vbus.") } else { info!("Device is no longer configured, the Vbus current limit is 100mA."); } @@ -275,9 +268,7 @@ impl DeviceStateHandler for MyDeviceStateHandler { } else { SUSPENDED.store(false, Ordering::Release); if self.configured.load(Ordering::Relaxed) { - info!( - "Device resumed, it may now draw up to the configured current limit from Vbus" - ); + info!("Device resumed, it may now draw up to the configured current limit from Vbus"); } else { info!("Device resumed, the Vbus current limit is 100mA"); } diff --git a/examples/nrf/src/bin/usb_hid_mouse.rs b/examples/nrf/src/bin/usb_hid_mouse.rs index c526c1c6..9c44e5cc 100644 --- a/examples/nrf/src/bin/usb_hid_mouse.rs +++ b/examples/nrf/src/bin/usb_hid_mouse.rs @@ -4,21 +4,18 @@ #![feature(type_alias_impl_trait)] use core::mem; + use defmt::*; use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; -use embassy_nrf::interrupt; -use embassy_nrf::pac; use embassy_nrf::usb::Driver; -use embassy_nrf::Peripherals; +use embassy_nrf::{interrupt, pac, Peripherals}; use embassy_usb::control::OutResponse; use embassy_usb::{Builder, Config}; use embassy_usb_hid::{HidWriter, ReportId, RequestHandler, State}; use futures::future::join; use usbd_hid::descriptor::{MouseReport, SerializedDescriptor}; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/nrf/src/bin/usb_serial.rs b/examples/nrf/src/bin/usb_serial.rs index 2551c4ba..f108db46 100644 --- a/examples/nrf/src/bin/usb_serial.rs +++ b/examples/nrf/src/bin/usb_serial.rs @@ -4,19 +4,16 @@ #![feature(type_alias_impl_trait)] use core::mem; + use defmt::{info, panic}; use embassy::executor::Spawner; -use embassy_nrf::interrupt; -use embassy_nrf::pac; use embassy_nrf::usb::{Driver, Instance}; -use embassy_nrf::Peripherals; +use embassy_nrf::{interrupt, pac, Peripherals}; use embassy_usb::driver::EndpointError; use embassy_usb::{Builder, Config}; use embassy_usb_serial::{CdcAcmClass, State}; use futures::future::join; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { @@ -104,9 +101,7 @@ impl From for Disconnected { } } -async fn echo<'d, T: Instance + 'd>( - class: &mut CdcAcmClass<'d, Driver<'d, T>>, -) -> Result<(), Disconnected> { +async fn echo<'d, T: Instance + 'd>(class: &mut CdcAcmClass<'d, Driver<'d, T>>) -> Result<(), Disconnected> { let mut buf = [0; 64]; loop { let n = class.read_packet(&mut buf).await?; diff --git a/examples/nrf/src/bin/usb_serial_multitask.rs b/examples/nrf/src/bin/usb_serial_multitask.rs index 0e82ba31..dc503e67 100644 --- a/examples/nrf/src/bin/usb_serial_multitask.rs +++ b/examples/nrf/src/bin/usb_serial_multitask.rs @@ -4,19 +4,16 @@ #![feature(type_alias_impl_trait)] use core::mem; + use defmt::{info, panic, unwrap}; use embassy::executor::Spawner; use embassy::util::Forever; -use embassy_nrf::pac; use embassy_nrf::usb::Driver; -use embassy_nrf::Peripherals; -use embassy_nrf::{interrupt, peripherals}; +use embassy_nrf::{interrupt, pac, peripherals, Peripherals}; use embassy_usb::driver::EndpointError; use embassy_usb::{Builder, Config, UsbDevice}; use embassy_usb_serial::{CdcAcmClass, State}; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; type MyDriver = Driver<'static, peripherals::USBD>; diff --git a/examples/nrf/src/bin/wdt.rs b/examples/nrf/src/bin/wdt.rs index 431ccca8..280e23bc 100644 --- a/examples/nrf/src/bin/wdt.rs +++ b/examples/nrf/src/bin/wdt.rs @@ -7,9 +7,7 @@ use embassy::executor::Spawner; use embassy_nrf::gpio::{Input, Pull}; use embassy_nrf::wdt::{Config, Watchdog}; use embassy_nrf::Peripherals; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/rp/src/bin/blinky.rs b/examples/rp/src/bin/blinky.rs index 6f199d07..35612a4c 100644 --- a/examples/rp/src/bin/blinky.rs +++ b/examples/rp/src/bin/blinky.rs @@ -7,9 +7,7 @@ use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; use embassy_rp::{gpio, Peripherals}; use gpio::{Level, Output}; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/rp/src/bin/button.rs b/examples/rp/src/bin/button.rs index 2418ad01..980e54ea 100644 --- a/examples/rp/src/bin/button.rs +++ b/examples/rp/src/bin/button.rs @@ -5,9 +5,7 @@ use embassy::executor::Spawner; use embassy_rp::gpio::{Input, Level, Output, Pull}; use embassy_rp::Peripherals; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/rp/src/bin/spi.rs b/examples/rp/src/bin/spi.rs index b3842436..d97aa94b 100644 --- a/examples/rp/src/bin/spi.rs +++ b/examples/rp/src/bin/spi.rs @@ -4,13 +4,10 @@ use defmt::*; use embassy::executor::Spawner; -use embassy_rp::spi; use embassy_rp::spi::Spi; -use embassy_rp::{gpio, Peripherals}; +use embassy_rp::{gpio, spi, Peripherals}; use gpio::{Level, Output}; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/rp/src/bin/spi_display.rs b/examples/rp/src/bin/spi_display.rs index 5c3c4c4c..f4a411ba 100644 --- a/examples/rp/src/bin/spi_display.rs +++ b/examples/rp/src/bin/spi_display.rs @@ -3,13 +3,13 @@ #![feature(type_alias_impl_trait)] use core::cell::RefCell; + use defmt::*; use embassy::executor::Spawner; use embassy::time::Delay; use embassy_rp::gpio::{Level, Output}; -use embassy_rp::spi; use embassy_rp::spi::Spi; -use embassy_rp::Peripherals; +use embassy_rp::{spi, Peripherals}; use embedded_graphics::image::{Image, ImageRawLE}; use embedded_graphics::mono_font::ascii::FONT_10X20; use embedded_graphics::mono_font::MonoTextStyle; @@ -18,14 +18,12 @@ use embedded_graphics::prelude::*; use embedded_graphics::primitives::{PrimitiveStyleBuilder, Rectangle}; use embedded_graphics::text::Text; use st7789::{Orientation, ST7789}; +use {defmt_rtt as _, panic_probe as _}; use crate::my_display_interface::SPIDeviceInterface; use crate::shared_spi::SpiDeviceWithCs; use crate::touch::Touch; -use defmt_rtt as _; // global logger -use panic_probe as _; - //const DISPLAY_FREQ: u32 = 64_000_000; const TOUCH_FREQ: u32 = 200_000; @@ -94,9 +92,7 @@ async fn main(_spawner: Spawner, p: Peripherals) { loop { if let Some((x, y)) = touch.read() { - let style = PrimitiveStyleBuilder::new() - .fill_color(Rgb565::BLUE) - .build(); + let style = PrimitiveStyleBuilder::new().fill_color(Rgb565::BLUE).build(); Rectangle::new(Point::new(x - 1, y - 1), Size::new(3, 3)) .into_styled(style) diff --git a/examples/rp/src/bin/uart.rs b/examples/rp/src/bin/uart.rs index bc941dd8..99072253 100644 --- a/examples/rp/src/bin/uart.rs +++ b/examples/rp/src/bin/uart.rs @@ -4,9 +4,7 @@ use embassy::executor::Spawner; use embassy_rp::{uart, Peripherals}; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/std/src/serial_port.rs b/examples/std/src/serial_port.rs index 6825cbeb..c41abd4d 100644 --- a/examples/std/src/serial_port.rs +++ b/examples/std/src/serial_port.rs @@ -1,18 +1,16 @@ +use std::io; +use std::os::unix::io::{AsRawFd, RawFd}; + use nix::errno::Errno; use nix::fcntl::OFlag; use nix::sys::termios; -use std::io; -use std::os::unix::io::{AsRawFd, RawFd}; pub struct SerialPort { fd: RawFd, } impl SerialPort { - pub fn new( - path: &P, - baudrate: termios::BaudRate, - ) -> io::Result { + pub fn new(path: &P, baudrate: termios::BaudRate) -> io::Result { let fd = nix::fcntl::open( path, OFlag::O_RDWR | OFlag::O_NOCTTY | OFlag::O_NONBLOCK, diff --git a/examples/std/src/tuntap.rs b/examples/std/src/tuntap.rs index b70767a3..a0cace7f 100644 --- a/examples/std/src/tuntap.rs +++ b/examples/std/src/tuntap.rs @@ -1,9 +1,10 @@ -use async_io::Async; -use log::*; use std::io; use std::io::{Read, Write}; use std::os::unix::io::{AsRawFd, RawFd}; +use async_io::Async; +use log::*; + pub const SIOCGIFMTU: libc::c_ulong = 0x8921; pub const _SIOCGIFINDEX: libc::c_ulong = 0x8933; pub const _ETH_P_ALL: libc::c_short = 0x0003; @@ -32,11 +33,7 @@ fn ifreq_for(name: &str) -> ifreq { ifreq } -fn ifreq_ioctl( - lower: libc::c_int, - ifreq: &mut ifreq, - cmd: libc::c_ulong, -) -> io::Result { +fn ifreq_ioctl(lower: libc::c_int, ifreq: &mut ifreq, cmd: libc::c_ulong) -> io::Result { unsafe { let res = libc::ioctl(lower, cmd as _, ifreq as *mut ifreq); if res == -1 { @@ -141,11 +138,10 @@ impl TunTapDevice { } use core::task::Waker; -use embassy_net::{ - Device, DeviceCapabilities, LinkState, Packet, PacketBox, PacketBoxExt, PacketBuf, -}; use std::task::Context; +use embassy_net::{Device, DeviceCapabilities, LinkState, Packet, PacketBox, PacketBoxExt, PacketBuf}; + impl Device for TunTapDevice { fn is_transmit_ready(&mut self) -> bool { true diff --git a/examples/stm32f0/src/bin/hello.rs b/examples/stm32f0/src/bin/hello.rs index 975e94f3..225f1c3a 100644 --- a/examples/stm32f0/src/bin/hello.rs +++ b/examples/stm32f0/src/bin/hello.rs @@ -6,9 +6,7 @@ use defmt::info; use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; use embassy_stm32::Peripherals; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, _p: Peripherals) -> ! { diff --git a/examples/stm32f1/src/bin/adc.rs b/examples/stm32f1/src/bin/adc.rs index af403423..09904d4c 100644 --- a/examples/stm32f1/src/bin/adc.rs +++ b/examples/stm32f1/src/bin/adc.rs @@ -7,9 +7,7 @@ use embassy::executor::Spawner; use embassy::time::{Delay, Duration, Timer}; use embassy_stm32::adc::Adc; use embassy_stm32::Peripherals; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/stm32f1/src/bin/blinky.rs b/examples/stm32f1/src/bin/blinky.rs index 657bcdd1..c98d0cda 100644 --- a/examples/stm32f1/src/bin/blinky.rs +++ b/examples/stm32f1/src/bin/blinky.rs @@ -7,9 +7,7 @@ use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; use embassy_stm32::gpio::{Level, Output, Speed}; use embassy_stm32::Peripherals; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/stm32f1/src/bin/hello.rs b/examples/stm32f1/src/bin/hello.rs index 8054a899..82f11bc2 100644 --- a/examples/stm32f1/src/bin/hello.rs +++ b/examples/stm32f1/src/bin/hello.rs @@ -6,11 +6,8 @@ use defmt::info; use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; use embassy_stm32::time::Hertz; -use embassy_stm32::Config; -use embassy_stm32::Peripherals; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use embassy_stm32::{Config, Peripherals}; +use {defmt_rtt as _, panic_probe as _}; fn config() -> Config { let mut config = Config::default(); diff --git a/examples/stm32f1/src/bin/usb_serial.rs b/examples/stm32f1/src/bin/usb_serial.rs index fe4aa4cc..d06315d7 100644 --- a/examples/stm32f1/src/bin/usb_serial.rs +++ b/examples/stm32f1/src/bin/usb_serial.rs @@ -2,24 +2,18 @@ #![no_main] #![feature(type_alias_impl_trait)] -use defmt::panic; -use defmt::*; -use defmt_rtt as _; // global logger +use defmt::{panic, *}; use embassy::executor::Spawner; -use embassy::time::Duration; -use embassy::time::Timer; -use embassy_stm32::gpio::Level; -use embassy_stm32::gpio::Output; -use embassy_stm32::gpio::Speed; -use embassy_stm32::interrupt; +use embassy::time::{Duration, Timer}; +use embassy_stm32::gpio::{Level, Output, Speed}; use embassy_stm32::time::Hertz; use embassy_stm32::usb::{Driver, Instance}; -use embassy_stm32::{Config, Peripherals}; +use embassy_stm32::{interrupt, Config, Peripherals}; use embassy_usb::driver::EndpointError; use embassy_usb::Builder; use embassy_usb_serial::{CdcAcmClass, State}; use futures::future::join; -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; fn config() -> Config { let mut config = Config::default(); @@ -104,9 +98,7 @@ impl From for Disconnected { } } -async fn echo<'d, T: Instance + 'd>( - class: &mut CdcAcmClass<'d, Driver<'d, T>>, -) -> Result<(), Disconnected> { +async fn echo<'d, T: Instance + 'd>(class: &mut CdcAcmClass<'d, Driver<'d, T>>) -> Result<(), Disconnected> { let mut buf = [0; 64]; loop { let n = class.read_packet(&mut buf).await?; diff --git a/examples/stm32f2/src/bin/blinky.rs b/examples/stm32f2/src/bin/blinky.rs index 395f4df5..dd20ba85 100644 --- a/examples/stm32f2/src/bin/blinky.rs +++ b/examples/stm32f2/src/bin/blinky.rs @@ -7,9 +7,7 @@ use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; use embassy_stm32::gpio::{Level, Output, Speed}; use embassy_stm32::Peripherals; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/stm32f2/src/bin/pll.rs b/examples/stm32f2/src/bin/pll.rs index 4bd74f0b..b09d64b0 100644 --- a/examples/stm32f2/src/bin/pll.rs +++ b/examples/stm32f2/src/bin/pll.rs @@ -3,20 +3,16 @@ #![feature(type_alias_impl_trait)] use core::convert::TryFrom; + use defmt::*; use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; -use embassy_stm32::{ - rcc::{ - APBPrescaler, ClockSrc, HSEConfig, HSESrc, PLL48Div, PLLConfig, PLLMainDiv, PLLMul, - PLLPreDiv, PLLSrc, - }, - time::Hertz, - Config, Peripherals, +use embassy_stm32::rcc::{ + APBPrescaler, ClockSrc, HSEConfig, HSESrc, PLL48Div, PLLConfig, PLLMainDiv, PLLMul, PLLPreDiv, PLLSrc, }; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use embassy_stm32::time::Hertz; +use embassy_stm32::{Config, Peripherals}; +use {defmt_rtt as _, panic_probe as _}; // Example config for maximum performance on a NUCLEO-F207ZG board fn config() -> Config { diff --git a/examples/stm32f3/src/bin/blinky.rs b/examples/stm32f3/src/bin/blinky.rs index 4b181a78..4d0b33f6 100644 --- a/examples/stm32f3/src/bin/blinky.rs +++ b/examples/stm32f3/src/bin/blinky.rs @@ -7,9 +7,7 @@ use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; use embassy_stm32::gpio::{Level, Output, Speed}; use embassy_stm32::Peripherals; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/stm32f3/src/bin/button.rs b/examples/stm32f3/src/bin/button.rs index 207381bd..b55bf390 100644 --- a/examples/stm32f3/src/bin/button.rs +++ b/examples/stm32f3/src/bin/button.rs @@ -4,9 +4,8 @@ use cortex_m_rt::entry; use defmt::*; -use defmt_rtt as _; // global logger use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[entry] fn main() -> ! { diff --git a/examples/stm32f3/src/bin/button_events.rs b/examples/stm32f3/src/bin/button_events.rs index 59370179..45862ddc 100644 --- a/examples/stm32f3/src/bin/button_events.rs +++ b/examples/stm32f3/src/bin/button_events.rs @@ -19,9 +19,7 @@ use embassy_stm32::exti::ExtiInput; use embassy_stm32::gpio::{AnyPin, Input, Level, Output, Pin, Pull, Speed}; use embassy_stm32::peripherals::PA0; use embassy_stm32::Peripherals; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; struct Leds<'a> { leds: [Output<'a, AnyPin>; 8], @@ -57,8 +55,7 @@ impl<'a> Leds<'a> { self.process_event(new_message).await; } else { self.leds[self.current_led].set_low(); - if let Ok(new_message) = with_timeout(Duration::from_millis(200), CHANNEL.recv()).await - { + if let Ok(new_message) = with_timeout(Duration::from_millis(200), CHANNEL.recv()).await { self.process_event(new_message).await; } } @@ -137,22 +134,16 @@ async fn button_waiter(mut button: ExtiInput<'static, PA0>) { button.wait_for_rising_edge().await; loop { - if with_timeout( - Duration::from_millis(HOLD_DELAY), - button.wait_for_falling_edge(), - ) - .await - .is_err() + if with_timeout(Duration::from_millis(HOLD_DELAY), button.wait_for_falling_edge()) + .await + .is_err() { info!("Hold"); CHANNEL.send(ButtonEvent::Hold).await; button.wait_for_falling_edge().await; - } else if with_timeout( - Duration::from_millis(DOUBLE_CLICK_DELAY), - button.wait_for_rising_edge(), - ) - .await - .is_err() + } else if with_timeout(Duration::from_millis(DOUBLE_CLICK_DELAY), button.wait_for_rising_edge()) + .await + .is_err() { info!("Single click"); CHANNEL.send(ButtonEvent::SingleClick).await; diff --git a/examples/stm32f3/src/bin/button_exti.rs b/examples/stm32f3/src/bin/button_exti.rs index 68d16636..add6712b 100644 --- a/examples/stm32f3/src/bin/button_exti.rs +++ b/examples/stm32f3/src/bin/button_exti.rs @@ -3,12 +3,11 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use defmt_rtt as _; // global logger use embassy::executor::Spawner; use embassy_stm32::exti::ExtiInput; use embassy_stm32::gpio::{Input, Pull}; use embassy_stm32::Peripherals; -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/stm32f3/src/bin/flash.rs b/examples/stm32f3/src/bin/flash.rs index 3890f051..ce16f6de 100644 --- a/examples/stm32f3/src/bin/flash.rs +++ b/examples/stm32f3/src/bin/flash.rs @@ -7,9 +7,7 @@ use embassy::executor::Spawner; use embassy_stm32::flash::Flash; use embassy_stm32::Peripherals; use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/stm32f3/src/bin/hello.rs b/examples/stm32f3/src/bin/hello.rs index a79d6838..3b89f1c7 100644 --- a/examples/stm32f3/src/bin/hello.rs +++ b/examples/stm32f3/src/bin/hello.rs @@ -6,11 +6,8 @@ use defmt::info; use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; use embassy_stm32::time::Hertz; -use embassy_stm32::Config; -use embassy_stm32::Peripherals; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use embassy_stm32::{Config, Peripherals}; +use {defmt_rtt as _, panic_probe as _}; fn config() -> Config { let mut config = Config::default(); diff --git a/examples/stm32f3/src/bin/multiprio.rs b/examples/stm32f3/src/bin/multiprio.rs index 68429560..4f2cf9a6 100644 --- a/examples/stm32f3/src/bin/multiprio.rs +++ b/examples/stm32f3/src/bin/multiprio.rs @@ -57,16 +57,14 @@ #![no_main] #![feature(type_alias_impl_trait)] -use defmt::*; -use defmt_rtt as _; // global logger -use panic_probe as _; - use cortex_m_rt::entry; +use defmt::*; use embassy::time::{Duration, Instant, Timer}; use embassy::util::Forever; use embassy_stm32::executor::{Executor, InterruptExecutor}; use embassy_stm32::interrupt; use embassy_stm32::interrupt::InterruptExt; +use {defmt_rtt as _, panic_probe as _}; #[embassy::task] async fn run_high() { diff --git a/examples/stm32f3/src/bin/spi_dma.rs b/examples/stm32f3/src/bin/spi_dma.rs index 6d80c408..ece1ae6f 100644 --- a/examples/stm32f3/src/bin/spi_dma.rs +++ b/examples/stm32f3/src/bin/spi_dma.rs @@ -4,14 +4,14 @@ use core::fmt::Write; use core::str::from_utf8; + use defmt::*; -use defmt_rtt as _; // global logger use embassy::executor::Spawner; use embassy_stm32::spi::{Config, Spi}; use embassy_stm32::time::Hertz; use embassy_stm32::Peripherals; use heapless::String; -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { @@ -32,9 +32,7 @@ async fn main(_spawner: Spawner, p: Peripherals) { let mut write: String<128> = String::new(); let mut read = [0; 128]; core::write!(&mut write, "Hello DMA World {}!\r\n", n).unwrap(); - spi.transfer(&mut read[0..write.len()], write.as_bytes()) - .await - .ok(); + spi.transfer(&mut read[0..write.len()], write.as_bytes()).await.ok(); info!("read via spi+dma: {}", from_utf8(&read).unwrap()); } } diff --git a/examples/stm32f3/src/bin/usart_dma.rs b/examples/stm32f3/src/bin/usart_dma.rs index 859749eb..4660f812 100644 --- a/examples/stm32f3/src/bin/usart_dma.rs +++ b/examples/stm32f3/src/bin/usart_dma.rs @@ -3,14 +3,14 @@ #![feature(type_alias_impl_trait)] use core::fmt::Write; + use defmt::*; -use defmt_rtt as _; // global logger use embassy::executor::Spawner; use embassy_stm32::dma::NoDma; use embassy_stm32::usart::{Config, Uart}; use embassy_stm32::Peripherals; use heapless::String; -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/stm32f3/src/bin/usb_serial.rs b/examples/stm32f3/src/bin/usb_serial.rs index fc33d0bc..8a76d454 100644 --- a/examples/stm32f3/src/bin/usb_serial.rs +++ b/examples/stm32f3/src/bin/usb_serial.rs @@ -2,24 +2,18 @@ #![no_main] #![feature(type_alias_impl_trait)] -use defmt::panic; -use defmt::*; -use defmt_rtt as _; // global logger +use defmt::{panic, *}; use embassy::executor::Spawner; -use embassy::time::Duration; -use embassy::time::Timer; -use embassy_stm32::gpio::Level; -use embassy_stm32::gpio::Output; -use embassy_stm32::gpio::Speed; -use embassy_stm32::interrupt; +use embassy::time::{Duration, Timer}; +use embassy_stm32::gpio::{Level, Output, Speed}; use embassy_stm32::time::U32Ext; use embassy_stm32::usb::{Driver, Instance}; -use embassy_stm32::{Config, Peripherals}; +use embassy_stm32::{interrupt, Config, Peripherals}; use embassy_usb::driver::EndpointError; use embassy_usb::Builder; use embassy_usb_serial::{CdcAcmClass, State}; use futures::future::join; -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; fn config() -> Config { let mut config = Config::default(); @@ -103,9 +97,7 @@ impl From for Disconnected { } } -async fn echo<'d, T: Instance + 'd>( - class: &mut CdcAcmClass<'d, Driver<'d, T>>, -) -> Result<(), Disconnected> { +async fn echo<'d, T: Instance + 'd>(class: &mut CdcAcmClass<'d, Driver<'d, T>>) -> Result<(), Disconnected> { let mut buf = [0; 64]; loop { let n = class.read_packet(&mut buf).await?; diff --git a/examples/stm32f4/src/bin/adc.rs b/examples/stm32f4/src/bin/adc.rs index f0b1ad23..84ddbfd3 100644 --- a/examples/stm32f4/src/bin/adc.rs +++ b/examples/stm32f4/src/bin/adc.rs @@ -2,14 +2,12 @@ #![no_main] #![feature(type_alias_impl_trait)] -use defmt_rtt as _; // global logger -use panic_probe as _; - use defmt::*; use embassy::executor::Spawner; use embassy::time::{Delay, Duration, Timer}; use embassy_stm32::adc::Adc; use embassy_stm32::Peripherals; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/stm32f4/src/bin/blinky.rs b/examples/stm32f4/src/bin/blinky.rs index 8b85ca96..907492b3 100644 --- a/examples/stm32f4/src/bin/blinky.rs +++ b/examples/stm32f4/src/bin/blinky.rs @@ -3,12 +3,11 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use defmt_rtt as _; // global logger use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; use embassy_stm32::gpio::{Level, Output, Speed}; use embassy_stm32::Peripherals; -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/stm32f4/src/bin/button.rs b/examples/stm32f4/src/bin/button.rs index 4f9af7fb..b13e6453 100644 --- a/examples/stm32f4/src/bin/button.rs +++ b/examples/stm32f4/src/bin/button.rs @@ -4,9 +4,8 @@ use cortex_m_rt::entry; use defmt::*; -use defmt_rtt as _; // global logger use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[entry] fn main() -> ! { diff --git a/examples/stm32f4/src/bin/button_exti.rs b/examples/stm32f4/src/bin/button_exti.rs index 78f2e6ee..24ece992 100644 --- a/examples/stm32f4/src/bin/button_exti.rs +++ b/examples/stm32f4/src/bin/button_exti.rs @@ -3,12 +3,11 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use defmt_rtt as _; // global logger use embassy::executor::Spawner; use embassy_stm32::exti::ExtiInput; use embassy_stm32::gpio::{Input, Pull}; use embassy_stm32::Peripherals; -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/stm32f4/src/bin/can.rs b/examples/stm32f4/src/bin/can.rs index 0f41d686..8abce87a 100644 --- a/examples/stm32f4/src/bin/can.rs +++ b/examples/stm32f4/src/bin/can.rs @@ -2,15 +2,13 @@ #![no_main] #![feature(type_alias_impl_trait)] -use defmt_rtt as _; // global logger -use panic_probe as _; - use cortex_m_rt::entry; use defmt::*; use embassy_stm32::can::bxcan::filter::Mask32; use embassy_stm32::can::bxcan::{Frame, StandardId}; use embassy_stm32::can::Can; use embassy_stm32::gpio::{Input, Pull}; +use {defmt_rtt as _, panic_probe as _}; #[entry] fn main() -> ! { diff --git a/examples/stm32f4/src/bin/hello.rs b/examples/stm32f4/src/bin/hello.rs index 92d87ced..8e69e89d 100644 --- a/examples/stm32f4/src/bin/hello.rs +++ b/examples/stm32f4/src/bin/hello.rs @@ -6,11 +6,8 @@ use defmt::info; use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; use embassy_stm32::time::Hertz; -use embassy_stm32::Config; -use embassy_stm32::Peripherals; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use embassy_stm32::{Config, Peripherals}; +use {defmt_rtt as _, panic_probe as _}; fn config() -> Config { let mut config = Config::default(); diff --git a/examples/stm32f4/src/bin/multiprio.rs b/examples/stm32f4/src/bin/multiprio.rs index 68429560..4f2cf9a6 100644 --- a/examples/stm32f4/src/bin/multiprio.rs +++ b/examples/stm32f4/src/bin/multiprio.rs @@ -57,16 +57,14 @@ #![no_main] #![feature(type_alias_impl_trait)] -use defmt::*; -use defmt_rtt as _; // global logger -use panic_probe as _; - use cortex_m_rt::entry; +use defmt::*; use embassy::time::{Duration, Instant, Timer}; use embassy::util::Forever; use embassy_stm32::executor::{Executor, InterruptExecutor}; use embassy_stm32::interrupt; use embassy_stm32::interrupt::InterruptExt; +use {defmt_rtt as _, panic_probe as _}; #[embassy::task] async fn run_high() { diff --git a/examples/stm32f4/src/bin/sdmmc.rs b/examples/stm32f4/src/bin/sdmmc.rs index eab0fad4..b08d26f4 100644 --- a/examples/stm32f4/src/bin/sdmmc.rs +++ b/examples/stm32f4/src/bin/sdmmc.rs @@ -2,14 +2,12 @@ #![no_main] #![feature(type_alias_impl_trait)] -use defmt_rtt as _; // global logger -use panic_probe as _; - use defmt::*; use embassy::executor::Spawner; use embassy_stm32::sdmmc::Sdmmc; use embassy_stm32::time::U32Ext; use embassy_stm32::{interrupt, Config, Peripherals}; +use {defmt_rtt as _, panic_probe as _}; fn config() -> Config { let mut config = Config::default(); diff --git a/examples/stm32f4/src/bin/spi.rs b/examples/stm32f4/src/bin/spi.rs index 69be8143..05b48f47 100644 --- a/examples/stm32f4/src/bin/spi.rs +++ b/examples/stm32f4/src/bin/spi.rs @@ -2,15 +2,13 @@ #![no_main] #![feature(type_alias_impl_trait)] -use defmt_rtt as _; // global logger -use panic_probe as _; - use cortex_m_rt::entry; use defmt::*; use embassy_stm32::dma::NoDma; use embassy_stm32::gpio::{Level, Output, Speed}; use embassy_stm32::spi::{Config, Spi}; use embassy_stm32::time::Hertz; +use {defmt_rtt as _, panic_probe as _}; #[entry] fn main() -> ! { diff --git a/examples/stm32f4/src/bin/spi_dma.rs b/examples/stm32f4/src/bin/spi_dma.rs index 1bf9b856..f3c0f2cd 100644 --- a/examples/stm32f4/src/bin/spi_dma.rs +++ b/examples/stm32f4/src/bin/spi_dma.rs @@ -4,14 +4,14 @@ use core::fmt::Write; use core::str::from_utf8; + use defmt::*; -use defmt_rtt as _; // global logger use embassy::executor::Spawner; use embassy_stm32::spi::{Config, Spi}; use embassy_stm32::time::Hertz; use embassy_stm32::Peripherals; use heapless::String; -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { @@ -32,9 +32,7 @@ async fn main(_spawner: Spawner, p: Peripherals) { let mut write: String<128> = String::new(); let mut read = [0; 128]; core::write!(&mut write, "Hello DMA World {}!\r\n", n).unwrap(); - spi.transfer(&mut read[0..write.len()], write.as_bytes()) - .await - .ok(); + spi.transfer(&mut read[0..write.len()], write.as_bytes()).await.ok(); info!("read via spi+dma: {}", from_utf8(&read).unwrap()); } } diff --git a/examples/stm32f4/src/bin/usart.rs b/examples/stm32f4/src/bin/usart.rs index a302667e..90ad882b 100644 --- a/examples/stm32f4/src/bin/usart.rs +++ b/examples/stm32f4/src/bin/usart.rs @@ -4,10 +4,9 @@ use cortex_m_rt::entry; use defmt::*; -use defmt_rtt as _; // global logger use embassy_stm32::dma::NoDma; use embassy_stm32::usart::{Config, Uart}; -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[entry] fn main() -> ! { diff --git a/examples/stm32f4/src/bin/usart_buffered.rs b/examples/stm32f4/src/bin/usart_buffered.rs index 2a613ee4..039e43bd 100644 --- a/examples/stm32f4/src/bin/usart_buffered.rs +++ b/examples/stm32f4/src/bin/usart_buffered.rs @@ -3,13 +3,12 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use defmt_rtt as _; // global logger use embassy::executor::Spawner; use embassy_stm32::dma::NoDma; use embassy_stm32::usart::{BufferedUart, Config, State, Uart}; use embassy_stm32::{interrupt, Peripherals}; use embedded_io::asynch::BufRead; -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/stm32f4/src/bin/usart_dma.rs b/examples/stm32f4/src/bin/usart_dma.rs index cf45b71c..8d06f843 100644 --- a/examples/stm32f4/src/bin/usart_dma.rs +++ b/examples/stm32f4/src/bin/usart_dma.rs @@ -3,14 +3,14 @@ #![feature(type_alias_impl_trait)] use core::fmt::Write; + use defmt::*; -use defmt_rtt as _; // global logger use embassy::executor::Spawner; use embassy_stm32::dma::NoDma; use embassy_stm32::usart::{Config, Uart}; use embassy_stm32::Peripherals; use heapless::String; -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/stm32f7/build.rs b/examples/stm32f7/build.rs index b72dd55e..c4e15f19 100644 --- a/examples/stm32f7/build.rs +++ b/examples/stm32f7/build.rs @@ -1,7 +1,8 @@ //! adapted from https://github.com/stm32-rs/stm32f7xx-hal/blob/master/build.rs use std::env; use std::fs::File; -use std::io::{self, prelude::*}; +use std::io::prelude::*; +use std::io::{self}; use std::path::PathBuf; #[derive(Debug)] diff --git a/examples/stm32f7/src/bin/adc.rs b/examples/stm32f7/src/bin/adc.rs index 87f5d30d..fc835962 100644 --- a/examples/stm32f7/src/bin/adc.rs +++ b/examples/stm32f7/src/bin/adc.rs @@ -2,14 +2,12 @@ #![no_main] #![feature(type_alias_impl_trait)] -use defmt_rtt as _; // global logger -use panic_probe as _; - use defmt::*; use embassy::executor::Spawner; use embassy::time::{Delay, Duration, Timer}; use embassy_stm32::adc::Adc; use embassy_stm32::Peripherals; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/stm32f7/src/bin/blinky.rs b/examples/stm32f7/src/bin/blinky.rs index 8b85ca96..907492b3 100644 --- a/examples/stm32f7/src/bin/blinky.rs +++ b/examples/stm32f7/src/bin/blinky.rs @@ -3,12 +3,11 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use defmt_rtt as _; // global logger use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; use embassy_stm32::gpio::{Level, Output, Speed}; use embassy_stm32::Peripherals; -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/stm32f7/src/bin/button.rs b/examples/stm32f7/src/bin/button.rs index 4f9af7fb..b13e6453 100644 --- a/examples/stm32f7/src/bin/button.rs +++ b/examples/stm32f7/src/bin/button.rs @@ -4,9 +4,8 @@ use cortex_m_rt::entry; use defmt::*; -use defmt_rtt as _; // global logger use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[entry] fn main() -> ! { diff --git a/examples/stm32f7/src/bin/button_exti.rs b/examples/stm32f7/src/bin/button_exti.rs index 78f2e6ee..24ece992 100644 --- a/examples/stm32f7/src/bin/button_exti.rs +++ b/examples/stm32f7/src/bin/button_exti.rs @@ -3,12 +3,11 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use defmt_rtt as _; // global logger use embassy::executor::Spawner; use embassy_stm32::exti::ExtiInput; use embassy_stm32::gpio::{Input, Pull}; use embassy_stm32::Peripherals; -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/stm32f7/src/bin/eth.rs b/examples/stm32f7/src/bin/eth.rs index af012f82..dc0b3c60 100644 --- a/examples/stm32f7/src/bin/eth.rs +++ b/examples/stm32f7/src/bin/eth.rs @@ -13,13 +13,10 @@ use embassy_stm32::eth::{Ethernet, State}; use embassy_stm32::peripherals::ETH; use embassy_stm32::rng::Rng; use embassy_stm32::time::U32Ext; -use embassy_stm32::Config; -use embassy_stm32::{interrupt, Peripherals}; +use embassy_stm32::{interrupt, Config, Peripherals}; use embedded_io::asynch::Write; - -use defmt_rtt as _; // global logger -use panic_probe as _; use rand_core::RngCore; +use {defmt_rtt as _, panic_probe as _}; macro_rules! forever { ($val:expr) => {{ diff --git a/examples/stm32f7/src/bin/flash.rs b/examples/stm32f7/src/bin/flash.rs index 9eb8e4b9..af66275d 100644 --- a/examples/stm32f7/src/bin/flash.rs +++ b/examples/stm32f7/src/bin/flash.rs @@ -8,9 +8,7 @@ use embassy::time::{Duration, Timer}; use embassy_stm32::flash::Flash; use embassy_stm32::Peripherals; use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { @@ -40,8 +38,8 @@ async fn main(_spawner: Spawner, p: Peripherals) { unwrap!(f.write( ADDR, &[ - 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, - 25, 26, 27, 28, 29, 30, 31, 32 + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, + 30, 31, 32 ] )); @@ -52,8 +50,8 @@ async fn main(_spawner: Spawner, p: Peripherals) { assert_eq!( &buf[..], &[ - 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, - 25, 26, 27, 28, 29, 30, 31, 32 + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, + 30, 31, 32 ] ); } diff --git a/examples/stm32f7/src/bin/hello.rs b/examples/stm32f7/src/bin/hello.rs index 92d87ced..8e69e89d 100644 --- a/examples/stm32f7/src/bin/hello.rs +++ b/examples/stm32f7/src/bin/hello.rs @@ -6,11 +6,8 @@ use defmt::info; use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; use embassy_stm32::time::Hertz; -use embassy_stm32::Config; -use embassy_stm32::Peripherals; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use embassy_stm32::{Config, Peripherals}; +use {defmt_rtt as _, panic_probe as _}; fn config() -> Config { let mut config = Config::default(); diff --git a/examples/stm32f7/src/bin/sdmmc.rs b/examples/stm32f7/src/bin/sdmmc.rs index dae07c30..1af1061b 100644 --- a/examples/stm32f7/src/bin/sdmmc.rs +++ b/examples/stm32f7/src/bin/sdmmc.rs @@ -2,14 +2,12 @@ #![no_main] #![feature(type_alias_impl_trait)] -use defmt_rtt as _; // global logger -use panic_probe as _; - use defmt::*; use embassy::executor::Spawner; use embassy_stm32::sdmmc::Sdmmc; use embassy_stm32::time::U32Ext; use embassy_stm32::{interrupt, Config, Peripherals}; +use {defmt_rtt as _, panic_probe as _}; fn config() -> Config { let mut config = Config::default(); diff --git a/examples/stm32f7/src/bin/usart_dma.rs b/examples/stm32f7/src/bin/usart_dma.rs index 69fa21a0..d8551620 100644 --- a/examples/stm32f7/src/bin/usart_dma.rs +++ b/examples/stm32f7/src/bin/usart_dma.rs @@ -3,15 +3,14 @@ #![feature(type_alias_impl_trait)] use core::fmt::Write; + use defmt::*; -use defmt_rtt as _; // global logger use embassy::executor::Spawner; use embassy_stm32::dma::NoDma; use embassy_stm32::usart::{Config, Uart}; use embassy_stm32::Peripherals; -use panic_probe as _; - use heapless::String; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/stm32g0/src/bin/blinky.rs b/examples/stm32g0/src/bin/blinky.rs index 8b85ca96..907492b3 100644 --- a/examples/stm32g0/src/bin/blinky.rs +++ b/examples/stm32g0/src/bin/blinky.rs @@ -3,12 +3,11 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use defmt_rtt as _; // global logger use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; use embassy_stm32::gpio::{Level, Output, Speed}; use embassy_stm32::Peripherals; -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/stm32g0/src/bin/button.rs b/examples/stm32g0/src/bin/button.rs index 78d7ba1f..72a3f5cb 100644 --- a/examples/stm32g0/src/bin/button.rs +++ b/examples/stm32g0/src/bin/button.rs @@ -4,9 +4,8 @@ use cortex_m_rt::entry; use defmt::*; -use defmt_rtt as _; // global logger use embassy_stm32::gpio::{Input, Pull}; -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[entry] fn main() -> ! { diff --git a/examples/stm32g0/src/bin/button_exti.rs b/examples/stm32g0/src/bin/button_exti.rs index 4b1cadcb..924feeb3 100644 --- a/examples/stm32g0/src/bin/button_exti.rs +++ b/examples/stm32g0/src/bin/button_exti.rs @@ -3,12 +3,11 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use defmt_rtt as _; // global logger use embassy::executor::Spawner; use embassy_stm32::exti::ExtiInput; use embassy_stm32::gpio::{Input, Pull}; use embassy_stm32::Peripherals; -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/stm32g4/src/bin/blinky.rs b/examples/stm32g4/src/bin/blinky.rs index 92ec2b57..cd488327 100644 --- a/examples/stm32g4/src/bin/blinky.rs +++ b/examples/stm32g4/src/bin/blinky.rs @@ -3,12 +3,11 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use defmt_rtt as _; // global logger use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; use embassy_stm32::gpio::{Level, Output, Speed}; use embassy_stm32::Peripherals; -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/stm32g4/src/bin/button.rs b/examples/stm32g4/src/bin/button.rs index f6c98130..15abd86d 100644 --- a/examples/stm32g4/src/bin/button.rs +++ b/examples/stm32g4/src/bin/button.rs @@ -4,9 +4,8 @@ use cortex_m_rt::entry; use defmt::*; -use defmt_rtt as _; // global logger use embassy_stm32::gpio::{Input, Pull}; -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[entry] fn main() -> ! { diff --git a/examples/stm32g4/src/bin/button_exti.rs b/examples/stm32g4/src/bin/button_exti.rs index 78f2e6ee..24ece992 100644 --- a/examples/stm32g4/src/bin/button_exti.rs +++ b/examples/stm32g4/src/bin/button_exti.rs @@ -3,12 +3,11 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use defmt_rtt as _; // global logger use embassy::executor::Spawner; use embassy_stm32::exti::ExtiInput; use embassy_stm32::gpio::{Input, Pull}; use embassy_stm32::Peripherals; -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/stm32g4/src/bin/pwm.rs b/examples/stm32g4/src/bin/pwm.rs index 3770f6f3..525b6001 100644 --- a/examples/stm32g4/src/bin/pwm.rs +++ b/examples/stm32g4/src/bin/pwm.rs @@ -3,13 +3,13 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use defmt_rtt as _; // global logger use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; -use embassy_stm32::pwm::{simple_pwm::SimplePwm, Channel}; +use embassy_stm32::pwm::simple_pwm::SimplePwm; +use embassy_stm32::pwm::Channel; use embassy_stm32::time::U32Ext; use embassy_stm32::Peripherals; -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/stm32h7/src/bin/adc.rs b/examples/stm32h7/src/bin/adc.rs index b12bca30..e2439074 100644 --- a/examples/stm32h7/src/bin/adc.rs +++ b/examples/stm32h7/src/bin/adc.rs @@ -2,16 +2,14 @@ #![no_main] #![feature(type_alias_impl_trait)] +use defmt::*; use embassy::executor::Spawner; use embassy::time::{Delay, Duration, Timer}; use embassy_stm32::adc::{Adc, SampleTime}; use embassy_stm32::rcc::AdcClockSource; use embassy_stm32::time::U32Ext; use embassy_stm32::{Config, Peripherals}; - -use defmt::*; -use defmt_rtt as _; // global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; pub fn config() -> Config { let mut config = Config::default(); diff --git a/examples/stm32h7/src/bin/blinky.rs b/examples/stm32h7/src/bin/blinky.rs index 2329125a..7982f4a0 100644 --- a/examples/stm32h7/src/bin/blinky.rs +++ b/examples/stm32h7/src/bin/blinky.rs @@ -3,12 +3,11 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use defmt_rtt as _; // global logger use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; use embassy_stm32::gpio::{Level, Output, Speed}; use embassy_stm32::Peripherals; -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/stm32h7/src/bin/button_exti.rs b/examples/stm32h7/src/bin/button_exti.rs index 78f2e6ee..24ece992 100644 --- a/examples/stm32h7/src/bin/button_exti.rs +++ b/examples/stm32h7/src/bin/button_exti.rs @@ -3,12 +3,11 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use defmt_rtt as _; // global logger use embassy::executor::Spawner; use embassy_stm32::exti::ExtiInput; use embassy_stm32::gpio::{Input, Pull}; use embassy_stm32::Peripherals; -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/stm32h7/src/bin/camera.rs b/examples/stm32h7/src/bin/camera.rs index 3311ba85..918eab65 100644 --- a/examples/stm32h7/src/bin/camera.rs +++ b/examples/stm32h7/src/bin/camera.rs @@ -7,14 +7,10 @@ use embassy::time::{Duration, Timer}; use embassy_stm32::dcmi::{self, *}; use embassy_stm32::gpio::{Level, Output, Speed}; use embassy_stm32::i2c::I2c; -use embassy_stm32::interrupt; use embassy_stm32::rcc::{Mco, Mco1Source, McoClock}; use embassy_stm32::time::U32Ext; -use embassy_stm32::Config; -use embassy_stm32::Peripherals; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use embassy_stm32::{interrupt, Config, Peripherals}; +use {defmt_rtt as _, panic_probe as _}; #[allow(unused)] pub fn config() -> Config { @@ -43,15 +39,7 @@ async fn main(_spawner: Spawner, p: Peripherals) { let mut led = Output::new(p.PE3, Level::High, Speed::Low); let i2c_irq = interrupt::take!(I2C1_EV); - let cam_i2c = I2c::new( - p.I2C1, - p.PB8, - p.PB9, - i2c_irq, - p.DMA1_CH1, - p.DMA1_CH2, - 100u32.khz(), - ); + let cam_i2c = I2c::new(p.I2C1, p.PB8, p.PB9, i2c_irq, p.DMA1_CH1, p.DMA1_CH2, 100u32.khz()); let mut camera = Ov7725::new(cam_i2c, mco); @@ -60,17 +48,13 @@ async fn main(_spawner: Spawner, p: Peripherals) { let manufacturer_id = defmt::unwrap!(camera.read_manufacturer_id().await); let camera_id = defmt::unwrap!(camera.read_product_id().await); - defmt::info!( - "manufacturer: 0x{:x}, pid: 0x{:x}", - manufacturer_id, - camera_id - ); + defmt::info!("manufacturer: 0x{:x}, pid: 0x{:x}", manufacturer_id, camera_id); let dcmi_irq = interrupt::take!(DCMI); let config = dcmi::Config::default(); let mut dcmi = Dcmi::new_8bit( - p.DCMI, p.DMA1_CH0, dcmi_irq, p.PC6, p.PC7, p.PE0, p.PE1, p.PE4, p.PD3, p.PE5, p.PE6, - p.PB7, p.PA4, p.PA6, config, + p.DCMI, p.DMA1_CH0, dcmi_irq, p.PC6, p.PC7, p.PE0, p.PE1, p.PE4, p.PD3, p.PE5, p.PE6, p.PB7, p.PA4, p.PA6, + config, ); defmt::info!("attempting capture"); @@ -258,10 +242,8 @@ mod ov7725 { let com3 = self.read(Register::Com3).await?; let vflip = com3 & 0x80 > 0; - self.modify(Register::HRef, |reg| { - reg & 0xbf | if vflip { 0x40 } else { 0x40 } - }) - .await?; + self.modify(Register::HRef, |reg| reg & 0xbf | if vflip { 0x40 } else { 0x40 }) + .await?; if horizontal <= 320 || vertical <= 240 { self.write(Register::HStart, 0x3f).await?; @@ -291,11 +273,7 @@ mod ov7725 { .map_err(Error::I2c) } - async fn modify u8>( - &mut self, - register: Register, - f: F, - ) -> Result<(), Error> { + async fn modify u8>(&mut self, register: Register, f: F) -> Result<(), Error> { let value = self.read(register).await?; let value = f(value); self.write(register, value).await diff --git a/examples/stm32h7/src/bin/dac.rs b/examples/stm32h7/src/bin/dac.rs index 86c874a6..8ed33350 100644 --- a/examples/stm32h7/src/bin/dac.rs +++ b/examples/stm32h7/src/bin/dac.rs @@ -2,14 +2,12 @@ #![no_main] #![feature(type_alias_impl_trait)] -use defmt_rtt as _; // global logger -use panic_probe as _; - use cortex_m_rt::entry; use defmt::*; use embassy_stm32::dac::{Channel, Dac, Value}; use embassy_stm32::time::U32Ext; use embassy_stm32::Config; +use {defmt_rtt as _, panic_probe as _}; pub fn config() -> Config { let mut config = Config::default(); diff --git a/examples/stm32h7/src/bin/eth.rs b/examples/stm32h7/src/bin/eth.rs index 649ff260..6dabadc4 100644 --- a/examples/stm32h7/src/bin/eth.rs +++ b/examples/stm32h7/src/bin/eth.rs @@ -13,13 +13,10 @@ use embassy_stm32::eth::{Ethernet, State}; use embassy_stm32::peripherals::ETH; use embassy_stm32::rng::Rng; use embassy_stm32::time::U32Ext; -use embassy_stm32::Config; -use embassy_stm32::{interrupt, Peripherals}; +use embassy_stm32::{interrupt, Config, Peripherals}; use embedded_io::asynch::Write; - -use defmt_rtt as _; // global logger -use panic_probe as _; use rand_core::RngCore; +use {defmt_rtt as _, panic_probe as _}; macro_rules! forever { ($val:expr) => {{ diff --git a/examples/stm32h7/src/bin/flash.rs b/examples/stm32h7/src/bin/flash.rs index b008c088..5f97d2b3 100644 --- a/examples/stm32h7/src/bin/flash.rs +++ b/examples/stm32h7/src/bin/flash.rs @@ -3,13 +3,12 @@ #![feature(type_alias_impl_trait)] use defmt::{info, unwrap}; -use defmt_rtt as _; // global logger use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; use embassy_stm32::flash::Flash; use embassy_stm32::Peripherals; use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { @@ -39,8 +38,8 @@ async fn main(_spawner: Spawner, p: Peripherals) { unwrap!(f.write( ADDR, &[ - 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, - 25, 26, 27, 28, 29, 30, 31, 32 + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, + 30, 31, 32 ] )); @@ -51,8 +50,8 @@ async fn main(_spawner: Spawner, p: Peripherals) { assert_eq!( &buf[..], &[ - 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, - 25, 26, 27, 28, 29, 30, 31, 32 + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, + 30, 31, 32 ] ); } diff --git a/examples/stm32h7/src/bin/fmc.rs b/examples/stm32h7/src/bin/fmc.rs index ba8215d6..2f55479c 100644 --- a/examples/stm32h7/src/bin/fmc.rs +++ b/examples/stm32h7/src/bin/fmc.rs @@ -3,14 +3,12 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use defmt_rtt as _; // global logger use embassy::executor::Spawner; use embassy::time::{Delay, Duration, Timer}; use embassy_stm32::fmc::Fmc; use embassy_stm32::time::U32Ext; -use embassy_stm32::Config; -use embassy_stm32::Peripherals; -use panic_probe as _; +use embassy_stm32::{Config, Peripherals}; +use {defmt_rtt as _, panic_probe as _}; pub fn config() -> Config { let mut config = Config::default(); @@ -62,16 +60,8 @@ async fn main(_spawner: Spawner, p: Peripherals) { const REGION_WRITE_BACK: u32 = 0x01; const REGION_ENABLE: u32 = 0x01; - crate::assert_eq!( - size & (size - 1), - 0, - "SDRAM memory region size must be a power of 2" - ); - crate::assert_eq!( - size & 0x1F, - 0, - "SDRAM memory region size must be 32 bytes or more" - ); + crate::assert_eq!(size & (size - 1), 0, "SDRAM memory region size must be a power of 2"); + crate::assert_eq!(size & 0x1F, 0, "SDRAM memory region size must be 32 bytes or more"); fn log2minus1(sz: u32) -> u32 { for i in 5..=31 { if sz == (1 << i) { @@ -104,8 +94,7 @@ async fn main(_spawner: Spawner, p: Peripherals) { // Enable unsafe { - mpu.ctrl - .modify(|r| r | MPU_DEFAULT_MMAP_FOR_PRIVILEGED | MPU_ENABLE); + mpu.ctrl.modify(|r| r | MPU_DEFAULT_MMAP_FOR_PRIVILEGED | MPU_ENABLE); scb.shcsr.modify(|r| r | MEMFAULTENA); diff --git a/examples/stm32h7/src/bin/low_level_timer_api.rs b/examples/stm32h7/src/bin/low_level_timer_api.rs index 647c5a8f..3a728a0d 100644 --- a/examples/stm32h7/src/bin/low_level_timer_api.rs +++ b/examples/stm32h7/src/bin/low_level_timer_api.rs @@ -3,8 +3,6 @@ #![feature(type_alias_impl_trait)] use core::marker::PhantomData; -use defmt_rtt as _; // global logger -use panic_probe as _; use defmt::*; use embassy::executor::Spawner; @@ -13,9 +11,8 @@ use embassy_stm32::gpio::low_level::AFType; use embassy_stm32::gpio::Speed; use embassy_stm32::pwm::*; use embassy_stm32::time::{Hertz, U32Ext}; -use embassy_stm32::unborrow; -use embassy_stm32::Unborrow; -use embassy_stm32::{Config, Peripherals}; +use embassy_stm32::{unborrow, Config, Peripherals, Unborrow}; +use {defmt_rtt as _, panic_probe as _}; pub fn config() -> Config { let mut config = Config::default(); @@ -108,25 +105,18 @@ impl<'d, T: CaptureCompare32bitInstance> SimplePwm32<'d, T> { pub fn enable(&mut self, channel: Channel) { unsafe { - T::regs_gp32() - .ccer() - .modify(|w| w.set_cce(channel.raw(), true)); + T::regs_gp32().ccer().modify(|w| w.set_cce(channel.raw(), true)); } } pub fn disable(&mut self, channel: Channel) { unsafe { - T::regs_gp32() - .ccer() - .modify(|w| w.set_cce(channel.raw(), false)); + T::regs_gp32().ccer().modify(|w| w.set_cce(channel.raw(), false)); } } pub fn set_freq>(&mut self, freq: F) { - ::set_frequency( - &mut self.inner, - freq, - ); + ::set_frequency(&mut self.inner, freq); } pub fn get_max_duty(&self) -> u32 { @@ -135,10 +125,6 @@ impl<'d, T: CaptureCompare32bitInstance> SimplePwm32<'d, T> { pub fn set_duty(&mut self, channel: Channel, duty: u32) { defmt::assert!(duty < self.get_max_duty()); - unsafe { - T::regs_gp32() - .ccr(channel.raw()) - .modify(|w| w.set_ccr(duty)) - } + unsafe { T::regs_gp32().ccr(channel.raw()).modify(|w| w.set_ccr(duty)) } } } diff --git a/examples/stm32h7/src/bin/mco.rs b/examples/stm32h7/src/bin/mco.rs index a6735036..6f03b547 100644 --- a/examples/stm32h7/src/bin/mco.rs +++ b/examples/stm32h7/src/bin/mco.rs @@ -3,13 +3,12 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use defmt_rtt as _; // global logger use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; use embassy_stm32::gpio::{Level, Output, Speed}; use embassy_stm32::rcc::{Mco, Mco1Source, McoClock}; use embassy_stm32::Peripherals; -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/stm32h7/src/bin/pwm.rs b/examples/stm32h7/src/bin/pwm.rs index c33ba066..0e85b8d8 100644 --- a/examples/stm32h7/src/bin/pwm.rs +++ b/examples/stm32h7/src/bin/pwm.rs @@ -3,13 +3,13 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use defmt_rtt as _; // global logger use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; -use embassy_stm32::pwm::{simple_pwm::SimplePwm, Channel}; +use embassy_stm32::pwm::simple_pwm::SimplePwm; +use embassy_stm32::pwm::Channel; use embassy_stm32::time::U32Ext; use embassy_stm32::{Config, Peripherals}; -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; pub fn config() -> Config { let mut config = Config::default(); diff --git a/examples/stm32h7/src/bin/rng.rs b/examples/stm32h7/src/bin/rng.rs index b914fa70..2b42a6af 100644 --- a/examples/stm32h7/src/bin/rng.rs +++ b/examples/stm32h7/src/bin/rng.rs @@ -3,11 +3,10 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use defmt_rtt as _; // global logger use embassy::executor::Spawner; use embassy_stm32::rng::Rng; use embassy_stm32::Peripherals; -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/stm32h7/src/bin/sdmmc.rs b/examples/stm32h7/src/bin/sdmmc.rs index c3b2ebcd..4a74780f 100644 --- a/examples/stm32h7/src/bin/sdmmc.rs +++ b/examples/stm32h7/src/bin/sdmmc.rs @@ -2,14 +2,12 @@ #![no_main] #![feature(type_alias_impl_trait)] -use defmt_rtt as _; // global logger -use panic_probe as _; - use defmt::*; use embassy::executor::Spawner; use embassy_stm32::sdmmc::Sdmmc; use embassy_stm32::time::U32Ext; use embassy_stm32::{interrupt, Config, Peripherals}; +use {defmt_rtt as _, panic_probe as _}; fn config() -> Config { let mut config = Config::default(); diff --git a/examples/stm32h7/src/bin/signal.rs b/examples/stm32h7/src/bin/signal.rs index c63b2836..f798b1c9 100644 --- a/examples/stm32h7/src/bin/signal.rs +++ b/examples/stm32h7/src/bin/signal.rs @@ -2,17 +2,12 @@ #![no_main] #![feature(type_alias_impl_trait)] -// global logger use defmt::{info, unwrap}; -use defmt_rtt as _; - -use panic_probe as _; - use embassy::channel::signal::Signal; use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; - use embassy_stm32::Peripherals; +use {defmt_rtt as _, panic_probe as _}; static SIGNAL: Signal = Signal::new(); diff --git a/examples/stm32h7/src/bin/spi.rs b/examples/stm32h7/src/bin/spi.rs index a0acb03d..d4ee4429 100644 --- a/examples/stm32h7/src/bin/spi.rs +++ b/examples/stm32h7/src/bin/spi.rs @@ -2,21 +2,19 @@ #![no_main] #![feature(type_alias_impl_trait)] -use defmt_rtt as _; // global logger -use panic_probe as _; - use core::fmt::Write; use core::str::from_utf8; + use cortex_m_rt::entry; use defmt::*; use embassy::executor::Executor; use embassy::util::Forever; use embassy_stm32::dma::NoDma; use embassy_stm32::peripherals::SPI3; -use embassy_stm32::spi; use embassy_stm32::time::U32Ext; -use embassy_stm32::Config; +use embassy_stm32::{spi, Config}; use heapless::String; +use {defmt_rtt as _, panic_probe as _}; pub fn config() -> Config { let mut config = Config::default(); diff --git a/examples/stm32h7/src/bin/spi_dma.rs b/examples/stm32h7/src/bin/spi_dma.rs index 8f77b1d0..003bc7ad 100644 --- a/examples/stm32h7/src/bin/spi_dma.rs +++ b/examples/stm32h7/src/bin/spi_dma.rs @@ -2,20 +2,18 @@ #![no_main] #![feature(type_alias_impl_trait)] -use defmt_rtt as _; // global logger -use panic_probe as _; - use core::fmt::Write; use core::str::from_utf8; + use cortex_m_rt::entry; use defmt::*; use embassy::executor::Executor; use embassy::util::Forever; use embassy_stm32::peripherals::{DMA1_CH3, DMA1_CH4, SPI3}; -use embassy_stm32::spi; use embassy_stm32::time::U32Ext; -use embassy_stm32::Config; +use embassy_stm32::{spi, Config}; use heapless::String; +use {defmt_rtt as _, panic_probe as _}; pub fn config() -> Config { let mut config = Config::default(); diff --git a/examples/stm32h7/src/bin/usart.rs b/examples/stm32h7/src/bin/usart.rs index 0982a6ac..fc3db5a3 100644 --- a/examples/stm32h7/src/bin/usart.rs +++ b/examples/stm32h7/src/bin/usart.rs @@ -2,15 +2,13 @@ #![no_main] #![feature(type_alias_impl_trait)] +use cortex_m_rt::entry; use defmt::*; -use defmt_rtt as _; // global logger use embassy::executor::Executor; use embassy::util::Forever; use embassy_stm32::dma::NoDma; use embassy_stm32::usart::{Config, Uart}; -use panic_probe as _; - -use cortex_m_rt::entry; +use {defmt_rtt as _, panic_probe as _}; #[embassy::task] async fn main_task() { diff --git a/examples/stm32h7/src/bin/usart_dma.rs b/examples/stm32h7/src/bin/usart_dma.rs index 74de8b2a..d3325b0c 100644 --- a/examples/stm32h7/src/bin/usart_dma.rs +++ b/examples/stm32h7/src/bin/usart_dma.rs @@ -3,16 +3,15 @@ #![feature(type_alias_impl_trait)] use core::fmt::Write; + +use cortex_m_rt::entry; use defmt::*; -use defmt_rtt as _; // global logger use embassy::executor::Executor; use embassy::util::Forever; use embassy_stm32::dma::NoDma; use embassy_stm32::usart::{Config, Uart}; -use panic_probe as _; - -use cortex_m_rt::entry; use heapless::String; +use {defmt_rtt as _, panic_probe as _}; #[embassy::task] async fn main_task() { diff --git a/examples/stm32h7/src/bin/usart_split.rs b/examples/stm32h7/src/bin/usart_split.rs index eb3f9578..678d8c91 100644 --- a/examples/stm32h7/src/bin/usart_split.rs +++ b/examples/stm32h7/src/bin/usart_split.rs @@ -3,17 +3,14 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use defmt_rtt as _; // global logger use embassy::blocking_mutex::raw::ThreadModeRawMutex; use embassy::channel::mpmc::Channel; use embassy::executor::Spawner; use embassy_stm32::dma::NoDma; -use embassy_stm32::{ - peripherals::{DMA1_CH1, UART7}, - usart::{Config, Uart, UartRx}, - Peripherals, -}; -use panic_probe as _; +use embassy_stm32::peripherals::{DMA1_CH1, UART7}; +use embassy_stm32::usart::{Config, Uart, UartRx}; +use embassy_stm32::Peripherals; +use {defmt_rtt as _, panic_probe as _}; #[embassy::task] async fn writer(mut usart: Uart<'static, UART7, NoDma, NoDma>) { diff --git a/examples/stm32l0/src/bin/blinky.rs b/examples/stm32l0/src/bin/blinky.rs index 72f13f06..e027192b 100644 --- a/examples/stm32l0/src/bin/blinky.rs +++ b/examples/stm32l0/src/bin/blinky.rs @@ -2,14 +2,12 @@ #![no_main] #![feature(type_alias_impl_trait)] -use defmt_rtt as _; // global logger -use panic_probe as _; - use defmt::*; use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; use embassy_stm32::gpio::{Level, Output, Speed}; use embassy_stm32::Peripherals; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/stm32l0/src/bin/button.rs b/examples/stm32l0/src/bin/button.rs index dfa91259..43ea8c2a 100644 --- a/examples/stm32l0/src/bin/button.rs +++ b/examples/stm32l0/src/bin/button.rs @@ -3,11 +3,10 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use defmt_rtt as _; // global logger use embassy::executor::Spawner; use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; use embassy_stm32::Peripherals; -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/stm32l0/src/bin/button_exti.rs b/examples/stm32l0/src/bin/button_exti.rs index b1892e2c..d87870a0 100644 --- a/examples/stm32l0/src/bin/button_exti.rs +++ b/examples/stm32l0/src/bin/button_exti.rs @@ -2,14 +2,12 @@ #![no_main] #![feature(type_alias_impl_trait)] -use defmt_rtt as _; // global logger -use panic_probe as _; - use defmt::*; use embassy::executor::Spawner; use embassy_stm32::exti::ExtiInput; use embassy_stm32::gpio::{Input, Pull}; use embassy_stm32::Peripherals; +use {defmt_rtt as _, panic_probe as _}; fn config() -> embassy_stm32::Config { let mut config = embassy_stm32::Config::default(); diff --git a/examples/stm32l0/src/bin/flash.rs b/examples/stm32l0/src/bin/flash.rs index c2ccb5b6..a2fec929 100644 --- a/examples/stm32l0/src/bin/flash.rs +++ b/examples/stm32l0/src/bin/flash.rs @@ -7,9 +7,7 @@ use embassy::executor::Spawner; use embassy_stm32::flash::Flash; use embassy_stm32::Peripherals; use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/stm32l0/src/bin/lorawan.rs b/examples/stm32l0/src/bin/lorawan.rs index c3b97de5..8b7e8f82 100644 --- a/examples/stm32l0/src/bin/lorawan.rs +++ b/examples/stm32l0/src/bin/lorawan.rs @@ -6,20 +6,16 @@ #![feature(generic_associated_types)] #![feature(type_alias_impl_trait)] -use defmt_rtt as _; // global logger -use panic_probe as _; - -use embassy_lora::{sx127x::*, LoraTimer}; -use embassy_stm32::{ - exti::ExtiInput, - gpio::{Input, Level, Output, Pull, Speed}, - rng::Rng, - spi, - time::U32Ext, - Peripherals, -}; +use embassy_lora::sx127x::*; +use embassy_lora::LoraTimer; +use embassy_stm32::exti::ExtiInput; +use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; +use embassy_stm32::rng::Rng; +use embassy_stm32::time::U32Ext; +use embassy_stm32::{spi, Peripherals}; use lorawan::default_crypto::DefaultFactory as Crypto; use lorawan_device::async_device::{region, Device, JoinMode}; +use {defmt_rtt as _, panic_probe as _}; fn config() -> embassy_stm32::Config { let mut config = embassy_stm32::Config::default(); @@ -49,13 +45,10 @@ async fn main(_spawner: embassy::executor::Spawner, p: Peripherals) { let ready = Input::new(p.PB4, Pull::Up); let ready_pin = ExtiInput::new(ready, p.EXTI4); - let radio = Sx127xRadio::new(spi, cs, reset, ready_pin, DummySwitch) - .await - .unwrap(); + let radio = Sx127xRadio::new(spi, cs, reset, ready_pin, DummySwitch).await.unwrap(); let region = region::EU868::default().into(); - let mut device: Device<_, Crypto, _, _> = - Device::new(region, radio, LoraTimer, Rng::new(p.RNG)); + let mut device: Device<_, Crypto, _, _> = Device::new(region, radio, LoraTimer, Rng::new(p.RNG)); defmt::info!("Joining LoRaWAN network"); diff --git a/examples/stm32l0/src/bin/raw_spawn.rs b/examples/stm32l0/src/bin/raw_spawn.rs index 4601d85d..dfe2cddb 100644 --- a/examples/stm32l0/src/bin/raw_spawn.rs +++ b/examples/stm32l0/src/bin/raw_spawn.rs @@ -1,17 +1,15 @@ #![no_std] #![no_main] -use defmt::*; -use defmt_rtt as _; // global logger -use panic_probe as _; - use core::mem; -use cortex_m_rt::entry; +use cortex_m_rt::entry; +use defmt::*; use embassy::executor::raw::TaskStorage; use embassy::executor::Executor; use embassy::time::{Duration, Timer}; use embassy::util::Forever; +use {defmt_rtt as _, panic_probe as _}; async fn run1() { loop { diff --git a/examples/stm32l0/src/bin/spi.rs b/examples/stm32l0/src/bin/spi.rs index 5ed783b1..dba0b281 100644 --- a/examples/stm32l0/src/bin/spi.rs +++ b/examples/stm32l0/src/bin/spi.rs @@ -2,17 +2,14 @@ #![no_main] #![feature(type_alias_impl_trait)] -use defmt_rtt as _; // global logger -use panic_probe as _; - use defmt::*; use embassy::executor::Spawner; -use embassy_stm32::gpio::{Level, Output, Speed}; - use embassy_stm32::dma::NoDma; +use embassy_stm32::gpio::{Level, Output, Speed}; use embassy_stm32::spi::{Config, Spi}; use embassy_stm32::time::Hertz; use embassy_stm32::Peripherals; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/stm32l0/src/bin/usart_dma.rs b/examples/stm32l0/src/bin/usart_dma.rs index b3fdcacb..86124163 100644 --- a/examples/stm32l0/src/bin/usart_dma.rs +++ b/examples/stm32l0/src/bin/usart_dma.rs @@ -2,25 +2,15 @@ #![no_main] #![feature(type_alias_impl_trait)] -use defmt_rtt as _; // global logger -use panic_probe as _; - use defmt::*; - use embassy::executor::Spawner; use embassy_stm32::usart::{Config, Uart}; use embassy_stm32::Peripherals; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { - let mut usart = Uart::new( - p.USART1, - p.PB7, - p.PB6, - p.DMA1_CH2, - p.DMA1_CH3, - Config::default(), - ); + let mut usart = Uart::new(p.USART1, p.PB7, p.PB6, p.DMA1_CH2, p.DMA1_CH3, Config::default()); usart.write(b"Hello Embassy World!\r\n").await.unwrap(); info!("wrote Hello, starting echo"); diff --git a/examples/stm32l0/src/bin/usart_irq.rs b/examples/stm32l0/src/bin/usart_irq.rs index 4413a294..09b1b0b0 100644 --- a/examples/stm32l0/src/bin/usart_irq.rs +++ b/examples/stm32l0/src/bin/usart_irq.rs @@ -2,18 +2,13 @@ #![no_main] #![feature(type_alias_impl_trait)] -use defmt_rtt as _; -use embedded_io::asynch::{Read, Write}; -// global logger -use panic_probe as _; - use defmt::*; - use embassy::executor::Spawner; use embassy_stm32::dma::NoDma; -use embassy_stm32::interrupt; use embassy_stm32::usart::{BufferedUart, Config, State, Uart}; -use embassy_stm32::Peripherals; +use embassy_stm32::{interrupt, Peripherals}; +use embedded_io::asynch::{Read, Write}; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/stm32l1/src/bin/blinky.rs b/examples/stm32l1/src/bin/blinky.rs index e8145552..bace53d9 100644 --- a/examples/stm32l1/src/bin/blinky.rs +++ b/examples/stm32l1/src/bin/blinky.rs @@ -2,14 +2,12 @@ #![no_main] #![feature(type_alias_impl_trait)] -use defmt_rtt as _; // global logger -use panic_probe as _; - use defmt::*; use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; use embassy_stm32::gpio::{Level, Output, Speed}; use embassy_stm32::Peripherals; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/stm32l1/src/bin/flash.rs b/examples/stm32l1/src/bin/flash.rs index eea838cb..fc519b07 100644 --- a/examples/stm32l1/src/bin/flash.rs +++ b/examples/stm32l1/src/bin/flash.rs @@ -7,9 +7,7 @@ use embassy::executor::Spawner; use embassy_stm32::flash::Flash; use embassy_stm32::Peripherals; use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/stm32l1/src/bin/spi.rs b/examples/stm32l1/src/bin/spi.rs index bced0c54..81ccba4e 100644 --- a/examples/stm32l1/src/bin/spi.rs +++ b/examples/stm32l1/src/bin/spi.rs @@ -2,17 +2,14 @@ #![no_main] #![feature(type_alias_impl_trait)] -use defmt_rtt as _; // global logger -use panic_probe as _; - use defmt::*; use embassy::executor::Spawner; -use embassy_stm32::gpio::{Level, Output, Speed}; - use embassy_stm32::dma::NoDma; +use embassy_stm32::gpio::{Level, Output, Speed}; use embassy_stm32::spi::{Config, Spi}; use embassy_stm32::time::Hertz; use embassy_stm32::Peripherals; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/stm32l4/src/bin/adc.rs b/examples/stm32l4/src/bin/adc.rs index 58ef6eba..499ea47d 100644 --- a/examples/stm32l4/src/bin/adc.rs +++ b/examples/stm32l4/src/bin/adc.rs @@ -2,13 +2,11 @@ #![no_main] #![feature(type_alias_impl_trait)] -use defmt_rtt as _; // global logger -use panic_probe as _; - use defmt::*; use embassy::time::Delay; use embassy_stm32::adc::{Adc, Resolution}; use embassy_stm32::pac; +use {defmt_rtt as _, panic_probe as _}; #[cortex_m_rt::entry] fn main() -> ! { diff --git a/examples/stm32l4/src/bin/blinky.rs b/examples/stm32l4/src/bin/blinky.rs index e24a5bd3..54f8e03b 100644 --- a/examples/stm32l4/src/bin/blinky.rs +++ b/examples/stm32l4/src/bin/blinky.rs @@ -3,12 +3,11 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use defmt_rtt as _; // global logger use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; use embassy_stm32::gpio::{Level, Output, Speed}; use embassy_stm32::Peripherals; -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/stm32l4/src/bin/button.rs b/examples/stm32l4/src/bin/button.rs index ff270b51..73b1962e 100644 --- a/examples/stm32l4/src/bin/button.rs +++ b/examples/stm32l4/src/bin/button.rs @@ -3,9 +3,8 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use defmt_rtt as _; // global logger use embassy_stm32::gpio::{Input, Pull}; -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[cortex_m_rt::entry] fn main() -> ! { diff --git a/examples/stm32l4/src/bin/button_exti.rs b/examples/stm32l4/src/bin/button_exti.rs index 4b1cadcb..924feeb3 100644 --- a/examples/stm32l4/src/bin/button_exti.rs +++ b/examples/stm32l4/src/bin/button_exti.rs @@ -3,12 +3,11 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use defmt_rtt as _; // global logger use embassy::executor::Spawner; use embassy_stm32::exti::ExtiInput; use embassy_stm32::gpio::{Input, Pull}; use embassy_stm32::Peripherals; -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/stm32l4/src/bin/dac.rs b/examples/stm32l4/src/bin/dac.rs index c26e7e70..d6e744aa 100644 --- a/examples/stm32l4/src/bin/dac.rs +++ b/examples/stm32l4/src/bin/dac.rs @@ -2,12 +2,10 @@ #![no_main] #![feature(type_alias_impl_trait)] -use defmt_rtt as _; // global logger -use panic_probe as _; - use defmt::*; use embassy_stm32::dac::{Channel, Dac, Value}; use embassy_stm32::pac; +use {defmt_rtt as _, panic_probe as _}; #[cortex_m_rt::entry] fn main() -> ! { diff --git a/examples/stm32l4/src/bin/i2c.rs b/examples/stm32l4/src/bin/i2c.rs index 46776564..a22b5218 100644 --- a/examples/stm32l4/src/bin/i2c.rs +++ b/examples/stm32l4/src/bin/i2c.rs @@ -2,16 +2,13 @@ #![no_main] #![feature(type_alias_impl_trait)] -use defmt_rtt as _; // global logger -use panic_probe as _; - use defmt::*; use embassy::executor::Spawner; use embassy_stm32::dma::NoDma; use embassy_stm32::i2c::I2c; -use embassy_stm32::interrupt; use embassy_stm32::time::Hertz; -use embassy_stm32::Peripherals; +use embassy_stm32::{interrupt, Peripherals}; +use {defmt_rtt as _, panic_probe as _}; const ADDRESS: u8 = 0x5F; const WHOAMI: u8 = 0x0F; diff --git a/examples/stm32l4/src/bin/i2c_blocking_async.rs b/examples/stm32l4/src/bin/i2c_blocking_async.rs index eb74223b..6c4a8670 100644 --- a/examples/stm32l4/src/bin/i2c_blocking_async.rs +++ b/examples/stm32l4/src/bin/i2c_blocking_async.rs @@ -2,18 +2,15 @@ #![no_main] #![feature(type_alias_impl_trait)] -use defmt_rtt as _; // global logger -use panic_probe as _; - use defmt::*; use embassy::executor::Spawner; use embassy_embedded_hal::adapter::BlockingAsync; use embassy_stm32::dma::NoDma; use embassy_stm32::i2c::I2c; -use embassy_stm32::interrupt; use embassy_stm32::time::Hertz; -use embassy_stm32::Peripherals; +use embassy_stm32::{interrupt, Peripherals}; use embedded_hal_async::i2c::I2c as I2cTrait; +use {defmt_rtt as _, panic_probe as _}; const ADDRESS: u8 = 0x5F; const WHOAMI: u8 = 0x0F; diff --git a/examples/stm32l4/src/bin/i2c_dma.rs b/examples/stm32l4/src/bin/i2c_dma.rs index 886a0e09..48d2e92c 100644 --- a/examples/stm32l4/src/bin/i2c_dma.rs +++ b/examples/stm32l4/src/bin/i2c_dma.rs @@ -2,15 +2,12 @@ #![no_main] #![feature(type_alias_impl_trait)] -use defmt_rtt as _; // global logger -use panic_probe as _; - use defmt::*; use embassy::executor::Spawner; use embassy_stm32::i2c::I2c; -use embassy_stm32::interrupt; use embassy_stm32::time::Hertz; -use embassy_stm32::Peripherals; +use embassy_stm32::{interrupt, Peripherals}; +use {defmt_rtt as _, panic_probe as _}; const ADDRESS: u8 = 0x5F; const WHOAMI: u8 = 0x0F; @@ -18,15 +15,7 @@ const WHOAMI: u8 = 0x0F; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) -> ! { let irq = interrupt::take!(I2C2_EV); - let mut i2c = I2c::new( - p.I2C2, - p.PB10, - p.PB11, - irq, - p.DMA1_CH4, - p.DMA1_CH5, - Hertz(100_000), - ); + let mut i2c = I2c::new(p.I2C2, p.PB10, p.PB11, irq, p.DMA1_CH4, p.DMA1_CH5, Hertz(100_000)); let mut data = [0u8; 1]; unwrap!(i2c.write_read(ADDRESS, &[WHOAMI], &mut data).await); diff --git a/examples/stm32l4/src/bin/rng.rs b/examples/stm32l4/src/bin/rng.rs index 03773e61..7aaa122e 100644 --- a/examples/stm32l4/src/bin/rng.rs +++ b/examples/stm32l4/src/bin/rng.rs @@ -3,12 +3,11 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use defmt_rtt as _; // global logger use embassy::executor::Spawner; use embassy_stm32::rcc::{ClockSrc, PLLClkDiv, PLLMul, PLLSource, PLLSrcDiv}; use embassy_stm32::rng::Rng; use embassy_stm32::{Config, Peripherals}; -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; fn config() -> Config { let mut config = Config::default(); diff --git a/examples/stm32l4/src/bin/spi.rs b/examples/stm32l4/src/bin/spi.rs index 44fdf81a..76e316a2 100644 --- a/examples/stm32l4/src/bin/spi.rs +++ b/examples/stm32l4/src/bin/spi.rs @@ -2,14 +2,12 @@ #![no_main] #![feature(type_alias_impl_trait)] -use defmt_rtt as _; // global logger -use panic_probe as _; - use defmt::*; use embassy_stm32::dma::NoDma; use embassy_stm32::gpio::{Level, Output, Speed}; use embassy_stm32::spi::{Config, Spi}; use embassy_stm32::time::Hertz; +use {defmt_rtt as _, panic_probe as _}; #[cortex_m_rt::entry] fn main() -> ! { diff --git a/examples/stm32l4/src/bin/spi_blocking_async.rs b/examples/stm32l4/src/bin/spi_blocking_async.rs index e1a40010..20a2ff80 100644 --- a/examples/stm32l4/src/bin/spi_blocking_async.rs +++ b/examples/stm32l4/src/bin/spi_blocking_async.rs @@ -2,9 +2,6 @@ #![no_main] #![feature(type_alias_impl_trait)] -use defmt_rtt as _; // global logger -use panic_probe as _; - use defmt::*; use embassy::executor::Spawner; use embassy_embedded_hal::adapter::BlockingAsync; @@ -14,6 +11,7 @@ use embassy_stm32::spi::{Config, Spi}; use embassy_stm32::time::Hertz; use embassy_stm32::Peripherals; use embedded_hal_async::spi::SpiBus; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/stm32l4/src/bin/spi_dma.rs b/examples/stm32l4/src/bin/spi_dma.rs index 88d02c7e..d0c3609a 100644 --- a/examples/stm32l4/src/bin/spi_dma.rs +++ b/examples/stm32l4/src/bin/spi_dma.rs @@ -2,15 +2,13 @@ #![no_main] #![feature(type_alias_impl_trait)] -use defmt_rtt as _; // global logger -use panic_probe as _; - use defmt::*; use embassy::executor::Spawner; use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; use embassy_stm32::spi::{Config, Spi}; use embassy_stm32::time::Hertz; use embassy_stm32::Peripherals; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/stm32l4/src/bin/usart.rs b/examples/stm32l4/src/bin/usart.rs index b38f5545..4a4b46c5 100644 --- a/examples/stm32l4/src/bin/usart.rs +++ b/examples/stm32l4/src/bin/usart.rs @@ -2,12 +2,10 @@ #![no_main] #![feature(type_alias_impl_trait)] -use defmt_rtt as _; // global logger -use panic_probe as _; - use defmt::*; use embassy_stm32::dma::NoDma; use embassy_stm32::usart::{Config, Uart}; +use {defmt_rtt as _, panic_probe as _}; #[cortex_m_rt::entry] fn main() -> ! { diff --git a/examples/stm32l4/src/bin/usart_dma.rs b/examples/stm32l4/src/bin/usart_dma.rs index 40e2c367..7ae7e9e1 100644 --- a/examples/stm32l4/src/bin/usart_dma.rs +++ b/examples/stm32l4/src/bin/usart_dma.rs @@ -3,14 +3,14 @@ #![feature(type_alias_impl_trait)] use core::fmt::Write; + use defmt::*; -use defmt_rtt as _; // global logger use embassy::executor::Spawner; use embassy_stm32::dma::NoDma; use embassy_stm32::usart::{Config, Uart}; use embassy_stm32::Peripherals; use heapless::String; -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/stm32l5/src/bin/button_exti.rs b/examples/stm32l5/src/bin/button_exti.rs index 304ce0a8..c7a6cfa2 100644 --- a/examples/stm32l5/src/bin/button_exti.rs +++ b/examples/stm32l5/src/bin/button_exti.rs @@ -3,12 +3,11 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use defmt_rtt as _; // global logger use embassy::executor::Spawner; use embassy_stm32::exti::ExtiInput; use embassy_stm32::gpio::{Input, Pull}; use embassy_stm32::Peripherals; -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/stm32l5/src/bin/rng.rs b/examples/stm32l5/src/bin/rng.rs index 5f75c1ff..d3627d2c 100644 --- a/examples/stm32l5/src/bin/rng.rs +++ b/examples/stm32l5/src/bin/rng.rs @@ -3,12 +3,11 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use defmt_rtt as _; // global logger use embassy::executor::Spawner; use embassy_stm32::rcc::{ClockSrc, PLLClkDiv, PLLMul, PLLSource, PLLSrcDiv}; use embassy_stm32::rng::Rng; use embassy_stm32::{Config, Peripherals}; -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; fn config() -> Config { let mut config = Config::default(); diff --git a/examples/stm32l5/src/bin/usb_ethernet.rs b/examples/stm32l5/src/bin/usb_ethernet.rs index 526b2753..d711616e 100644 --- a/examples/stm32l5/src/bin/usb_ethernet.rs +++ b/examples/stm32l5/src/bin/usb_ethernet.rs @@ -5,29 +5,24 @@ use core::sync::atomic::{AtomicBool, Ordering}; use core::task::Waker; + use defmt::*; -use defmt_rtt as _; // global logger use embassy::blocking_mutex::raw::ThreadModeRawMutex; use embassy::channel::mpmc::Channel; use embassy::executor::Spawner; use embassy::util::Forever; use embassy_net::tcp::TcpSocket; use embassy_net::{PacketBox, PacketBoxExt, PacketBuf, Stack, StackResources}; -use embassy_stm32::interrupt; use embassy_stm32::rcc::*; use embassy_stm32::rng::Rng; use embassy_stm32::time::Hertz; use embassy_stm32::usb::Driver; -use embassy_stm32::{Config, Peripherals}; +use embassy_stm32::{interrupt, Config, Peripherals}; use embassy_usb::{Builder, UsbDevice}; use embassy_usb_ncm::{CdcNcmClass, Receiver, Sender, State}; -use panic_probe as _; - -use defmt_rtt as _; use embedded_io::asynch::{Read, Write}; -// global logger -use panic_probe as _; use rand_core::RngCore; +use {defmt_rtt as _, panic_probe as _}; type MyDriver = Driver<'static, embassy_stm32::peripherals::USB>; @@ -92,13 +87,7 @@ fn config() -> Config { let mut config = Config::default(); config.rcc.mux = ClockSrc::HSE(Hertz(16_000_000)); - config.rcc.mux = ClockSrc::PLL( - PLLSource::HSI16, - PLLClkDiv::Div2, - PLLSrcDiv::Div1, - PLLMul::Mul10, - None, - ); + config.rcc.mux = ClockSrc::PLL(PLLSource::HSI16, PLLClkDiv::Div2, PLLSrcDiv::Div1, PLLMul::Mul10, None); config.rcc.hsi48 = true; config @@ -186,9 +175,7 @@ async fn main(spawner: Spawner, p: Peripherals) { let seed = rng.next_u64(); // Init network stack - let device = Device { - mac_addr: our_mac_addr, - }; + let device = Device { mac_addr: our_mac_addr }; let stack = &*forever!(Stack::new( device, config, diff --git a/examples/stm32l5/src/bin/usb_hid_mouse.rs b/examples/stm32l5/src/bin/usb_hid_mouse.rs index d275aba3..d139e6bb 100644 --- a/examples/stm32l5/src/bin/usb_hid_mouse.rs +++ b/examples/stm32l5/src/bin/usb_hid_mouse.rs @@ -6,31 +6,22 @@ use defmt::*; use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; -use embassy_stm32::interrupt; use embassy_stm32::rcc::*; use embassy_stm32::time::Hertz; use embassy_stm32::usb::Driver; -use embassy_stm32::{Config, Peripherals}; +use embassy_stm32::{interrupt, Config, Peripherals}; use embassy_usb::control::OutResponse; use embassy_usb::Builder; use embassy_usb_hid::{HidWriter, ReportId, RequestHandler, State}; use futures::future::join; use usbd_hid::descriptor::{MouseReport, SerializedDescriptor}; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; fn config() -> Config { let mut config = Config::default(); config.rcc.mux = ClockSrc::HSE(Hertz(16_000_000)); - config.rcc.mux = ClockSrc::PLL( - PLLSource::HSI16, - PLLClkDiv::Div2, - PLLSrcDiv::Div1, - PLLMul::Mul10, - None, - ); + config.rcc.mux = ClockSrc::PLL(PLLSource::HSI16, PLLClkDiv::Div2, PLLSrcDiv::Div1, PLLMul::Mul10, None); config.rcc.hsi48 = true; config diff --git a/examples/stm32l5/src/bin/usb_serial.rs b/examples/stm32l5/src/bin/usb_serial.rs index 987f1b69..8dab001c 100644 --- a/examples/stm32l5/src/bin/usb_serial.rs +++ b/examples/stm32l5/src/bin/usb_serial.rs @@ -2,32 +2,23 @@ #![no_main] #![feature(type_alias_impl_trait)] -use defmt::panic; -use defmt::*; -use defmt_rtt as _; // global logger +use defmt::{panic, *}; use embassy::executor::Spawner; -use embassy_stm32::interrupt; use embassy_stm32::rcc::*; use embassy_stm32::time::Hertz; use embassy_stm32::usb::{Driver, Instance}; -use embassy_stm32::{Config, Peripherals}; +use embassy_stm32::{interrupt, Config, Peripherals}; use embassy_usb::driver::EndpointError; use embassy_usb::Builder; use embassy_usb_serial::{CdcAcmClass, State}; use futures::future::join; -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; fn config() -> Config { let mut config = Config::default(); config.rcc.mux = ClockSrc::HSE(Hertz(16_000_000)); - config.rcc.mux = ClockSrc::PLL( - PLLSource::HSI16, - PLLClkDiv::Div2, - PLLSrcDiv::Div1, - PLLMul::Mul10, - None, - ); + config.rcc.mux = ClockSrc::PLL(PLLSource::HSI16, PLLClkDiv::Div2, PLLSrcDiv::Div1, PLLMul::Mul10, None); config.rcc.hsi48 = true; config @@ -99,9 +90,7 @@ impl From for Disconnected { } } -async fn echo<'d, T: Instance + 'd>( - class: &mut CdcAcmClass<'d, Driver<'d, T>>, -) -> Result<(), Disconnected> { +async fn echo<'d, T: Instance + 'd>(class: &mut CdcAcmClass<'d, Driver<'d, T>>) -> Result<(), Disconnected> { let mut buf = [0; 64]; loop { let n = class.read_packet(&mut buf).await?; diff --git a/examples/stm32u5/src/bin/blinky.rs b/examples/stm32u5/src/bin/blinky.rs index e1bcccf5..4910e0b9 100644 --- a/examples/stm32u5/src/bin/blinky.rs +++ b/examples/stm32u5/src/bin/blinky.rs @@ -3,13 +3,11 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use defmt_rtt as _; use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; use embassy_stm32::gpio::{Level, Output, Speed}; use embassy_stm32::Peripherals; -// global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) -> ! { diff --git a/examples/stm32u5/src/bin/boot.rs b/examples/stm32u5/src/bin/boot.rs index e0402134..e2112ce5 100644 --- a/examples/stm32u5/src/bin/boot.rs +++ b/examples/stm32u5/src/bin/boot.rs @@ -3,10 +3,7 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use defmt_rtt as _; // global logger -use panic_probe as _; - -use embassy_stm32 as _; +use {defmt_rtt as _, embassy_stm32 as _, panic_probe as _}; #[cortex_m_rt::entry] fn main() -> ! { diff --git a/examples/stm32wb/src/bin/blinky.rs b/examples/stm32wb/src/bin/blinky.rs index 59324161..8ab9b749 100644 --- a/examples/stm32wb/src/bin/blinky.rs +++ b/examples/stm32wb/src/bin/blinky.rs @@ -3,12 +3,11 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use defmt_rtt as _; // global logger use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; use embassy_stm32::gpio::{Level, Output, Speed}; use embassy_stm32::Peripherals; -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/stm32wb/src/bin/button_exti.rs b/examples/stm32wb/src/bin/button_exti.rs index a30a4a21..2ddeb887 100644 --- a/examples/stm32wb/src/bin/button_exti.rs +++ b/examples/stm32wb/src/bin/button_exti.rs @@ -3,12 +3,11 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use defmt_rtt as _; // global logger use embassy::executor::Spawner; use embassy_stm32::exti::ExtiInput; use embassy_stm32::gpio::{Input, Pull}; use embassy_stm32::Peripherals; -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/stm32wl/src/bin/blinky.rs b/examples/stm32wl/src/bin/blinky.rs index 78079bfd..9393af1c 100644 --- a/examples/stm32wl/src/bin/blinky.rs +++ b/examples/stm32wl/src/bin/blinky.rs @@ -3,12 +3,11 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use defmt_rtt as _; // global logger use embassy::executor::Spawner; use embassy::time::{Duration, Timer}; use embassy_stm32::gpio::{Level, Output, Speed}; use embassy_stm32::Peripherals; -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/stm32wl/src/bin/button.rs b/examples/stm32wl/src/bin/button.rs index f80b9ab4..982a7a11 100644 --- a/examples/stm32wl/src/bin/button.rs +++ b/examples/stm32wl/src/bin/button.rs @@ -2,12 +2,10 @@ #![no_main] #![feature(type_alias_impl_trait)] -use defmt::*; -use defmt_rtt as _; // global logger -use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; -use panic_probe as _; - use cortex_m_rt::entry; +use defmt::*; +use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; +use {defmt_rtt as _, panic_probe as _}; #[entry] fn main() -> ! { diff --git a/examples/stm32wl/src/bin/button_exti.rs b/examples/stm32wl/src/bin/button_exti.rs index 9a427c2d..7d5c1b3c 100644 --- a/examples/stm32wl/src/bin/button_exti.rs +++ b/examples/stm32wl/src/bin/button_exti.rs @@ -3,12 +3,11 @@ #![feature(type_alias_impl_trait)] use defmt::*; -use defmt_rtt as _; // global logger use embassy::executor::Spawner; use embassy_stm32::exti::ExtiInput; use embassy_stm32::gpio::{Input, Pull}; use embassy_stm32::Peripherals; -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/stm32wl/src/bin/flash.rs b/examples/stm32wl/src/bin/flash.rs index f8481822..6531feae 100644 --- a/examples/stm32wl/src/bin/flash.rs +++ b/examples/stm32wl/src/bin/flash.rs @@ -7,9 +7,7 @@ use embassy::executor::Spawner; use embassy_stm32::flash::Flash; use embassy_stm32::Peripherals; use embedded_storage::nor_flash::{NorFlash, ReadNorFlash}; - -use defmt_rtt as _; // global logger -use panic_probe as _; +use {defmt_rtt as _, panic_probe as _}; #[embassy::main] async fn main(_spawner: Spawner, p: Peripherals) { diff --git a/examples/stm32wl/src/bin/lorawan.rs b/examples/stm32wl/src/bin/lorawan.rs index 393828c8..4f0dc7df 100644 --- a/examples/stm32wl/src/bin/lorawan.rs +++ b/examples/stm32wl/src/bin/lorawan.rs @@ -5,20 +5,16 @@ #![feature(generic_associated_types)] #![feature(type_alias_impl_trait)] -use defmt_rtt as _; // global logger -use panic_probe as _; - -use embassy_lora::{stm32wl::*, LoraTimer}; -use embassy_stm32::{ - dma::NoDma, - gpio::{Level, Output, Pin, Speed}, - interrupt, pac, - rng::Rng, - subghz::*, - Peripherals, -}; +use embassy_lora::stm32wl::*; +use embassy_lora::LoraTimer; +use embassy_stm32::dma::NoDma; +use embassy_stm32::gpio::{Level, Output, Pin, Speed}; +use embassy_stm32::rng::Rng; +use embassy_stm32::subghz::*; +use embassy_stm32::{interrupt, pac, Peripherals}; use lorawan::default_crypto::DefaultFactory as Crypto; use lorawan_device::async_device::{region, Device, JoinMode}; +use {defmt_rtt as _, panic_probe as _}; fn config() -> embassy_stm32::Config { let mut config = embassy_stm32::Config::default(); @@ -43,8 +39,7 @@ async fn main(_spawner: embassy::executor::Spawner, p: Peripherals) { let radio = unsafe { SubGhzRadio::new(&mut RADIO_STATE, radio, rfs, irq) }; let region = region::EU868::default().into(); - let mut device: Device<_, Crypto, _, _> = - Device::new(region, radio, LoraTimer, Rng::new(p.RNG)); + let mut device: Device<_, Crypto, _, _> = Device::new(region, radio, LoraTimer, Rng::new(p.RNG)); defmt::info!("Joining LoRaWAN network"); diff --git a/examples/stm32wl/src/bin/subghz.rs b/examples/stm32wl/src/bin/subghz.rs index f5f9b6a3..c5f6e502 100644 --- a/examples/stm32wl/src/bin/subghz.rs +++ b/examples/stm32wl/src/bin/subghz.rs @@ -5,18 +5,15 @@ #![feature(generic_associated_types)] #![feature(type_alias_impl_trait)] -use defmt_rtt as _; // global logger -use panic_probe as _; - use defmt::*; use embassy::channel::signal::Signal; use embassy_stm32::dma::NoDma; use embassy_stm32::exti::ExtiInput; use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; -use embassy_stm32::interrupt; use embassy_stm32::interrupt::{Interrupt, InterruptExt}; use embassy_stm32::subghz::*; -use embassy_stm32::Peripherals; +use embassy_stm32::{interrupt, Peripherals}; +use {defmt_rtt as _, panic_probe as _}; const PING_DATA: &str = "PING"; const DATA_LEN: u8 = PING_DATA.len() as u8; @@ -46,20 +43,13 @@ const LORA_MOD_PARAMS: LoRaModParams = LoRaModParams::new() // configuration for +10 dBm output power // see table 35 "PA optimal setting and operating modes" -const PA_CONFIG: PaConfig = PaConfig::new() - .set_pa_duty_cycle(0x1) - .set_hp_max(0x0) - .set_pa(PaSel::Lp); +const PA_CONFIG: PaConfig = PaConfig::new().set_pa_duty_cycle(0x1).set_hp_max(0x0).set_pa(PaSel::Lp); const TCXO_MODE: TcxoMode = TcxoMode::new() .set_txco_trim(TcxoTrim::Volts1pt7) - .set_timeout(Timeout::from_duration_sat( - core::time::Duration::from_millis(10), - )); + .set_timeout(Timeout::from_duration_sat(core::time::Duration::from_millis(10))); -const TX_PARAMS: TxParams = TxParams::new() - .set_power(0x0D) - .set_ramp_time(RampTime::Micros40); +const TX_PARAMS: TxParams = TxParams::new().set_power(0x0D).set_ramp_time(RampTime::Micros40); fn config() -> embassy_stm32::Config { let mut config = embassy_stm32::Config::default(); diff --git a/examples/wasm/src/lib.rs b/examples/wasm/src/lib.rs index 0aa32a70..61757ebd 100644 --- a/examples/wasm/src/lib.rs +++ b/examples/wasm/src/lib.rs @@ -1,10 +1,8 @@ #![feature(type_alias_impl_trait)] #![allow(incomplete_features)] -use embassy::{ - executor::Spawner, - time::{Duration, Timer}, -}; +use embassy::executor::Spawner; +use embassy::time::{Duration, Timer}; #[embassy::task] async fn ticker() { @@ -13,13 +11,9 @@ async fn ticker() { let mut counter = 0; loop { let document = window.document().expect("should have a document on window"); - let list = document - .get_element_by_id("log") - .expect("should have a log element"); + let list = document.get_element_by_id("log").expect("should have a log element"); - let li = document - .create_element("li") - .expect("error creating list item element"); + let li = document.create_element("li").expect("error creating list item element"); li.set_text_content(Some(&format!("tick {}", counter))); list.append_child(&li).expect("error appending list item"); diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 00000000..3639f438 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,3 @@ +group_imports = "StdExternalCrate" +imports_granularity = "Module" +max_width=120 \ No newline at end of file diff --git a/stm32-gen-features/src/main.rs b/stm32-gen-features/src/main.rs index 72a90752..f4092516 100644 --- a/stm32-gen-features/src/main.rs +++ b/stm32-gen-features/src/main.rs @@ -1,6 +1,5 @@ use gen_features::{ - chip_names_and_cores, embassy_stm32_needed_data, generate_cargo_toml_file, - stm32_metapac_needed_data, + chip_names_and_cores, embassy_stm32_needed_data, generate_cargo_toml_file, stm32_metapac_needed_data, }; fn main() { diff --git a/stm32-metapac-gen/src/lib.rs b/stm32-metapac-gen/src/lib.rs index f5d61ca3..0d761508 100644 --- a/stm32-metapac-gen/src/lib.rs +++ b/stm32-metapac-gen/src/lib.rs @@ -1,16 +1,16 @@ -use chiptool::generate::CommonModule; -use chiptool::{generate, ir, transform}; -use proc_macro2::TokenStream; -use regex::Regex; use std::collections::{BTreeMap, HashMap, HashSet}; use std::fmt::{Debug, Write as _}; use std::fs; use std::fs::File; use std::io::Write; -use std::path::Path; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use std::str::FromStr; +use chiptool::generate::CommonModule; +use chiptool::{generate, ir, transform}; +use proc_macro2::TokenStream; +use regex::Regex; + mod data; use data::*; @@ -56,12 +56,7 @@ impl Gen { let mut peripheral_versions: BTreeMap = BTreeMap::new(); - let gpio_base = core - .peripherals - .iter() - .find(|p| p.name == "GPIOA") - .unwrap() - .address as u32; + let gpio_base = core.peripherals.iter().find(|p| p.name == "GPIOA").unwrap().address as u32; let gpio_stride = 0x400; for p in &core.peripherals { @@ -75,9 +70,7 @@ impl Gen { }; if let Some(bi) = &p.registers { - if let Some(old_version) = - peripheral_versions.insert(bi.kind.clone(), bi.version.clone()) - { + if let Some(old_version) = peripheral_versions.insert(bi.kind.clone(), bi.version.clone()) { if old_version != bi.version { panic!( "Peripheral {} has multiple versions: {} and {}", @@ -113,8 +106,7 @@ impl Gen { ); for (module, version) in &peripheral_versions { - self.all_peripheral_versions - .insert((module.clone(), version.clone())); + self.all_peripheral_versions.insert((module.clone(), version.clone())); write!( &mut extra, "#[path=\"../../peripherals/{}_{}.rs\"] pub mod {};\n", @@ -122,45 +114,15 @@ impl Gen { ) .unwrap(); } - write!( - &mut extra, - "pub const CORE_INDEX: usize = {};\n", - core_index - ) - .unwrap(); + write!(&mut extra, "pub const CORE_INDEX: usize = {};\n", core_index).unwrap(); let flash = chip.memory.iter().find(|r| r.name == "BANK_1").unwrap(); - write!( - &mut extra, - "pub const FLASH_BASE: usize = {};\n", - flash.address, - ) - .unwrap(); - write!( - &mut extra, - "pub const FLASH_SIZE: usize = {};\n", - flash.size, - ) - .unwrap(); + write!(&mut extra, "pub const FLASH_BASE: usize = {};\n", flash.address,).unwrap(); + write!(&mut extra, "pub const FLASH_SIZE: usize = {};\n", flash.size,).unwrap(); if let Some(settings) = &flash.settings { - write!( - &mut extra, - "pub const ERASE_SIZE: usize = {};\n", - settings.erase_size, - ) - .unwrap(); - write!( - &mut extra, - "pub const WRITE_SIZE: usize = {};\n", - settings.write_size, - ) - .unwrap(); - write!( - &mut extra, - "pub const ERASE_VALUE: u8 = {};\n", - settings.erase_value, - ) - .unwrap(); + write!(&mut extra, "pub const ERASE_SIZE: usize = {};\n", settings.erase_size,).unwrap(); + write!(&mut extra, "pub const WRITE_SIZE: usize = {};\n", settings.write_size,).unwrap(); + write!(&mut extra, "pub const ERASE_VALUE: u8 = {};\n", settings.erase_value,).unwrap(); } // Cleanups! @@ -260,11 +222,7 @@ impl Gen { } fn load_chip(&mut self, name: &str) -> Chip { - let chip_path = self - .opts - .data_dir - .join("chips") - .join(&format!("{}.json", name)); + let chip_path = self.opts.data_dir.join("chips").join(&format!("{}.json", name)); let chip = fs::read(chip_path).expect(&format!("Could not load chip {}", name)); serde_yaml::from_slice(&chip).unwrap() } @@ -313,9 +271,7 @@ impl Gen { let mut ir: ir::IR = serde_yaml::from_reader(File::open(regs_path).unwrap()).unwrap(); - transform::expand_extends::ExpandExtends {} - .run(&mut ir) - .unwrap(); + transform::expand_extends::ExpandExtends {}.run(&mut ir).unwrap(); transform::map_names(&mut ir, |k, s| match k { transform::NameKind::Block => *s = format!("{}", s), @@ -378,9 +334,7 @@ impl Gen { } fn bytes_find(haystack: &[u8], needle: &[u8]) -> Option { - haystack - .windows(needle.len()) - .position(|window| window == needle) + haystack.windows(needle.len()).position(|window| window == needle) } fn stringify(metadata: T) -> String { diff --git a/stm32-metapac-gen/src/main.rs b/stm32-metapac-gen/src/main.rs index 39144130..40a73adf 100644 --- a/stm32-metapac-gen/src/main.rs +++ b/stm32-metapac-gen/src/main.rs @@ -1,5 +1,6 @@ use std::env::args; use std::path::PathBuf; + use stm32_metapac_gen::*; fn main() { diff --git a/stm32-metapac/build.rs b/stm32-metapac/build.rs index 2b3fca80..0c183fa2 100644 --- a/stm32-metapac/build.rs +++ b/stm32-metapac/build.rs @@ -1,5 +1,6 @@ use std::env; use std::path::PathBuf; + use stm32_metapac_gen::*; fn parse_chip_core(chip_and_core: &str) -> (String, Option) { diff --git a/stm32-metapac/build_pregenerated.rs b/stm32-metapac/build_pregenerated.rs index 660a9553..0f035807 100644 --- a/stm32-metapac/build_pregenerated.rs +++ b/stm32-metapac/build_pregenerated.rs @@ -25,10 +25,7 @@ fn main() { crate_dir.display(), chip_core_name ); - println!( - "cargo:rustc-env=STM32_METAPAC_PAC_PATH=chips/{}/pac.rs", - chip_core_name - ); + println!("cargo:rustc-env=STM32_METAPAC_PAC_PATH=chips/{}/pac.rs", chip_core_name); println!( "cargo:rustc-env=STM32_METAPAC_METADATA_PATH=chips/{}/metadata.rs", chip_core_name diff --git a/tests/stm32/src/example_common.rs b/tests/stm32/src/example_common.rs index 11b11d68..c47ed75c 100644 --- a/tests/stm32/src/example_common.rs +++ b/tests/stm32/src/example_common.rs @@ -1,14 +1,12 @@ #![macro_use] -use defmt_rtt as _; +use core::sync::atomic::{AtomicUsize, Ordering}; + +pub use defmt::*; #[allow(unused)] use embassy_stm32::time::Hertz; use embassy_stm32::Config; -use panic_probe as _; - -pub use defmt::*; - -use core::sync::atomic::{AtomicUsize, Ordering}; +use {defmt_rtt as _, panic_probe as _}; defmt::timestamp! {"{=u64}", { static COUNT: AtomicUsize = AtomicUsize::new(0); diff --git a/xtask/src/main.rs b/xtask/src/main.rs index d8d5e07d..b8b453fd 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -1,10 +1,9 @@ #![allow(dead_code)] #![deny(unused_must_use)] -use std::format; -use std::{env, fs, path::PathBuf}; +use std::path::{Path, PathBuf}; +use std::{env, format, fs}; -use std::path::Path; use walkdir::WalkDir; use xshell::{cmd, Cmd}; use yaml_rust::YamlLoader; @@ -67,10 +66,7 @@ impl Realm { fn task_check(realm: Realm) -> Result<(), anyhow::Error> { let _e = xshell::pushenv("CI", "true"); - let matrix_yaml = root_dir() - .join(".github") - .join("workflows") - .join("rust.yml"); + let matrix_yaml = root_dir().join(".github").join("workflows").join("rust.yml"); let matrix = YamlLoader::load_from_str(&*fs::read_to_string(matrix_yaml).unwrap()).unwrap();