summaryrefslogtreecommitdiff
path: root/embassy-nrf
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-nrf')
-rw-r--r--embassy-nrf/src/buffered_uarte.rs22
-rw-r--r--embassy-nrf/src/chips/nrf52805.rs3
-rw-r--r--embassy-nrf/src/chips/nrf52810.rs3
-rw-r--r--embassy-nrf/src/chips/nrf52811.rs3
-rw-r--r--embassy-nrf/src/chips/nrf52820.rs3
-rw-r--r--embassy-nrf/src/chips/nrf52832.rs3
-rw-r--r--embassy-nrf/src/chips/nrf52833.rs3
-rw-r--r--embassy-nrf/src/chips/nrf52840.rs3
-rw-r--r--embassy-nrf/src/chips/nrf5340_app.rs3
-rw-r--r--embassy-nrf/src/chips/nrf5340_net.rs3
-rw-r--r--embassy-nrf/src/chips/nrf9160.rs3
-rw-r--r--embassy-nrf/src/gpio.rs12
-rw-r--r--embassy-nrf/src/gpiote.rs10
-rw-r--r--embassy-nrf/src/lib.rs9
-rw-r--r--embassy-nrf/src/nvmc.rs11
-rw-r--r--embassy-nrf/src/ppi/dppi.rs19
-rw-r--r--embassy-nrf/src/ppi/mod.rs5
-rw-r--r--embassy-nrf/src/ppi/ppi.rs18
-rw-r--r--embassy-nrf/src/pwm.rs80
-rw-r--r--embassy-nrf/src/qdec.rs28
-rw-r--r--embassy-nrf/src/qspi.rs60
-rw-r--r--embassy-nrf/src/rng.rs14
-rw-r--r--embassy-nrf/src/saadc.rs66
-rw-r--r--embassy-nrf/src/spim.rs27
-rw-r--r--embassy-nrf/src/temp.rs19
-rw-r--r--embassy-nrf/src/time_driver.rs22
-rw-r--r--embassy-nrf/src/timer.rs16
-rw-r--r--embassy-nrf/src/twim.rs88
-rw-r--r--embassy-nrf/src/uarte.rs31
-rw-r--r--embassy-nrf/src/usb.rs59
30 files changed, 197 insertions, 449 deletions
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,28 +13,26 @@
//!
//! 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;
+// 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::pac;
+use crate::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::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::{pac, Unborrow};
#[derive(Copy, Clone, Debug, PartialEq)]
enum RxState {
@@ -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<Output = Result<&'a [u8], Self::Error>>
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<Output = Result<usize, Self::Error>>
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<Target = T> + 'd,
- initial_output: Level,
- drive: OutputDrive,
- ) -> Self {
+ pub fn new(pin: impl Unborrow<Target = T> + '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<bool, Self::Error> {
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<Target = C> + 'd,
- event: Event,
- task1: Task,
- task2: Task,
- ) -> Self {
+ pub fn new_one_to_two(ch: impl Unborrow<Target = C> + '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<Target = C> + 'd,
- event: Event,
- task1: Task,
- task2: Task,
- ) -> Self {
+ pub fn new_one_to_two(ch: impl Unborrow<Target = C> + '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<Self, Error> {
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<Sequence<'s>>,
- ) -> Self {
+ pub fn new(pwm: &'s mut SequencePwm<'d, T>, sequence0: Sequence<'s>, sequence1: Option<Sequence<'s>>) -> 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<Target = T> + 'd,
- ch0: impl Unborrow<Target = impl GpioPin> + 'd,
- ) -> Self {
+ pub fn new_1ch(pwm: impl Unborrow<Target = T> + 'd, ch0: impl Unborrow<Target = impl GpioPin> + '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<Target = impl GpioPin> + '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<Target = RNG> + 'd,
- irq: impl Unborrow<Target = interrupt::RNG> + 'd,
- ) -> Self {
+ pub fn new(_rng: impl Unborrow<Target = RNG> + 'd, irq: impl Unborrow<Target = interrupt::RNG> + '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<Target = TEMP> + 'd,
- irq: impl Unborrow<Target = interrupt::TEMP> + 'd,
- ) -> Self {
+ pub fn new(_t: impl Unborrow<Target = TEMP> + 'd, irq: impl Unborrow<Target = interrupt::TEMP> + '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<AlarmHandle> {
- 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<Target = T> + '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<T, I> {
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<B>(
- &mut self,
- _address: u8,
- _bytes: B,
- _buffer: &mut [u8],
- ) -> Result<(), Self::Error>
+ fn write_iter_read<B>(&mut self, _address: u8, _bytes: B, _buffer: &mut [u8]) -> Result<(), Self::Error>
where
B: IntoIterator<Item = u8>,
{
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<Item = embedded_hal_1::i2c::blocking::Operation<'a>>,
{
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<u8>
- for UarteWithIdle<'d, U, T>
- {
+ impl<'d, U: Instance, T: TimerInstance> embedded_hal_02::blocking::serial::Write<u8> 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<Target = T> + 'd,
- irq: impl Unborrow<Target = T::Interrupt> + 'd,
- ) -> Self {
+ pub fn new(_usb: impl Unborrow<Target = T> + 'd, irq: impl Unborrow<Target = T::Interrupt> + '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<T: Instance>(i: usize, buf: &mut [u8]) -> Result<usize, Endpo
dma_start();
regs.events_endepout[i].reset();
regs.tasks_startepout[i].write(|w| w.tasks_startepout().set_bit());
- while regs.events_endepout[i]
- .read()
- .events_endepout()
- .bit_is_clear()
- {}
+ while regs.events_endepout[i].read().events_endepout().bit_is_clear() {}
regs.events_endepout[i].reset();
dma_end();
@@ -579,9 +566,7 @@ impl<'d, T: Instance> 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::<T>(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::<T>(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));
}
}