Ensure that the sampling is stopped
Ensures that nRF saadc sampling is stopped and is awaited prior to exiting the two sampling methods. Not doing so causes a potential power drain and the potential for dropped buffer writes when having finished continuous sampling.
This commit is contained in:
parent
1125d57842
commit
9a873d1dbf
@ -183,6 +183,11 @@ impl<'d, const N: usize> Saadc<'d, N> {
|
|||||||
r.intenclr.write(|w| w.started().clear());
|
r.intenclr.write(|w| w.started().clear());
|
||||||
WAKER.wake();
|
WAKER.wake();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if r.events_stopped.read().bits() != 0 {
|
||||||
|
r.intenclr.write(|w| w.stopped().clear());
|
||||||
|
WAKER.wake();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn regs() -> &'static saadc::RegisterBlock {
|
fn regs() -> &'static saadc::RegisterBlock {
|
||||||
@ -251,6 +256,8 @@ impl<'d, const N: usize> Saadc<'d, N> {
|
|||||||
Poll::Pending
|
Poll::Pending
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
Self::stop_sampling().await;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Continuous sampling with double buffers.
|
/// Continuous sampling with double buffers.
|
||||||
@ -403,6 +410,42 @@ impl<'d, const N: usize> Saadc<'d, N> {
|
|||||||
Poll::Pending
|
Poll::Pending
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
Self::stop_sampling().await;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stop sampling and wait for it to stop
|
||||||
|
async fn stop_sampling() {
|
||||||
|
let r = Self::regs();
|
||||||
|
|
||||||
|
// Reset and enable the events
|
||||||
|
|
||||||
|
compiler_fence(Ordering::SeqCst);
|
||||||
|
|
||||||
|
r.events_stopped.reset();
|
||||||
|
r.intenset.write(|w| {
|
||||||
|
w.stopped().set();
|
||||||
|
w
|
||||||
|
});
|
||||||
|
|
||||||
|
// Stop
|
||||||
|
|
||||||
|
r.tasks_stop.write(|w| unsafe { w.bits(1) });
|
||||||
|
|
||||||
|
// Wait for 'stopped' event.
|
||||||
|
poll_fn(|cx| {
|
||||||
|
let r = Self::regs();
|
||||||
|
|
||||||
|
WAKER.register(cx.waker());
|
||||||
|
|
||||||
|
if r.events_stopped.read().bits() != 0 {
|
||||||
|
r.events_stopped.reset();
|
||||||
|
return Poll::Ready(());
|
||||||
|
}
|
||||||
|
|
||||||
|
Poll::Pending
|
||||||
|
})
|
||||||
|
.await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user