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`.
This commit is contained in:
Wilfried Chauveau 2021-10-29 12:34:49 +01:00
parent 7729091b39
commit 4d75035098
No known key found for this signature in database
GPG key ID: 0BC4C0B2B0879D6A

View file

@ -171,3 +171,22 @@ pub trait I2c<A: AddressMode = SevenBitAddress> {
buffer: &'a mut [u8], buffer: &'a mut [u8],
) -> Self::WriteReadFuture<'a>; ) -> Self::WriteReadFuture<'a>;
} }
pub trait WriteIter<A: AddressMode = SevenBitAddress> {
/// Error type
type Error;
type WriteIterFuture<'a, U>: Future<Output = Result<(), Self::Error>> + '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<Item = u8> + 'a;
}