Expand description
Linux backends: the kernel’s I2C, SPI, and GPIO character devices as the bus traits.
On a Raspberry Pi or any Linux single-board computer the buses are files:
/dev/i2c-1, /dev/spidev0.0, /dev/gpiochip0. These functions open them as the
traits every driver is written against, through linux-embedded-hal, so a driver
moves from a scripted test to a gateway by being handed a different bus and
nothing else. The kernel drivers have to be enabled first: on a Raspberry Pi that
is raspi-config, or dtparam=i2c_arm=on and dtparam=spi=on in config.txt.
A DS18B20 is the one part that should not be bit-banged from a Linux process,
because user space cannot hold the microsecond slot timing the bus needs. Enable
the kernel’s own w1-gpio driver instead (dtoverlay=w1-gpio) and read the
thermometer through the sysfs file it exposes, which the DS18B20 driver in
pamoja-sensors does.
§Examples
use pamoja_hal::i2c::I2c;
use pamoja_hal::linux;
// The BME280 on the Raspberry Pi's user I2C bus answers its chip id at 0xD0.
const BME280: u8 = 0x76;
let mut bus = linux::i2c("/dev/i2c-1")?;
let mut id = [0u8; 1];
bus.write_read(BME280, &[0xD0], &mut id)?;
println!("chip id 0x{:02X}", id[0]);Re-exports§
pub use linux_embedded_hal::gpio_cdev;pub use linux_embedded_hal::i2cdev;pub use linux_embedded_hal::spidev;
Structs§
- CdevPin
- Newtype around
gpio_cdev::LineHandlethat implements theembedded-haltraits - Cdev
PinError - Error type wrapping gpio_cdev::errors::Error to implement embedded_hal::digital::Error
- Delay
- Empty struct that provides delay functionality on top of
thread::sleep, andtokio::time::sleepif theasync-tokiofeature is enabled. - I2CError
- Error type wrapping LinuxI2CError to implement embedded_hal::i2c::ErrorKind
- I2cdev
- Newtype around
i2cdev::linux::LinuxI2CDevicethat implements theembedded-haltraits - SPIError
- Error type wrapping io::Error to implement embedded_hal::spi::ErrorKind
- Spidev
Bus - Spidev wrapper providing the embedded-hal
SpiBustrait. - Spidev
Device - Spidev wrapper providing the embedded-hal
SpiDevicetrait.
Enums§
- Open
Error - Why a bus or a line could not be opened.