I changed the following things and would like to see those changes integrated into the official Multiwii tree:
- unify i2c_readNak and i2c_readAck into one function
- add i2c_read_reg_to_buf to read multiple bytes in a single call
- add swap_endianness function to change to endianness of a transferred buffer
- changes i2c addresses of peripherals to 7bit notation
You might ask why? Nearly every I2C library utlizes this notation, and most data sheets also specify the 7 bit notation of the device address. I also changed the code "ADDRESS + 1" to "ADDRESS<<1 | 1", since adding 1 will not yield a correct result if the LSB is alread set for some reason.
I also removed a few occurances of undefined behaviour:
E.g. i2c_readReg16 does the following:
Code: Select all
return (i2c_readAck() <<8) | i2c_readNak();
C(++) however does not define the orderin which both subexpressions are evaluated; depending on the compiler, optimizer settings and lunar phase i2c_readNak might be called before i2c_readAck, trashing the transfer (https://en.wikipedia.org/wiki/Sequence_point).
Thanks for reading, please feel free to leave feedback