Skip to content

Commit

Permalink
blocking SPI API
Browse files Browse the repository at this point in the history
  • Loading branch information
japaric committed Nov 27, 2017
1 parent 43628a2 commit d47c618
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/blocking/mod.rs
@@ -0,0 +1,3 @@
//! Blocking API

pub mod spi;
16 changes: 16 additions & 0 deletions src/blocking/spi.rs
@@ -0,0 +1,16 @@
//! Blocking SPI API

use Spi;

/// Transfers bytes to the slave, returns the bytes received from the slave
pub fn transfer<'a, S>(spi: &mut S, bytes: &'a mut [u8]) -> Result<&'a [u8], S::Error>
where
S: Spi<u8>,
{
for byte in bytes.iter_mut() {
block!(spi.send(*byte))?;
*byte = block!(spi.read())?;
}

Ok(bytes)
}
2 changes: 2 additions & 0 deletions src/lib.rs
Expand Up @@ -609,8 +609,10 @@
#![feature(never_type)]
#![no_std]

#[macro_use]
extern crate nb;

pub mod blocking;
pub mod prelude;
pub mod serial;

Expand Down

0 comments on commit d47c618

Please sign in to comment.