资料下载&百问网技术交流群,百万嵌入式工程师聚集地: https://www.100ask.net/page/2248041
资料下载coding无法使用浏览器打开,必须用git工具下载:
git clone https://e.coding.net/weidongshan/linux/doc_and_source_for_drivers.git
视频观看
百问网驱动大全
通用驱动i2c-dev分析参考资料:
- Linux驱动程序:
drivers/i2c/i2c-dev.c
- I2C-Tools-4.2:
https://mirrors.edge.kernel.org/pub/software/utils/i2c-tools/
- AT24cxx.pdf
怎么编写字符设备驱动程序?
- 确定主设备号
- 创建file_operations结构体
- 在里面填充drv_open/drv_read/drv_ioctl等函数
- 注册file_operations结构体
- register_chrdev(major, &fops, name)
- 谁调用register_chrdev?在入口函数调用
- 有入口自然就有出口
- 在出口函数unregister_chrdev
- 辅助函数(帮助系统自动创建设备节点)
- class_create
- device_create
i2c-dev.c的核心:
static const struct file_operations i2cdev_fops = {
.owner = THIS_MODULE,
.llseek = no_llseek,
.read = i2cdev_read,
.write = i2cdev_write,
.unlocked_ioctl = i2cdev_ioctl,
.compat_ioctl = compat_i2cdev_ioctl,
.open = i2cdev_open,
.release = i2cdev_release,
};
主要的系统调用:open, ioctl:
要理解这些接口,记住一句话:APP通过I2C Controller与I2C Device传输数据。
3.1 i2cdev_open 资料下载&百问网技术交流群,百万嵌入式工程师聚集地: https://www.100ask.net/page/2248041
百问网技术论坛: http://bbs.100ask.net/
百问网嵌入式视频官网: https://www.100ask.net/index
百问网开发板: 淘宝:https://100ask.taobao.com/ 天猫:https://weidongshan.tmall.com/