Subversion Repositories NaviCtrl

Rev

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

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