Plans for I2C Tools 4
There is a major issue with I2C Tools 3, which has been present since the beginning, even when the code was still part of lm-sensors, and which I want to solve now. This problem is
There have always been two flavors of file
i2c-dev.h. One comes from the kernel and contains a description of the
/dev/i2c-* kernel interface, as kernel header files are supposed to do. The other comes from the i2c-tools package, and contains not only the description of the
/dev/i2c-* kernel interface but also definitions copied from
<linux/i2c.h> as well as inline functions duplicating the
i2c_smbus_* functions from the kernel to make the same functionality available to user-space applications. This was an afternoon hack but nobody ever bothered cleaning it up so it's still there over ten years later.
There are many problems with the current situation:
- Having two public header files with the same name is confusing. Application developers as well as distribution packagers don't know which file they should use. They can't package both.
- One has to keep all files in sync continuously. Thankfully they don't change much, but when they do, it's easy to overlook the change and forget to propagate it.
- The inline
i2c_smbus_*functions are actually too large to be inline functions, and recent versions of gcc will complain loudly about that.
I propose to solve this problem in four steps.
Step 1: Cleaning up
We need to get rid of the
i2c-dev.h file in i2c-tools, and before we can do that, this copy should be aligned with the one in the kernel. This means that anything extra must be moved somewhere else. Then all applications must be adjusted to include the right header files. Later, we can just remove the
i2c-dev.h file from i2c-tools and use the kernel version of the file instead.
Discussion: Do we create a header file that includes all other often-needed header files, to make the migration easier?
Step 2: Creating a library for
i2c_smbus_* inline functions should be moved to a proper shared library.
Step 3: Extending the library
More functions may be added to the library, for example the ones currently in
Status: Code moved from
lib/busses.c, functions renamed to meet a reasonable naming convention. Needs self-review.
Step 4: Documentation
Document the library API.
Status: Not started yet.