no-OS
i2c.h
Go to the documentation of this file.
1 /***************************************************************************/
40 #ifndef I2C_H_
41 #define I2C_H_
42 
43 /******************************************************************************/
44 /***************************** Include Files **********************************/
45 /******************************************************************************/
46 
47 #include <stdint.h>
48 
49 /******************************************************************************/
50 /*************************** Types Declarations *******************************/
51 /******************************************************************************/
52 
58 struct i2c_platform_ops ;
59 
64 typedef struct i2c_init_param {
66  uint32_t max_speed_hz;
68  uint8_t slave_address;
72  void *extra;
74 
79 typedef struct i2c_desc {
81  uint32_t max_speed_hz;
83  uint8_t slave_address;
87  void *extra;
88 } i2c_desc;
89 
97  int32_t (*i2c_ops_init)(struct i2c_desc **, const struct i2c_init_param *);
99  int32_t (*i2c_ops_write)(struct i2c_desc *, uint8_t *, uint8_t, uint8_t);
101  int32_t (*i2c_ops_read)(struct i2c_desc *, uint8_t *, uint8_t, uint8_t);
103  int32_t (*i2c_ops_remove)(struct i2c_desc *);
104 };
105 
106 /******************************************************************************/
107 /************************ Functions Declarations ******************************/
108 /******************************************************************************/
109 
110 /* Initialize the I2C communication peripheral. */
111 int32_t i2c_init(struct i2c_desc **desc,
112  const struct i2c_init_param *param);
113 
114 /* Free the resources allocated by i2c_init(). */
115 int32_t i2c_remove(struct i2c_desc *desc);
116 
117 /* Write data to a slave device. */
118 int32_t i2c_write(struct i2c_desc *desc,
119  uint8_t *data,
120  uint8_t bytes_number,
121  uint8_t stop_bit);
122 
123 /* Read data from a slave device. */
124 int32_t i2c_read(struct i2c_desc *desc,
125  uint8_t *data,
126  uint8_t bytes_number,
127  uint8_t stop_bit);
128 
129 #endif // I2C_H_
i2c_platform_ops
Structure holding I2C function pointers that point to the platform specific function.
Definition: i2c.h:95
i2c_init
int32_t i2c_init(struct i2c_desc **desc, const struct i2c_init_param *param)
Initialize the I2C communication peripheral.
Definition: i2c.c:51
i2c_desc
Structure holding I2C descriptor.
Definition: i2c.h:79
i2c_init_param::platform_ops
const struct i2c_platform_ops * platform_ops
Definition: i2c.h:70
i2c_init_param::max_speed_hz
uint32_t max_speed_hz
Definition: i2c.h:66
i2c_read
int32_t i2c_read(struct i2c_desc *desc, uint8_t *data, uint8_t bytes_number, uint8_t stop_bit)
I2C Read data from slave device.
Definition: i2c.c:104
i2c_platform_ops::i2c_ops_write
int32_t(* i2c_ops_write)(struct i2c_desc *, uint8_t *, uint8_t, uint8_t)
Definition: i2c.h:99
i2c_init_param::slave_address
uint8_t slave_address
Definition: i2c.h:68
i2c_desc::platform_ops
const struct i2c_platform_ops * platform_ops
Definition: i2c.h:85
i2c_desc
struct i2c_desc i2c_desc
i2c_remove
int32_t i2c_remove(struct i2c_desc *desc)
Free the resources allocated by i2c_init().
Definition: i2c.c:70
i2c_platform_ops::i2c_ops_init
int32_t(* i2c_ops_init)(struct i2c_desc **, const struct i2c_init_param *)
Definition: i2c.h:97
i2c_platform_ops::i2c_ops_remove
int32_t(* i2c_ops_remove)(struct i2c_desc *)
Definition: i2c.h:103
i2c_platform_ops::i2c_ops_read
int32_t(* i2c_ops_read)(struct i2c_desc *, uint8_t *, uint8_t, uint8_t)
Definition: i2c.h:101
i2c_init_param::extra
void * extra
Definition: i2c.h:72
i2c_desc::max_speed_hz
uint32_t max_speed_hz
Definition: i2c.h:81
i2c_desc::slave_address
uint8_t slave_address
Definition: i2c.h:83
i2c_write
int32_t i2c_write(struct i2c_desc *desc, uint8_t *data, uint8_t bytes_number, uint8_t stop_bit)
I2C Write data to slave device.
Definition: i2c.c:85
i2c_desc::extra
void * extra
Definition: i2c.h:87
i2c_init_param
Structure holding the parameters for I2C initialization.
Definition: i2c.h:64
i2c_init_param
struct i2c_init_param i2c_init_param