embeddedlibrary
reusable software modules for embedded systems
i2c.h
1 /*
2  * File: i2c.h
3  * Author: Anthony Merlino
4  *
5  * Created on February 24, 2015, 11:03 PM
6  */
7 
8 #ifndef _I2C_H_
9 #define _I2C_H_
10 
11 #include "system.h"
12 #include "hal_i2c.h"
13 
14 #ifndef I2C_MAX_TX_SIZE
15 #define I2C_MAX_TX_SIZE 4
16 #endif
17 
18 #ifndef I2C_MAX_RX_SIZE
19 #define I2C_MAX_RX_SIZE 4
20 #endif
21 
22 #ifndef I2C_MAX_TRANSACTIONS
23 #define I2C_MAX_TRANSACTIONS 4
24 #endif
25 
27  uint8_t writeData[I2C_MAX_TX_SIZE];
28  uint8_t readData[I2C_MAX_RX_SIZE];
29  uint16_t slave_address;
30  struct {
31  uint16_t writeLength : 4;
32  uint16_t readLength : 4;
33  uint16_t channel : 3;
34  uint16_t retryCount : 3;
35  uint16_t blocking : 1;
36  uint16_t finished : 1;
37  uint16_t error : 1;
38  };
39  void (*callback)(struct i2c_transaction);
40 };
41 
42 typedef struct i2c_transaction i2c_transaction_t;
43 
44 #define TRANSACTION_FAILED 1
45 #define TRANSACTION_SUCCESSFUL 0
46 
47 void I2C_Init(i2c_settings_t* i2c_settings);
48 void I2C_Transact(i2c_transaction_t* transaction);
49 
50 uint8_t I2C_Tx_Handler(uint8_t channel);
51 void I2C_Rx_Handler(uint8_t channel, uint8_t byte);
52 
53 /******************************************
54  * HAL Support Functions
55  *****************************************/
56 uint16_t I2C_GetSlaveAddress(uint8_t channel);
57 void I2C_Rx_Handler(uint8_t channel, uint8_t byte);
58 uint8_t I2C_GetTxByte(uint8_t channel);
59 uint8_t I2C_GetTxSize(uint8_t channel);
60 uint8_t I2C_GetRxSize(uint8_t channel);
61 void I2C_TransactionSuccess(uint8_t channel);
62 void I2C_TransactionFail(uint8_t channel);
63 
64 /******************************************
65  * HAL Functions
66  *****************************************/
67 void hal_I2C_Init(i2c_settings_t* settings);
68 void hal_I2C_Enable(uint8_t channel);
69 void hal_I2C_Disable(uint8_t channel);
70 void hal_I2C_SendStart(uint8_t channel);
71 
72 void hal_I2C_EnableInterrupts(uint8_t channel);
73 void hal_I2C_DisableInterrupts(uint8_t channel);
74 
75 #endif // _I2C_H_
Definition: i2c.h:26
Definition: hal_i2c.h:16