微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 3.4.2内核下I2C驱动之24CXX实例

3.4.2内核下I2C驱动之24CXX实例

时间:11-21 来源:互联网 点击:

if (fd " 0)

{

printf("cant open /dev/at24cxx\n");

return -1;

}

if (strcmp(argv[1], "r") == 0)

{

buf[0] = strtoul(argv[2], NULL, 0);

read(fd, buf, 1);

printf("data: %c, %d, 0x%2x\n", buf[0], buf[0], buf[0]);

}

else if ((strcmp(argv[1], "w") == 0) && (argc == 4))

{

buf[0] = strtoul(argv[2], NULL, 0);

buf[1] = strtoul(argv[3], NULL, 0);

if (write(fd, buf, 2) != 2)

printf("write err, addr = 0xx, data = 0xx\n", buf[0], buf[1]);

}

else

{

print_usage(argv[0]);

return -1;

}

return 0;

}

================================================================

Makefile:

KERN_DIR = /work/system/linux-3.4.2

all:

make -C $(KERN_DIR) M=`pwd` modules

clean:

make -C $(KERN_DIR) M=`pwd` modules clean

rm -rf modules.order

obj-m += at24cxx_dev.o

obj-m += at24cxx_drv.o

#obj-m += i2c_bus_s3c2440.o


Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top