Subversion Repositories NaviCtrl

Rev

Rev 189 | Rev 248 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

#ifndef __I2C_H
#define __I2C_H

extern volatile u32 I2C1_Timeout;

// I2C states
#define I2C_STATE_UNDEF                 0
#define I2C_STATE_IDLE                  1
#define I2C_STATE_TX_PENDING    2
#define I2C_STATE_TX_PROGRESS   3
#define I2C_STATE_RX_PENDING    4
#define I2C_STATE_RX_PROGRESS   5
#define I2C_STATE_OFF                   6

// current I2C state
extern volatile u8 I2C_State;

#define I2C1_TIMEOUT 500 // 500 ms

// define the sizte of the rx and tx buffer
#define I2C_TXBUFFER_LEN 50
#define I2C_RXBUFFER_LEN 50
// transfer buffer should be filled before start of transmission only when I2C_State is I2C_STATE_IDLE
extern volatile u8 I2C_TxBufferSize;
extern volatile u8 I2C_TxBuffer[];

void I2C1_Init(void);

void I2C1_Deinit(void);

// the pointer to the rxbuffer handler function
// called by the IRQ routine after all bytes are recieved from slave
typedef void (*I2C_pRxHandler_t) (u8* pRxBuffer, u8 RxBufferSize);
// initiate i2c transmission
// first all bytes from TxBuffer are send to slave
// and then all bytes are read from slave and the RxHandler function is called
// returns 1 if a transmission was started, otherwise 0
u8 I2C_Transmission(u8 SlaveAddr, I2C_pRxHandler_t pRxHandler, u8 RxBytes);

#endif // I2C_H