Skip to content

Commit ae9fdd0

Browse files
committed
add iterator based Write traits
1 parent 4b6b9ce commit ae9fdd0

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

src/blocking/i2c.rs

+38
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,22 @@ pub trait Write {
5050
fn write(&mut self, addr: u8, bytes: &[u8]) -> Result<(), Self::Error>;
5151
}
5252

53+
/// Blocking write (iterator version)
54+
#[cfg(feature = "unproven")]
55+
pub trait WriteIter {
56+
/// Error type
57+
type Error;
58+
59+
/// Sends bytes to slave with address `addr`
60+
///
61+
/// # I2C Events (contract)
62+
///
63+
/// Same as `Write`
64+
fn write<B>(&mut self, addr: u8, bytes: B) -> Result<(), Self::Error>
65+
where
66+
B: IntoIterator<Item = u8>;
67+
}
68+
5369
/// Blocking write + read
5470
pub trait WriteRead {
5571
/// Error type
@@ -84,3 +100,25 @@ pub trait WriteRead {
84100
buffer: &mut [u8],
85101
) -> Result<(), Self::Error>;
86102
}
103+
104+
/// Blocking write (iterator version) + read
105+
#[cfg(feature = "unproven")]
106+
pub trait WriteIterRead {
107+
/// Error type
108+
type Error;
109+
110+
/// Sends bytes to slave with address `addr` and then reads enough bytes to fill `buffer` *in a
111+
/// single transaction*
112+
///
113+
/// # I2C Events (contract)
114+
///
115+
/// Same as the `WriteRead` trait
116+
fn write_iter_read<B>(
117+
&mut self,
118+
address: u8,
119+
bytes: B,
120+
buffer: &mut [u8],
121+
) -> Result<(), Self::Error>
122+
where
123+
B: IntoIterator<Item = u8>;
124+
}

src/blocking/spi.rs

+12
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ pub trait Write<W> {
1818
fn write(&mut self, words: &[W]) -> Result<(), Self::Error>;
1919
}
2020

21+
/// Blocking write (iterator version)
22+
#[cfg(feature = "unproven")]
23+
pub trait WriteIter<W> {
24+
/// Error type
25+
type Error;
26+
27+
/// Sends `words` to the slave, ignoring all the incoming words
28+
fn write_iter<WI>(&mut self, words: WI) -> Result<(), Self::Error>
29+
where
30+
WI: IntoIterator<Item = W>;
31+
}
32+
2133
/// Blocking transfer
2234
pub mod transfer {
2335
/// Default implementation of `blocking::spi::Transfer<W>` for implementers of

0 commit comments

Comments
 (0)