Skip to content

Commit

Permalink
Add the WriteIter and WriteIterRead traits
Browse files Browse the repository at this point in the history
Adds wrappers for the two iterator-based traits from embedded-hal.
  • Loading branch information
thejpster authored and Rahix committed Oct 22, 2023
1 parent e87c2a5 commit 402a748
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/proxies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,40 @@ where
}
}

impl<'a, M: crate::BusMutex> i2c::WriteIterRead for I2cProxy<'a, M>
where
M::Bus: i2c::WriteIterRead,
{
type Error = <M::Bus as i2c::WriteIterRead>::Error;

fn write_iter_read<B>(
&mut self,
address: u8,
bytes: B,
buffer: &mut [u8],
) -> Result<(), Self::Error>
where
B: IntoIterator<Item = u8>,
{
self.mutex
.lock(|bus| bus.write_iter_read(address, bytes, buffer))
}
}

impl<'a, M: crate::BusMutex> i2c::WriteIter for I2cProxy<'a, M>
where
M::Bus: i2c::WriteIter,
{
type Error = <M::Bus as i2c::WriteIter>::Error;

fn write<B>(&mut self, address: u8, bytes: B) -> Result<(), Self::Error>
where
B: IntoIterator<Item = u8>,
{
self.mutex.lock(|bus| bus.write(address, bytes))
}
}

// Implementations for the embedded_hal alpha

#[cfg(feature = "eh-alpha")]
Expand Down

0 comments on commit 402a748

Please sign in to comment.