TMPM4G9  V1.0.0.0
bsp_i2c.h
Go to the documentation of this file.
1 
13 /*------------------------------------------------------------------------------*/
14 /* Define to prevent recursive inclusion */
15 /*------------------------------------------------------------------------------*/
16 #ifndef __BSP_I2C_H
17 #define __BSP_I2C_H
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 /*------------------------------------------------------------------------------*/
24 /* Includes */
25 /*------------------------------------------------------------------------------*/
26 #include "txz_i2c.h"
27 #include "txz_cg.h"
28 
38 /*------------------------------------------------------------------------------*/
39 /* Macro Function */
40 /*------------------------------------------------------------------------------*/
46 /* no define */
47  /* End of group UTILITIES_Exported_macro */
51 
52 
53 /*------------------------------------------------------------------------------*/
54 /* Configuration */
55 /*------------------------------------------------------------------------------*/
65 #define I2C_NULL ((void *)0)
66  /* End of group I2C_NullPointer */
69  /* End of group UTILITIES_Exported_define */
73 
74 
75 /*------------------------------------------------------------------------------*/
76 /* Macro Definition */
77 /*------------------------------------------------------------------------------*/
88 #define I2C_NACK (0)
89 #define I2C_ACK (1) /* End of group I2C_ACK */
93 
94 
100 #define I2C_ERROR_NO_ERROR (0)
101 #define I2C_ERROR_NO_SLAVE (-1)
102 #define I2C_ERROR_BUS_BUSY (-2)
103 #define I2C_ERROR_PARAM (-3)
104 #define I2C_ERROR_OTHERS (-4)
105 #define I2C_ERROR_ARBITRATION (-5) /* End of group I2C_ERROR */
109 
110 
116 #define I2C_EVENT_ERROR (1 << 1)
117 #define I2C_EVENT_ERROR_NO_SLAVE (1 << 2)
118 #define I2C_EVENT_TRANSFER_COMPLETE (1 << 3)
119 #define I2C_EVENT_TRANSFER_EARLY_NACK (1 << 4)
120 #define I2C_EVENT_ALL (I2C_EVENT_ERROR | I2C_EVENT_TRANSFER_COMPLETE | I2C_EVENT_ERROR_NO_SLAVE | I2C_EVENT_TRANSFER_EARLY_NACK)
121  /* End of group I2C_Events */
124 
130 #define I2C_NO_DATA (0)
131 #define I2C_READ_ADDRESSED (1)
132 #define I2C_WRITE_GENERAL (2)
133 #define I2C_WRITE_ADDRESSED (3) /* End of group I2C_SlaveReceive */
137  /* End of group UTILITIES_Exported_define */
141 
142 
143 /*------------------------------------------------------------------------------*/
144 /* Enumerated Type Definition */
145 /*------------------------------------------------------------------------------*/
151 /*----------------------------------*/
155 /*----------------------------------*/
156 typedef enum {
167 i2c_port_t;
168 
169 /*----------------------*/
170 /* I2C Setting */
171 /*----------------------*/
172 /* #define I2C_CHANNEL0 */
173 #define I2C_CHANNEL3
174 /* #define I2C_CHANNEL2 */
175 /* #define I2C_CHANNEL3 */
176 /* #define I2C_CHANNEL4 */
177 #if defined(I2C_CHANNEL0)
178  #define I2Cx_TEXT "I2C0"
179  #define I2C_CFG_PORT_SCL (I2C_PORT_PG3)
180  #define I2C_CFG_PORT_SDA (I2C_PORT_PG2)
181 #elif defined(I2C_CHANNEL1)
182  #define I2Cx_TEXT "I2C1"
183  #define I2C_CFG_PORT_SCL (I2C_PORT_PF3)
184  #define I2C_CFG_PORT_SDA (I2C_PORT_PF2)
185 #elif defined(I2C_CHANNEL2)
186  #define I2Cx_TEXT "I2C2"
187  #define I2C_CFG_PORT_SCL (I2C_PORT_PG5)
188  #define I2C_CFG_PORT_SDA (I2C_PORT_PG4)
189 #elif defined(I2C_CHANNEL3)
190  #define I2Cx_TEXT "I2C3"
191  #define I2C_CFG_PORT_SCL (I2C_PORT_PJ7)
192  #define I2C_CFG_PORT_SDA (I2C_PORT_PJ6)
193 #elif defined(I2C_CHANNEL4)
194  #define I2Cx_TEXT "I2C4"
195  #define I2C_CFG_PORT_SCL (I2C_PORT_PJ3)
196  #define I2C_CFG_PORT_SDA (I2C_PORT_PJ2)
197 #else
198  #error "target channel is non-select."
199 #endif
200  /* End of group UTILITIES_Exported_define */
204 
205 /*------------------------------------------------------------------------------*/
206 /* Structure Definition */
207 /*------------------------------------------------------------------------------*/
212 /*----------------------------------*/
216 /*----------------------------------*/
217 typedef struct
218 {
219  uint8_t bus_free;
220  uint8_t start;
221  uint32_t irqn;
222  struct
223  {
224  uint32_t address;
225  uint32_t stop;
226  uint32_t event;
227  uint32_t state;
228  } asynch;
230 
231 /*----------------------------------*/
235 /*----------------------------------*/
236 typedef struct
237 {
238  uint8_t *p_buffer;
239  uint32_t length;
240  uint32_t pos;
241 } i2c_buffer_t;
242 
243 /*----------------------------------*/
247 /*----------------------------------*/
248 typedef struct
249 {
254 } i2c_t;
255  /* End of group UTILITIES_Exported_typedef */
259 
260 
261 /*------------------------------------------------------------------------------*/
262 /* Functions */
263 /*------------------------------------------------------------------------------*/
268 TXZ_Result i2c_init(i2c_t *p_obj, i2c_port_t sda, i2c_port_t scl);
269 TXZ_Result i2c_frequency(i2c_t *p_obj, int32_t hz);
270 void i2c_reset(i2c_t *p_obj);
272 TXZ_Result i2c_start(i2c_t *p_obj);
273 TXZ_Result i2c_stop(i2c_t *p_obj);
274 int32_t i2c_read(i2c_t *p_obj, int32_t address, uint8_t *p_data, int32_t length, int32_t stop);
275 int32_t i2c_write(i2c_t *p_obj, int32_t address, uint8_t *p_data, int32_t length, int32_t stop);
276 int32_t i2c_byte_read(i2c_t *p_obj, int32_t last);
277 int32_t i2c_byte_write(i2c_t *p_obj, int32_t data);
278 uint8_t i2c_active(i2c_t *p_obj);
279 TXZ_Result i2c_transfer_asynch(i2c_t *p_obj, uint8_t *p_tx, int32_t tx_length, uint8_t *p_rx, int32_t rx_length, int32_t address, int32_t stop);
280 uint32_t i2c_irq_handler_asynch(i2c_t *p_obj);
281 void i2c_abort_asynch(i2c_t *p_obj);
282 
283 /* For slave */
284 void i2c_slave_mode(i2c_t *p_obj, int32_t enable_slave);
285 int32_t i2c_slave_receive(i2c_t *p_obj);
286 int32_t i2c_slave_read(i2c_t *p_obj, uint8_t *p_data, int32_t length);
287 int32_t i2c_slave_write(i2c_t *p_obj, uint8_t *p_data, int32_t length);
288 void i2c_slave_address(i2c_t *p_obj, uint32_t address);
289 TXZ_Result i2c_slave_transfer_asynch(i2c_t *p_obj, uint8_t *p_tx, int32_t tx_length, uint8_t *p_rx, int32_t rx_length);
290 uint32_t i2c_slave_irq_handler_asynch(i2c_t *p_obj);
291 void i2c_slave_abort_asynch(i2c_t *p_obj);
292  /* End of group UTILITIES_Exported_functions */
296  /* End of group UTILITIES */
300  /* End of group Example */
304 
305 #ifdef __cplusplus
306 }
307 #endif /* __cplusplus */
308 #endif /* __BSP_I2C_H */
309 
310 
TXZ_Result i2c_slave_transfer_asynch(i2c_t *p_obj, uint8_t *p_tx, int32_t tx_length, uint8_t *p_rx, int32_t rx_length)
Start I2C asynchronous transfer.
Definition: bsp_i2c.c:1789
int32_t i2c_write(i2c_t *p_obj, int32_t address, uint8_t *p_data, int32_t length, int32_t stop)
Blocking sending data.
Definition: bsp_i2c.c:1266
I2C_t i2c
Definition: bsp_i2c.h:250
Definition: bsp_i2c.h:158
Definition: bsp_i2c.h:165
uint32_t i2c_slave_irq_handler_asynch(i2c_t *p_obj)
The asynchronous IRQ handler.
Definition: bsp_i2c.c:1835
Definition: bsp_i2c.h:159
Definition: bsp_i2c.h:160
uint8_t bus_free
Definition: bsp_i2c.h:219
TXZ_Result i2c_transfer_asynch(i2c_t *p_obj, uint8_t *p_tx, int32_t tx_length, uint8_t *p_rx, int32_t rx_length, int32_t address, int32_t stop)
Start I2C asynchronous transfer.
Definition: bsp_i2c.c:1486
TXZ_Result
Definition: txz_driver_def.h:43
Definition: bsp_i2c.h:164
int32_t i2c_slave_read(i2c_t *p_obj, uint8_t *p_data, int32_t length)
Blocking reading data.
Definition: bsp_i2c.c:1673
Definition: bsp_i2c.h:163
Definition: bsp_i2c.h:166
void i2c_slave_address(i2c_t *p_obj, uint32_t address)
Configure I2C slave address.
Definition: bsp_i2c.c:1760
void i2c_reset(i2c_t *p_obj)
Reset I2C peripheral.
Definition: bsp_i2c.c:1023
TXZ_Result i2c_init(i2c_t *p_obj, i2c_port_t sda, i2c_port_t scl)
Initialize the I2C Driver.
Definition: bsp_i2c.c:945
i2c_buffer_t tx_buff
Definition: bsp_i2c.h:252
I2C handle structure definenition.
Definition: bsp_i2c.h:248
I2C buffer structure definenition.
Definition: bsp_i2c.h:236
Definition: bsp_i2c.h:157
TXZ_Result i2c_start(i2c_t *p_obj)
Creates a start condition on the I2C bus.
Definition: bsp_i2c.c:1126
int32_t i2c_slave_receive(i2c_t *p_obj)
Check to see if the I2C slave has been addressed.
Definition: bsp_i2c.c:1635
This file provides all the functions prototypes for I2C Class.
void i2c_slave_abort_asynch(i2c_t *p_obj)
Abort asynchronous transfer.
Definition: bsp_i2c.c:1860
Definition: bsp_i2c.h:161
uint32_t irqn
Definition: bsp_i2c.h:221
uint32_t state
Definition: bsp_i2c.h:227
uint32_t i2c_irq_handler_asynch(i2c_t *p_obj)
The asynchronous IRQ handler.
Definition: bsp_i2c.c:1543
uint8_t i2c_active(i2c_t *p_obj)
Attempts to determine if the I2C bus is already in use.
Definition: bsp_i2c.c:1447
i2c_buffer_t rx_buff
Definition: bsp_i2c.h:253
This file provides all the functions prototypes for CG driver.
uint32_t length
Definition: bsp_i2c.h:239
uint8_t * p_buffer
Definition: bsp_i2c.h:238
i2c_port_t
i2c Port Enumerated Type Definition.
Definition: bsp_i2c.h:156
int32_t i2c_byte_read(i2c_t *p_obj, int32_t last)
Read one byte.
Definition: bsp_i2c.c:1334
int32_t i2c_slave_write(i2c_t *p_obj, uint8_t *p_data, int32_t length)
Blocking sending data.
Definition: bsp_i2c.c:1716
uint8_t start
Definition: bsp_i2c.h:220
Definition: bsp_i2c.h:162
i2c_internal_info_t info
Definition: bsp_i2c.h:251
TXZ_Result i2c_stop(i2c_t *p_obj)
Creates a stop condition on the I2C bus.
Definition: bsp_i2c.c:1152
int32_t i2c_read(i2c_t *p_obj, int32_t address, uint8_t *p_data, int32_t length, int32_t stop)
Blocking reading data.
Definition: bsp_i2c.c:1193
void i2c_slave_mode(i2c_t *p_obj, int32_t enable_slave)
Configure I2C as slave or master.
Definition: bsp_i2c.c:1597
TXZ_Result i2c_frequency(i2c_t *p_obj, int32_t hz)
Configure the I2C frequency.
Definition: bsp_i2c.c:1047
uint32_t event
Definition: bsp_i2c.h:226
I2C handle structure definition.
Definition: txz_i2c.h:342
int32_t i2c_byte_write(i2c_t *p_obj, int32_t data)
Write one byte.
Definition: bsp_i2c.c:1372
void i2c_abort_asynch(i2c_t *p_obj)
Abort asynchronous transfer.
Definition: bsp_i2c.c:1567
uint32_t pos
Definition: bsp_i2c.h:240
uint32_t address
Definition: bsp_i2c.h:224
TXZ_Result i2c_check_bus_free(i2c_t *p_obj)
Check bus free on the I2C bus.
Definition: bsp_i2c.c:1100
uint32_t stop
Definition: bsp_i2c.h:225
I2C internal information structure definenition.
Definition: bsp_i2c.h:217