tca9534_driver_rs/lib.rs
1#![no_std]
2#![cfg_attr(docsrs, feature(doc_cfg))]
3
4//! TCA9534 I2C IO Expander driver
5//!
6//! This is a platform-independent Rust driver for the TCA9534, an 8-bit I2C
7//! IO expander, with optional [`embedded-hal`](https://github.com/rust-embedded/embedded-hal) integration.
8//!
9//! Both synchronous and asynchronous versions are provided, selectable via feature flags.
10//!
11//! ## Example Usage
12//!
13//! ### Synchronous Usage
14//!
15//! ```rust,ignore
16//! use tca9534::{TCA9534Sync, PinConfig, PinLevel, addresses};
17//!
18//! // Initialize I2C bus (platform specific)
19//! let i2c = setup_i2c(); // Your I2C initialization code
20//!
21//! // Create TCA9534 driver with address 0x20
22//! let mut tca9534 = TCA9534Sync::new(i2c, addresses::ADDR_000);
23//!
24//! // Or use default address constructor
25//! let mut tca9534 = TCA9534Sync::new_with_default_address(i2c);
26//!
27//! // Initialize the device
28//! tca9534.init()?;
29//!
30//! // Configure pin 0 as output, others as input
31//! tca9534.set_pin_config(0, PinConfig::Output)?;
32//! tca9534.set_pin_config(1, PinConfig::Input)?;
33//!
34//! // Set pin 0 to high
35//! tca9534.set_pin_output(0, PinLevel::High)?;
36//!
37//! // Read pin 1 input
38//! let pin1_level = tca9534.read_pin_input(1)?;
39//! ```
40//!
41//! ### Asynchronous Usage (with async feature)
42//!
43//! ```rust,ignore
44//! use tca9534::{TCA9534Async, PinConfig, PinLevel, addresses};
45//!
46//! // Initialize async I2C bus (platform specific)
47//! let i2c = setup_async_i2c(); // Your async I2C initialization code
48//!
49//! // Create TCA9534 driver with address 0x20
50//! let mut tca9534 = TCA9534Async::new(i2c, addresses::ADDR_000);
51//!
52//! // Initialize the device
53//! tca9534.init().await?;
54//!
55//! // Configure and use pins
56//! tca9534.set_pin_config(0, PinConfig::Output).await?;
57//! tca9534.set_pin_output(0, PinLevel::High).await?;
58//!
59//! let input_level = tca9534.read_pin_input(1).await?;
60//! ```
61
62mod registers;
63mod errors;
64mod transport;
65
66// TCA9534 driver implementations
67mod tca9534;
68
69// Re-export common types
70pub use registers::*;
71pub use errors::{TCA9534Error, TCA9534CoreError};
72pub use transport::SyncTransport;
73
74#[cfg(feature = "async")]
75pub use transport::AsyncTransport;
76
77// Re-export driver implementations from tca9534 module
78pub use tca9534::TCA9534Sync;
79
80#[cfg(feature = "async")]
81pub use tca9534::TCA9534Async;