Crates.io | aw9523b |
lib.rs | aw9523b |
version | 0.1.0 |
source | src |
created_at | 2024-08-13 05:14:54.754835 |
updated_at | 2024-08-13 05:14:54.754835 |
description | A general driver for AW9523B which is 16 bit gpio explander & led driver |
homepage | https://github.com/xpulabs/aw9523b-rs |
repository | https://github.com/xpulabs/aw9523b-rs |
max_upload_size | |
id | 1335493 |
size | 38,029 |
This is a platform agnostic Rust driver for the aw9523b in handheld
and portable equipment using the embedded-hal
traits.
This driver allows you to:
The rust driver is tested with AnalogLamb CiC AW9523B Breakout. You can buy the breakout from AnalogLamb .
AW9523B is a 16 multi-function LED driver and GPIO controller. Any of the 16 I/O ports can be configured as LED drive mode or GPIO mode.Furthermore, any GPIO can be configured as an input or an output independently.
After power on, all the 16 I/O ports are configured as GPIO output as default, which default states areset according to the I2C device address selectioninputs, AD0 and AD1. All I/O ports configured as inputs are continuously monitored for state changes. State changes are indicated by the INTN output. When AW9523B reads GPIO state through the I2C interface, the interrupt is cleared. Interrupt has 8μs deglitch.
When the I/O ports are configured as LED drive mode, AW9523B can set the current of LED drive between 0~IMAX by I2C interface, which is divided by 256 steps linear dimming. The default maximum current (IMAX) is 37mA, and IMAX can be changed in GCR register.
To use this driver, import this crate and an embedded_hal
implementation,
then instantiate the device.
Please find additional examples using hardware in CIC AW9523B Breakout Wiki - CIC AW9523B Breakout
use linux_embedded_hal::I2cdev;
use aw9523b::Aw9523b;
fn main() {
let dev = I2cdev::new("/dev/i2c-3").unwrap();
let mut ic = Aw9523b::new(dev, 0x58);
let id = ic.id().unwrap();
println!("aw9523b id = {:02x}", id);
std::thread::sleep(std::time::Duration::from_secs(1));
ic.set_io_direction(aw9523b::Pin::P00, aw9523b::Dir::INPUT).unwrap();
loop {
while !ic.pin_is_low(aw9523b::Pin::P00).unwrap() {
println!("P00 is high");
std::thread::sleep(std::time::Duration::from_millis(200));
}
println!("P00 is low");
}
}
For questions, issues, feature requests, and other changes, please file an issue in wiki FAQ.
This crate is guaranteed to compile on stable Rust 1.62 and up. It might compile with older versions but that may change in any new patch release.
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.