Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement WriteIter and WriteIterRead #703

Merged
merged 1 commit into from
Oct 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading