Crate aw9523_embedded

Crate aw9523_embedded 

Source
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_std compatible
  • Uses embedded-hal traits 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 async feature (requires embedded-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§

Aw9523Error
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_mode to 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_INPUT1
Input port 1 register (pins 8-15)
AW9523_REG_INTENABLE1
Interrupt enable port 1 register
HIGH
Constant for HIGH pin state
INPUT
Pin mode constant for input direction (deprecated, use PinMode::Input instead)
LOW
Constant for LOW pin state
OUTPUT
Pin mode constant for output direction (deprecated, use PinMode::Output instead)