#ifndef I2C_H
#define	I2C_H

/* define FCY for I2C1BRG calculation                               */
/* note: the FCY define enables __delay_us and __delay_ms macros    */
#ifndef FCY
#define FCY     40000000L
#endif

/* 100KHz I2C clock */
#ifndef FSCL
#define FSCL    100000L
#endif

#include <xc.h>
#include <libpic30.h>

/***************************************************************************/
/* EEPROM functions                                                        */
/***************************************************************************/

int i2c_readEEPROM(unsigned char* data, int len);
int i2c_writeEEPROM(unsigned char* data, int len);

/***************************************************************************/
/* HIH6130 function                                                        */
/***************************************************************************/

int i2c_getHumTemp(float* rh, float* temp);

/***************************************************************************/
/* MPL115A2 functions  (Pressure Sensor)                                   */
/***************************************************************************/

int i2c_getMPL115A2Coeff(float* a0, float* b1, float* b2, float* c12);

int i2c_getPressTemp(float a0, float b1, float b2, float c12,
                     float* pressure, float* temp);

/***************************************************************************/
/* I2C functions                                                           */
/***************************************************************************/
/* If successful I2C functions will return 0, otherwise a value of 1 will  */
/* be returned                                                             */
/***************************************************************************/

void i2c_init();
int i2c_start();
int i2c_restart();
int i2c_stop();
int i2c_idle();
int i2c_ack();
int i2c_nack();
int i2c_wait_ack();
int i2c_read(unsigned char* c);
int i2c_write(unsigned char c);

#endif