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)?
);