From 415db448c7c476f8c2d81e157437657868d10158 Mon Sep 17 00:00:00 2001 From: Alexander Walter Date: Fri, 13 Dec 2024 19:38:30 +0100 Subject: [PATCH 1/5] Added system off and wake-on-field --- embassy-nrf/src/lib.rs | 3 +++ embassy-nrf/src/power.rs | 13 +++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 embassy-nrf/src/power.rs diff --git a/embassy-nrf/src/lib.rs b/embassy-nrf/src/lib.rs index e7ec4eb9d4..b6283c7f55 100644 --- a/embassy-nrf/src/lib.rs +++ b/embassy-nrf/src/lib.rs @@ -107,6 +107,9 @@ pub mod nvmc; ))] pub mod pdm; #[cfg(not(feature = "_nrf54l"))] // TODO +#[cfg(feature = "nrf52840")] +pub mod power; +#[cfg(not(feature = "_nrf54l"))] // TODO pub mod ppi; #[cfg(not(feature = "_nrf54l"))] // TODO #[cfg(not(any( diff --git a/embassy-nrf/src/power.rs b/embassy-nrf/src/power.rs new file mode 100644 index 0000000000..440028380b --- /dev/null +++ b/embassy-nrf/src/power.rs @@ -0,0 +1,13 @@ +//! Power + +use crate::chip::pac::{NFCT, POWER}; + +/// Puts the MCU into "System Off" mode with a power usage 0f 0.4 uA +pub fn set_system_off() { + POWER.systemoff().write(|w| w.set_systemoff(true)); +} + +/// Wake the system if there if an NFC field close to the nrf52840's antenna +pub fn wake_on_nfc_sense() { + NFCT.tasks_sense().write_value(0x01); +} From 6f08c62d5ddcbeba01e098e11b9bc4ed1dfa7cc2 Mon Sep 17 00:00:00 2001 From: Alexander Walter Date: Sat, 14 Dec 2024 00:11:32 +0100 Subject: [PATCH 2/5] Add nrf9160 --- embassy-nrf/src/lib.rs | 2 +- embassy-nrf/src/power.rs | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/embassy-nrf/src/lib.rs b/embassy-nrf/src/lib.rs index b6283c7f55..ec5e9f8644 100644 --- a/embassy-nrf/src/lib.rs +++ b/embassy-nrf/src/lib.rs @@ -107,7 +107,7 @@ pub mod nvmc; ))] pub mod pdm; #[cfg(not(feature = "_nrf54l"))] // TODO -#[cfg(feature = "nrf52840")] +#[cfg(any(feature = "nrf52840", feature = "nrf9160-s", feature = "nrf9160-ns"))] pub mod power; #[cfg(not(feature = "_nrf54l"))] // TODO pub mod ppi; diff --git a/embassy-nrf/src/power.rs b/embassy-nrf/src/power.rs index 440028380b..66dfbae652 100644 --- a/embassy-nrf/src/power.rs +++ b/embassy-nrf/src/power.rs @@ -1,13 +1,24 @@ //! Power -use crate::chip::pac::{NFCT, POWER}; +#[cfg(feature = "nrf52840")] +use crate::chip::pac::NFCT; -/// Puts the MCU into "System Off" mode with a power usage 0f 0.4 uA +#[cfg(feature = "nrf52840")] +use crate::chip::pac::POWER; + +#[cfg(any(feature = "nrf9160-s", feature = "nrf9160-ns"))] +use crate::chip::pac::REGULATORS; + +/// Puts the MCU into "System Off" mode with minimal power usage pub fn set_system_off() { + #[cfg(feature = "nrf52840")] POWER.systemoff().write(|w| w.set_systemoff(true)); + #[cfg(any(feature = "nrf9160-s", feature = "nrf9160-ns"))] + REGULATORS.systemoff().write(|w| w.set_systemoff(true)); } /// Wake the system if there if an NFC field close to the nrf52840's antenna +#[cfg(feature = "nrf52840")] pub fn wake_on_nfc_sense() { NFCT.tasks_sense().write_value(0x01); } From c4f6509cf28e1a8c2401a67f771dd8b959ae7c49 Mon Sep 17 00:00:00 2001 From: Alexander Walter Date: Sat, 14 Dec 2024 01:02:35 +0100 Subject: [PATCH 3/5] rustfmt --- embassy-nrf/src/power.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/embassy-nrf/src/power.rs b/embassy-nrf/src/power.rs index 66dfbae652..ab6460625e 100644 --- a/embassy-nrf/src/power.rs +++ b/embassy-nrf/src/power.rs @@ -2,10 +2,8 @@ #[cfg(feature = "nrf52840")] use crate::chip::pac::NFCT; - #[cfg(feature = "nrf52840")] use crate::chip::pac::POWER; - #[cfg(any(feature = "nrf9160-s", feature = "nrf9160-ns"))] use crate::chip::pac::REGULATORS; From 3b5993cf48c0a1a5f88f5d0f771df16ceb4de3fb Mon Sep 17 00:00:00 2001 From: Alexander Walter Date: Sat, 14 Dec 2024 15:40:08 +0100 Subject: [PATCH 4/5] Move wake on sense to nfct --- embassy-nrf/src/nfct.rs | 7 ++++++- embassy-nrf/src/power.rs | 6 ------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/embassy-nrf/src/nfct.rs b/embassy-nrf/src/nfct.rs index cbd3920eed..06cb0916c0 100644 --- a/embassy-nrf/src/nfct.rs +++ b/embassy-nrf/src/nfct.rs @@ -18,7 +18,7 @@ use embassy_sync::waitqueue::AtomicWaker; pub use vals::{Bitframesdd as SddPat, Discardmode as DiscardMode}; use crate::interrupt::InterruptExt; -use crate::pac::nfct::vals; +use crate::pac::{nfct::vals, NFCT}; use crate::peripherals::NFCT; use crate::util::slice_in_ram; use crate::{interrupt, pac, Peripheral}; @@ -420,3 +420,8 @@ impl<'d> NfcT<'d> { Ok(n) } } + +/// Wake the system if there if an NFC field close to the antenna +pub fn wake_on_nfc_sense() { + NFCT.tasks_sense().write_value(0x01); +} diff --git a/embassy-nrf/src/power.rs b/embassy-nrf/src/power.rs index ab6460625e..730efe0942 100644 --- a/embassy-nrf/src/power.rs +++ b/embassy-nrf/src/power.rs @@ -14,9 +14,3 @@ pub fn set_system_off() { #[cfg(any(feature = "nrf9160-s", feature = "nrf9160-ns"))] REGULATORS.systemoff().write(|w| w.set_systemoff(true)); } - -/// Wake the system if there if an NFC field close to the nrf52840's antenna -#[cfg(feature = "nrf52840")] -pub fn wake_on_nfc_sense() { - NFCT.tasks_sense().write_value(0x01); -} From ea374a47368fb917e6a89b0bc567a225778f4f9f Mon Sep 17 00:00:00 2001 From: Alexander Walter Date: Sat, 14 Dec 2024 15:48:18 +0100 Subject: [PATCH 5/5] Fix rustfm and warning --- embassy-nrf/src/nfct.rs | 3 ++- embassy-nrf/src/power.rs | 2 -- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/embassy-nrf/src/nfct.rs b/embassy-nrf/src/nfct.rs index 06cb0916c0..8b4b6dfe07 100644 --- a/embassy-nrf/src/nfct.rs +++ b/embassy-nrf/src/nfct.rs @@ -18,7 +18,8 @@ use embassy_sync::waitqueue::AtomicWaker; pub use vals::{Bitframesdd as SddPat, Discardmode as DiscardMode}; use crate::interrupt::InterruptExt; -use crate::pac::{nfct::vals, NFCT}; +use crate::pac::nfct::vals; +use crate::pac::NFCT; use crate::peripherals::NFCT; use crate::util::slice_in_ram; use crate::{interrupt, pac, Peripheral}; diff --git a/embassy-nrf/src/power.rs b/embassy-nrf/src/power.rs index 730efe0942..f93bf8f495 100644 --- a/embassy-nrf/src/power.rs +++ b/embassy-nrf/src/power.rs @@ -1,7 +1,5 @@ //! Power -#[cfg(feature = "nrf52840")] -use crate::chip::pac::NFCT; #[cfg(feature = "nrf52840")] use crate::chip::pac::POWER; #[cfg(any(feature = "nrf9160-s", feature = "nrf9160-ns"))]