From a3d4ae85b021b888a78ef2214a7ecae0a49741c4 Mon Sep 17 00:00:00 2001 From: pennae Date: Thu, 20 Jul 2023 15:48:59 +0200 Subject: [PATCH] rp: disable adc hardware on Adc drop the adc constantly pulls a small but significant amount of current while the hardware is enabled. this can have quite an effect on sleeping devices that also use the adc. --- embassy-rp/src/adc.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/embassy-rp/src/adc.rs b/embassy-rp/src/adc.rs index dfa1b877..95780c06 100644 --- a/embassy-rp/src/adc.rs +++ b/embassy-rp/src/adc.rs @@ -81,6 +81,16 @@ pub struct Adc<'d, M: Mode> { phantom: PhantomData<(&'d ADC, M)>, } +impl<'d, M: Mode> Drop for Adc<'d, M> { + fn drop(&mut self) { + let r = Self::regs(); + // disable ADC. leaving it enabled comes with a ~150µA static + // current draw. the temperature sensor has already been disabled + // by the temperature-reading methods, so we don't need to touch that. + r.cs().write(|w| w.set_en(false)); + } +} + impl<'d, M: Mode> Adc<'d, M> { #[inline] fn regs() -> pac::adc::Adc {