aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilfried Chauveau <[email protected]>2021-10-29 12:34:49 +0100
committerWilfried Chauveau <[email protected]>2021-10-29 12:34:49 +0100
commit4d75035098e813e667a21bfcd0d3321794e53d84 (patch)
tree4689da093823444097161e52e7a8dc8659fb6808
parent7729091b3959896fcf38727cd492c0ff13f02b68 (diff)
Add the `embassy_traits::i2c::WriteIter` trait
This trait makes the parallel with `embedded_hal::i2c::WriteIter`. It allows to fetch bytes to write from an Iterator rather than requiring an allocation for an array. It is provided as an extra Trait to avoid breaking existing implementations of `embassy_traits::i2c::I2c`.
-rw-r--r--embassy-traits/src/i2c.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/embassy-traits/src/i2c.rs b/embassy-traits/src/i2c.rs
index e426a00b0..7e2b9a773 100644
--- a/embassy-traits/src/i2c.rs
+++ b/embassy-traits/src/i2c.rs
@@ -171,3 +171,22 @@ pub trait I2c<A: AddressMode = SevenBitAddress> {
171 buffer: &'a mut [u8], 171 buffer: &'a mut [u8],
172 ) -> Self::WriteReadFuture<'a>; 172 ) -> Self::WriteReadFuture<'a>;
173} 173}
174
175pub trait WriteIter<A: AddressMode = SevenBitAddress> {
176 /// Error type
177 type Error;
178
179 type WriteIterFuture<'a, U>: Future<Output = Result<(), Self::Error>> + 'a
180 where
181 U: 'a,
182 Self: 'a;
183
184 /// Sends bytes to slave with address `address`
185 ///
186 /// # I2C Events (contract)
187 ///
188 /// Same as `I2c::write`
189 fn write_iter<'a, U>(&'a mut self, address: A, bytes: U) -> Self::WriteIterFuture<'a, U>
190 where
191 U: IntoIterator<Item = u8> + 'a;
192}