[][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.

This example is not tested
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 the pin() function, which returns a Pin. This type implements the embedded-hal GPIO traits, InputPin and OutputPin, 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

This example is not tested
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

This example is not tested
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 I/O pins

This example is not tested
use embedded_hal::digital::v2::{InputPin, OutputPin};
use linux_embedded_hal::I2cdev;
use stmpe1600::{PinMode, Stmpe1600Builder};
 
let dev = I2cdev::new("/dev/i2c-1").unwrap();
let stmpe1600 = Stmpe1600Builder::new(dev)
	// The pins default to input, so we don't need to configure pin 0 here
	.pin(1, PinMode::Output)
	.build()
	.expect("Could not initialise STMPE1600 driver");
 
let input_pin = stmpe1600.pin(0);
let output_pin = stmpe1600.pin(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.

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.

Register

The different adresses of the registers on the STMPE1600's I²C bus.

Constants

DEFAULT_ADDRESS

The default I²C address for the STMPE1600.