diff options
Diffstat (limited to 'embassy-nrf/src')
| -rw-r--r-- | embassy-nrf/src/twim.rs | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/embassy-nrf/src/twim.rs b/embassy-nrf/src/twim.rs index ebad39df2..df1de83a2 100644 --- a/embassy-nrf/src/twim.rs +++ b/embassy-nrf/src/twim.rs | |||
| @@ -85,6 +85,8 @@ pub enum Error { | |||
| 85 | Overrun, | 85 | Overrun, |
| 86 | /// Timeout error. | 86 | /// Timeout error. |
| 87 | Timeout, | 87 | Timeout, |
| 88 | /// Bus error. | ||
| 89 | Bus, | ||
| 88 | } | 90 | } |
| 89 | 91 | ||
| 90 | /// Interrupt handler. | 92 | /// Interrupt handler. |
| @@ -329,7 +331,7 @@ impl<'d, T: Instance> Twim<'d, T> { | |||
| 329 | } | 331 | } |
| 330 | 332 | ||
| 331 | /// Wait for stop or error | 333 | /// Wait for stop or error |
| 332 | fn async_wait(&mut self) -> impl Future<Output = ()> { | 334 | fn async_wait(&mut self) -> impl Future<Output = Result<(), Error>> { |
| 333 | poll_fn(move |cx| { | 335 | poll_fn(move |cx| { |
| 334 | let r = T::regs(); | 336 | let r = T::regs(); |
| 335 | let s = T::state(); | 337 | let s = T::state(); |
| @@ -338,13 +340,23 @@ impl<'d, T: Instance> Twim<'d, T> { | |||
| 338 | if r.events_suspended().read() != 0 || r.events_stopped().read() != 0 { | 340 | if r.events_suspended().read() != 0 || r.events_stopped().read() != 0 { |
| 339 | r.events_stopped().write_value(0); | 341 | r.events_stopped().write_value(0); |
| 340 | 342 | ||
| 341 | return Poll::Ready(()); | 343 | return Poll::Ready(Ok(())); |
| 342 | } | 344 | } |
| 343 | 345 | ||
| 344 | // stop if an error occurred | 346 | // stop if an error occurred |
| 345 | if r.events_error().read() != 0 { | 347 | if r.events_error().read() != 0 { |
| 346 | r.events_error().write_value(0); | 348 | r.events_error().write_value(0); |
| 347 | r.tasks_stop().write_value(1); | 349 | r.tasks_stop().write_value(1); |
| 350 | let errorsrc = r.errorsrc().read(); | ||
| 351 | if errorsrc.overrun() { | ||
| 352 | return Poll::Ready(Err(Error::Overrun)); | ||
| 353 | } else if errorsrc.anack() { | ||
| 354 | return Poll::Ready(Err(Error::AddressNack)); | ||
| 355 | } else if errorsrc.dnack() { | ||
| 356 | return Poll::Ready(Err(Error::DataNack)); | ||
| 357 | } else { | ||
| 358 | return Poll::Ready(Err(Error::Bus)); | ||
| 359 | } | ||
| 348 | } | 360 | } |
| 349 | 361 | ||
| 350 | Poll::Pending | 362 | Poll::Pending |
| @@ -626,7 +638,7 @@ impl<'d, T: Instance> Twim<'d, T> { | |||
| 626 | while !operations.is_empty() { | 638 | while !operations.is_empty() { |
| 627 | let ops = self.setup_operations(address, operations, Some(&mut tx_ram_buffer), last_op, true)?; | 639 | 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); | 640 | let (in_progress, rest) = operations.split_at_mut(ops); |
| 629 | self.async_wait().await; | 641 | self.async_wait().await?; |
| 630 | self.check_operations(in_progress)?; | 642 | self.check_operations(in_progress)?; |
| 631 | last_op = in_progress.last(); | 643 | last_op = in_progress.last(); |
| 632 | operations = rest; | 644 | operations = rest; |
| @@ -644,7 +656,7 @@ impl<'d, T: Instance> Twim<'d, T> { | |||
| 644 | while !operations.is_empty() { | 656 | while !operations.is_empty() { |
| 645 | let ops = self.setup_operations(address, operations, None, last_op, true)?; | 657 | let ops = self.setup_operations(address, operations, None, last_op, true)?; |
| 646 | let (in_progress, rest) = operations.split_at_mut(ops); | 658 | let (in_progress, rest) = operations.split_at_mut(ops); |
| 647 | self.async_wait().await; | 659 | self.async_wait().await?; |
| 648 | self.check_operations(in_progress)?; | 660 | self.check_operations(in_progress)?; |
| 649 | last_op = in_progress.last(); | 661 | last_op = in_progress.last(); |
| 650 | operations = rest; | 662 | operations = rest; |
| @@ -910,6 +922,7 @@ impl embedded_hal_1::i2c::Error for Error { | |||
| 910 | } | 922 | } |
| 911 | Self::Overrun => embedded_hal_1::i2c::ErrorKind::Overrun, | 923 | Self::Overrun => embedded_hal_1::i2c::ErrorKind::Overrun, |
| 912 | Self::Timeout => embedded_hal_1::i2c::ErrorKind::Other, | 924 | Self::Timeout => embedded_hal_1::i2c::ErrorKind::Other, |
| 925 | Self::Bus => embedded_hal_1::i2c::ErrorKind::Other, | ||
| 913 | } | 926 | } |
| 914 | } | 927 | } |
| 915 | } | 928 | } |
