Crate stmpe1600[][src]

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 access the I/O pins, call either Stmpe1600::pin_input, Stmpe1600::pin_output or Stmpe1600::pin_interrupt, which will return a Pin object.

This type implements embedded_hal::digital::v2::InputPin or embedded_hal::digital::v2::OutputPin (depending on the pin’s mode), which means that they can also be passed to any function which takes these types as arguments; this allows these pins to be passed transparently to platform-agnostic drivers easily and efficiently.

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");

Read and write I/O pins

use embedded_hal::digital::v2::{InputPin, OutputPin};
use linux_embedded_hal::I2cdev;
use stmpe1600::Stmpe1600Builder;

let dev = I2cdev::new("/dev/i2c-1").unwrap();
let stmpe1600 = Stmpe1600Builder::new(dev)
	.build()
	.expect("Could not initialise STMPE1600 driver");

let mut input_pin = stmpe1600.pin_input(0);
let mut output_pin = stmpe1600.pin_output(1);

if input_pin.is_high()? {
	output_pin.set_high()?
} else {
	output_pin.set_low()?;
}

Structs

Pin

A single I/O pin on the STMPE1600.

Stmpe1600

A struct representing the STMPE1600 device driver.

Stmpe1600Builder

A builder that allows for configuring all the various options available to edit on the STMPE1600.

Enums

Error

The different types of errors that can occur while interacting with the STMPE1600.

Polarity

Input/Interrupt polarity.

Constants

DEFAULT_ADDRESS

The default I²C address for the STMPE1600.