2 releases
Uses old Rust 2015
0.1.1 | Jul 20, 2017 |
---|---|
0.1.0 | Jul 20, 2017 |
#1810 in Hardware support
25KB
617 lines
Overview
Sometimes it's a pain to get the kernel modules loaded for SPIDev on Raspberry Pi.
Sometimes you just need a quick way to access SPI devices.
This is a library for accessing SPI devices quickly, but with little regard to playing nice with other processes/peripherals. The access to the SPI peripheral is mmap()'d, without any provosion for mutual exclusion of the peripheral.
Initializiation will update GPIO registers for MUXing the pins to SPI functions. So don't use this with anything that uses the Linux GPIO drivers on the same pins as the SPI pins.
Interrupts are not implemented.
lib.rs
:
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();
}
Dependencies
~49KB