From f073bdfe43a243a2f5846c27c6a9af09a9bbe702 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Wed, 30 Jun 2021 23:43:22 +0200 Subject: [PATCH] rp/spi: add Transfer --- embassy-rp/src/spi.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) 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::*;