mirror of
https://github.com/embassy-rs/embassy.git
synced 2024-11-29 10:12:35 +00:00
Merge #1160
1160: Stop sampling when exiting the Saadc methods r=huntc a=huntc Prior to this commit, the onDrop function was being dropped immediately and not on exiting the Saadc sampling methods. A few other places have been corrected also. Thanks to Peter Hansen for pointing out this issue. Co-authored-by: huntc <huntchr@gmail.com>
This commit is contained in:
commit
db8e9efe73
@ -225,7 +225,7 @@ impl<'d, const N: usize> Saadc<'d, N> {
|
||||
/// also cause the sampling to be stopped.
|
||||
pub async fn sample(&mut self, buf: &mut [i16; N]) {
|
||||
// In case the future is dropped, stop the task and wait for it to end.
|
||||
OnDrop::new(Self::stop_sampling_immediately);
|
||||
let on_drop = OnDrop::new(Self::stop_sampling_immediately);
|
||||
|
||||
let r = Self::regs();
|
||||
|
||||
@ -258,6 +258,8 @@ impl<'d, const N: usize> Saadc<'d, N> {
|
||||
Poll::Pending
|
||||
})
|
||||
.await;
|
||||
|
||||
drop(on_drop);
|
||||
}
|
||||
|
||||
/// Continuous sampling with double buffers.
|
||||
@ -335,7 +337,7 @@ impl<'d, const N: usize> Saadc<'d, N> {
|
||||
S: FnMut(&[[i16; N]]) -> SamplerState,
|
||||
{
|
||||
// In case the future is dropped, stop the task and wait for it to end.
|
||||
OnDrop::new(Self::stop_sampling_immediately);
|
||||
let on_drop = OnDrop::new(Self::stop_sampling_immediately);
|
||||
|
||||
let r = Self::regs();
|
||||
|
||||
@ -382,7 +384,7 @@ impl<'d, const N: usize> Saadc<'d, N> {
|
||||
let mut current_buffer = 0;
|
||||
|
||||
// Wait for events and complete when the sampler indicates it has had enough.
|
||||
poll_fn(|cx| {
|
||||
let r = poll_fn(|cx| {
|
||||
let r = Self::regs();
|
||||
|
||||
WAKER.register(cx.waker());
|
||||
@ -419,6 +421,10 @@ impl<'d, const N: usize> Saadc<'d, N> {
|
||||
Poll::Pending
|
||||
})
|
||||
.await;
|
||||
|
||||
drop(on_drop);
|
||||
|
||||
r
|
||||
}
|
||||
|
||||
// Stop sampling and wait for it to stop in a blocking fashion
|
||||
|
@ -483,7 +483,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
|
||||
state.chunks_transferred.store(0, Ordering::Relaxed);
|
||||
let mut remaining_len = total_len;
|
||||
|
||||
let _on_drop = OnDrop::new(|| {
|
||||
let on_drop = OnDrop::new(|| {
|
||||
let regs = T::regs();
|
||||
unsafe {
|
||||
regs.cr1().modify(|w| {
|
||||
@ -542,6 +542,9 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
|
||||
self.wait_tc(&check_timeout)?;
|
||||
self.master_stop();
|
||||
}
|
||||
|
||||
drop(on_drop);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -580,7 +583,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
|
||||
state.chunks_transferred.store(0, Ordering::Relaxed);
|
||||
let mut remaining_len = total_len;
|
||||
|
||||
let _on_drop = OnDrop::new(|| {
|
||||
let on_drop = OnDrop::new(|| {
|
||||
let regs = T::regs();
|
||||
unsafe {
|
||||
regs.cr1().modify(|w| {
|
||||
@ -629,6 +632,9 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
|
||||
// This should be done already
|
||||
self.wait_tc(&check_timeout)?;
|
||||
self.master_stop();
|
||||
|
||||
drop(on_drop);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -405,7 +405,7 @@ impl<'d, T: BasicInstance, RxDma> UartRx<'d, T, RxDma> {
|
||||
let r = T::regs();
|
||||
|
||||
// make sure USART state is restored to neutral state when this future is dropped
|
||||
let _drop = OnDrop::new(move || {
|
||||
let on_drop = OnDrop::new(move || {
|
||||
// defmt::trace!("Clear all USART interrupts and DMA Read Request");
|
||||
// clear all interrupts and DMA Rx Request
|
||||
// SAFETY: only clears Rx related flags
|
||||
@ -563,7 +563,7 @@ impl<'d, T: BasicInstance, RxDma> UartRx<'d, T, RxDma> {
|
||||
// wait for the first of DMA request or idle line detected to completes
|
||||
// select consumes its arguments
|
||||
// when transfer is dropped, it will stop the DMA request
|
||||
match select(transfer, idle).await {
|
||||
let r = match select(transfer, idle).await {
|
||||
// DMA transfer completed first
|
||||
Either::First(()) => Ok(ReadCompletionEvent::DmaCompleted),
|
||||
|
||||
@ -572,7 +572,11 @@ impl<'d, T: BasicInstance, RxDma> UartRx<'d, T, RxDma> {
|
||||
|
||||
// error occurred
|
||||
Either::Second(Err(e)) => Err(e),
|
||||
}
|
||||
};
|
||||
|
||||
drop(on_drop);
|
||||
|
||||
r
|
||||
}
|
||||
|
||||
async fn inner_read(&mut self, buffer: &mut [u8], enable_idle_line_detection: bool) -> Result<usize, Error>
|
||||
|
Loading…
Reference in New Issue
Block a user