Android Studio C++ missing i2c related definitions

92 Views Asked by At

Building a C++ module with Android Studio under Windows targetting an Orange Pi CM4 (which uses a Rockchip 3566 running Android 11 with Linux kernel 4.19.232) I'm faced with missing definitions for all smbus related methods.

Included in my project are the following:

#include <sys/ioctl.h>
#include <fcntl.h>
#include <linux/i2c-dev.h>
#include <linux/types.h>
#include <linux/i2c.h>
#include <i2c/smbus.h>      //THIS ONE CAN'T BE FOUND

These currently allow me to succesfully access the desired i2c port (/dev/i2c-2) and open it. I am also able to write and read to and from this port using the write() and read() methods provided by <unistd.h>. I would however prefer to use smbus methods such as i2c_smbus_read_word_data() and i2c_smbus_write_word_data() but these don't seem to be available. Although the smbus related constants such as I2C_FUNC_SMBUS_READ_WORD_DATA are indeed provided in NDK 25.1's <linux/i2c.h>, the prototypes of the actual methods I want are not.

My understanding is that these methods are implemented at the kernel level and I've checked in the manufacturer's kernel source of this particular device and the function definitions are indeed present under RK356X_Android11/kernel/drivers/i2c-core-smbus.c so I think I should be able to use these methods on this device and I'm simply missing the proper includes. I believe the prototypes to these smbus methods are possibly within the i2c/smbus.h file I am currently missing but I don't know where I should look for it.

While searching for a solution to similar problems under Linux I noticed it is often suggested to install the libi2c-dev package. I am not sure however if I can do something similar under Android. I've read that busybox i2c_tools may provide what I need under Android but I'm not sure how I can include that within Android Studio under Windows.

0

There are 0 best solutions below