Expand description
This is a crate that provides a general abstraction for an I²C port expander used in the GPIO Port Expander (Troyka Module)
, Troyka HAT
and Slot Expander Expansion Board
products. This abstraction is not necessarily the most performant, but it allows pins to be used in the same way as direct GPIOs. Because pin types also implement embedded-hal
digital I/O characteristics, they can also be passed to subsequent drivers (for example, as a reset or chip select pin).
Это крейт, предоставляющий общую абстракцию для I²C расширителя портов, используемый в продуктах Расширитель GPIO-портов (Troyka-модуль)
, Troyka HAT
и Плата расширения Slot Expander
. Эта абстракция не обязательно самая производительная, но она позволяет использовать контакты так же, как прямые GPIO из HAL. Поскольку типы выводов также реализуют характеристики embedded-hal
цифрового ввода-вывода, они также могут быть переданы последующим драйверам (например, в качестве вывода сброса или выбора микросхемы).
§Example (for TroykaHAT)
use std::error::Error;
use std::thread;
use std::time::Duration;
use gpio_expander::{prelude::*, GpioExpander};
use rppal::i2c::I2c;
fn main() -> Result<(), Box<dyn Error>> {
// Initializing an I²C Peripheral from HAL
let i2c = I2c::with_bus(1)?;
// Initializing GpioExpander with default I²C address
let mut expander = GpioExpander::new(i2c, None);
let expander_pins = expander.pins();
// Pin 0 into output mode
let mut led = expander_pins.p00.into_output()?;
loop {
led.set_high()?;
thread::sleep(Duration::from_secs(1));
led.set_low()?;
thread::sleep(Duration::from_secs(1));
}
}
More examples in the examples
folder.
Modules§
- prelude
- Convenience re-export of multiple traits.
Structs§
- Driver
- Driver
- Floating
- Floating input (type state)
- Gpio
Expander - GpioExpander device driver
- Input
- Input mode (type state)
- Output
- Output mode (type state)
- Pin
- Pin
- Pins
- GPIO
Constants§
- DEFAULT_
I2C_ ADDRESS - Default I²C address