Skip to content

Add transactional traits for SPI and I2C #178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/blocking/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,26 @@ pub trait WriteIterRead {
where
B: IntoIterator<Item = u8>;
}

/// Actions for transactional I2C trait
///
/// This allows composition of I2C operations into a single bus transaction
#[cfg(feature = "unproven")]
#[derive(Debug, PartialEq)]
pub enum Actions<'a> {
/// Read data into the provided buffer
Read(&'a mut [u8]),
/// Write data from the provided buffer
Write(&'a [u8]),
}

/// Transactional trait allows multiple actions to be executed
/// as part of a single I2C transaction
#[cfg(feature = "unproven")]
pub trait Transactional {
/// Associated error type
type Error;

/// Execute the provided actions against the provided I2C address
fn exec(&mut self, addr: u8, actions: &[Actions]) -> Result<(), Self::Error>;
}
23 changes: 23 additions & 0 deletions src/blocking/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,26 @@ pub mod write_iter {
}
}
}

/// Actions for transactional SPI trait
///
/// This allows composition of SPI operations into a single bus transaction
#[cfg(feature = "unproven")]
#[derive(Debug, PartialEq)]
pub enum Actions<'a> {
/// Write data from the provided buffer, discarding read data
Write(&'a [u8]),
/// Transfer data from the provided buffer, overwriting the output buffer with read data
Transfer(&'a mut [u8]),
}

/// Transactional trait allows multiple actions to be executed
/// as part of a single SPI transaction
#[cfg(feature = "unproven")]
pub trait Transactional {
/// Associated error type
type Error;

/// Execute the provided actions
fn exec(&mut self, actions: &[Actions]) -> Result<(), Self::Error>;
}