2 releases
0.1.1 | Dec 19, 2023 |
---|---|
0.1.0 | Nov 25, 2023 |
#16 in #expander
21KB
428 lines
Rust no_std NXP SC16IS752 I2C driver
Dual UART and 8x GPIO port expander
AKA:
- Waveshare Serial Expansion HAT
- MCU-752
- Isolated 485 HAT
- Raspberry Pi UART Expander
lib.rs
:
Example
let mut device = SC16IS752::new(SC16IS750_ADDRESS, i2c)?;
device.initalise(Channel::A, UartConfig::default().baudrate(9600))?;
device.gpio_set_pin_mode(GPIO::GPIO0, PinMode::Output)?;
device.flush(Channel::A)?;
loop {
device.write_byte(Channel::A, "a".as_bytes()[0])?;
println!("RX A = {:?}", device.read_byte(Channel::A)?);
for byte in b"This is channel A" {
device.write_byte(Channel::A, byte)?;
}
let mut buf_a: Vec<u8> = vec![];
for _ in 0..device.fifo_available_data(Channel::A)? {
match device.read_byte(Channel::A)? {
Some(byte) => buf_a.push(byte),
None => break,
}
}
println!("RX UART A = {}", String::from_utf8_lossy(&buf_a));
thread::sleep(Duration::from_millis(250));
println!("Testing GPIO states");
device.gpio_set_pin_state(GPIO::GPIO0, PinState::High)?;
println!(
"GPIO0 = {:?} (Output)",
device.gpio_get_pin_state(GPIO::GPIO0)?
);
println!("Set GPIO0 to low");
device.gpio_set_pin_state(GPIO::GPIO0, PinState::Low)?;
thread::sleep(Duration::from_millis(250));
println!(
"GPIO0 = {:?} (Output toggled)",
device.gpio_get_pin_state(GPIO::GPIO0)?
);
Dependencies
~68KB