Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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>;
}

/// Operation for transactional I2C trait
///
/// This allows composition of I2C operations into a single bus transaction
#[cfg(feature = "unproven")]
#[derive(Debug, PartialEq)]
pub enum Operation<'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<'a>(&mut self, address: u8, operations: &mut[Operation<'a>]) -> 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 {
}
}
}

/// Operation for transactional SPI trait
///
/// This allows composition of SPI operations into a single bus transaction
#[cfg(feature = "unproven")]
#[derive(Debug, PartialEq)]
pub enum Operation<'a, W: 'static> {
/// Write data from the provided buffer, discarding read data
Write(&'a [W]),
/// Write data out while reading data into the provided buffer
WriteRead(&'a mut [W]),
}

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

/// Execute the provided transactions
fn exec<'a>(&mut self, operations: &mut [Operation<'a, W>]) -> Result<(), Self::Error>;
}