Subversion Repositories Code-Repo

Rev

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

Rev Author Line No. Line
260 Kevin 1
#ifndef I2C1_H
2
#define I2C1_H
3
 
4
#define MAXI2C1BUF 32
5
 
6
// I2C Operating Speed
275 Kevin 7
#define I2C_100KHZ              0x0
8
#define I2C_400KHZ              0x1
9
#define I2C_1MHZ                0x2
260 Kevin 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_len_tmp;
50
    uint8_t buffer_in_read_ind;
51
    uint8_t buffer_in_write_ind;
52
 
53
    uint8_t buffer_out[MAXI2C1BUF];
54
    uint8_t buffer_out_len;
55
    uint8_t buffer_out_ind;
56
 
57
    uint8_t operating_mode;
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);
69
void I2C1_Interrupt_Handler(void);
70
void I2C1_Interrupt_Slave(void);
71
void I2C1_Interrupt_Master(void);
72
void I2C1_Configure_Slave(uint8_t address);
73
void I2C1_Configure_Master(uint8_t speed);
74
void I2C1_Master_Send(uint8_t address, uint8_t length, uint8_t *msg);
75
void I2C1_Master_Recv(uint8_t address, uint8_t length);
76
void I2C1_Master_Restart(uint8_t address, uint8_t msg, uint8_t length);
77
uint8_t I2C1_Get_Status(void);
78
uint8_t I2C1_Buffer_Len(void);
79
uint8_t I2C1_Read_Buffer(uint8_t *buffer);
80
uint8_t I2C1_Process_Receive(uint8_t);
81
 
82
#endif