From 4d75035098e813e667a21bfcd0d3321794e53d84 Mon Sep 17 00:00:00 2001 From: Wilfried Chauveau Date: Fri, 29 Oct 2021 12:34:49 +0100 Subject: [PATCH] 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`. --- embassy-traits/src/i2c.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/embassy-traits/src/i2c.rs b/embassy-traits/src/i2c.rs index e426a00b..7e2b9a77 100644 --- a/embassy-traits/src/i2c.rs +++ b/embassy-traits/src/i2c.rs @@ -171,3 +171,22 @@ pub trait I2c { buffer: &'a mut [u8], ) -> Self::WriteReadFuture<'a>; } + +pub trait WriteIter { + /// Error type + type Error; + + type WriteIterFuture<'a, U>: Future> + 'a + where + U: 'a, + Self: 'a; + + /// Sends bytes to slave with address `address` + /// + /// # I2C Events (contract) + /// + /// Same as `I2c::write` + fn write_iter<'a, U>(&'a mut self, address: A, bytes: U) -> Self::WriteIterFuture<'a, U> + where + U: IntoIterator + 'a; +}