Skip to content

Commit bcaa268

Browse files
committed
Add iterator version of transactional interface
1 parent 63034e3 commit bcaa268

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
@@ -164,6 +164,31 @@ pub trait Transactional {
164164
) -> Result<(), Self::Error>;
165165
}
166166

167+
/// Transactional I2C interface (iterator version).
168+
///
169+
/// This allows combining operation within an I2C transaction.
170+
pub trait TransactionalIter {
171+
/// Error type
172+
type Error;
173+
174+
/// Execute the provided operations on the I2C bus (iterator version).
175+
///
176+
/// Transaction contract:
177+
/// - Before executing the first operation an ST is sent automatically. This is followed by SAD+R/W as appropriate.
178+
/// - Data from adjacent operations of the same type are sent after each other without an SP or SR.
179+
/// - Between adjacent operations of a different type an SR and SAD+R/W is sent.
180+
/// - After executing the last operation an SP is sent automatically.
181+
/// - If the last operation is a `Read` the master does not send an acknowledge for the last byte.
182+
///
183+
/// - `ST` = start condition
184+
/// - `SAD+R/W` = slave address followed by bit 1 to indicate reading or 0 to indicate writing
185+
/// - `SR` = repeated start condition
186+
/// - `SP` = stop condition
187+
fn try_exec_iter<'a, O>(&mut self, address: u8, operations: O) -> Result<(), Self::Error>
188+
where
189+
O: IntoIterator<Item = Operation<'a>>;
190+
}
191+
167192
/// Default implementation of `blocking::i2c::Write`, `blocking::i2c::Read` and
168193
/// `blocking::i2c::WriteRead` traits for `blocking::i2c::Transactional` implementers.
169194
pub mod transactional {

0 commit comments

Comments
 (0)