Skip to content

Commit cfa13de

Browse files
committed
Add iterator version of transactional interface
1 parent 6b562e0 commit cfa13de

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/blocking/i2c.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,31 @@ pub trait Transactional {
271271
) -> Result<(), Self::Error>;
272272
}
273273

274+
/// Transactional I2C interface (iterator version).
275+
///
276+
/// This allows combining operation within an I2C transaction.
277+
pub trait TransactionalIter {
278+
/// Error type
279+
type Error;
280+
281+
/// Execute the provided operations on the I2C bus (iterator version).
282+
///
283+
/// Transaction contract:
284+
/// - Before executing the first operation an ST is sent automatically. This is followed by SAD+R/W as appropriate.
285+
/// - Data from adjacent operations of the same type are sent after each other without an SP or SR.
286+
/// - Between adjacent operations of a different type an SR and SAD+R/W is sent.
287+
/// - After executing the last operation an SP is sent automatically.
288+
/// - If the last operation is a `Read` the master does not send an acknowledge for the last byte.
289+
///
290+
/// - `ST` = start condition
291+
/// - `SAD+R/W` = slave address followed by bit 1 to indicate reading or 0 to indicate writing
292+
/// - `SR` = repeated start condition
293+
/// - `SP` = stop condition
294+
fn try_exec_iter<'a, O>(&mut self, address: u8, operations: O) -> Result<(), Self::Error>
295+
where
296+
O: IntoIterator<Item = Operation<'a>>;
297+
}
298+
274299
/// Default implementation of `blocking::i2c::Write`, `blocking::i2c::Read` and
275300
/// `blocking::i2c::WriteRead` traits for `blocking::i2c::Transactional` implementers.
276301
pub mod transactional {

0 commit comments

Comments
 (0)