How to include SMBus commands in my i2c program

Hi, I’m trying to write a demo for i2c on my Colibri iMX6

I followed the instructions here

It seemed worked will before I use SMBus commands

  res = i2c_smbus_read_word_data(file, register);
  if (res < 0) {
    /* ERROR HANDLING: i2c transaction failed */
  } else {
    /* res contains the read word */

There is an error saying that cannot find the i2c_smbus_read_word_data() function.
I have included linux/i2c and linux/i2c-dev
What should I do?


As the kernel document states, you need to use the i2c-dev.h header of the i2c-tools project if you want the SMBus inline functions.

If you did your own OE build you have that file renamed to i2c-dev-user.h in the resulting sysroot after building the package. Otherwise you could download the project sources and use the header file contained in the unpacked sources.