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
235 Kevin 23
#define I2C1_STOPPED            0xD
234 Kevin 24
 
25
// Operating Mode
26
#define I2C1_MODE_SLAVE          0x10
27
#define I2C1_MODE_MASTER         0x11
28
 
29
// Master Status
30
#define I2C1_MASTER_SEND         0x20
31
#define I2C1_MASTER_RECV         0x21
32
#define I2C1_MASTER_RESTART      0x22
33
#define I2C1_MASTER_IDLE         0x23
34
 
35
// Return Status
36
#define I2C1_SEND_OK             0x30
37
#define I2C1_SEND_FAIL           0x31
38
#define I2C1_RECV_OK             0x32
39
#define I2C1_RECV_FAIL           0x33
40
#define I2C1_DATA_AVAL           0x34
41
#define I2C1_ERR_NOADDR          0x35
42
#define I2C1_ERR_OVERRUN         0x36
43
#define I2C1_ERR_NODATA          0x37
44
#define I2C1_ERR_BUFFER_OVERRUN  0x38
45
 
46
typedef struct {
47
    uint8_t buffer_in[MAXI2C1BUF];
48
    uint32_t buffer_in_len;
49
    uint32_t buffer_in_read_ind;
50
    uint32_t buffer_in_write_ind;
51
 
52
    uint8_t buffer_out[MAXI2C1BUF];
53
    uint32_t buffer_out_len;
54
    uint32_t buffer_out_ind;
55
 
56
    uint8_t operating_state;
57
    uint8_t return_status;
58
 
59
    uint8_t master_dest_addr;
60
    uint8_t master_status;
61
 
62
    uint8_t slave_in_last_byte;
63
    uint8_t slave_sending_data;
64
} I2C1_DATA;
65
 
66
void I2C1_Init(I2C1_DATA *data, uint8_t speed, uint8_t address);
67
void I2C1_Master_Send(uint8_t address, uint8_t *msg, uint32_t length);
68
void I2C1_Master_Recv(uint8_t address, uint32_t length);
69
void I2C1_Master_Restart(uint8_t address, uint8_t msg, uint32_t length);
70
void I2C1_Interrupt_Master(void);
71
void I2C1_Interrupt_Slave(void);
72
uint8_t I2C1_Get_Status(void);
73
uint8_t I2C1_Buffer_Len(void);
74
uint8_t I2C1_Read_Buffer(uint8_t *buffer);
75
uint8_t I2C1_Process_Request(uint8_t);
76
 
77
#endif	/* I2C1_H */
78