| Crates.io | xr2280x-hid |
| lib.rs | xr2280x-hid |
| version | 0.9.9 |
| created_at | 2025-04-13 22:37:03.263325+00 |
| updated_at | 2025-06-27 09:50:47.789243+00 |
| description | Control XR2280x I2C and GPIO/PWM/Interrupts over USB HID |
| homepage | https://github.com/tiborgats/xr2280x-hid |
| repository | https://github.com/tiborgats/xr2280x-hid |
| max_upload_size | |
| id | 1632205 |
| size | 441,448 |
Rust library for controlling MaxLinear/Exar XR2280x series USB-to-I²C/GPIO/PWM bridge chips via HID interface.
Add to your Cargo.toml:
[dependencies]
xr2280x-hid = "0.9.6"
hidapi = "2.6"
Basic usage:
use xr2280x_hid::{Xr2280x, GpioPin, GpioDirection, GpioLevel};
use hidapi::HidApi;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let hid_api = HidApi::new()?;
let device = Xr2280x::device_open_first(&hid_api)?;
// I²C
device.i2c_set_speed_khz(100)?;
let devices = device.i2c_scan_default()?;
// GPIO
let pin = GpioPin::new(0)?;
device.gpio_assign_to_edge(pin)?;
device.gpio_set_direction(pin, GpioDirection::Output)?;
device.gpio_write(pin, GpioLevel::High)?;
Ok(())
}
Run examples to see various features in action:
cargo run --example enumerate_hardware # List connected devices
cargo run --example i2c_scan # Scan I²C bus
cargo run --example blink # GPIO blink
cargo run --example gpio_transactions # Efficient batch GPIO operations
cargo run --example pwm_out # PWM output
cargo run --example gpio_interrupt_safe_usage # Safe vs unsafe interrupt handling
For GPIO performance optimization, transaction APIs, and best practices, see the comprehensive GPIO module documentation which includes:
Install hidapi development library:
sudo apt-get install libhidapi-dev # Debian/Ubuntu
sudo dnf install hidapi-devel # Fedora/RHEL
Add udev rules for device permissions:
# /etc/udev/rules.d/99-xr2280x.rules
SUBSYSTEM=="hidraw", ATTRS{idVendor}=="04e2", ATTRS{idProduct}=="1100", MODE="0666"
SUBSYSTEM=="hidraw", ATTRS{idVendor}=="04e2", ATTRS{idProduct}=="1200", MODE="0666"
brew install hidapi
Download hidapi.dll or use vcpkg. See hidapi crate docs for details.
When multiple devices are connected:
// List all devices
let devices = Xr2280x::device_enumerate(&hid_api)?;
// Open by serial number
let device = Xr2280x::open_by_serial(&hid_api, "ABC123456")?;
// Open by index
let device = Xr2280x::open_by_index(&hid_api, 0)?;
WTFPL - See LICENSE file for details.
Issues and pull requests welcome on GitHub.