Subversion Repositories NaviCtrl

Rev

Rev 252 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 252 Rev 470
Line 1... Line 1...
1
#ifndef __I2C_H
1
#ifndef __I2C_H
2
#define __I2C_H
2
#define __I2C_H
Line 3... Line -...
3
 
-
 
4
extern volatile u32 I2C1_Timeout;
-
 
5
 
3
 
6
// I2C states
4
// I2C states
7
#define I2C_STATE_UNDEF                 0
5
#define I2C_STATE_UNDEF                 0
8
#define I2C_STATE_IDLE                  1
6
#define I2C_STATE_IDLE                  1
9
#define I2C_STATE_BUFFBUSY              2
7
#define I2C_STATE_BUFFBUSY              2
10
#define I2C_STATE_TX_PENDING    3
8
#define I2C_STATE_TX_PENDING    3
11
#define I2C_STATE_TX_PROGRESS   4
9
#define I2C_STATE_TX_PROGRESS   4
12
#define I2C_STATE_RX_PENDING    5
10
#define I2C_STATE_RX_PENDING    5
13
#define I2C_STATE_RX_PROGRESS   6
11
#define I2C_STATE_RX_PROGRESS   6
14
#define I2C_STATE_OFF                   7
12
#define I2C_STATE_OFF                   7
15
 
13
// I2C Errors
16
#define I2C_ERROR_NONE                  0
14
#define I2C_ERROR_NONE                  0
17
#define I2C_ERROR_UNKNOWN               1
15
#define I2C_ERROR_UNKNOWN               1
Line -... Line 16...
-
 
16
#define I2C_ERROR_NOACK                 2
-
 
17
 
-
 
18
// the pointer to the rxbuffer handler function
-
 
19
// called by the IRQ routine after all bytes are recieved from slave
-
 
20
typedef void (*I2C_pRxHandler_t) (u8* pRxBuffer, u8 RxBufferSize);
18
#define I2C_ERROR_NOACK                 2
21
 
19
 
22
extern volatile u32 I2C1_Timeout;
20
// current I2C state
23
// current I2C state
21
extern volatile u8 I2C_State;
24
extern volatile u8 I2C1_State;
Line 22... Line 25...
22
// the last I2C error
25
// the last I2C error
Line 23... Line 26...
23
extern volatile u8 I2C_Error;
26
extern volatile u8 I2C1_Error;
24
 
27
 
25
#define I2C1_TIMEOUT 500 // 500 ms
28
#define I2C1_TIMEOUT 500 // 500 ms
26
 
29
 
27
// define the size of the rx/tx buffer
30
// define the size of the rx/tx buffer
28
#define I2C_BUFFER_LEN 100
31
#define I2C1_BUFFER_LEN 100
Line 29... Line 32...
29
// transfer buffer should be filled after a successful
32
// transfer buffer should be filled after a successful
Line 30... Line 33...
30
// I2C_LockBuffer(...) and before a start of transmission
33
// I2C_LockBuffer(...) and before a start of transmission
Line 31... Line -...
31
// initiated by  I2C_Transmission(...).
-
 
32
extern volatile u8 I2C_Buffer[];
-
 
33
 
-
 
34
void I2C1_Init(void);
34
// initiated by  I2C_Transmission(...).
35
 
35
extern volatile u8 I2C1_Buffer[];
36
void I2C1_Deinit(void);
36
 
37
 
37
void I2C1_Init(void);
38
// the pointer to the rxbuffer handler function
38
 
39
// called by the IRQ routine after all bytes are recieved from slave
39
void I2C1_Deinit(void);
40
typedef void (*I2C_pRxHandler_t) (u8* pRxBuffer, u8 RxBufferSize);
40
 
41
// Initiate i2c transmission
41
// Initiate i2c transmission
42
// A transmission sends first TxBytes from I2C_Buffer to slave
42
// A transmission sends first TxBytes from I2C1_Buffer to slave
43
// and then RxBytes are read from slave to I2C_Buffer
43
// and then RxBytes are read from slave to I2C1_Buffer
44
// replacing the byte that have been sent.
44
// replacing the byte that have been sent.
45
// Then the RxHandler function is called to handle the result.
45
// Then the RxHandler function is called to handle the result.
46
// This function returns imediatly after a start condition.
46
// This function returns imediatly after a start condition.
47
// returns 1 if a transmission has been started, otherwise 0
47
// returns 1 if a transmission has been started, otherwise 0
Line 48... Line 48...
48
u8 I2C_Transmission(u8 SlaveAddr, u8 TxBytes, I2C_pRxHandler_t pRxHandler, u8 RxBytes);
48
u8 I2C1_Transmission(u8 SlaveAddr, u8 TxBytes, I2C_pRxHandler_t pRxHandler, u8 RxBytes);