Representing I2C devices in the Linux kernel
I2C buses and devices are exposed in user space as files in the /dev
filesystem. I2C buses are exposed as the /dev/i2c-X
file, where X
is the logical number of the I2C channel. While the hardware signals for the I2C bus are clearly numbered as 0, 1, and 2, the logical channel numbers won't necessarily be the same as their hardware counterparts.
Logical channel numbers are assigned in the order that the I2C channels are initialized in the Device Tree. For example, the I2C2 channel is usually the second I2C channel initialized by the kernel. Therefore, even though it is physical I2C channel 2, it will be logical I2C channel 1 and accessible as the /dev/i2c-1
file.
Underneath all of the layers of Android APIs and services, Android ultimately interacts with device drivers in the kernel by opening files in the /dev
and /sys
filesystems and then reading, writing, or performing ioctl()
calls on those files. While it is possible to interact with any I2C...