Subversion Repositories Code-Repo

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
234 Kevin 1
#ifndef I2C1_H
2
#define	I2C1_H
3
 
4
#define MAXI2C1BUF 32
5
 
6
// I2C Operating Speed
7
#define I2C1_400KHZ              0x0
8
#define I2C1_100KHZ              0x1
9
 
10
// Operating State
11
#define I2C1_IDLE                0x1
12
//#define I2C1_STARTED             0x2
13
#define	I2C1_RCV_DATA            0x3
14
//#define I2C1_SEND_DATA           0x4
15
#define I2C1_SEND_ADDR           0x5
16
#define I2C1_SEND_ADDR_2         0x6
17
#define I2C1_CHECK_ACK_SEND      0x7
18
#define I2C1_CHECK_ACK_RECV      0x8
19
#define I2C1_CHECK_ACK_RESTART   0x9
20
#define I2C1_REQ_DATA            0xA
21
#define I2C1_SEND_STOP           0xB
22
//#define I2C1_SEND_START          0xC
23
 
24
// Operating Mode
25
#define I2C1_MODE_SLAVE          0x10
26
#define I2C1_MODE_MASTER         0x11
27
 
28
// Master Status
29
#define I2C1_MASTER_SEND         0x20
30
#define I2C1_MASTER_RECV         0x21
31
#define I2C1_MASTER_RESTART      0x22
32
#define I2C1_MASTER_IDLE         0x23
33
 
34
// Return Status
35
#define I2C1_SEND_OK             0x30
36
#define I2C1_SEND_FAIL           0x31
37
#define I2C1_RECV_OK             0x32
38
#define I2C1_RECV_FAIL           0x33
39
#define I2C1_DATA_AVAL           0x34
40
#define I2C1_ERR_NOADDR          0x35
41
#define I2C1_ERR_OVERRUN         0x36
42
#define I2C1_ERR_NODATA          0x37
43
#define I2C1_ERR_BUFFER_OVERRUN  0x38
44
 
45
typedef struct {
46
    uint8_t buffer_in[MAXI2C1BUF];
47
    uint32_t buffer_in_len;
48
    uint32_t buffer_in_read_ind;
49
    uint32_t buffer_in_write_ind;
50
 
51
    uint8_t buffer_out[MAXI2C1BUF];
52
    uint32_t buffer_out_len;
53
    uint32_t buffer_out_ind;
54
 
55
    uint8_t operating_state;
56
    uint8_t return_status;
57
 
58
    uint8_t master_dest_addr;
59
    uint8_t master_status;
60
 
61
    uint8_t slave_in_last_byte;
62
    uint8_t slave_sending_data;
63
} I2C1_DATA;
64
 
65
void I2C1_Init(I2C1_DATA *data, uint8_t speed, uint8_t address);
66
void I2C1_Master_Send(uint8_t address, uint8_t *msg, uint32_t length);
67
void I2C1_Master_Recv(uint8_t address, uint32_t length);
68
void I2C1_Master_Restart(uint8_t address, uint8_t msg, uint32_t length);
69
void I2C1_Interrupt_Master(void);
70
void I2C1_Interrupt_Slave(void);
71
uint8_t I2C1_Get_Status(void);
72
uint8_t I2C1_Buffer_Len(void);
73
uint8_t I2C1_Read_Buffer(uint8_t *buffer);
74
uint8_t I2C1_Process_Request(uint8_t);
75
 
76
#endif	/* I2C1_H */
77