config write, docs, add address_match_index

This commit is contained in:
Henrik Alsér 2022-11-22 01:57:00 +01:00
parent 43c1afb6a6
commit 633ffe46ae
2 changed files with 15 additions and 13 deletions

View File

@ -268,11 +268,5 @@ pub fn init(config: config::Config) -> Peripherals {
#[cfg(feature = "_time-driver")] #[cfg(feature = "_time-driver")]
time_driver::init(config.time_interrupt_priority); time_driver::init(config.time_interrupt_priority);
// Disable UARTE (enabled by default for some reason)
#[cfg(feature = "_nrf9160")]
unsafe {
(*pac::UARTE0::ptr()).enable.write(|w| w.enable().disabled());
(*pac::UARTE1::ptr()).enable.write(|w| w.enable().disabled());
}
peripherals peripherals
} }

View File

@ -135,7 +135,7 @@ impl<'d, T: Instance> Twis<'d, T> {
// Set address // Set address
r.address[0].write(|w| unsafe { w.address().bits(config.address0) }); r.address[0].write(|w| unsafe { w.address().bits(config.address0) });
r.config.modify(|_r, w| w.address0().enabled()); r.config.write(|w| w.address0().enabled());
if let Some(address1) = config.address1 { if let Some(address1) = config.address1 {
r.address[1].write(|w| unsafe { w.address().bits(address1) }); r.address[1].write(|w| unsafe { w.address().bits(address1) });
r.config.modify(|_r, w| w.address1().enabled()); r.config.modify(|_r, w| w.address1().enabled());
@ -248,6 +248,11 @@ impl<'d, T: Instance> Twis<'d, T> {
r.address[r.match_.read().bits() as usize].read().address().bits() r.address[r.match_.read().bits() as usize].read().address().bits()
} }
/// Returns the index of the address matched in the latest command.
pub fn address_match_index(&self) -> usize {
T::regs().match_.read().bits() as _
}
/// Wait for read, write, stop or error /// Wait for read, write, stop or error
fn blocking_listen_wait(&mut self) -> Result<Status, Error> { fn blocking_listen_wait(&mut self) -> Result<Status, Error> {
let r = T::regs(); let r = T::regs();
@ -588,10 +593,11 @@ impl<'d, T: Instance> Twis<'d, T> {
Ok(()) Ok(())
} }
/// Listen for commands from an I2C master. /// Wait for commands from an I2C master.
/// /// `buffer` is provided in case master does a 'write' and is unused for 'read'.
/// The buffer must have a length of at most 255 bytes on the nRF52832 /// The buffer must have a length of at most 255 bytes on the nRF52832
/// and at most 65535 bytes on the nRF52840. /// and at most 65535 bytes on the nRF52840.
/// To know which one of the addresses were matched, call `address_match` or `address_match_index`
pub fn blocking_listen(&mut self, buffer: &mut [u8]) -> Result<Command, Error> { pub fn blocking_listen(&mut self, buffer: &mut [u8]) -> Result<Command, Error> {
self.setup_listen(buffer, false)?; self.setup_listen(buffer, false)?;
let status = self.blocking_listen_wait()?; let status = self.blocking_listen_wait()?;
@ -620,10 +626,11 @@ impl<'d, T: Instance> Twis<'d, T> {
// =========================================== // ===========================================
/// Listen for commands from an I2C master with timeout. /// Wait for commands from an I2C master, with timeout.
/// /// `buffer` is provided in case master does a 'write' and is unused for 'read'.
/// The buffer must have a length of at most 255 bytes on the nRF52832 /// The buffer must have a length of at most 255 bytes on the nRF52832
/// and at most 65535 bytes on the nRF52840. /// and at most 65535 bytes on the nRF52840.
/// To know which one of the addresses were matched, call `address_match` or `address_match_index`
#[cfg(feature = "time")] #[cfg(feature = "time")]
pub fn blocking_listen_timeout(&mut self, buffer: &mut [u8], timeout: Duration) -> Result<Command, Error> { pub fn blocking_listen_timeout(&mut self, buffer: &mut [u8], timeout: Duration) -> Result<Command, Error> {
self.setup_listen(buffer, false)?; self.setup_listen(buffer, false)?;
@ -654,10 +661,11 @@ impl<'d, T: Instance> Twis<'d, T> {
// =========================================== // ===========================================
/// Listen asynchronously for commands from an I2C master. /// Wait asynchronously for commands from an I2C master.
/// /// `buffer` is provided in case master does a 'write' and is unused for 'read'.
/// The buffer must have a length of at most 255 bytes on the nRF52832 /// The buffer must have a length of at most 255 bytes on the nRF52832
/// and at most 65535 bytes on the nRF52840. /// and at most 65535 bytes on the nRF52840.
/// To know which one of the addresses were matched, call `address_match` or `address_match_index`
pub async fn listen(&mut self, buffer: &mut [u8]) -> Result<Command, Error> { pub async fn listen(&mut self, buffer: &mut [u8]) -> Result<Command, Error> {
self.setup_listen(buffer, true)?; self.setup_listen(buffer, true)?;
let status = self.async_listen_wait().await?; let status = self.async_listen_wait().await?;