Subversion Repositories NaviCtrl

Rev

Rev 470 | Blame | Compare with Previous | Last modification | View Log | RSS feed

#ifndef __I2C0_H
#define __I2C0_H

#include "i2c1.h"

extern volatile u32 I2C0_Timeout;
// current I2C state
extern volatile u8 I2C0_State;
// the last I2C error
extern volatile u8 I2C0_Error;

#define I2C0_TIMEOUT 500 // 500 ms

// define the size of the rx/tx buffer
#define I2C0_BUFFER_LEN 100
// transfer buffer should be filled after a successful
// I2C_LockBuffer(...) and before a start of transmission
// initiated by  I2C_Transmission(...).
extern volatile u8 I2C0_Buffer[];

void I2C0_Init(void);

void I2C0_Deinit(void);

// Initiate i2c transmission
// A transmission sends first TxBytes from I2C0_Buffer to slave
// and then RxBytes are read from slave to I2C0_Buffer
// replacing the byte that have been sent.
// Then the RxHandler function is called to handle the result.
// This function returns imediatly after a start condition.
// returns 1 if a transmission has been started, otherwise 0
u8 I2C0_Transmission(u8 SlaveAddr, u8 TxBytes, I2C_pRxHandler_t pRxHandler, u8 RxBytes);
// try to allocate the I2C0_Buffer within the timeout limit
// returns 1 on success
u8 I2C0_LockBuffer(u32 timeout);
// wait until transmission progess is finished or timeout
// returns 1 if no timeout occurs
u8 I2C0_WaitForEndOfTransmission(u32 timeout);

#endif // I2C_H