1 /**
2  * @file i2c_core.h
3  * @copyright Copyright (C) 2015-2021 Alibaba Group Holding Limited
4  */
5 
6 #ifndef _I2C_CORE_H
7 #define _I2C_CORE_H
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 #include "aos/driver/i2c.h"
13 #include <aos/list.h>
14 #include <aos/kernel.h>
15 
16 #define AOS_I2C_MAGIC 0x12c12c12
17 
18 /* This struct define i2c main handle */
19 typedef struct {
20     i2c_slave_config_t  config;            /**< i2c slave device's config */
21     aos_mutex_t         lock;             /**< lock for i2c slave device's operations */
22     uint32_t            i2c_dev_handle;    /**< use &i2c_dev_handle as i2c device's handle */
23     dlist_t             node;              /**<  ode in i2c channel's slave device list */
24     void                *master;           /**<  pointer to i2c controller's struct */
25 } i2c_slave_dev_t;
26 
27 /**
28  * i2c master controller's settings
29  * all slave devices in the same I2C bus are connected to the list named with slave
30  * each time when an i2c transaction request is receiived, we check whether last i2c transaction on the same device or not
31  * if yes, skip slave device address/clock/device address bit mode setting, issue i2c tx/rx directly
32  * if current request is on a new device compared with the last one, check if target clock equals with clk or not, if not
33  * set clock; then set device's address and address bit mode, and then issue tx/rx request to driver
34 */
35 typedef struct i2c_master_dev {
36     uint32_t    id;          /**< i2c master controller's id */
37     aos_mutex_t lock;        /**< used to lock all operations on current i2c master device */
38     dlist_t     slave;       /**< node in i2c channel's slave device list */
39     uint32_t    clk;         /**< used to log i2c host's current clock setting, if current i2c transaction equals with
40                                 clk, skip slave clk setting procedure */
41     uint16_t    addr;        /**< used to log i2c host's current slave address, if current i2c transaction equals with
42                                 slave address, skip slave slave address setting procedure */
43     uint32_t    addr_width;  /**< used to log i2c host's current address width mode setting, if current i2c transaction equals with
44                                 address width mode, skip slave address width mode setting procedure */
45     csi_iic_t   csi_dev;     /**< CSI I2C device */
46     dlist_t     host;        /**< node in host i2c controller list*/
47     uint32_t    init;        /**< whether i2c controller is initialized or not >*/
48 } i2c_master_dev_t;
49 
50 
51 #ifdef __cplusplus
52 }
53 #endif
54 
55 #endif /* _I2C_CORE_H */
56