Skip to content

Commit 137b473

Browse files
committed
add default impl for spi::WriteIter
1 parent ae9fdd0 commit 137b473

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/blocking/spi.rs

+28
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,31 @@ pub mod write {
7676
}
7777
}
7878
}
79+
80+
/// Blocking write (iterator version)
81+
#[cfg(feature = "unproven")]
82+
pub mod write_iter {
83+
/// Default implementation of `blocking::spi::WriteIter<W>` for implementers of
84+
/// `spi::FullDuplex<W>`
85+
pub trait Default<W>: ::spi::FullDuplex<W> {}
86+
87+
impl<W, S> ::blocking::spi::WriteIter<W> for S
88+
where
89+
S: Default<W>,
90+
W: Clone,
91+
{
92+
type Error = S::Error;
93+
94+
fn write_iter<WI>(&mut self, words: WI) -> Result<(), S::Error>
95+
where
96+
WI: IntoIterator<Item = W>,
97+
{
98+
for word in words.into_iter() {
99+
block!(self.send(word.clone()))?;
100+
block!(self.read())?;
101+
}
102+
103+
Ok(())
104+
}
105+
}
106+
}

0 commit comments

Comments
 (0)