#include <stdio.h>
#include <linux/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <assert.h>
#include <string.h>
#include <linux/i2c.h>
#include <linux/i2c-dev.h>
int main(int argc, char **argv)
{
struct i2c_rdwr_ioctl_data work_queue;
unsigned int idx;
unsigned int fd;
unsigned int slave_address, reg_address;
unsigned char val;
int i;
int ret;
unsigned int num;
if(argc < 4)
{
printf("Usage:\n%s /dev/i2c-x start_addr reg_addr\n", argv[0]);
return 0;
}
fd = open(argv[1], O_RDWR);
if(!fd)
{
printf("Error on opening the device file \n");
return 0;
}
sscanf(argv[2], "%x", &slave_address);
sscanf(argv[3], "%x", ®_address);
if(argc == 4)
{
num = 1;
}
else
{
sscanf(argv[4], "%d", &num);
linux设备驱动开发详解 通过O_RDWR IOCTL 读写i2c设备
最新推荐文章于 2023-05-05 01:13:38 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)