aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-10-30 14:35:26 +0000
committerGitHub <[email protected]>2021-10-30 14:35:26 +0000
commit3dcf899babff5b735b1f1a5a99a9005ce06f517f (patch)
treecfa2b3df17cd88e39fd0df589a18c46b1d41d557
parentdfccb84fcbb9ab55c3d0f89d99d2049376bff901 (diff)
parent2d475b80d97af955fcd058a19de71276502e8e35 (diff)
Merge #462
462: Add the `embassy_traits::i2c::WriteIter` trait r=Dirbaio a=ithinuel 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`. Co-authored-by: Wilfried Chauveau <[email protected]>
-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..0fdf50a12 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, V>: Future<Output = Result<(), Self::Error>> + 'a
180 where
181 V: 'a + IntoIterator<Item = u8>,
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}