Expand description
AW9523 GPIO Expander Driver
A platform-agnostic driver for the AW9523 16-channel LED driver and GPIO expander.
The AW9523 is an I2C-controlled GPIO expander with 16 configurable pins that can operate as digital I/O or constant-current LED drivers. Each pin supports:
- Digital input/output with configurable direction
- Interrupt detection
- 256-step constant current LED driving
- Open-drain or push-pull output modes (port 0)
§Features
no_stdcompatible- Uses
embedded-haltraits for portability - Individual pin control or bulk 16-bit operations
- Configurable interrupt detection per pin
- LED mode with PWM-like current control
- Async support via the
asyncfeature (requiresembedded-hal-async)
§Blocking Example
ⓘ
use aw9523::{Aw9523, PinMode, HIGH};
// Create device with I2C bus and default address
let mut gpio = Aw9523::new(i2c, 0x58);
// Initialize with default configuration
gpio.init().unwrap();
// Configure pin 0 as output and set it high
gpio.pin_mode(0, PinMode::Output).unwrap();
gpio.digital_write(0, HIGH).unwrap();
// Configure pin 8 as input and read it
gpio.pin_mode(8, PinMode::Input).unwrap();
let state = gpio.digital_read(8).unwrap();§Async Example
Enable the async feature in your Cargo.toml:
[dependencies]
aw9523-embedded = { version = "0.1", features = ["async"] }Then use the async API:
ⓘ
use aw9523::{r#async::Aw9523Async, PinMode, HIGH};
async fn example() {
// Create device with async I2C bus
let mut gpio = Aw9523Async::new(i2c, 0x58);
// All methods are async
gpio.init().await.unwrap();
gpio.pin_mode(0, PinMode::Output).await.unwrap();
gpio.digital_write(0, HIGH).await.unwrap();
}Structs§
- Aw9523
- AW9523 driver instance
Enums§
- Aw9523
Error - Errors that can occur when interacting with the AW9523
- PinMode
- Pin mode/direction configuration.
- PinState
- Digital output pin state.
Constants§
- AW9523_
ALL_ PINS - Bitmask for all 16 pins
- AW9523_
LED_ MODE - Pin mode constant for LED/constant-current mode.
Use with
Aw9523::pin_modeto configure a pin for LED driving. - AW9523_
P0_ 0 - Port 0, pin 0 alias for PIN_0. The AW9523 organizes its 16 pins into two ports of 8 pins each, and this is the first pin in port 0.
- AW9523_
P0_ 1 - Port 0, pin 1 alias for PIN_1. This is the second pin in port 0, useful when you need port-based naming conventions.
- AW9523_
P0_ 2 - Port 0, pin 2 alias for PIN_2. This is the third pin in port 0, sharing the same register space as other port 0 pins.
- AW9523_
P0_ 3 - Port 0, pin 3 alias for PIN_3. This is the fourth pin in port 0, part of the lower byte of the 16-bit pin registers.
- AW9523_
P0_ 4 - Port 0, pin 4 alias for PIN_4. The middle pin of port 0, this can be configured for open-drain mode along with other port 0 pins.
- AW9523_
P0_ 5 - Port 0, pin 5 alias for PIN_5. This pin is part of port 0, which supports open-drain output configuration via the GCR register.
- AW9523_
P0_ 6 - Port 0, pin 6 alias for PIN_6. One of the higher-numbered pins in port 0, accessible through the lower-byte registers.
- AW9523_
P0_ 7 - Port 0, pin 7 alias for PIN_7. The last pin in port 0, representing bit 7 of the port 0 register space.
- AW9523_
P1_ 0 - Port 1, pin 0 alias for PIN_8. The first pin in port 1, which always operates in push-pull mode (unlike port 0).
- AW9523_
P1_ 1 - Port 1, pin 1 alias for PIN_9. This is the second pin in port 1, accessed through the upper-byte registers.
- AW9523_
P1_ 2 - Port 1, pin 2 alias for PIN_10. The third pin in port 1, part of the upper byte of the 16-bit pin registers.
- AW9523_
P1_ 3 - Port 1, pin 3 alias for PIN_11. This is the fourth pin in port 1, useful when organizing pins by port groups.
- AW9523_
P1_ 4 - Port 1, pin 4 alias for PIN_12. The middle pin of port 1, can be used with LED dimming functionality.
- AW9523_
P1_ 5 - Port 1, pin 5 alias for PIN_13. This pin is part of port 1’s push-pull output group, accessible via upper-byte registers.
- AW9523_
P1_ 6 - Port 1, pin 6 alias for PIN_14. One of the higher-numbered pins in port 1, supporting all standard GPIO and LED modes.
- AW9523_
P1_ 7 - Port 1, pin 7 alias for PIN_15. The last pin on the AW9523, representing the highest bit in the 16-bit register space.
- AW9523_
PIN_ 0 - Bitmask for pin 0
- AW9523_
PIN_ 1 - Bitmask for pin 1
- AW9523_
PIN_ 2 - Bitmask for pin 2
- AW9523_
PIN_ 3 - Bitmask for pin 3
- AW9523_
PIN_ 4 - Bitmask for pin 4
- AW9523_
PIN_ 5 - Bitmask for pin 5
- AW9523_
PIN_ 6 - Bitmask for pin 6
- AW9523_
PIN_ 7 - Bitmask for pin 7
- AW9523_
PIN_ 8 - Bitmask for pin 8
- AW9523_
PIN_ 9 - Bitmask for pin 9
- AW9523_
PIN_ 10 - Bitmask for pin 10
- AW9523_
PIN_ 11 - Bitmask for pin 11
- AW9523_
PIN_ 12 - Bitmask for pin 12
- AW9523_
PIN_ 13 - Bitmask for pin 13
- AW9523_
PIN_ 14 - Bitmask for pin 14
- AW9523_
PIN_ 15 - Bitmask for pin 15
- AW9523_
PORT0_ ALL - Bitmask for all pins in port 0 (pins 0-7)
- AW9523_
PORT1_ ALL - Bitmask for all pins in port 1 (pins 8-15)
- AW9523_
REG_ CHIPID - Chip ID register (read-only, returns 0x23)
- AW9523_
REG_ INPU T1 - Input port 1 register (pins 8-15)
- AW9523_
REG_ INTENABL E1 - Interrupt enable port 1 register
- HIGH
- Constant for HIGH pin state
- INPUT
- Pin mode constant for input direction (deprecated, use
PinMode::Inputinstead) - LOW
- Constant for LOW pin state
- OUTPUT
- Pin mode constant for output direction (deprecated, use
PinMode::Outputinstead)