Re: [RFC] I2C register access API


Benjamin Walsh <benjamin.walsh@...>
 

On Thu, Apr 21, 2016 at 09:19:56AM +0000, Davidoaia, Bogdan M wrote:
Hello all,

This is a proposal to add an API for reading, writing and updating
internal registers of I2C devices. This API would offer a simpler way of
communicating with I2C devices that have internal registers.

With the current I2C API, if you want to read the value of an internal
device register, you have to do an i2c_transfer call with two messages
(a write of the register address, followed by a read of the register
value).

Just looking at the sensor subsystem, all drivers define their own
register read/write functions which are more or less identical. This is
a case of code duplication that can be avoided if we add an API for
accessing registers.
Always in favour of removing code duplication! :)

I have written a patch that adds the I2C register access functions and
uploaded it to Gerrit [1]. All the new functions are implemented using
the existing I2C driver API.

What are your thoughts on this addition to the I2C API? If you think
this is a good idea, I can start updating the drivers to use the
register access function.

Thanks,
Bogdan

[1] https://gerrit.zephyrproject.org/r/#/c/1569/

Join devel@lists.zephyrproject.org to automatically receive all group messages.