From 8dcc41c7f04ebcb6246d3f4f3c672d7b947ab82d Mon Sep 17 00:00:00 2001 From: huntc Date: Mon, 18 Oct 2021 12:23:13 +1100 Subject: [PATCH 1/2] Optimises the buffer passing for nRF SAADC The buffer will always have been filled and we never explicitly stop the task outside of this code. Thus, we can assume the number of bytes in the slice. --- embassy-nrf/src/saadc.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/embassy-nrf/src/saadc.rs b/embassy-nrf/src/saadc.rs index 8bf4f727..d9b76642 100644 --- a/embassy-nrf/src/saadc.rs +++ b/embassy-nrf/src/saadc.rs @@ -320,7 +320,7 @@ impl<'d, const N: usize> Saadc<'d, N> { r.events_end.reset(); r.intenset.write(|w| w.end().set()); - if sampler(&bufs[current_buffer][0..r.result.amount.read().bits() as usize / N]) + if sampler(&bufs[current_buffer]) == SamplerState::Sampled { let next_buffer = 1 - current_buffer; From 3f31774674686bcd6c99a3d0443e9cf517dc0e82 Mon Sep 17 00:00:00 2001 From: huntc Date: Mon, 18 Oct 2021 12:29:31 +1100 Subject: [PATCH 2/2] Formatting --- embassy-nrf/src/saadc.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/embassy-nrf/src/saadc.rs b/embassy-nrf/src/saadc.rs index d9b76642..215f968a 100644 --- a/embassy-nrf/src/saadc.rs +++ b/embassy-nrf/src/saadc.rs @@ -320,9 +320,7 @@ impl<'d, const N: usize> Saadc<'d, N> { r.events_end.reset(); r.intenset.write(|w| w.end().set()); - if sampler(&bufs[current_buffer]) - == SamplerState::Sampled - { + if sampler(&bufs[current_buffer]) == SamplerState::Sampled { let next_buffer = 1 - current_buffer; current_buffer = next_buffer; r.tasks_start.write(|w| unsafe { w.bits(1) });