Subversion Repositories Code-Repo

Rev

Rev 281 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
281 Kevin 1
#ifndef I2C1_H
2
#define I2C1_H
3
 
4
#define MAXI2C1BUF 8
5
 
6
// I2C Operating Speed
7
#define I2C_100KHZ              0x0
8
#define I2C_400KHZ              0x1
9
#define I2C_1MHZ                0x2
10
 
11
// Operating State
12
#define I2C_IDLE                0x1
13
#define I2C_STARTED             0x2
14
#define	I2C_RCV_DATA            0x3
15
#define I2C_SEND_DATA           0x4
16
#define I2C_SEND_ADDR           0x5
17
#define I2C_SEND_ADDR_2         0x6
18
#define I2C_CHECK_ACK_SEND      0x7
19
#define I2C_CHECK_ACK_RECV      0x8
20
#define I2C_CHECK_ACK_RESTART   0x9
21
#define I2C_REQ_DATA            0xA
22
#define I2C_SEND_STOP           0xB
23
#define I2C_SEND_START          0xC
24
 
25
// Operating Mode
26
#define I2C_MODE_SLAVE          0x10
27
#define I2C_MODE_MASTER         0x11
28
 
29
// Master Status
30
#define I2C_MASTER_SEND         0x20
31
#define I2C_MASTER_RECV         0x21
32
#define I2C_MASTER_RESTART      0x22
33
#define I2C_MASTER_IDLE         0x23
34
 
35
// Return Status
36
#define I2C_SEND_OK             0x30
37
#define I2C_SEND_FAIL           0x31
38
#define I2C_RECV_OK             0x32
39
#define I2C_RECV_FAIL           0x33
40
#define I2C_DATA_AVAL           0x34
41
#define I2C_ERR_NOADDR          0x35
42
#define I2C_ERR_OVERRUN         0x36
43
#define I2C_ERR_NODATA          0x37
44
#define I2C_ERR_BUFFER_OVERRUN  0x38
45
 
46
typedef struct {
47
    uint8_t buffer_in[MAXI2C1BUF];
48
    uint8_t buffer_in_len;
49
    uint8_t buffer_in_read_ind;
50
    uint8_t buffer_in_write_ind;
51
 
52
    uint8_t operating_state;
53
    uint8_t return_status;
54
 
55
    uint8_t master_dest_addr;
56
    uint8_t master_status;
57
} I2C1_DATA;
58
 
59
void I2C1_Init(void);
60
void I2C1_Interrupt_Handler(void);
61
void I2C1_Configure_Master(uint8_t speed);
62
void I2C1_Master_Send(uint8_t address, uint8_t length, uint8_t *msg);
63
void I2C1_Master_Recv(uint8_t address, uint8_t length);
64
void I2C1_Master_Restart(uint8_t address, uint8_t msg, uint8_t length);
65
uint8_t I2C1_Get_Status(void);
66
uint8_t I2C1_Buffer_Len(void);
67
uint8_t I2C1_Read_Buffer(uint8_t *buffer);
68
 
69
#endif