mirror of
https://github.com/embassy-rs/embassy.git
synced 2024-11-22 06:42:32 +00:00
rp/spi: add Transfer
This commit is contained in:
parent
3059923b4f
commit
f073bdfe43
@ -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) {
|
pub fn flush(&mut self) {
|
||||||
unsafe {
|
unsafe {
|
||||||
let p = self.inner.regs();
|
let p = self.inner.regs();
|
||||||
@ -122,6 +135,14 @@ impl<'d, T: Instance> eh::Write<u8> for Spi<'d, T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'d, T: Instance> eh::Transfer<u8> 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 {
|
mod sealed {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user