diff options
| -rw-r--r-- | embassy-nrf/src/saadc.rs | 49 |
1 files changed, 2 insertions, 47 deletions
diff --git a/embassy-nrf/src/saadc.rs b/embassy-nrf/src/saadc.rs index 5f2ac64ef..9bc89eb38 100644 --- a/embassy-nrf/src/saadc.rs +++ b/embassy-nrf/src/saadc.rs | |||
| @@ -184,11 +184,6 @@ impl<'d, const N: usize> Saadc<'d, N> { | |||
| 184 | r.intenclr.write(|w| w.started().clear()); | 184 | r.intenclr.write(|w| w.started().clear()); |
| 185 | WAKER.wake(); | 185 | WAKER.wake(); |
| 186 | } | 186 | } |
| 187 | |||
| 188 | if r.events_stopped.read().bits() != 0 { | ||
| 189 | r.intenclr.write(|w| w.stopped().clear()); | ||
| 190 | WAKER.wake(); | ||
| 191 | } | ||
| 192 | } | 187 | } |
| 193 | 188 | ||
| 194 | fn regs() -> &'static saadc::RegisterBlock { | 189 | fn regs() -> &'static saadc::RegisterBlock { |
| @@ -230,7 +225,7 @@ impl<'d, const N: usize> Saadc<'d, N> { | |||
| 230 | /// also cause the sampling to be stopped. | 225 | /// also cause the sampling to be stopped. |
| 231 | pub async fn sample(&mut self, buf: &mut [i16; N]) { | 226 | pub async fn sample(&mut self, buf: &mut [i16; N]) { |
| 232 | // In case the future is dropped, stop the task and wait for it to end. | 227 | // In case the future is dropped, stop the task and wait for it to end. |
| 233 | let on_drop = OnDrop::new(Self::stop_sampling_immediately); | 228 | OnDrop::new(Self::stop_sampling_immediately); |
| 234 | 229 | ||
| 235 | let r = Self::regs(); | 230 | let r = Self::regs(); |
| 236 | 231 | ||
| @@ -263,9 +258,6 @@ impl<'d, const N: usize> Saadc<'d, N> { | |||
| 263 | Poll::Pending | 258 | Poll::Pending |
| 264 | }) | 259 | }) |
| 265 | .await; | 260 | .await; |
| 266 | |||
| 267 | on_drop.defuse(); | ||
| 268 | Self::stop_sampling().await; | ||
| 269 | } | 261 | } |
| 270 | 262 | ||
| 271 | /// Continuous sampling with double buffers. | 263 | /// Continuous sampling with double buffers. |
| @@ -343,7 +335,7 @@ impl<'d, const N: usize> Saadc<'d, N> { | |||
| 343 | S: FnMut(&[[i16; N]]) -> SamplerState, | 335 | S: FnMut(&[[i16; N]]) -> SamplerState, |
| 344 | { | 336 | { |
| 345 | // In case the future is dropped, stop the task and wait for it to end. | 337 | // In case the future is dropped, stop the task and wait for it to end. |
| 346 | let on_drop = OnDrop::new(Self::stop_sampling_immediately); | 338 | OnDrop::new(Self::stop_sampling_immediately); |
| 347 | 339 | ||
| 348 | let r = Self::regs(); | 340 | let r = Self::regs(); |
| 349 | 341 | ||
| @@ -427,9 +419,6 @@ impl<'d, const N: usize> Saadc<'d, N> { | |||
| 427 | Poll::Pending | 419 | Poll::Pending |
| 428 | }) | 420 | }) |
| 429 | .await; | 421 | .await; |
| 430 | |||
| 431 | on_drop.defuse(); | ||
| 432 | Self::stop_sampling().await; | ||
| 433 | } | 422 | } |
| 434 | 423 | ||
| 435 | // Stop sampling and wait for it to stop in a blocking fashion | 424 | // Stop sampling and wait for it to stop in a blocking fashion |
| @@ -444,40 +433,6 @@ impl<'d, const N: usize> Saadc<'d, N> { | |||
| 444 | while r.events_stopped.read().bits() == 0 {} | 433 | while r.events_stopped.read().bits() == 0 {} |
| 445 | r.events_stopped.reset(); | 434 | r.events_stopped.reset(); |
| 446 | } | 435 | } |
| 447 | |||
| 448 | // Stop sampling and wait for it to stop in a non-blocking fashino | ||
| 449 | async fn stop_sampling() { | ||
| 450 | let r = Self::regs(); | ||
| 451 | |||
| 452 | // Reset and enable the events | ||
| 453 | |||
| 454 | compiler_fence(Ordering::SeqCst); | ||
| 455 | |||
| 456 | r.events_stopped.reset(); | ||
| 457 | r.intenset.write(|w| { | ||
| 458 | w.stopped().set(); | ||
| 459 | w | ||
| 460 | }); | ||
| 461 | |||
| 462 | // Stop | ||
| 463 | |||
| 464 | r.tasks_stop.write(|w| unsafe { w.bits(1) }); | ||
| 465 | |||
| 466 | // Wait for 'stopped' event. | ||
| 467 | poll_fn(|cx| { | ||
| 468 | let r = Self::regs(); | ||
| 469 | |||
| 470 | WAKER.register(cx.waker()); | ||
| 471 | |||
| 472 | if r.events_stopped.read().bits() != 0 { | ||
| 473 | r.events_stopped.reset(); | ||
| 474 | return Poll::Ready(()); | ||
| 475 | } | ||
| 476 | |||
| 477 | Poll::Pending | ||
| 478 | }) | ||
| 479 | .await; | ||
| 480 | } | ||
| 481 | } | 436 | } |
| 482 | 437 | ||
| 483 | impl<'d> Saadc<'d, 1> { | 438 | impl<'d> Saadc<'d, 1> { |
