Subversion Repositories Code-Repo

Rev

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