Skip to content

Commit

Permalink
Implement WriteIter and WriteIterRead
Browse files Browse the repository at this point in the history
Implements the WriteIter and WriteIterRead traits from embedded-hal.
  • Loading branch information
thejpster committed Oct 21, 2023
1 parent c4fbc4b commit 001270f
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion rp2040-hal/src/i2c/controller.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use core::{marker::PhantomData, ops::Deref};
use embedded_hal::blocking::i2c::{Read, Write, WriteRead};
use embedded_hal::blocking::i2c::{Read, Write, WriteIter, WriteIterRead, WriteRead};
use fugit::HertzU32;

#[cfg(feature = "eh1_0_alpha")]
Expand Down Expand Up @@ -335,6 +335,7 @@ impl<T: Deref<Target = Block>, PINS> WriteRead for I2C<T, PINS, Controller> {
self.read_internal(rx, true, true)
}
}

impl<T: Deref<Target = Block>, PINS> Write for I2C<T, PINS, Controller> {
type Error = Error;

Expand All @@ -347,6 +348,33 @@ impl<T: Deref<Target = Block>, PINS> Write for I2C<T, PINS, Controller> {
}
}

impl<T: Deref<Target = Block>, PINS> WriteIter for I2C<T, PINS, Controller> {
type Error = Error;

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

impl<T: Deref<Target = Block>, PINS> WriteIterRead for I2C<T, PINS, Controller> {
type Error = Error;

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

#[cfg(feature = "eh1_0_alpha")]
impl<T: Deref<Target = Block>, PINS> eh1::ErrorType for I2C<T, PINS, Controller> {
type Error = Error;
Expand Down

0 comments on commit 001270f

Please sign in to comment.