[−][src]Crate stmpe1600
Platform-agnostic driver for the STMPE1600 I²C I/O expander.
The STMPE1600 is a device that provide 16 GPIO pins, which are configurable through software as either floating input or push-pull output. The pins can also be configured to use interrupts, so that when they are triggered, they send a signal (of a configurable polarity) through the interrupt output pin.
This driver is intended to work on any embedded platform, by using the embedded-hal
library.
This works by using the I²C traits of embedded-hal, which allows for a specific HAL (hardware abstraction layer) to provide its own interface
to allow using the specific implentation of I²C necessary to work on a specific device.
Driver construction
To construct the driver, you will need to use the Stmpe1600Builder
struct.
For more information on what configuration options can be changed, view the Stmpe1600Builder
documentation.
let i2c = /* construct something implementing embedded_hal::blocking::i2c::{Read, Write} */; let stmpe1600 = Stmpe1600Builder::new(i2c).build()?;
Accessing I/O
To read or write individual pins, use the get()
and set()
functions respectively. To read or write all the pins at once, use the get_all()
and
set_all()
functions instead.
Examples
Connecting to a device with a custom I²C address
use linux_embedded_hal::I2cdev; use stmpe1600::Stmpe1600Builder; let dev = I2cdev::new("/dev/i2c-1").unwrap(); let stmpe1600 = Stmpe1600Builder::new(dev) .address(0x43) .build() .expect("Could not initialise STMPE1600 driver");
Setting all the pins to output mode
use linux_embedded_hal::I2cdev; use stmpe1600::{PinMode, Stmpe1600Builder}; let dev = I2cdev::new("/dev/i2c-1").unwrap(); let stmpe1600 = Stmpe1600Builder::new(dev) .pins(0..16, PinMode::Output) .build() .expect("Could not initialise STMPE1600 driver");
Read and write individual pins
use linux_embedded_hal::I2cdev; use stmpe1600::{PinMode, Stmpe1600Builder}; let dev = I2cdev::new("/dev/i2c-1").unwrap(); let stmpe1600 = Stmpe1600Builder::new(dev) .pin(1, PinMode::Output) .build() .expect("Could not initialise STMPE1600 driver"); // Get the status of pin 0 let pin_status = stmpe1600.get(0)?; // Set the status of pin 1 to the status of pin 0 stmpe1600.set(1, pin_status);
Read and write multiple pins
use linux_embedded_hal::I2cdev; use stmpe1600::{PinMode, Stmpe1600Builder}; let dev = I2cdev::new("/dev/i2c-1").unwrap(); let stmpe1600 = Stmpe1600Builder::new(dev) .pins(2..=3, PinMode::Output) .build() .expect("Could not initialise STMPE1600 driver"); // Get the status of all the pins let pins = stmpe1600.get_all()?; // Set the status of pin 0 -> pin 2, and the status of pin 1 -> pin 3 stmpe1600.set_all((pins & 0b11) << 2);
Structs
Stmpe1600Builder | A builder that allows for configuring all the various options available to edit on the STMPE1600. |
Stmpe1600 | A struct representing the STMPE1600 device driver. |
Enums
Error | The different types of errors that can occur while interacting with the STMPE1600. |
InterruptPolarity | Tells the STMPE1600 what value the interrupt output pin should be set to, when an interrupt is triggered. |
PinMode | The types that the pins on the STMPE1600 may be configured as. |
Constants
DEFAULT_ADDRESS | The default I²C address for the STMPE1600. |