-
-
Save little-arhat/5d2d154d6792959813a2bac2fa8afc04 to your computer and use it in GitHub Desktop.
ehal spi transfer;; expanded
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Blocking transfer | |
pub mod transfer { | |
/// Default implementation of `blocking::spi::Transfer<W>` for implementers of | |
/// `spi::FullDuplex<W>` | |
pub trait Default<W>: ::spi::FullDuplex<W> { } | |
impl <W, S> ::blocking::spi::Transfer<W> for S where | |
S: Default<W>, W: Clone { | |
type | |
Error | |
= | |
S::Error; | |
fn transfer<'w>(&mut self, words: &'w mut [W]) | |
-> Result<&'w [W], S::Error> { | |
for word in words.iter_mut() { | |
loop { | |
#[allow(unreachable_patterns)] | |
match self.send(word.clone()) { | |
Err(::nb::Error::Other(e)) => { | |
#[allow(unreachable_code)] | |
break Err(e) | |
} | |
Err(::nb::Error::WouldBlock) => { } | |
Ok(x) => break Ok(x) , | |
} | |
}?; | |
*word = | |
loop { | |
#[allow(unreachable_patterns)] | |
match self.read() { | |
Err(::nb::Error::Other(e)) => { | |
#[allow(unreachable_code)] | |
break Err(e) | |
} | |
Err(::nb::Error::WouldBlock) => { } | |
Ok(x) => break Ok(x) , | |
} | |
}?; | |
} | |
Ok(words) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment