From 34e9e8581914af6f91ac21de9f027ddb0b67e9c4 Mon Sep 17 00:00:00 2001 From: huntc Date: Fri, 15 Oct 2021 08:12:13 +1100 Subject: [PATCH] We can kick start the internal timer outside of the main loop --- embassy-nrf/src/saadc.rs | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/embassy-nrf/src/saadc.rs b/embassy-nrf/src/saadc.rs index 039893d15..2a1059836 100644 --- a/embassy-nrf/src/saadc.rs +++ b/embassy-nrf/src/saadc.rs @@ -270,13 +270,16 @@ impl<'d, const N: usize> Saadc<'d, N> { // Establish mode and sample rate match mode { - Mode::Timers(sample_rate) => r.samplerate.write(|w| { - unsafe { - w.cc().bits(sample_rate); - w.mode().timers(); - } - w - }), + Mode::Timers(sample_rate) => { + r.samplerate.write(|w| { + unsafe { + w.cc().bits(sample_rate); + w.mode().timers(); + } + w + }); + r.tasks_sample.write(|w| unsafe { w.bits(1) }); // Need to kick-start the internal timer + } Mode::Task => r.samplerate.write(|w| { unsafe { w.cc().bits(0); @@ -334,10 +337,6 @@ impl<'d, const N: usize> Saadc<'d, N> { r.events_started.reset(); r.intenset.write(|w| w.started().set()); - if let Mode::Timers(_) = mode { - r.tasks_sample.write(|w| unsafe { w.bits(1) }); - } - let next_buffer = 1 - current_buffer; r.result .ptr