/****************************************************************************/
/* Copyright 2003-2016 MBARI                                                */
/****************************************************************************/
/* Summary  : Definitions for using I2C on PIC32MX470F512L                  */
/* Filename : i2c.h                                                         */
/* Author   : Robert Herlien (rah)                                          */
/* Project  : OASIS Mooring Replacement (OASIS5)                            */
/* Revision: 1.0                                                            */
/* Created  : 02/25/2016                                                    */
/*                                                                          */
/* MBARI provides this documentation and code "as is", with no warranty,    */
/* express or implied, of its quality or consistency. It is provided without*/
/* support and without obligation on the part of the Monterey Bay Aquarium  */
/* Research Institute to assist in its use, correction, modification, or    */
/* enhancement. This information should not be published or distributed to  */
/* third parties without specific written permission from MBARI.            */
/*                                                                          */
/****************************************************************************/
/* Modification History:                                                    */
/* 25feb2016 rah - created                                                  */
/* $Log: i2c.h,v $
/* Revision 1.1  2016/05/09 17:18:26  bobh
/* First rev of dbgTest ported to FreeRTOS
/*
/* Revision 1.1  2016/03/23 23:45:43  bobh
/* Initial revision of dbgTest.MX470
/*
 */
/****************************************************************************/

#ifndef I2C_H
#define I2C_H

#include <GenericTypeDefs.h>
#include <oasis.h>


/********************************************/
/*      Typedefs and Constants              */
/********************************************/

/* I2C Errors start at -10      */
#define I2C_SUCCESS               0
#define I2C_ERROR                (-10)
#define I2C_BUS_BUSY             (-11)
#define I2C_MASTER_BUS_COLLISION (-12)
#define I2C_RECEIVE_OVERFLOW     (-13)
#define I2C_NO_ACK               (-14)

#define i2c1BusIsBusy()  (I2C1CON & 0x1f)


/********************************************/
/*      Function Prototypes                 */
/********************************************/

void    i2cInit(void);
Errno   i2cWaitBusIdle(void);
Errno   i2cStart(void);
Errno   i2cRestart(void);
void    i2cStop(void);
Errno   i2cSendByte(BYTE dataByte);
void    i2cClrRcv(void);
Errno   i2cRcvByte(BYTE *dataByte);
Errno   i2cSendAck(void);
Errno   i2cSendNack(void);

#endif
