Giter Club home page Giter Club logo

pca9554-rs's Introduction

PCA9554 I/O Expander embedded-hal i2c driver

This is a shameless copy of a shameless copy of Zac Berkowitz' tca9535-rs library.

WARNING: Due to time constraints, this is not properly tested, although it does work for what I am using it for. This is an invitation to help me test it out and give me a PR when you find problems. :)

The PCA9554 is an 8-bit I/O expander for the two-line bidirectional bus (I2C) is designed for 1.65-V to 5.5-V VCC operation. It provides general-purpose remote I/O expansion for most micro-controller families through the I2C interface (serial clock, SCL, and serial data, SDA, pins).

Usage

Include the library as a dependency in your Cargo.toml

[dependencies.pca9554] version = "0.1"

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

use Pca9554::{Pca9554, 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 = Pca9554::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 {
    // ...
}

pca9554-rs's People

Contributors

arnstein avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.