diff --git a/src/blocking/i2c.rs b/src/blocking/i2c.rs index 57192cac8..e98ad3816 100644 --- a/src/blocking/i2c.rs +++ b/src/blocking/i2c.rs @@ -127,3 +127,26 @@ pub trait WriteIterRead { where B: IntoIterator; } + +/// 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>; +} diff --git a/src/blocking/spi.rs b/src/blocking/spi.rs index 90dc27afb..83e3e0f8d 100644 --- a/src/blocking/spi.rs +++ b/src/blocking/spi.rs @@ -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 { + /// Associated error type + type Error; + + /// Execute the provided transactions + fn exec<'a>(&mut self, operations: &mut [Operation<'a, W>]) -> Result<(), Self::Error>; +}