2个版本
0.1.1 | 2024年8月2日 |
---|---|
0.1.0 | 2024年7月15日 |
#484 in 嵌入式开发
每月256次下载
35KB
680 行
一个针对SX1509 I/O扩展器的嵌入式-hal专用驱动程序。
此crate允许您将SX1509的扩展引脚用作微控制器上的简单GPIO引脚。
可移植原子操作
此crate使用portable-atomic
来提供平台无关的原子操作。这是实现内部共享i2c总线的必要条件。您可能需要启用portable-atomic
的某些功能,才能在本地不支持原子操作的平台上将此crate编译。
用法
// 0x3F is used here, the actual address will vary
// depending on the configuration of the ADDR
// pins on the chip.
let mut expander = Sx1509::new(i2c, 0x3F).unwrap();
// This borrows the expander, so the expander
// cannot be dropped before it's pins.
let sx1509::Pins {
a0,
a1,
..
} = expander.split();
let pin_0 = a0.into_output().unwrap();
let pin_1 = a1.into_input().unwrap();
pin_0.set_high().unwrap();
assert_eq!(pin_1.is_high().unwrap(), true);
依赖项
~1MB
~18K SLoC