tca9535

Crates.iotca9535
lib.rstca9535
version0.1.0
sourcesrc
created_at2020-06-02 21:02:07.918261
updated_at2020-06-02 21:02:07.918261
descriptionembedded-hal driver for the TCA9535 port expander
homepage
repositoryhttps://gitlab.com/berkowski/tca9535-rs
max_upload_size
id249420
size13,513
Zac Berkowitz (berkowski)

documentation

README

TCA9535 I/O Expander embedded-hal i2c driver

From the datasheet:

The TCA9535is a 24-pin device that provides 16 bits of general purpose parallel input and output (I/O) expansion for the two-line bidirectional I2C bus or (SMBus) protocol. The device can operate with a power supply voltage ranging from 1.65 V to 5.5 V.

Usage

Include the library as a dependency in your Cargo.toml

[dependencies.tca9535] version = "0.1"

Use embedded-hal implementation to get the i2c bus for the chip then create the handle.

use tca9535::{Tca9535, Address, Port};

// Obtain an i2c bus using embedded-hal
// let mut i2c = ...;

// Note that the handle does *not* capture the i2c bus
// object and that the i2c bus object must be supplied for each method call.
// This slight inconvenience allows sharing the i2c bus between peripherals.
let gpio = Tca9535::new(&i2c, Address::ADDR_0x20);

// Set all outputs low
gpio.clear_outputs(&mut i2c)?;

// Set port P01 and P05 as inputs and the rest as outputs.
gpio.write_config(&mut i2c, Port::P01 | Port::P05)?;

// Read pin input logic levels
let inputs = gpio.read_inputs(&mut i2c)?;

// Do something if port P01 is high:
if inputs & Port::P01 {
    // ...
}
Commit count: 7

cargo fmt