stm32-rs / stm32l4xx-hal

A Hardware abstraction layer for the stm32l432xx series chips written in rust.
157 stars 105 forks source link

I2C NACK polling #233

Open Crzyrndm opened 3 years ago

Crzyrndm commented 3 years ago

current master branch asserts that the buffer length for I2C::read and I2C::write is at least 1 and less than 256 (1..=255)

write: https://github.com/stm32-rs/stm32l4xx-hal/blob/master/src/i2c.rs#L254 read: https://github.com/stm32-rs/stm32l4xx-hal/blob/master/src/i2c.rs#L308

A fairly common I2C operation is checking if an address is present/responding by just writing the address and checking for the device ACK. Note that this is a 0 length read/write and therefore the asserts linked above prevent this.

I see the motivation for preventing 0-sized reads/writes, but there isn't a solid alternative right now. There is some conversation in the embedded-hal crate about adding an explicit method for this but no real consensus or movement.

gauteh commented 2 years ago

Assert removed in #295 . Tested on r5.

gauteh commented 2 years ago

Fixed for write