AS1115 driver
Driver for ams AS1115 LED Driver IC. Many thanks to @blemasle's existing AS1115 Arduino library, which I used as a reference implementation.
Features:
- Using embedded-hal v1.0 traits for maximum compatibility with embedded platforms
- Generic numeric functions using num-traits for displaying decimal, hexadecimal and floating-point values
- Support for displaying ASCII characters and custom segment data
- Also supports hardware's global and individual brightness comtrol, self-test functionality, and keyscan input
- Example for Arduino Uno, based on avr-hal
Install
To install this driver in your project add the following line to your Cargo.toml's dependencies table:
= "0.1.0"
For projects needing float support (increases binary size, avoid using on MCUs without native float support):
= { = "0.1.0", = ["display_float_value"] }
How to Use
The AS1115 uses I2C for communication and requires access to an I2C bus that implements the embedded_hal::i2c::I2c trait. This allows the driver to work with any HAL that provides I2C functionality.
use AS1115;
const NUM_DIGITS: u8 = 4; // AS1115 supports 1-8 seven-segment displays
const INTENSITY: u8 = 3; // global brightness [0-15]
let mut as1115: = AS1115new;
as1115.init.unwrap;
as1115.display_value.unwrap;
as1115.display_hex_value.unwrap;
as1115.display_ascii.unwrap;
// Requires "display_float_value" feature
as1115.display_float_value.unwrap;
Or to specify an address using the self-addressing feature (also needs pins wired correctly):
use AS1115;
const NUM_DIGITS: u8 = 4;
const INTENSITY: u8 = 2;
const I2C_ADDR: u8 = 0x01;
let mut as1115: = AS1115new_with_addr;
as1115.init.unwrap;
as1115.display_value.unwrap;
as1115.display_hex_value.unwrap;
// Requires "display_float_value" feature
as1115.display_float_value.unwrap;
TODO
- More display configuration options, e.g. enabling leading zeros for values, showing float special values, etc.
- Handle edge cases better for NUM_DIGITS=1
- More complete set of tests
- Implement rest of hardware self-testing functionality