Rev 241 | Rev 252 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 241 | Rev 248 | ||
---|---|---|---|
1 | #ifndef __I2C_H |
1 | #ifndef __I2C_H |
2 | #define __I2C_H |
2 | #define __I2C_H |
3 | 3 | ||
4 | extern volatile u32 I2C1_Timeout; |
4 | extern volatile u32 I2C1_Timeout; |
5 | 5 | ||
6 | // I2C states |
6 | // I2C states |
7 | #define I2C_STATE_UNDEF 0 |
7 | #define I2C_STATE_UNDEF 0 |
8 | #define I2C_STATE_IDLE 1 |
8 | #define I2C_STATE_IDLE 1 |
- | 9 | #define I2C_STATE_BUFFBUSY 2 |
|
9 | #define I2C_STATE_TX_PENDING 2 |
10 | #define I2C_STATE_TX_PENDING 3 |
10 | #define I2C_STATE_TX_PROGRESS 3 |
11 | #define I2C_STATE_TX_PROGRESS 4 |
11 | #define I2C_STATE_RX_PENDING 4 |
12 | #define I2C_STATE_RX_PENDING 5 |
12 | #define I2C_STATE_RX_PROGRESS 5 |
13 | #define I2C_STATE_RX_PROGRESS 6 |
13 | #define I2C_STATE_OFF 6 |
14 | #define I2C_STATE_OFF 7 |
14 | 15 | ||
15 | // current I2C state |
16 | // current I2C state |
16 | extern volatile u8 I2C_State; |
17 | extern volatile u8 I2C_State; |
17 | 18 | ||
18 | #define I2C1_TIMEOUT 500 // 500 ms |
19 | #define I2C1_TIMEOUT 500 // 500 ms |
19 | 20 | ||
20 | // define the sizte of the rx and tx buffer |
21 | // define the size of the rx/tx buffer |
21 | #define I2C_TXBUFFER_LEN 50 |
22 | #define I2C_BUFFER_LEN 150 |
22 | #define I2C_RXBUFFER_LEN 50 |
23 | // transfer buffer should be filled after a successful |
23 | // transfer buffer should be filled before start of transmission only when I2C_State is I2C_STATE_IDLE |
24 | // I2C_LockBuffer(...) and before a start of transmission |
24 | extern volatile u8 I2C_TxBufferSize; |
25 | // initiated by I2C_Transmission(...). |
25 | extern volatile u8 I2C_TxBuffer[]; |
26 | extern volatile u8 I2C_Buffer[]; |
26 | 27 | ||
27 | void I2C1_Init(void); |
28 | void I2C1_Init(void); |
28 | 29 | ||
29 | void I2C1_Deinit(void); |
30 | void I2C1_Deinit(void); |
30 | 31 | ||
31 | // the pointer to the rxbuffer handler function |
32 | // the pointer to the rxbuffer handler function |
32 | // called by the IRQ routine after all bytes are recieved from slave |
33 | // called by the IRQ routine after all bytes are recieved from slave |
33 | typedef void (*I2C_pRxHandler_t) (u8* pRxBuffer, u8 RxBufferSize); |
34 | typedef void (*I2C_pRxHandler_t) (u8* pRxBuffer, u8 RxBufferSize); |
34 | // initiate i2c transmission |
35 | // Initiate i2c transmission |
35 | // first all bytes from TxBuffer are send to slave |
36 | // A transmission sends first TxBytes from I2C_Buffer to slave |
36 | // and then all bytes are read from slave and the RxHandler function is called |
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. |
|
37 | // returns 1 if a transmission was started, otherwise 0 |
41 | // returns 1 if a transmission has been started, otherwise 0 |
38 | u8 I2C_Transmission(u8 SlaveAddr, I2C_pRxHandler_t pRxHandler, u8 RxBytes); |
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); |
|
39 | 49 | ||
40 | #endif // I2C_H |
50 | #endif // I2C_H |
41 | 51 | ||
42 | 52 |