zoukankan      html  css  js  c++  java
  • 驱动_I2c驱动框架

     I2c驱动框架


    应用


    (从设备驱动层)

    i2c_driver层

     (自己编写)


     (核心层)

             

    i2c_core层                                                                                                    i2c_bus_type    

          

    (i2c_core.c)


     (控制器层)

    i2c_adapter层                                      

     (i2c_xxx.c)


    硬件 

    目录:linux/driver/i2c/ 

          algo/   (i2c-algo-bit.c)

          busses/   (原厂)

          muxes/      (无用)

    <从设备驱动层>  i2c-dev.c                           自己编写

    <核      心     层>  i2c-core.c                           内核提供

    <控   制   器  层>    busses/i2c-xxx.c(瑞芯微:i2c-rk3x.c  全志:i2c-sunxi.c)    原厂提供

    < 结构体> 


     struct i2c_msg {
        __u16 addr;     //从设备地址
        __u16 flags;    // 类型 (读1写0)
        __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;       //父类--用于加入总线
      
    };

      

    <函数>


    数据传输接口:i

    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_adapter   /   i2c_msg →  i2c_transfer(struct i2c_adapter * adap,struct i2c_msg * msgs,int num) //通用

       ↓

    i2c_algorithm → master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num); 

    代码示例:https://www.cnblogs.com/panda-w/p/11118591.html

    <代码框架> :


     <笔记>


    1.  i2c driver层:应用交互,知道数据,不知传输

       i2c core 层: 维护了一个i2c总线

       i2c adapter:  硬件交互,不知数据,只知传输

    2. 查看i2c设备信息:ls /sys/bus/i2c/devices/0-0050/(name)

     查看i2c驱动名字:/sys/bus/i2c/drivers

    3. 每个i2c控制器总线上都可以挂载多个i2c外设

    4.每个I2C器件在出厂时都会固化自己的I2C地址的,也有通过硬件引脚选择I2C地址的

    5. i2c控制器不用管,引出的引脚与控制器已经连死

    6. 宏定义在结构体,说明在结构体中有效

    3.

    Stay hungry, stay foolish 待续。。。
  • 相关阅读:
    牛客IOI周赛17-提高组 卷积 生成函数 多项式求逆 数列通项公式
    6.3 省选模拟赛 Decompose 动态dp 树链剖分 set
    AtCoder Grand Contest 044 A Pay to Win 贪心
    5.29 省选模拟赛 树的染色 dp 最优性优化
    luogu P6097 子集卷积 FST FWT
    CF724C Ray Tracing 扩展欧几里得 平面展开
    5.30 省选模拟赛 方格操作 扫描线 特殊性质
    5.29 省选模拟赛 波波老师 SAM 线段树 单调队列 并查集
    Spring main方法中怎么调用Dao层和Service层的方法
    Bug -- WebService报错(两个类具有相同的 XML 类型名称 "{http://webService.com/}getPriceResponse"。请使用 @XmlType.name 和 @XmlType.namespace 为类分配不同的名称。)
  • 原文地址:https://www.cnblogs.com/panda-w/p/10922747.html
Copyright © 2011-2022 走看看