用户空间操作i2c(User space operation I2C)
用户空间操作i2c(User space operation I2C)
Catalog
The first chapter user space using i2c_dev.................. 1.
1.1 prepare................................................ 1...
1.2 IOCTL control............................................. 1.
1.3 i2c_dev use routines.................................... 4.
1.3.1 (read) (/write).................................... 4.
1.3.2 I2C_RDWR.................................... 5...
A.1 i2c_dev in the user space interface.............................. 6.
The first chapter use i2c_dev user space
The I2C adapter is registered, users can also use their space. In the Linux kernel code file
The /include/linux/i2c-dev.c for each adapter to generate a master device number device node 89, to achieve the file
The operation of the user interface, I2C space can be accessed through the I2C device adapter node. The adapter number starting from 0, and
The adapter device node device number is the same.
The I2C adapter device node is /dev/i2c-x, where x is the number of representative figures, adapter. As the adapter series
The number is dynamically allocated (and related registration), we would like to know which one can see what the corresponding adapter number.
The contents of the file under the /sys/class/i2c-dev/ directory.
1.1 preparation.
In order to user space program operation I2C adapter, must contain the following sentences in the program:
#include
#include
The two header defines the structure and the need to use macros.
You can then open the device node. But on which one? Because the number is not fixed adapter. We run the following command in the end:
[root@zlg cat /sys/class/i2c-dev/i2c-0/name /]#
PNX4008-I2C0
[root@zlg cat /sys/class/i2c-dev/i2c-1/name /]#
PNX4008-I2C1
[root@zlg cat /sys/class/i2c-dev/i2c-2/name /]#
USB-I2C
If we want to open the second adapter, just its number is 1, the corresponding device node is /dev/i2c-1. You can open it in the following way:
Int fd;
If ((FD = open (/dev/i2c-1, O