Subversion Repositories Code-Repo

Rev

Details | Last modification | View Log | RSS feed

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