Expand description
TCA9534 I2C IO Expander driver
This is a platform-independent Rust driver for the TCA9534, an 8-bit I2C
IO expander, with optional embedded-hal integration.
Both synchronous and asynchronous versions are provided, selectable via feature flags.
§Example Usage
§Synchronous Usage
ⓘ
use tca9534::{TCA9534Sync, PinConfig, PinLevel, addresses};
// Initialize I2C bus (platform specific)
let i2c = setup_i2c(); // Your I2C initialization code
// Create TCA9534 driver with address 0x20
let mut tca9534 = TCA9534Sync::new(i2c, addresses::ADDR_000);
// Or use default address constructor
let mut tca9534 = TCA9534Sync::new_with_default_address(i2c);
// Initialize the device
tca9534.init()?;
// Configure pin 0 as output, others as input
tca9534.set_pin_config(0, PinConfig::Output)?;
tca9534.set_pin_config(1, PinConfig::Input)?;
// Set pin 0 to high
tca9534.set_pin_output(0, PinLevel::High)?;
// Read pin 1 input
let pin1_level = tca9534.read_pin_input(1)?;§Asynchronous Usage (with async feature)
ⓘ
use tca9534::{TCA9534Async, PinConfig, PinLevel, addresses};
// Initialize async I2C bus (platform specific)
let i2c = setup_async_i2c(); // Your async I2C initialization code
// Create TCA9534 driver with address 0x20
let mut tca9534 = TCA9534Async::new(i2c, addresses::ADDR_000);
// Initialize the device
tca9534.init().await?;
// Configure and use pins
tca9534.set_pin_config(0, PinConfig::Output).await?;
tca9534.set_pin_output(0, PinLevel::High).await?;
let input_level = tca9534.read_pin_input(1).await?;Modules§
Structs§
- TCA9534
Async async - TCA9534 asynchronous driver structure
- TCA9534
Sync - TCA9534 synchronous driver structure
Enums§
- PinConfig
- Pin configuration (direction)
- PinLevel
- Pin logic level
- PinPolarity
- Pin polarity setting
- Register
- TCA9534 register definitions
- TCA9534
Core Error - Core TCA9534 errors that don’t depend on transport
- TCA9534
Error - TCA9534 driver error type
Traits§
- Async
Transport async - An asynchronous I2C transport.
- Sync
Transport - A synchronous I2C transport.