diff options
| -rw-r--r-- | embassy-nrf/src/lib.rs | 6 | ||||
| -rw-r--r-- | embassy-nrf/src/twis.rs | 22 |
2 files changed, 15 insertions, 13 deletions
diff --git a/embassy-nrf/src/lib.rs b/embassy-nrf/src/lib.rs index 6c5a3202a..7f20f4fd6 100644 --- a/embassy-nrf/src/lib.rs +++ b/embassy-nrf/src/lib.rs | |||
| @@ -268,11 +268,5 @@ pub fn init(config: config::Config) -> Peripherals { | |||
| 268 | #[cfg(feature = "_time-driver")] | 268 | #[cfg(feature = "_time-driver")] |
| 269 | time_driver::init(config.time_interrupt_priority); | 269 | time_driver::init(config.time_interrupt_priority); |
| 270 | 270 | ||
| 271 | // Disable UARTE (enabled by default for some reason) | ||
| 272 | #[cfg(feature = "_nrf9160")] | ||
| 273 | unsafe { | ||
| 274 | (*pac::UARTE0::ptr()).enable.write(|w| w.enable().disabled()); | ||
| 275 | (*pac::UARTE1::ptr()).enable.write(|w| w.enable().disabled()); | ||
| 276 | } | ||
| 277 | peripherals | 271 | peripherals |
| 278 | } | 272 | } |
diff --git a/embassy-nrf/src/twis.rs b/embassy-nrf/src/twis.rs index 769522877..b8cb2eeb8 100644 --- a/embassy-nrf/src/twis.rs +++ b/embassy-nrf/src/twis.rs | |||
| @@ -135,7 +135,7 @@ impl<'d, T: Instance> Twis<'d, T> { | |||
| 135 | 135 | ||
| 136 | // Set address | 136 | // Set address |
| 137 | r.address[0].write(|w| unsafe { w.address().bits(config.address0) }); | 137 | r.address[0].write(|w| unsafe { w.address().bits(config.address0) }); |
| 138 | r.config.modify(|_r, w| w.address0().enabled()); | 138 | r.config.write(|w| w.address0().enabled()); |
| 139 | if let Some(address1) = config.address1 { | 139 | if let Some(address1) = config.address1 { |
| 140 | r.address[1].write(|w| unsafe { w.address().bits(address1) }); | 140 | r.address[1].write(|w| unsafe { w.address().bits(address1) }); |
| 141 | r.config.modify(|_r, w| w.address1().enabled()); | 141 | r.config.modify(|_r, w| w.address1().enabled()); |
| @@ -248,6 +248,11 @@ impl<'d, T: Instance> Twis<'d, T> { | |||
| 248 | r.address[r.match_.read().bits() as usize].read().address().bits() | 248 | r.address[r.match_.read().bits() as usize].read().address().bits() |
| 249 | } | 249 | } |
| 250 | 250 | ||
| 251 | /// Returns the index of the address matched in the latest command. | ||
| 252 | pub fn address_match_index(&self) -> usize { | ||
| 253 | T::regs().match_.read().bits() as _ | ||
| 254 | } | ||
| 255 | |||
| 251 | /// Wait for read, write, stop or error | 256 | /// Wait for read, write, stop or error |
| 252 | fn blocking_listen_wait(&mut self) -> Result<Status, Error> { | 257 | fn blocking_listen_wait(&mut self) -> Result<Status, Error> { |
| 253 | let r = T::regs(); | 258 | let r = T::regs(); |
| @@ -588,10 +593,11 @@ impl<'d, T: Instance> Twis<'d, T> { | |||
| 588 | Ok(()) | 593 | Ok(()) |
| 589 | } | 594 | } |
| 590 | 595 | ||
| 591 | /// Listen for commands from an I2C master. | 596 | /// Wait for commands from an I2C master. |
| 592 | /// | 597 | /// `buffer` is provided in case master does a 'write' and is unused for 'read'. |
| 593 | /// The buffer must have a length of at most 255 bytes on the nRF52832 | 598 | /// The buffer must have a length of at most 255 bytes on the nRF52832 |
| 594 | /// and at most 65535 bytes on the nRF52840. | 599 | /// and at most 65535 bytes on the nRF52840. |
| 600 | /// To know which one of the addresses were matched, call `address_match` or `address_match_index` | ||
| 595 | pub fn blocking_listen(&mut self, buffer: &mut [u8]) -> Result<Command, Error> { | 601 | pub fn blocking_listen(&mut self, buffer: &mut [u8]) -> Result<Command, Error> { |
| 596 | self.setup_listen(buffer, false)?; | 602 | self.setup_listen(buffer, false)?; |
| 597 | let status = self.blocking_listen_wait()?; | 603 | let status = self.blocking_listen_wait()?; |
| @@ -620,10 +626,11 @@ impl<'d, T: Instance> Twis<'d, T> { | |||
| 620 | 626 | ||
| 621 | // =========================================== | 627 | // =========================================== |
| 622 | 628 | ||
| 623 | /// Listen for commands from an I2C master with timeout. | 629 | /// Wait for commands from an I2C master, with timeout. |
| 624 | /// | 630 | /// `buffer` is provided in case master does a 'write' and is unused for 'read'. |
| 625 | /// The buffer must have a length of at most 255 bytes on the nRF52832 | 631 | /// The buffer must have a length of at most 255 bytes on the nRF52832 |
| 626 | /// and at most 65535 bytes on the nRF52840. | 632 | /// and at most 65535 bytes on the nRF52840. |
| 633 | /// To know which one of the addresses were matched, call `address_match` or `address_match_index` | ||
| 627 | #[cfg(feature = "time")] | 634 | #[cfg(feature = "time")] |
| 628 | pub fn blocking_listen_timeout(&mut self, buffer: &mut [u8], timeout: Duration) -> Result<Command, Error> { | 635 | pub fn blocking_listen_timeout(&mut self, buffer: &mut [u8], timeout: Duration) -> Result<Command, Error> { |
| 629 | self.setup_listen(buffer, false)?; | 636 | self.setup_listen(buffer, false)?; |
| @@ -654,10 +661,11 @@ impl<'d, T: Instance> Twis<'d, T> { | |||
| 654 | 661 | ||
| 655 | // =========================================== | 662 | // =========================================== |
| 656 | 663 | ||
| 657 | /// Listen asynchronously for commands from an I2C master. | 664 | /// Wait asynchronously for commands from an I2C master. |
| 658 | /// | 665 | /// `buffer` is provided in case master does a 'write' and is unused for 'read'. |
| 659 | /// The buffer must have a length of at most 255 bytes on the nRF52832 | 666 | /// The buffer must have a length of at most 255 bytes on the nRF52832 |
| 660 | /// and at most 65535 bytes on the nRF52840. | 667 | /// and at most 65535 bytes on the nRF52840. |
| 668 | /// To know which one of the addresses were matched, call `address_match` or `address_match_index` | ||
| 661 | pub async fn listen(&mut self, buffer: &mut [u8]) -> Result<Command, Error> { | 669 | pub async fn listen(&mut self, buffer: &mut [u8]) -> Result<Command, Error> { |
| 662 | self.setup_listen(buffer, true)?; | 670 | self.setup_listen(buffer, true)?; |
| 663 | let status = self.async_listen_wait().await?; | 671 | let status = self.async_listen_wait().await?; |
