6、使用i2c_put_adapter()函数释放先前获取的I2C适配器对象。 sx1_i2c_read_byte主要完成了以下功能: 1、通过调用i2c_get_adapter(0)函数获取指定索引的I2C适配器对象并赋值给adap变量。 2、初始化一个struct i2c_msg类型的数组msg,该数组包含一个元素用于I2C消息的传输。 3、设置msg结构体中的字段: addr:设备...
struct i2c_adapter *padap, struct i2c_board_info const *pinfo ); /*示例: struct i2c_adapter *ad; struct i2c_board_info info={ I2C_BOARD_INFO(name,二级外设地址) }; //假设设备挂在i2c-2总线上 ad=i2c_get_adapter(2); //动态创建i2c_client并且注册 i2c_new_device(ad,&info); i2c_put_...
定义板级I2C从设备信息; 通过i2c_get_adapter函数获取I2C适配器,参数是I2C适配器编号; 调用i2c_new_device进行I2C从设备的注册,将I2C从设备关联到当前I2C适配器上; 调用i2c_put_adapter将添加完设备的结构体放回去, 1.4 at24c08_drv.c 创建文件at24c08_drv.c: #include <linux/init.h>#include<linux/module.h>...
funcs = i2c_get_functionality(client->adapter); return put_user(funcs, (unsigned long __user *)arg); case I2C_RDWR: //读取和接收数据,后面讲述 return i2cdev_ioctl_rdrw(client, arg); case I2C_SMBUS: //smbus协议数据传输,后面讲述 return i2cdev_ioctl_smbus(client, arg); case I2C_RETRI...
15 i2c_put_adapter(i2c_adap); 16 (...) 17 } 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 这类方法适用于事先不知道I2C总线号的情况,前者用i2c_new_device来声明设备获得一个i2c_client结构体,后者通过i2c_new_probed_device来实现,两者的区别在于i2c_new_probed...
adapter=i2c_get_adapter(0); if(!adapter){ pr_err("Failed to get I2C adapter\n"); return-ENODEV; } //使用适配器进行操作... i2c_put_adapter(adapter); 这段代码先获取适配器,然后在完成操作后调用 i2c_put_adapter 函数释放适配器资源。 5. 可以使用 i2c_for_each_dev 函数来遍历所有 I2C 适配...
= 1) { return -EIO; } return 0; } static int __init i2c_driver_init(void) { struct i2c_adapter *adapter; adapter = i2c_get_adapter(1); // 假设使用I2C总线1 if (!adapter) { return -ENODEV; } client = i2c_new_client_device(adapter, &i2c_device_id); if (!client) { i2c_put...
适配器i2c_adapter 算法结构Algorithm。 I2C设备驱动层 I2C设备驱动(也称为客户驱动)是对设备端的实现,设备一般挂接在受CPU控制的I2C适配器上,通过I2C适配器与CPU交换数据。 使用了I2C总线-设备-驱动模型 i2c_driver和i2c_client 4个数据结构的的关系
algo代表i2c_adapter所对应的i2c_algorithm,i2c_algorithm中的函数主要是为了实现设备与驱动的通信 struct i2c_algorithm { int (*master_xfer)(struct i2c_adapter *adap, struct i2c_msg *msgs, int num); int (*master_xfer_atomic)(struct i2c_adapter *adap, ...
2.3.1 i2c_match_id()函数 3 3 i2c_driver驱动 3 3.1 i2c_driver注册 4 3.1.1 i2c_add_driver添加一个驱动 4 3.1.2 i2c_register_driver注册一个驱动 4 3.2 驱动注册中重要函数 5 4 适配器adapter驱动程序 5 4.1 i2c_adapter适配器 5 4.1.1 IIC适配器加载函数 ...