no-OS
no_os_i2c.h
Go to the documentation of this file.
1 /***************************************************************************/
34 #ifndef _NO_OS_I2C_H_
35 #define _NO_OS_I2C_H_
36 
37 /******************************************************************************/
38 /***************************** Include Files **********************************/
39 /******************************************************************************/
40 
41 #include <stdint.h>
42 
43 /******************************************************************************/
44 /********************** Macros and Constants Definitions **********************/
45 /******************************************************************************/
46 
47 #define I2C_MAX_BUS_NUMBER 4
48 
49 /******************************************************************************/
50 /*************************** Types Declarations *******************************/
51 /******************************************************************************/
52 
59 
66  uint32_t device_id;
68  uint32_t max_speed_hz;
70  uint8_t slave_address;
74  void *extra;
75 };
76 
83  void* mutex;
85  uint8_t slave_number;
87  uint32_t device_id;
89  uint32_t max_speed_hz;
93  void *extra;
94 };
95 
96 
105  uint32_t device_id;
107  uint32_t max_speed_hz;
109  uint8_t slave_address;
113  void *extra;
114 };
115 
123  int32_t (*i2c_ops_init)(struct no_os_i2c_desc **,
124  const struct no_os_i2c_init_param *);
126  int32_t (*i2c_ops_write)(struct no_os_i2c_desc *, uint8_t *, uint8_t, uint8_t);
128  int32_t (*i2c_ops_read)(struct no_os_i2c_desc *, uint8_t *, uint8_t, uint8_t);
130  int32_t (*i2c_ops_remove)(struct no_os_i2c_desc *);
131 };
132 
133 /******************************************************************************/
134 /************************ Functions Declarations ******************************/
135 /******************************************************************************/
136 
137 /* Initialize the I2C communication peripheral. */
138 int32_t no_os_i2c_init(struct no_os_i2c_desc **desc,
139  const struct no_os_i2c_init_param *param);
140 
141 /* Free the resources allocated by no_os_i2c_init(). */
142 int32_t no_os_i2c_remove(struct no_os_i2c_desc *desc);
143 
144 /* Write data to a slave device. */
145 int32_t no_os_i2c_write(struct no_os_i2c_desc *desc,
146  uint8_t *data,
147  uint8_t bytes_number,
148  uint8_t stop_bit);
149 
150 /* Read data from a slave device. */
151 int32_t no_os_i2c_read(struct no_os_i2c_desc *desc,
152  uint8_t *data,
153  uint8_t bytes_number,
154  uint8_t stop_bit);
155 
156 /* Initialize I2C bus descriptor*/
157 int32_t no_os_i2cbus_init(const struct no_os_i2c_init_param *param);
158 
159 /* Free the resources allocated for I2C bus desc*/
160 void no_os_i2cbus_remove(uint32_t bus_number);
161 
162 #endif // _NO_OS_I2C_H_
no_os_i2cbus_desc
Structure holding I2C bus descriptor.
Definition: no_os_i2c.h:81
no_os_i2c_write
int32_t no_os_i2c_write(struct no_os_i2c_desc *desc, uint8_t *data, uint8_t bytes_number, uint8_t stop_bit)
I2C Write data to slave device.
Definition: no_os_i2c.c:159
no_os_i2c_init
int32_t no_os_i2c_init(struct no_os_i2c_desc **desc, const struct no_os_i2c_init_param *param)
Initialize the I2C communication peripheral.
Definition: no_os_i2c.c:52
no_os_i2c_platform_ops::i2c_ops_read
int32_t(* i2c_ops_read)(struct no_os_i2c_desc *, uint8_t *, uint8_t, uint8_t)
Definition: no_os_i2c.h:128
no_os_i2c_init_param::slave_address
uint8_t slave_address
Definition: no_os_i2c.h:70
no_os_i2c_remove
int32_t no_os_i2c_remove(struct no_os_i2c_desc *desc)
Free the resources allocated by no_os_i2c_init().
Definition: no_os_i2c.c:113
no_os_i2c_platform_ops::i2c_ops_write
int32_t(* i2c_ops_write)(struct no_os_i2c_desc *, uint8_t *, uint8_t, uint8_t)
Definition: no_os_i2c.h:126
no_os_i2cbus_remove
void no_os_i2cbus_remove(uint32_t bus_number)
Removes i2c bus instance.
Definition: no_os_i2c.c:131
no_os_i2c_desc::device_id
uint32_t device_id
Definition: no_os_i2c.h:105
no_os_i2c_init_param::extra
void * extra
Definition: no_os_i2c.h:74
no_os_i2cbus_desc::max_speed_hz
uint32_t max_speed_hz
Definition: no_os_i2c.h:89
no_os_i2c_desc::slave_address
uint8_t slave_address
Definition: no_os_i2c.h:109
no_os_i2cbus_init
int32_t no_os_i2cbus_init(const struct no_os_i2c_init_param *param)
Initialize the i2c bus communication peripheral.
Definition: no_os_i2c.c:86
no_os_i2c_init_param::max_speed_hz
uint32_t max_speed_hz
Definition: no_os_i2c.h:68
no_os_i2c_desc::bus
struct no_os_i2cbus_desc * bus
Definition: no_os_i2c.h:103
no_os_i2c_desc::max_speed_hz
uint32_t max_speed_hz
Definition: no_os_i2c.h:107
no_os_i2c_platform_ops
Structure holding I2C function pointers that point to the platform specific function.
Definition: no_os_i2c.h:121
no_os_i2c_platform_ops::i2c_ops_init
int32_t(* i2c_ops_init)(struct no_os_i2c_desc **, const struct no_os_i2c_init_param *)
Definition: no_os_i2c.h:123
no_os_i2c_desc::platform_ops
const struct no_os_i2c_platform_ops * platform_ops
Definition: no_os_i2c.h:111
no_os_i2c_desc
Structure holding I2C address descriptor.
Definition: no_os_i2c.h:101
no_os_i2cbus_desc::extra
void * extra
Definition: no_os_i2c.h:93
no_os_i2c_read
int32_t no_os_i2c_read(struct no_os_i2c_desc *desc, uint8_t *data, uint8_t bytes_number, uint8_t stop_bit)
I2C Read data from slave device.
Definition: no_os_i2c.c:190
no_os_i2cbus_desc::device_id
uint32_t device_id
Definition: no_os_i2c.h:87
no_os_i2cbus_desc::platform_ops
const struct no_os_i2c_platform_ops * platform_ops
Definition: no_os_i2c.h:91
no_os_i2c_platform_ops::i2c_ops_remove
int32_t(* i2c_ops_remove)(struct no_os_i2c_desc *)
Definition: no_os_i2c.h:130
no_os_i2cbus_desc::mutex
void * mutex
Definition: no_os_i2c.h:83
no_os_i2c_init_param
Structure holding the parameters for I2C initialization.
Definition: no_os_i2c.h:64
no_os_i2cbus_desc::slave_number
uint8_t slave_number
Definition: no_os_i2c.h:85
no_os_i2c_init_param::platform_ops
const struct no_os_i2c_platform_ops * platform_ops
Definition: no_os_i2c.h:72
no_os_i2c_desc::extra
void * extra
Definition: no_os_i2c.h:113
no_os_i2c_init_param::device_id
uint32_t device_id
Definition: no_os_i2c.h:66