From 6e7abba9ff0d1b17e0b81b1a3f87794e59e65128 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Mon, 11 Oct 2021 01:09:57 +0200 Subject: [PATCH 1/3] nrf: rename Cargo feature references from "51" to "nrf51". Note: the feature doesn't actually exist, references are there just in case nrf51xx is supported in the future. --- embassy-nrf/src/gpiote.rs | 8 ++++---- embassy-nrf/src/ppi.rs | 18 +++++++++--------- embassy-nrf/src/util.rs | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/embassy-nrf/src/gpiote.rs b/embassy-nrf/src/gpiote.rs index 001ee7fb..25d09db4 100644 --- a/embassy-nrf/src/gpiote.rs +++ b/embassy-nrf/src/gpiote.rs @@ -239,14 +239,14 @@ impl<'d, C: Channel, T: GpioPin> OutputChannel<'d, C, T> { } /// Triggers `task set` (set associated pin high). - #[cfg(not(feature = "51"))] + #[cfg(not(feature = "nrf51"))] pub fn set(&self) { let g = unsafe { &*pac::GPIOTE::ptr() }; g.tasks_set[self.ch.number()].write(|w| unsafe { w.bits(1) }); } /// Triggers `task clear` (set associated pin low). - #[cfg(not(feature = "51"))] + #[cfg(not(feature = "nrf51"))] pub fn clear(&self) { let g = unsafe { &*pac::GPIOTE::ptr() }; g.tasks_clr[self.ch.number()].write(|w| unsafe { w.bits(1) }); @@ -259,14 +259,14 @@ impl<'d, C: Channel, T: GpioPin> OutputChannel<'d, C, T> { } /// Returns the CLR task, for use with PPI. - #[cfg(not(feature = "51"))] + #[cfg(not(feature = "nrf51"))] pub fn task_clr(&self) -> Task { let g = unsafe { &*pac::GPIOTE::ptr() }; Task::from_reg(&g.tasks_clr[self.ch.number()]) } /// Returns the SET task, for use with PPI. - #[cfg(not(feature = "51"))] + #[cfg(not(feature = "nrf51"))] pub fn task_set(&self) -> Task { let g = unsafe { &*pac::GPIOTE::ptr() }; Task::from_reg(&g.tasks_set[self.ch.number()]) diff --git a/embassy-nrf/src/ppi.rs b/embassy-nrf/src/ppi.rs index 61028c03..a18dec12 100644 --- a/embassy-nrf/src/ppi.rs +++ b/embassy-nrf/src/ppi.rs @@ -31,7 +31,7 @@ impl<'d, C: Channel> Ppi<'d, C> { ch, phantom: PhantomData, }; - #[cfg(not(feature = "51"))] + #[cfg(not(feature = "nrf51"))] this.clear_fork_task(); this } @@ -50,7 +50,7 @@ impl<'d, C: Channel> Ppi<'d, C> { .write(|w| unsafe { w.bits(1 << self.ch.number()) }); } - #[cfg(not(feature = "51"))] + #[cfg(not(feature = "nrf51"))] /// Sets the fork task that must be triggered when the configured event occurs. The user must /// provide a reference to the task. pub fn set_fork_task(&mut self, task: Task) { @@ -60,7 +60,7 @@ impl<'d, C: Channel> Ppi<'d, C> { .write(|w| unsafe { w.bits(task.0.as_ptr() as u32) }) } - #[cfg(not(feature = "51"))] + #[cfg(not(feature = "nrf51"))] /// Clear the fork task endpoint. Previously set task will no longer be triggered. pub fn clear_fork_task(&mut self) { let r = unsafe { &*pac::PPI::ptr() }; @@ -199,13 +199,13 @@ impl_channel!(PPI_CH12, 12, configurable); impl_channel!(PPI_CH13, 13, configurable); impl_channel!(PPI_CH14, 14, configurable); impl_channel!(PPI_CH15, 15, configurable); -#[cfg(not(feature = "51"))] +#[cfg(not(feature = "nrf51"))] impl_channel!(PPI_CH16, 16, configurable); -#[cfg(not(feature = "51"))] +#[cfg(not(feature = "nrf51"))] impl_channel!(PPI_CH17, 17, configurable); -#[cfg(not(feature = "51"))] +#[cfg(not(feature = "nrf51"))] impl_channel!(PPI_CH18, 18, configurable); -#[cfg(not(feature = "51"))] +#[cfg(not(feature = "nrf51"))] impl_channel!(PPI_CH19, 19, configurable); impl_channel!(PPI_CH20, 20); impl_channel!(PPI_CH21, 21); @@ -249,7 +249,7 @@ impl_group!(PPI_GROUP0, 0); impl_group!(PPI_GROUP1, 1); impl_group!(PPI_GROUP2, 2); impl_group!(PPI_GROUP3, 3); -#[cfg(not(feature = "51"))] +#[cfg(not(feature = "nrf51"))] impl_group!(PPI_GROUP4, 4); -#[cfg(not(feature = "51"))] +#[cfg(not(feature = "nrf51"))] impl_group!(PPI_GROUP5, 5); diff --git a/embassy-nrf/src/util.rs b/embassy-nrf/src/util.rs index 7c3974ee..344fb01f 100644 --- a/embassy-nrf/src/util.rs +++ b/embassy-nrf/src/util.rs @@ -8,7 +8,7 @@ pub(crate) fn slice_in_ram(slice: &[u8]) -> bool { } /// Return an error if slice is not in RAM. -#[cfg(not(feature = "51"))] +#[cfg(not(feature = "nrf51"))] pub(crate) fn slice_in_ram_or(slice: &[u8], err: T) -> Result<(), T> { if slice.len() == 0 || slice_in_ram(slice) { Ok(()) From cf13dd7df860afeb9bccee2ca64004f0ac3643d2 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Mon, 11 Oct 2021 01:19:06 +0200 Subject: [PATCH 2/3] nrf/ppi: nrf52805 only has 10 configurable channels. --- embassy-nrf/src/chips/nrf52805.rs | 23 ++++++++++++++ embassy-nrf/src/chips/nrf52810.rs | 33 +++++++++++++++++++ embassy-nrf/src/chips/nrf52811.rs | 33 +++++++++++++++++++ embassy-nrf/src/chips/nrf52820.rs | 33 +++++++++++++++++++ embassy-nrf/src/chips/nrf52832.rs | 33 +++++++++++++++++++ embassy-nrf/src/chips/nrf52833.rs | 33 +++++++++++++++++++ embassy-nrf/src/chips/nrf52840.rs | 33 +++++++++++++++++++ embassy-nrf/src/ppi.rs | 53 ++++++------------------------- 8 files changed, 230 insertions(+), 44 deletions(-) diff --git a/embassy-nrf/src/chips/nrf52805.rs b/embassy-nrf/src/chips/nrf52805.rs index f214d927..3bf87e3d 100644 --- a/embassy-nrf/src/chips/nrf52805.rs +++ b/embassy-nrf/src/chips/nrf52805.rs @@ -159,6 +159,29 @@ impl_pin!(P0_29, 0, 29); impl_pin!(P0_30, 0, 30); impl_pin!(P0_31, 0, 31); +impl_ppi_channel!(PPI_CH0, 0, configurable); +impl_ppi_channel!(PPI_CH1, 1, configurable); +impl_ppi_channel!(PPI_CH2, 2, configurable); +impl_ppi_channel!(PPI_CH3, 3, configurable); +impl_ppi_channel!(PPI_CH4, 4, configurable); +impl_ppi_channel!(PPI_CH5, 5, configurable); +impl_ppi_channel!(PPI_CH6, 6, configurable); +impl_ppi_channel!(PPI_CH7, 7, configurable); +impl_ppi_channel!(PPI_CH8, 8, configurable); +impl_ppi_channel!(PPI_CH9, 9, configurable); +impl_ppi_channel!(PPI_CH20, 20); +impl_ppi_channel!(PPI_CH21, 21); +impl_ppi_channel!(PPI_CH22, 22); +impl_ppi_channel!(PPI_CH23, 23); +impl_ppi_channel!(PPI_CH24, 24); +impl_ppi_channel!(PPI_CH25, 25); +impl_ppi_channel!(PPI_CH26, 26); +impl_ppi_channel!(PPI_CH27, 27); +impl_ppi_channel!(PPI_CH28, 28); +impl_ppi_channel!(PPI_CH29, 29); +impl_ppi_channel!(PPI_CH30, 30); +impl_ppi_channel!(PPI_CH31, 31); + pub mod irqs { use crate::pac::Interrupt as InterruptEnum; use embassy_macros::interrupt_declare as declare; diff --git a/embassy-nrf/src/chips/nrf52810.rs b/embassy-nrf/src/chips/nrf52810.rs index caef3e7e..d3241364 100644 --- a/embassy-nrf/src/chips/nrf52810.rs +++ b/embassy-nrf/src/chips/nrf52810.rs @@ -164,6 +164,39 @@ impl_pin!(P0_29, 0, 29); impl_pin!(P0_30, 0, 30); impl_pin!(P0_31, 0, 31); +impl_ppi_channel!(PPI_CH0, 0, configurable); +impl_ppi_channel!(PPI_CH1, 1, configurable); +impl_ppi_channel!(PPI_CH2, 2, configurable); +impl_ppi_channel!(PPI_CH3, 3, configurable); +impl_ppi_channel!(PPI_CH4, 4, configurable); +impl_ppi_channel!(PPI_CH5, 5, configurable); +impl_ppi_channel!(PPI_CH6, 6, configurable); +impl_ppi_channel!(PPI_CH7, 7, configurable); +impl_ppi_channel!(PPI_CH8, 8, configurable); +impl_ppi_channel!(PPI_CH9, 9, configurable); +impl_ppi_channel!(PPI_CH10, 10, configurable); +impl_ppi_channel!(PPI_CH11, 11, configurable); +impl_ppi_channel!(PPI_CH12, 12, configurable); +impl_ppi_channel!(PPI_CH13, 13, configurable); +impl_ppi_channel!(PPI_CH14, 14, configurable); +impl_ppi_channel!(PPI_CH15, 15, configurable); +impl_ppi_channel!(PPI_CH16, 16, configurable); +impl_ppi_channel!(PPI_CH17, 17, configurable); +impl_ppi_channel!(PPI_CH18, 18, configurable); +impl_ppi_channel!(PPI_CH19, 19, configurable); +impl_ppi_channel!(PPI_CH20, 20); +impl_ppi_channel!(PPI_CH21, 21); +impl_ppi_channel!(PPI_CH22, 22); +impl_ppi_channel!(PPI_CH23, 23); +impl_ppi_channel!(PPI_CH24, 24); +impl_ppi_channel!(PPI_CH25, 25); +impl_ppi_channel!(PPI_CH26, 26); +impl_ppi_channel!(PPI_CH27, 27); +impl_ppi_channel!(PPI_CH28, 28); +impl_ppi_channel!(PPI_CH29, 29); +impl_ppi_channel!(PPI_CH30, 30); +impl_ppi_channel!(PPI_CH31, 31); + pub mod irqs { use crate::pac::Interrupt as InterruptEnum; use embassy_macros::interrupt_declare as declare; diff --git a/embassy-nrf/src/chips/nrf52811.rs b/embassy-nrf/src/chips/nrf52811.rs index cbf14df2..1231ae62 100644 --- a/embassy-nrf/src/chips/nrf52811.rs +++ b/embassy-nrf/src/chips/nrf52811.rs @@ -165,6 +165,39 @@ impl_pin!(P0_29, 0, 29); impl_pin!(P0_30, 0, 30); impl_pin!(P0_31, 0, 31); +impl_ppi_channel!(PPI_CH0, 0, configurable); +impl_ppi_channel!(PPI_CH1, 1, configurable); +impl_ppi_channel!(PPI_CH2, 2, configurable); +impl_ppi_channel!(PPI_CH3, 3, configurable); +impl_ppi_channel!(PPI_CH4, 4, configurable); +impl_ppi_channel!(PPI_CH5, 5, configurable); +impl_ppi_channel!(PPI_CH6, 6, configurable); +impl_ppi_channel!(PPI_CH7, 7, configurable); +impl_ppi_channel!(PPI_CH8, 8, configurable); +impl_ppi_channel!(PPI_CH9, 9, configurable); +impl_ppi_channel!(PPI_CH10, 10, configurable); +impl_ppi_channel!(PPI_CH11, 11, configurable); +impl_ppi_channel!(PPI_CH12, 12, configurable); +impl_ppi_channel!(PPI_CH13, 13, configurable); +impl_ppi_channel!(PPI_CH14, 14, configurable); +impl_ppi_channel!(PPI_CH15, 15, configurable); +impl_ppi_channel!(PPI_CH16, 16, configurable); +impl_ppi_channel!(PPI_CH17, 17, configurable); +impl_ppi_channel!(PPI_CH18, 18, configurable); +impl_ppi_channel!(PPI_CH19, 19, configurable); +impl_ppi_channel!(PPI_CH20, 20); +impl_ppi_channel!(PPI_CH21, 21); +impl_ppi_channel!(PPI_CH22, 22); +impl_ppi_channel!(PPI_CH23, 23); +impl_ppi_channel!(PPI_CH24, 24); +impl_ppi_channel!(PPI_CH25, 25); +impl_ppi_channel!(PPI_CH26, 26); +impl_ppi_channel!(PPI_CH27, 27); +impl_ppi_channel!(PPI_CH28, 28); +impl_ppi_channel!(PPI_CH29, 29); +impl_ppi_channel!(PPI_CH30, 30); +impl_ppi_channel!(PPI_CH31, 31); + pub mod irqs { use crate::pac::Interrupt as InterruptEnum; use embassy_macros::interrupt_declare as declare; diff --git a/embassy-nrf/src/chips/nrf52820.rs b/embassy-nrf/src/chips/nrf52820.rs index e434c009..fc7a367e 100644 --- a/embassy-nrf/src/chips/nrf52820.rs +++ b/embassy-nrf/src/chips/nrf52820.rs @@ -160,6 +160,39 @@ impl_pin!(P0_29, 0, 29); impl_pin!(P0_30, 0, 30); impl_pin!(P0_31, 0, 31); +impl_ppi_channel!(PPI_CH0, 0, configurable); +impl_ppi_channel!(PPI_CH1, 1, configurable); +impl_ppi_channel!(PPI_CH2, 2, configurable); +impl_ppi_channel!(PPI_CH3, 3, configurable); +impl_ppi_channel!(PPI_CH4, 4, configurable); +impl_ppi_channel!(PPI_CH5, 5, configurable); +impl_ppi_channel!(PPI_CH6, 6, configurable); +impl_ppi_channel!(PPI_CH7, 7, configurable); +impl_ppi_channel!(PPI_CH8, 8, configurable); +impl_ppi_channel!(PPI_CH9, 9, configurable); +impl_ppi_channel!(PPI_CH10, 10, configurable); +impl_ppi_channel!(PPI_CH11, 11, configurable); +impl_ppi_channel!(PPI_CH12, 12, configurable); +impl_ppi_channel!(PPI_CH13, 13, configurable); +impl_ppi_channel!(PPI_CH14, 14, configurable); +impl_ppi_channel!(PPI_CH15, 15, configurable); +impl_ppi_channel!(PPI_CH16, 16, configurable); +impl_ppi_channel!(PPI_CH17, 17, configurable); +impl_ppi_channel!(PPI_CH18, 18, configurable); +impl_ppi_channel!(PPI_CH19, 19, configurable); +impl_ppi_channel!(PPI_CH20, 20); +impl_ppi_channel!(PPI_CH21, 21); +impl_ppi_channel!(PPI_CH22, 22); +impl_ppi_channel!(PPI_CH23, 23); +impl_ppi_channel!(PPI_CH24, 24); +impl_ppi_channel!(PPI_CH25, 25); +impl_ppi_channel!(PPI_CH26, 26); +impl_ppi_channel!(PPI_CH27, 27); +impl_ppi_channel!(PPI_CH28, 28); +impl_ppi_channel!(PPI_CH29, 29); +impl_ppi_channel!(PPI_CH30, 30); +impl_ppi_channel!(PPI_CH31, 31); + pub mod irqs { use crate::pac::Interrupt as InterruptEnum; use embassy_macros::interrupt_declare as declare; diff --git a/embassy-nrf/src/chips/nrf52832.rs b/embassy-nrf/src/chips/nrf52832.rs index b95aa604..9bbef543 100644 --- a/embassy-nrf/src/chips/nrf52832.rs +++ b/embassy-nrf/src/chips/nrf52832.rs @@ -178,6 +178,39 @@ impl_pin!(P0_29, 0, 29); impl_pin!(P0_30, 0, 30); impl_pin!(P0_31, 0, 31); +impl_ppi_channel!(PPI_CH0, 0, configurable); +impl_ppi_channel!(PPI_CH1, 1, configurable); +impl_ppi_channel!(PPI_CH2, 2, configurable); +impl_ppi_channel!(PPI_CH3, 3, configurable); +impl_ppi_channel!(PPI_CH4, 4, configurable); +impl_ppi_channel!(PPI_CH5, 5, configurable); +impl_ppi_channel!(PPI_CH6, 6, configurable); +impl_ppi_channel!(PPI_CH7, 7, configurable); +impl_ppi_channel!(PPI_CH8, 8, configurable); +impl_ppi_channel!(PPI_CH9, 9, configurable); +impl_ppi_channel!(PPI_CH10, 10, configurable); +impl_ppi_channel!(PPI_CH11, 11, configurable); +impl_ppi_channel!(PPI_CH12, 12, configurable); +impl_ppi_channel!(PPI_CH13, 13, configurable); +impl_ppi_channel!(PPI_CH14, 14, configurable); +impl_ppi_channel!(PPI_CH15, 15, configurable); +impl_ppi_channel!(PPI_CH16, 16, configurable); +impl_ppi_channel!(PPI_CH17, 17, configurable); +impl_ppi_channel!(PPI_CH18, 18, configurable); +impl_ppi_channel!(PPI_CH19, 19, configurable); +impl_ppi_channel!(PPI_CH20, 20); +impl_ppi_channel!(PPI_CH21, 21); +impl_ppi_channel!(PPI_CH22, 22); +impl_ppi_channel!(PPI_CH23, 23); +impl_ppi_channel!(PPI_CH24, 24); +impl_ppi_channel!(PPI_CH25, 25); +impl_ppi_channel!(PPI_CH26, 26); +impl_ppi_channel!(PPI_CH27, 27); +impl_ppi_channel!(PPI_CH28, 28); +impl_ppi_channel!(PPI_CH29, 29); +impl_ppi_channel!(PPI_CH30, 30); +impl_ppi_channel!(PPI_CH31, 31); + pub mod irqs { use crate::pac::Interrupt as InterruptEnum; use embassy_macros::interrupt_declare as declare; diff --git a/embassy-nrf/src/chips/nrf52833.rs b/embassy-nrf/src/chips/nrf52833.rs index 570e4b10..d9495dd9 100644 --- a/embassy-nrf/src/chips/nrf52833.rs +++ b/embassy-nrf/src/chips/nrf52833.rs @@ -218,6 +218,39 @@ impl_pin!(P1_13, 1, 13); impl_pin!(P1_14, 1, 14); impl_pin!(P1_15, 1, 15); +impl_ppi_channel!(PPI_CH0, 0, configurable); +impl_ppi_channel!(PPI_CH1, 1, configurable); +impl_ppi_channel!(PPI_CH2, 2, configurable); +impl_ppi_channel!(PPI_CH3, 3, configurable); +impl_ppi_channel!(PPI_CH4, 4, configurable); +impl_ppi_channel!(PPI_CH5, 5, configurable); +impl_ppi_channel!(PPI_CH6, 6, configurable); +impl_ppi_channel!(PPI_CH7, 7, configurable); +impl_ppi_channel!(PPI_CH8, 8, configurable); +impl_ppi_channel!(PPI_CH9, 9, configurable); +impl_ppi_channel!(PPI_CH10, 10, configurable); +impl_ppi_channel!(PPI_CH11, 11, configurable); +impl_ppi_channel!(PPI_CH12, 12, configurable); +impl_ppi_channel!(PPI_CH13, 13, configurable); +impl_ppi_channel!(PPI_CH14, 14, configurable); +impl_ppi_channel!(PPI_CH15, 15, configurable); +impl_ppi_channel!(PPI_CH16, 16, configurable); +impl_ppi_channel!(PPI_CH17, 17, configurable); +impl_ppi_channel!(PPI_CH18, 18, configurable); +impl_ppi_channel!(PPI_CH19, 19, configurable); +impl_ppi_channel!(PPI_CH20, 20); +impl_ppi_channel!(PPI_CH21, 21); +impl_ppi_channel!(PPI_CH22, 22); +impl_ppi_channel!(PPI_CH23, 23); +impl_ppi_channel!(PPI_CH24, 24); +impl_ppi_channel!(PPI_CH25, 25); +impl_ppi_channel!(PPI_CH26, 26); +impl_ppi_channel!(PPI_CH27, 27); +impl_ppi_channel!(PPI_CH28, 28); +impl_ppi_channel!(PPI_CH29, 29); +impl_ppi_channel!(PPI_CH30, 30); +impl_ppi_channel!(PPI_CH31, 31); + pub mod irqs { use crate::pac::Interrupt as InterruptEnum; use embassy_macros::interrupt_declare as declare; diff --git a/embassy-nrf/src/chips/nrf52840.rs b/embassy-nrf/src/chips/nrf52840.rs index 1221f23b..ad89afbc 100644 --- a/embassy-nrf/src/chips/nrf52840.rs +++ b/embassy-nrf/src/chips/nrf52840.rs @@ -223,6 +223,39 @@ impl_pin!(P1_13, 1, 13); impl_pin!(P1_14, 1, 14); impl_pin!(P1_15, 1, 15); +impl_ppi_channel!(PPI_CH0, 0, configurable); +impl_ppi_channel!(PPI_CH1, 1, configurable); +impl_ppi_channel!(PPI_CH2, 2, configurable); +impl_ppi_channel!(PPI_CH3, 3, configurable); +impl_ppi_channel!(PPI_CH4, 4, configurable); +impl_ppi_channel!(PPI_CH5, 5, configurable); +impl_ppi_channel!(PPI_CH6, 6, configurable); +impl_ppi_channel!(PPI_CH7, 7, configurable); +impl_ppi_channel!(PPI_CH8, 8, configurable); +impl_ppi_channel!(PPI_CH9, 9, configurable); +impl_ppi_channel!(PPI_CH10, 10, configurable); +impl_ppi_channel!(PPI_CH11, 11, configurable); +impl_ppi_channel!(PPI_CH12, 12, configurable); +impl_ppi_channel!(PPI_CH13, 13, configurable); +impl_ppi_channel!(PPI_CH14, 14, configurable); +impl_ppi_channel!(PPI_CH15, 15, configurable); +impl_ppi_channel!(PPI_CH16, 16, configurable); +impl_ppi_channel!(PPI_CH17, 17, configurable); +impl_ppi_channel!(PPI_CH18, 18, configurable); +impl_ppi_channel!(PPI_CH19, 19, configurable); +impl_ppi_channel!(PPI_CH20, 20); +impl_ppi_channel!(PPI_CH21, 21); +impl_ppi_channel!(PPI_CH22, 22); +impl_ppi_channel!(PPI_CH23, 23); +impl_ppi_channel!(PPI_CH24, 24); +impl_ppi_channel!(PPI_CH25, 25); +impl_ppi_channel!(PPI_CH26, 26); +impl_ppi_channel!(PPI_CH27, 27); +impl_ppi_channel!(PPI_CH28, 28); +impl_ppi_channel!(PPI_CH29, 29); +impl_ppi_channel!(PPI_CH30, 30); +impl_ppi_channel!(PPI_CH31, 31); + pub mod irqs { use crate::pac::Interrupt as InterruptEnum; use embassy_macros::interrupt_declare as declare; diff --git a/embassy-nrf/src/ppi.rs b/embassy-nrf/src/ppi.rs index a18dec12..1b12b1e9 100644 --- a/embassy-nrf/src/ppi.rs +++ b/embassy-nrf/src/ppi.rs @@ -1,3 +1,5 @@ +#![macro_use] + //! HAL interface for the PPI peripheral. //! //! The Programmable Peripheral Interconnect interface allows for an autonomous interoperability @@ -109,7 +111,7 @@ impl Event { } } -mod sealed { +pub(crate) mod sealed { pub trait ConfigurableChannel {} pub trait Channel {} pub trait Group {} @@ -167,15 +169,15 @@ impl Channel for AnyConfigurableChannel { } } -macro_rules! impl_channel { +macro_rules! impl_ppi_channel { ($type:ident, $number:expr, configurable) => { - impl_channel!($type, $number); - impl sealed::ConfigurableChannel for peripherals::$type {} - impl ConfigurableChannel for peripherals::$type {} + impl_ppi_channel!($type, $number); + impl crate::ppi::sealed::ConfigurableChannel for peripherals::$type {} + impl crate::ppi::ConfigurableChannel for peripherals::$type {} }; ($type:ident, $number:expr) => { - impl sealed::Channel for peripherals::$type {} - impl Channel for peripherals::$type { + impl crate::ppi::sealed::Channel for peripherals::$type {} + impl crate::ppi::Channel for peripherals::$type { fn number(&self) -> usize { $number } @@ -183,43 +185,6 @@ macro_rules! impl_channel { }; } -impl_channel!(PPI_CH0, 0, configurable); -impl_channel!(PPI_CH1, 1, configurable); -impl_channel!(PPI_CH2, 2, configurable); -impl_channel!(PPI_CH3, 3, configurable); -impl_channel!(PPI_CH4, 4, configurable); -impl_channel!(PPI_CH5, 5, configurable); -impl_channel!(PPI_CH6, 6, configurable); -impl_channel!(PPI_CH7, 7, configurable); -impl_channel!(PPI_CH8, 8, configurable); -impl_channel!(PPI_CH9, 9, configurable); -impl_channel!(PPI_CH10, 10, configurable); -impl_channel!(PPI_CH11, 11, configurable); -impl_channel!(PPI_CH12, 12, configurable); -impl_channel!(PPI_CH13, 13, configurable); -impl_channel!(PPI_CH14, 14, configurable); -impl_channel!(PPI_CH15, 15, configurable); -#[cfg(not(feature = "nrf51"))] -impl_channel!(PPI_CH16, 16, configurable); -#[cfg(not(feature = "nrf51"))] -impl_channel!(PPI_CH17, 17, configurable); -#[cfg(not(feature = "nrf51"))] -impl_channel!(PPI_CH18, 18, configurable); -#[cfg(not(feature = "nrf51"))] -impl_channel!(PPI_CH19, 19, configurable); -impl_channel!(PPI_CH20, 20); -impl_channel!(PPI_CH21, 21); -impl_channel!(PPI_CH22, 22); -impl_channel!(PPI_CH23, 23); -impl_channel!(PPI_CH24, 24); -impl_channel!(PPI_CH25, 25); -impl_channel!(PPI_CH26, 26); -impl_channel!(PPI_CH27, 27); -impl_channel!(PPI_CH28, 28); -impl_channel!(PPI_CH29, 29); -impl_channel!(PPI_CH30, 30); -impl_channel!(PPI_CH31, 31); - // ====================== // groups From 14c3260d88b95a7354dd1d0686d113602e25becb Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Mon, 11 Oct 2021 01:22:01 +0200 Subject: [PATCH 3/3] nrf/saadc: move chip-specific mappings to chips/ --- embassy-nrf/src/chips/nrf52805.rs | 3 ++ embassy-nrf/src/chips/nrf52810.rs | 9 ++++++ embassy-nrf/src/chips/nrf52811.rs | 9 ++++++ embassy-nrf/src/chips/nrf52832.rs | 9 ++++++ embassy-nrf/src/chips/nrf52833.rs | 9 ++++++ embassy-nrf/src/chips/nrf52840.rs | 9 ++++++ embassy-nrf/src/saadc.rs | 47 ++++++------------------------- 7 files changed, 56 insertions(+), 39 deletions(-) diff --git a/embassy-nrf/src/chips/nrf52805.rs b/embassy-nrf/src/chips/nrf52805.rs index 3bf87e3d..db1fac2f 100644 --- a/embassy-nrf/src/chips/nrf52805.rs +++ b/embassy-nrf/src/chips/nrf52805.rs @@ -182,6 +182,9 @@ impl_ppi_channel!(PPI_CH29, 29); impl_ppi_channel!(PPI_CH30, 30); impl_ppi_channel!(PPI_CH31, 31); +impl_saadc_input!(P0_04, ANALOGINPUT2); +impl_saadc_input!(P0_05, ANALOGINPUT3); + pub mod irqs { use crate::pac::Interrupt as InterruptEnum; use embassy_macros::interrupt_declare as declare; diff --git a/embassy-nrf/src/chips/nrf52810.rs b/embassy-nrf/src/chips/nrf52810.rs index d3241364..06b9bfb3 100644 --- a/embassy-nrf/src/chips/nrf52810.rs +++ b/embassy-nrf/src/chips/nrf52810.rs @@ -197,6 +197,15 @@ impl_ppi_channel!(PPI_CH29, 29); impl_ppi_channel!(PPI_CH30, 30); impl_ppi_channel!(PPI_CH31, 31); +impl_saadc_input!(P0_02, ANALOGINPUT0); +impl_saadc_input!(P0_03, ANALOGINPUT1); +impl_saadc_input!(P0_04, ANALOGINPUT2); +impl_saadc_input!(P0_05, ANALOGINPUT3); +impl_saadc_input!(P0_28, ANALOGINPUT4); +impl_saadc_input!(P0_29, ANALOGINPUT5); +impl_saadc_input!(P0_30, ANALOGINPUT6); +impl_saadc_input!(P0_31, ANALOGINPUT7); + pub mod irqs { use crate::pac::Interrupt as InterruptEnum; use embassy_macros::interrupt_declare as declare; diff --git a/embassy-nrf/src/chips/nrf52811.rs b/embassy-nrf/src/chips/nrf52811.rs index 1231ae62..2f8d98b3 100644 --- a/embassy-nrf/src/chips/nrf52811.rs +++ b/embassy-nrf/src/chips/nrf52811.rs @@ -198,6 +198,15 @@ impl_ppi_channel!(PPI_CH29, 29); impl_ppi_channel!(PPI_CH30, 30); impl_ppi_channel!(PPI_CH31, 31); +impl_saadc_input!(P0_02, ANALOGINPUT0); +impl_saadc_input!(P0_03, ANALOGINPUT1); +impl_saadc_input!(P0_04, ANALOGINPUT2); +impl_saadc_input!(P0_05, ANALOGINPUT3); +impl_saadc_input!(P0_28, ANALOGINPUT4); +impl_saadc_input!(P0_29, ANALOGINPUT5); +impl_saadc_input!(P0_30, ANALOGINPUT6); +impl_saadc_input!(P0_31, ANALOGINPUT7); + pub mod irqs { use crate::pac::Interrupt as InterruptEnum; use embassy_macros::interrupt_declare as declare; diff --git a/embassy-nrf/src/chips/nrf52832.rs b/embassy-nrf/src/chips/nrf52832.rs index 9bbef543..47cf27de 100644 --- a/embassy-nrf/src/chips/nrf52832.rs +++ b/embassy-nrf/src/chips/nrf52832.rs @@ -211,6 +211,15 @@ impl_ppi_channel!(PPI_CH29, 29); impl_ppi_channel!(PPI_CH30, 30); impl_ppi_channel!(PPI_CH31, 31); +impl_saadc_input!(P0_02, ANALOGINPUT0); +impl_saadc_input!(P0_03, ANALOGINPUT1); +impl_saadc_input!(P0_04, ANALOGINPUT2); +impl_saadc_input!(P0_05, ANALOGINPUT3); +impl_saadc_input!(P0_28, ANALOGINPUT4); +impl_saadc_input!(P0_29, ANALOGINPUT5); +impl_saadc_input!(P0_30, ANALOGINPUT6); +impl_saadc_input!(P0_31, ANALOGINPUT7); + pub mod irqs { use crate::pac::Interrupt as InterruptEnum; use embassy_macros::interrupt_declare as declare; diff --git a/embassy-nrf/src/chips/nrf52833.rs b/embassy-nrf/src/chips/nrf52833.rs index d9495dd9..b3d813e2 100644 --- a/embassy-nrf/src/chips/nrf52833.rs +++ b/embassy-nrf/src/chips/nrf52833.rs @@ -251,6 +251,15 @@ impl_ppi_channel!(PPI_CH29, 29); impl_ppi_channel!(PPI_CH30, 30); impl_ppi_channel!(PPI_CH31, 31); +impl_saadc_input!(P0_02, ANALOGINPUT0); +impl_saadc_input!(P0_03, ANALOGINPUT1); +impl_saadc_input!(P0_04, ANALOGINPUT2); +impl_saadc_input!(P0_05, ANALOGINPUT3); +impl_saadc_input!(P0_28, ANALOGINPUT4); +impl_saadc_input!(P0_29, ANALOGINPUT5); +impl_saadc_input!(P0_30, ANALOGINPUT6); +impl_saadc_input!(P0_31, ANALOGINPUT7); + pub mod irqs { use crate::pac::Interrupt as InterruptEnum; use embassy_macros::interrupt_declare as declare; diff --git a/embassy-nrf/src/chips/nrf52840.rs b/embassy-nrf/src/chips/nrf52840.rs index ad89afbc..473036f6 100644 --- a/embassy-nrf/src/chips/nrf52840.rs +++ b/embassy-nrf/src/chips/nrf52840.rs @@ -256,6 +256,15 @@ impl_ppi_channel!(PPI_CH29, 29); impl_ppi_channel!(PPI_CH30, 30); impl_ppi_channel!(PPI_CH31, 31); +impl_saadc_input!(P0_02, ANALOGINPUT0); +impl_saadc_input!(P0_03, ANALOGINPUT1); +impl_saadc_input!(P0_04, ANALOGINPUT2); +impl_saadc_input!(P0_05, ANALOGINPUT3); +impl_saadc_input!(P0_28, ANALOGINPUT4); +impl_saadc_input!(P0_29, ANALOGINPUT5); +impl_saadc_input!(P0_30, ANALOGINPUT6); +impl_saadc_input!(P0_31, ANALOGINPUT7); + pub mod irqs { use crate::pac::Interrupt as InterruptEnum; use embassy_macros::interrupt_declare as declare; diff --git a/embassy-nrf/src/saadc.rs b/embassy-nrf/src/saadc.rs index 2f2baefa..2ce7ef16 100644 --- a/embassy-nrf/src/saadc.rs +++ b/embassy-nrf/src/saadc.rs @@ -1,3 +1,5 @@ +#![macro_use] + use core::marker::PhantomData; use core::sync::atomic::{compiler_fence, Ordering}; use core::task::Poll; @@ -231,45 +233,12 @@ pub trait Input { fn channel(&self) -> InputChannel; } -macro_rules! input_mappings { - ( $($ch:ident => $input:ident,)*) => { - $( - impl Input for crate::peripherals::$input { - fn channel(&self) -> InputChannel { - InputChannel::$ch - } +macro_rules! impl_saadc_input { + ($pin:ident, $ch:ident) => { + impl crate::saadc::Input for crate::peripherals::$pin { + fn channel(&self) -> crate::saadc::InputChannel { + crate::saadc::InputChannel::$ch } - )* + } }; } - -// TODO the variant names are unchecked -// the inputs are copied from nrf hal -#[cfg(feature = "nrf9160")] -input_mappings! { - ANALOGINPUT0 => P0_13, - ANALOGINPUT1 => P0_14, - ANALOGINPUT2 => P0_15, - ANALOGINPUT3 => P0_16, - ANALOGINPUT4 => P0_17, - ANALOGINPUT5 => P0_18, - ANALOGINPUT6 => P0_19, - ANALOGINPUT7 => P0_20, -} -#[cfg(feature = "nrf52805")] -input_mappings! { - ANALOGINPUT2 => P0_04, - ANALOGINPUT3 => P0_05, -} - -#[cfg(not(any(feature = "nrf52805", feature = "nrf9160")))] -input_mappings! { - ANALOGINPUT0 => P0_02, - ANALOGINPUT1 => P0_03, - ANALOGINPUT2 => P0_04, - ANALOGINPUT3 => P0_05, - ANALOGINPUT4 => P0_28, - ANALOGINPUT5 => P0_29, - ANALOGINPUT6 => P0_30, - ANALOGINPUT7 => P0_31, -}