Crate bcm2709_spi [] [src]

rust-bcm-2709-spi

Low-performance SPI interface to BCM2709 hardware peripherals via mmap(...) and direct memory I/O.

For use when you don't/can't load a specific driver on Raspberry Pi. It is probably better to use SPIDev kernel module. But this may help for some testing in a pinch.

Usage

extern crate bcm2709_spi;
use bcm2709_spi::{gpio, spi, DirectMemory};
 
pub fn main() {
  let mem = match DirectMemory::get() {
    Err(x) => { println!("Failed: {}", x); return; },
    Ok(x) => x
  }
   
  let spi = match mem.spi() {
    Err(x) => { println!("Couldn't create SPI: {}", x); return; },
    Ok(x)  => x
  }
   
  spi.set_clock( 32 );   // Recommend above 4; loopback misses bits at clk=4.
   
  spi.start_transaction();
  let byte_read = spi.write_byte( b'A' );   // =65u8 when a loopback wire placed between MISO and MOSI
  spi.stop_transaction();
}

Modules

gpio

Simplified GPIO interface; reads/writes to direct memory. Take care not to conflict with /sys/class/gpio interface.

spi

SPI hardware implementation; borrowed from constructs from Japaric's SVD2Rust MCU rust-code generator

Structs

DirectMemory

Interface for getting structs to map to /dev/mem blocks