whitecatboard / Lua-RTOS-ESP32

Lua RTOS for ESP32
Other
1.18k stars 222 forks source link

i2c driver ACK handling for bytes #382

Open xopxe opened 3 years ago

xopxe commented 3 years ago

Is there a reason why this snippet

    if (len > 1) {
        i2c_master_read(cmd, (uint8_t *) data, len, I2C_MASTER_LAST_NACK);
    } else {
        i2c_master_read_byte(cmd, (uint8_t *) data, I2C_MASTER_ACK);
    }

in the i2c driver has different ack flags when reading single bytes?

I have a device that treats the i2c as a serial device (a Pixy2 camera), and the code scans one byte at a time to find a header sync. With the i2c driver as is, i'm missing each other byte, this is, between two reads there's a byte lost. If I change the ack flag to I2C_MASTER_LAST_NACK also for the i2c_master_read_byte call, everything works. It also works if I use the i2c_master_read for reading single bytes also.

I suppose that change can break other devices, but I don't fully understand how i2c is supposed to work in this case.