Skip to content

Commit d84543f

Browse files
committed
backport spi::Transactional
1 parent 1ef9f26 commit d84543f

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/blocking/spi.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,24 @@ pub mod write_iter {
104104
}
105105
}
106106
}
107+
108+
/// Operation for transactional SPI trait
109+
///
110+
/// This allows composition of SPI operations into a single bus transaction
111+
#[derive(Debug, PartialEq)]
112+
pub enum Operation<'a, W: 'static> {
113+
/// Write data from the provided buffer, discarding read data
114+
Write(&'a [W]),
115+
/// Write data out while reading data into the provided buffer
116+
Transfer(&'a mut [W]),
117+
}
118+
119+
/// Transactional trait allows multiple actions to be executed
120+
/// as part of a single SPI transaction
121+
pub trait Transactional<W: 'static> {
122+
/// Associated error type
123+
type Error;
124+
125+
/// Execute the provided transactions
126+
fn exec<'a>(&mut self, operations: &mut [Operation<'a, W>]) -> Result<(), Self::Error>;
127+
}

0 commit comments

Comments
 (0)