rust-embedded / rust-i2cdev

Rust library for interfacing with i2c devices under Linux
Apache License 2.0
205 stars 53 forks source link

smbus_read_word_data() on MockI2CDevice fails at address 0x00 #77

Closed tnagyzambo closed 8 months ago

tnagyzambo commented 1 year ago

To reproduce:

let mut dev = MockI2CDevice::new();
dev.regmap.write_regs(0, &[0x00, 0x01]);
let _fails = dev.smbus_read_word_data(0x00); // fails with: thread 'main' panicked at 'attempt to subtract with overflow'

The offending line of code seems to be println!("READ | 0x{:X} : {:?}", self.offset - data.len(), data); from read() in the I2CRegisterMap implementation.

eldruin commented 1 year ago

Thank you for noticing this. A PR fixing it would be very welcome.