aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2025-01-08 19:40:10 +0100
committerGitHub <[email protected]>2025-01-08 19:40:10 +0100
commitcd70c19ab5652fd58ad397ccef207298d52e66aa (patch)
tree5e00e34f7b94cae5a27c4921eb05fb11959112b5
parentc48fc857cf537ff2ec45131d729f12343ac5f15a (diff)
parentcd38669ac2239c484e181bbcc8e4804e9de28039 (diff)
Merge pull request #3745 from dragonnn/nrf_twim
nrf twim return errors in async_wait instead of waiting indefinitely
-rw-r--r--embassy-nrf/src/twim.rs17
1 files changed, 11 insertions, 6 deletions
diff --git a/embassy-nrf/src/twim.rs b/embassy-nrf/src/twim.rs
index ebad39df2..bfce00f1b 100644
--- a/embassy-nrf/src/twim.rs
+++ b/embassy-nrf/src/twim.rs
@@ -255,7 +255,7 @@ impl<'d, T: Instance> Twim<'d, T> {
255 } 255 }
256 256
257 /// Get Error instance, if any occurred. 257 /// Get Error instance, if any occurred.
258 fn check_errorsrc(&self) -> Result<(), Error> { 258 fn check_errorsrc() -> Result<(), Error> {
259 let r = T::regs(); 259 let r = T::regs();
260 260
261 let err = r.errorsrc().read(); 261 let err = r.errorsrc().read();
@@ -329,7 +329,7 @@ impl<'d, T: Instance> Twim<'d, T> {
329 } 329 }
330 330
331 /// Wait for stop or error 331 /// Wait for stop or error
332 fn async_wait(&mut self) -> impl Future<Output = ()> { 332 fn async_wait(&mut self) -> impl Future<Output = Result<(), Error>> {
333 poll_fn(move |cx| { 333 poll_fn(move |cx| {
334 let r = T::regs(); 334 let r = T::regs();
335 let s = T::state(); 335 let s = T::state();
@@ -338,13 +338,18 @@ impl<'d, T: Instance> Twim<'d, T> {
338 if r.events_suspended().read() != 0 || r.events_stopped().read() != 0 { 338 if r.events_suspended().read() != 0 || r.events_stopped().read() != 0 {
339 r.events_stopped().write_value(0); 339 r.events_stopped().write_value(0);
340 340
341 return Poll::Ready(()); 341 return Poll::Ready(Ok(()));
342 } 342 }
343 343
344 // stop if an error occurred 344 // stop if an error occurred
345 if r.events_error().read() != 0 { 345 if r.events_error().read() != 0 {
346 r.events_error().write_value(0); 346 r.events_error().write_value(0);
347 r.tasks_stop().write_value(1); 347 r.tasks_stop().write_value(1);
348 if let Err(e) = Self::check_errorsrc() {
349 return Poll::Ready(Err(e));
350 } else {
351 panic!("Found events_error bit without an error in errorsrc reg");
352 }
348 } 353 }
349 354
350 Poll::Pending 355 Poll::Pending
@@ -503,7 +508,7 @@ impl<'d, T: Instance> Twim<'d, T> {
503 508
504 fn check_operations(&mut self, operations: &[Operation<'_>]) -> Result<(), Error> { 509 fn check_operations(&mut self, operations: &[Operation<'_>]) -> Result<(), Error> {
505 compiler_fence(SeqCst); 510 compiler_fence(SeqCst);
506 self.check_errorsrc()?; 511 Self::check_errorsrc()?;
507 512
508 assert!(operations.len() == 1 || operations.len() == 2); 513 assert!(operations.len() == 1 || operations.len() == 2);
509 match operations { 514 match operations {
@@ -626,7 +631,7 @@ impl<'d, T: Instance> Twim<'d, T> {
626 while !operations.is_empty() { 631 while !operations.is_empty() {
627 let ops = self.setup_operations(address, operations, Some(&mut tx_ram_buffer), last_op, true)?; 632 let ops = self.setup_operations(address, operations, Some(&mut tx_ram_buffer), last_op, true)?;
628 let (in_progress, rest) = operations.split_at_mut(ops); 633 let (in_progress, rest) = operations.split_at_mut(ops);
629 self.async_wait().await; 634 self.async_wait().await?;
630 self.check_operations(in_progress)?; 635 self.check_operations(in_progress)?;
631 last_op = in_progress.last(); 636 last_op = in_progress.last();
632 operations = rest; 637 operations = rest;
@@ -644,7 +649,7 @@ impl<'d, T: Instance> Twim<'d, T> {
644 while !operations.is_empty() { 649 while !operations.is_empty() {
645 let ops = self.setup_operations(address, operations, None, last_op, true)?; 650 let ops = self.setup_operations(address, operations, None, last_op, true)?;
646 let (in_progress, rest) = operations.split_at_mut(ops); 651 let (in_progress, rest) = operations.split_at_mut(ops);
647 self.async_wait().await; 652 self.async_wait().await?;
648 self.check_operations(in_progress)?; 653 self.check_operations(in_progress)?;
649 last_op = in_progress.last(); 654 last_op = in_progress.last();
650 operations = rest; 655 operations = rest;