I2c_驱动框架
Posted panda-w
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了I2c_驱动框架相关的知识,希望对你有一定的参考价值。
应用
i2c_driver层
(自己编写)
i2c_core层 i2c_bus_type
(i2c_core.c)
i2c_adapter层
(i2c_xxx.c)
硬件
< 结构体>
struct i2c_msg
__u16 addr; //数据是传送个哪个从设备
__u16 flags;
__u16 len; /* msg length */
__u8 *buf; /* pointer to msg data */
;
struct i2c_driver //描述一个i2c从设备驱动的操作方法
unsigned int class;
/* Standard driver model interfaces */
int (*probe)(struct i2c_client *, const struct i2c_device_id *);
int (*remove)(struct i2c_client *);
struct device_driver driver; //父类
const struct i2c_device_id *id_table; //用于匹配的id_table(列表)
const unsigned short *address_list;
struct list_head clients;
;
struct i2c_adapter
const struct i2c_algorithm *algo; /* the algorithm to access the bus */
|
int (*master_xfer)(struct i2c_adapter *adap, struct i2c_msg *msgs,int num);
int nr; //编号
struct device dev; //父类
struct i2c_client //代表i2c 从设备的信息
unsigned short addr;//7bit从地址
char name[I2C_NAME_SIZE]; //用于和i2c driver进行匹配
struct i2c_adapter *adapter; //指向创建自己的适配器(控制器)
struct i2c_driver *driver; // 指针已经匹配成功之后的i2c driver
struct device dev; //父类--用于加入总线
;
<函数>
i2c_master_send(const struct i2c_client * client,const char * buf,int count)
i2c_master_recv(const struct i2c_client * client,char * buf,int count)
↓
i2c_transfer(struct i2c_adapter * adap,struct i2c_msg * msgs,int num) //通用
↓
client->adapter->algo->master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num);
<笔记>
1. i2c driver层:应用交互,知道数据,不知传输
i2c core 层: 维护了一个i2c总线
i2c adapter: 硬件交互,不知数据,只知传输
2. 查看i2c设备:ls /sys/bus/i2c/devices/0-0050/
3.
以上是关于I2c_驱动框架的主要内容,如果未能解决你的问题,请参考以下文章