diff --git a/embassy-rp/src/spi.rs b/embassy-rp/src/spi.rs index 766f0861..c919672a 100644 --- a/embassy-rp/src/spi.rs +++ b/embassy-rp/src/spi.rs @@ -105,6 +105,19 @@ impl<'d, T: Instance> Spi<'d, T> { } } + pub fn transfer(&mut self, data: &mut [u8]) { + unsafe { + let p = self.inner.regs(); + for b in data { + while !p.sr().read().tnf() {} + p.dr().write(|w| w.set_data(*b as _)); + while !p.sr().read().rne() {} + *b = p.dr().read().data() as u8; + } + self.flush(); + } + } + pub fn flush(&mut self) { unsafe { let p = self.inner.regs(); @@ -122,6 +135,14 @@ impl<'d, T: Instance> eh::Write for Spi<'d, T> { } } +impl<'d, T: Instance> eh::Transfer for Spi<'d, T> { + type Error = core::convert::Infallible; + fn transfer<'w>(&mut self, words: &'w mut [u8]) -> Result<&'w [u8], Self::Error> { + self.transfer(words); + Ok(words) + } +} + mod sealed { use super::*;