Go to most recent revision | Details | 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 | // I2C states |
5 | #define I2C_STATE_UNDEF 0 |
||
6 | #define I2C_STATE_IDLE 1 |
||
248 | killagreg | 7 | #define I2C_STATE_BUFFBUSY 2 |
8 | #define I2C_STATE_TX_PENDING 3 |
||
9 | #define I2C_STATE_TX_PROGRESS 4 |
||
10 | #define I2C_STATE_RX_PENDING 5 |
||
11 | #define I2C_STATE_RX_PROGRESS 6 |
||
12 | #define I2C_STATE_OFF 7 |
||
470 | killagreg | 13 | // I2C Errors |
252 | killagreg | 14 | #define I2C_ERROR_NONE 0 |
15 | #define I2C_ERROR_UNKNOWN 1 |
||
16 | #define I2C_ERROR_NOACK 2 |
||
17 | |||
470 | killagreg | 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); |
||
21 | |||
22 | extern volatile u32 I2C1_Timeout; |
||
241 | killagreg | 23 | // current I2C state |
470 | killagreg | 24 | extern volatile u8 I2C1_State; |
252 | killagreg | 25 | // the last I2C error |
470 | killagreg | 26 | extern volatile u8 I2C1_Error; |
1 | ingob | 27 | |
241 | killagreg | 28 | #define I2C1_TIMEOUT 500 // 500 ms |
1 | ingob | 29 | |
248 | killagreg | 30 | // define the size of the rx/tx buffer |
470 | killagreg | 31 | #define I2C1_BUFFER_LEN 100 |
248 | killagreg | 32 | // transfer buffer should be filled after a successful |
33 | // I2C_LockBuffer(...) and before a start of transmission |
||
34 | // initiated by I2C_Transmission(...). |
||
470 | killagreg | 35 | extern volatile u8 I2C1_Buffer[]; |
41 | ingob | 36 | |
241 | killagreg | 37 | void I2C1_Init(void); |
1 | ingob | 38 | |
241 | killagreg | 39 | void I2C1_Deinit(void); |
41 | ingob | 40 | |
248 | killagreg | 41 | // Initiate i2c transmission |
470 | killagreg | 42 | // A transmission sends first TxBytes from I2C1_Buffer to slave |
43 | // and then RxBytes are read from slave to I2C1_Buffer |
||
248 | killagreg | 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 |
||
470 | killagreg | 48 | u8 I2C1_Transmission(u8 SlaveAddr, u8 TxBytes, I2C_pRxHandler_t pRxHandler, u8 RxBytes); |
49 | // try to allocate the I2C1_Buffer within the timeout limit |
||
248 | killagreg | 50 | // returns 1 on success |
470 | killagreg | 51 | u8 I2C1_LockBuffer(u32 timeout); |
248 | killagreg | 52 | // wait until transmission progess is finished or timeout |
53 | // returns 1 if no timeout occurs |
||
470 | killagreg | 54 | u8 I2C1_WaitForEndOfTransmission(u32 timeout); |
1 | ingob | 55 | |
41 | ingob | 56 | #endif // I2C_H |
1 | ingob | 57 |