Rev 241 | Rev 252 | Go to most recent revision | 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 | |
241 | killagreg | 16 | // current I2C state |
17 | extern volatile u8 I2C_State; |
||
1 | ingob | 18 | |
241 | killagreg | 19 | #define I2C1_TIMEOUT 500 // 500 ms |
1 | ingob | 20 | |
248 | killagreg | 21 | // define the size of the rx/tx buffer |
22 | #define I2C_BUFFER_LEN 150 |
||
23 | // transfer buffer should be filled after a successful |
||
24 | // I2C_LockBuffer(...) and before a start of transmission |
||
25 | // initiated by I2C_Transmission(...). |
||
26 | extern volatile u8 I2C_Buffer[]; |
||
41 | ingob | 27 | |
241 | killagreg | 28 | void I2C1_Init(void); |
1 | ingob | 29 | |
241 | killagreg | 30 | void I2C1_Deinit(void); |
41 | ingob | 31 | |
241 | killagreg | 32 | // the pointer to the rxbuffer handler function |
33 | // called by the IRQ routine after all bytes are recieved from slave |
||
34 | typedef void (*I2C_pRxHandler_t) (u8* pRxBuffer, u8 RxBufferSize); |
||
248 | killagreg | 35 | // Initiate i2c transmission |
36 | // A transmission sends first TxBytes from I2C_Buffer to slave |
||
37 | // and then RxBytes are read from slave to I2C_Buffer |
||
38 | // replacing the byte that have been sent. |
||
39 | // Then the RxHandler function is called to handle the result. |
||
40 | // This function returns imediatly after a start condition. |
||
41 | // returns 1 if a transmission has been started, otherwise 0 |
||
42 | u8 I2C_Transmission(u8 SlaveAddr, u8 TxBytes, I2C_pRxHandler_t pRxHandler, u8 RxBytes); |
||
43 | // try to allocate the I2C_Buffer within the timeout limit |
||
44 | // returns 1 on success |
||
45 | u8 I2C_LockBuffer(u32 timeout); |
||
46 | // wait until transmission progess is finished or timeout |
||
47 | // returns 1 if no timeout occurs |
||
48 | u8 I2C_WaitForEndOfTransmission(u32 timeout); |
||
1 | ingob | 49 | |
41 | ingob | 50 | #endif // I2C_H |
1 | ingob | 51 |