| 156 |
Kevin |
1 |
#ifndef I2C_H
|
|
|
2 |
#define I2C_H
|
| 119 |
Kevin |
3 |
|
| 120 |
Kevin |
4 |
#define MAXI2CBUF 64
|
| 119 |
Kevin |
5 |
|
| 121 |
Kevin |
6 |
// I2C Operating Speed
|
|
|
7 |
#define I2C_400KHZ 0x0
|
|
|
8 |
#define I2C_100KHZ 0x1
|
|
|
9 |
|
| 120 |
Kevin |
10 |
// Operating State
|
|
|
11 |
#define I2C_IDLE 0x1
|
|
|
12 |
#define I2C_STARTED 0x2
|
|
|
13 |
#define I2C_RCV_DATA 0x3
|
|
|
14 |
#define I2C_SEND_DATA 0x4
|
|
|
15 |
#define I2C_SEND_ADDR 0x5
|
|
|
16 |
#define I2C_SEND_ADDR_2 0x6
|
|
|
17 |
#define I2C_CHECK_ACK_SEND 0x7
|
|
|
18 |
#define I2C_CHECK_ACK_RECV 0x8
|
|
|
19 |
#define I2C_CHECK_ACK_RESTART 0x9
|
|
|
20 |
#define I2C_REQ_DATA 0xA
|
|
|
21 |
#define I2C_SEND_STOP 0xB
|
|
|
22 |
#define I2C_SEND_START 0xC
|
| 119 |
Kevin |
23 |
|
| 120 |
Kevin |
24 |
// Operating Mode
|
|
|
25 |
#define I2C_MODE_SLAVE 0x10
|
|
|
26 |
#define I2C_MODE_MASTER 0x11
|
| 119 |
Kevin |
27 |
|
| 120 |
Kevin |
28 |
// Master Status
|
|
|
29 |
#define I2C_MASTER_SEND 0x20
|
|
|
30 |
#define I2C_MASTER_RECV 0x21
|
|
|
31 |
#define I2C_MASTER_RESTART 0x22
|
|
|
32 |
#define I2C_MASTER_IDLE 0x23
|
| 119 |
Kevin |
33 |
|
| 120 |
Kevin |
34 |
// Return Status
|
|
|
35 |
#define I2C_SEND_OK 0x30
|
|
|
36 |
#define I2C_SEND_FAIL 0x31
|
|
|
37 |
#define I2C_RECV_OK 0x32
|
|
|
38 |
#define I2C_RECV_FAIL 0x33
|
|
|
39 |
#define I2C_DATA_AVAL 0x34
|
|
|
40 |
#define I2C_ERR_NOADDR 0x35
|
|
|
41 |
#define I2C_ERR_OVERRUN 0x36
|
|
|
42 |
#define I2C_ERR_NODATA 0x37
|
|
|
43 |
#define I2C_ERR_BUFFER_OVERRUN 0x38
|
| 119 |
Kevin |
44 |
|
|
|
45 |
typedef struct __I2C_DATA {
|
| 120 |
Kevin |
46 |
unsigned char buffer_in[MAXI2CBUF];
|
|
|
47 |
unsigned char buffer_in_len;
|
|
|
48 |
unsigned char buffer_in_len_tmp;
|
|
|
49 |
unsigned char buffer_in_read_ind;
|
|
|
50 |
unsigned char buffer_in_write_ind;
|
|
|
51 |
|
|
|
52 |
unsigned char buffer_out[MAXI2CBUF];
|
|
|
53 |
unsigned char buffer_out_len;
|
|
|
54 |
unsigned char buffer_out_ind;
|
|
|
55 |
|
|
|
56 |
unsigned char operating_mode;
|
|
|
57 |
unsigned char operating_state;
|
|
|
58 |
unsigned char return_status;
|
|
|
59 |
|
|
|
60 |
unsigned char master_dest_addr;
|
|
|
61 |
unsigned char master_status;
|
|
|
62 |
|
| 119 |
Kevin |
63 |
unsigned char slave_in_last_byte;
|
|
|
64 |
unsigned char slave_sending_data;
|
|
|
65 |
} I2C_DATA;
|
|
|
66 |
|
| 120 |
Kevin |
67 |
void I2C_Init(void);
|
|
|
68 |
void I2C_Interrupt_Handler(void);
|
|
|
69 |
void I2C_Interrupt_Slave(void);
|
|
|
70 |
void I2C_Interrupt_Master(void);
|
|
|
71 |
void I2C_Configure_Slave(unsigned char);
|
| 121 |
Kevin |
72 |
void I2C_Configure_Master(unsigned char speed);
|
| 147 |
Kevin |
73 |
void I2C_Master_Send(unsigned char address, unsigned char length, unsigned char *msg);
|
| 120 |
Kevin |
74 |
void I2C_Master_Recv(unsigned char address, unsigned char length);
|
|
|
75 |
void I2C_Master_Restart(unsigned char address, unsigned char msg, unsigned char length);
|
|
|
76 |
unsigned char I2C_Get_Status(void);
|
| 121 |
Kevin |
77 |
unsigned char I2C_Buffer_Len(void);
|
| 120 |
Kevin |
78 |
unsigned char I2C_Read_Buffer(char *buffer);
|
|
|
79 |
unsigned char I2C_Process_Send(unsigned char);
|
| 119 |
Kevin |
80 |
|
|
|
81 |
#endif
|