xl9555-hal
An embedded-hal 1.0 driver for the XL9555 16-bit I²C GPIO expander.
Features
embedded-hal1.0 digital traits (InputPin,OutputPin,StatefulOutputPin)- Register cache for efficient read-modify-write GPIO operations
- Low-level driver API (set/get direction, level, toggle)
- High-level pin API (
input(),output()on anyDriverHandler) - Interrupt-safe shared access via
critical_section::Mutex<RefCell<_>> #![no_std]compatible — no alloc required- Extensible
DriverHandlertrait — easy to add new backends - Async support (optional):
Waittrait (wait_for_high,wait_for_low,wait_for_rising_edge,wait_for_falling_edge,wait_for_any_edge) +monitor()task - Up to 8 XL9555 devices per I²C bus (3 address pins)
Driver Handler
Instead of coupling pins to a specific synchronization primitive, the library introduces the DriverHandler trait:
Input / Output
│
▼
DriverHandler
│
├── Xl9555<I> (direct &mut access)
├── Xl9555Shared<I> (critical_section::Mutex<RefCell<Xl9555<I>>>)
└── ... (extensible)
Any type implementing DriverHandler can construct GPIO pins — the GPIO API
stays independent of the sharing strategy.
Usage
Add to your Cargo.toml:
[]
= "0.3"
Low-level API
use DriverHandler;
use Xl9555Shared;
use PinId;
// Address pins: A3=GND, A2=GND, A1=GND → 7-bit address 0x20
let gpio = new?;
gpio.set_output?;
gpio.set_high?;
let level = gpio.get_level?; // reads INPUT register
gpio.toggle?;
High-level Pin API
use PinState;
use DriverHandler;
let mut led = gpio.output?;
led.set_low?;
let button = gpio.input?;
if button.is_high?
Shared Access (interrupt-safe)
use Xl9555Shared;
let gpio = new?;
// Use `gpio` anywhere `DriverHandler` is expected
let mut led = gpio.output?;
Async Edge Detection (feature = "async")
use Spawner;
use ;
use i2c;
use I2c;
use Timer;
use StaticCell;
use DriverHandler;
use Xl9555Shared;
use PinId;
async
async
async
Cargo Features
| Feature | Description | Default |
|---|---|---|
critical-section |
DriverHandler impl for critical_section::Mutex<RefCell> |
yes |
async |
Wait trait impl + monitor() for edge/level detection |
no |
Examples
blink— synchronous LED blink and button inputasync_embassy— async edge detection via Embassy (requires--features async)
Status
- XL9555 driver with register cache
- GPIO direction control (input / output)
- GPIO output with
set_high,set_low,toggle - GPIO input reading
-
OutputPin+StatefulOutputPin -
InputPin -
ErrorType -
Xl9555Shared(critical_section::Mutex<RefCell<_>>) -
DriverHandlertrait (extensible access pattern) - Built-in
input()/output()convenience methods -
Waittrait (wait_for_high,wait_for_low,wait_for_rising_edge,wait_for_falling_edge,wait_for_any_edge) -
monitor()task (INT pin → signal dispatch) -
embassy-timedebounce / retry support
MSRV
Current stable Rust (compatible with embedded-hal 1.0).
License
Licensed under either of
at your option.