Coming from C# and the .NET world, I needed to go bare metal with some IC (in this case the rp2040), and choose Rust based on every comment that I saw for the language.
Until now, I been able to easily use gpio, I2C as master, but my usage case, the rp2040 will be acting as a slave (or peripheral as the rp2040_hal calls it).
I'm able to see the device address when scanning the bus with Linux i2cdetect, but I am struggling with reading and writing to the device.
Sadly i wasn't able to see any useful example/usage case online, I'm wandering if someone had the "pleasure" to use this struct.
Keep in mind that I am bare metal #![no_std]
My main loop looks like this:
match i2c.next() {
Some(I2CEvent::TransferRead) => {
info!("transfer read");
let write: [u8; 1] = [0x55];
let byteswrite = i2c.write(&write);
info!("{}", byteswrite);
}
Some(I2CEvent::TransferWrite) => {
info!("transfer write");
let mut result: [u8; 1] = [0; 1];
let mut bytesread: usize;
loop {
bytesread = i2c.read(&mut result);
if bytesread == 0 {
break;
}
info!("{:#04x}", &result);
}
}
Some(I2CEvent::Start) => {}
Some(I2CEvent::Stop) => {}
Some(I2CEvent::Restart) => {
info!("Restart");
}
None => {}
}
I was expecting that using Linux i2cget and i2ctransfer, to be able to read and write to the device.