| 119 |
Kevin |
1 |
#ifndef __i2c_h
|
|
|
2 |
#define __i2c_h
|
|
|
3 |
|
|
|
4 |
#define MAXI2CBUF MSGLEN
|
|
|
5 |
|
|
|
6 |
#define I2C_IDLE 0x5
|
|
|
7 |
#define I2C_STARTED 0x6
|
|
|
8 |
#define I2C_RCV_DATA 0x7
|
|
|
9 |
#define I2C_SEND_DATA 0x8
|
|
|
10 |
#define I2C_SEND_ADDR 0x9
|
|
|
11 |
#define I2C_CHECK_ACK 0xB
|
|
|
12 |
#define I2C_REQ_DATA 0xC
|
|
|
13 |
#define I2C_SEND_STOP 0xD
|
|
|
14 |
|
|
|
15 |
#define I2C_MODE_SLAVE 0x10
|
|
|
16 |
#define I2C_MODE_MASTER 0x11
|
|
|
17 |
|
|
|
18 |
#define I2C_MASTER_SEND 0x20
|
|
|
19 |
#define I2C_MASTER_RECV 0x21
|
|
|
20 |
#define I2C_MASTER_IDLE 0x22
|
|
|
21 |
|
|
|
22 |
#define I2C_ERR_THRESHOLD 1
|
|
|
23 |
#define I2C_ERR_OVERRUN 0x4
|
|
|
24 |
#define I2C_ERR_NOADDR 0x5
|
|
|
25 |
#define I2C_ERR_NODATA 0x6
|
|
|
26 |
#define I2C_ERR_MSGTOOLONG 0x7
|
|
|
27 |
#define I2C_ERR_MSG_TRUNC 0x8
|
|
|
28 |
|
|
|
29 |
typedef struct __I2C_DATA {
|
|
|
30 |
unsigned char buffer[MAXI2CBUF];
|
|
|
31 |
int buflen;
|
|
|
32 |
unsigned char status;
|
|
|
33 |
unsigned char bufind;
|
|
|
34 |
unsigned char slave_event_count;
|
|
|
35 |
unsigned char slave_error_code;
|
|
|
36 |
unsigned char slave_error_count;
|
|
|
37 |
unsigned char slave_in_last_byte;
|
|
|
38 |
unsigned char slave_outbufmsgtype;
|
|
|
39 |
unsigned char slave_sending_data;
|
|
|
40 |
unsigned char slave_sending_blank_data;
|
|
|
41 |
|
|
|
42 |
unsigned char master_dest_addr;
|
|
|
43 |
unsigned char master_state;
|
|
|
44 |
unsigned char mode;
|
|
|
45 |
} I2C_DATA;
|
|
|
46 |
|
|
|
47 |
void i2c_init(I2C_DATA *);
|
|
|
48 |
void i2c_interrupt_handler(void);
|
|
|
49 |
void i2c_interrupt_slave(void);
|
|
|
50 |
void i2c_interrupt_master(void);
|
|
|
51 |
void i2c_configure_slave(unsigned char);
|
|
|
52 |
void i2c_configure_master(void);
|
|
|
53 |
void i2c_master_send(unsigned char address, unsigned char length,unsigned char *msg);
|
|
|
54 |
void i2c_master_recv(unsigned char address, unsigned char length);
|
|
|
55 |
unsigned char i2c_master_busy(void);
|
|
|
56 |
|
|
|
57 |
#endif
|