

/***********************************************************************
MODULE:    I2C
VERSION:   1.03
CONTAINS:  Routines for controlling the I2C Peripheral on the Philips
           P89LPC936
COPYRIGHT: Embedded Systems Academy, Inc. - www.esacademy.com
LICENSE:   May be freely used in commercial and non-commercial code
           without royalties provided this copyright notice remains
           in this file and unaltered
WARNING:   IF THIS FILE IS REGENERATED BY CODE ARCHITECT ANY CHANGES
           MADE WILL BE LOST. WHERE POSSIBLE USE ONLY CODE ARCHITECT
           TO CHANGE THE CONTENTS OF THIS FILE
GENERATED: On "Jun 09 2008" at "11:54:01" by Code Architect 2.12
***********************************************************************/

#ifndef _I2CH_
#define _I2CH_

// possible states for the I2C peripheral
#define I2C_IDLE   0x00
#define I2C_BUSY   0x01
#define I2C_BUSYTX 0x03
#define I2C_BUSYRX 0x05
#define I2C_OK     0x02
#define I2C_ERROR  0x04

/***********************************************************************
DESC:    initializes the I2C peripheral and interrupt
         sets the device's I2C address and whether it will
         respond to the general call address
         Uses a data rate of 100kHz
RETURNS: Nothing
************************************************************************/
extern void i2c_init
  (
  unsigned char address,  // The 7-bit I2C address to use
  bit generalcall         // 1 = respond to general call, 0 = ignore
                          // general call
  );

/***********************************************************************
DESC:    attempts to start an I2C transmission as a master to a
         device with a specific address. If successful then
         master callback functions will be called to handle the
         data for the transfer
RETURNS: I2C_BUSYTX if I2C is already busy transmitting data
         I2C_BUSYRX if I2C is already busy receiving data
         I2C_OK if transmission started
NOTES:   Can check if I2C busy by ANDing returned value with
         I2C_BUSY
************************************************************************/
extern unsigned char i2c_transmit
  (
  unsigned char address    // address of device to transmit to
  );

/***********************************************************************
DESC:    attempts to start an I2C reception as a master from a
         device with a specific address. If successful then
         master callback functions will be called to handle the
         data for the transfer
RETURNS: I2C_BUSYTX if I2C is already busy transmitting data
         I2C_BUSYRX if I2C is already busy receiving data
         I2C_OK if reception started
NOTES:   Can check if I2C busy by ANDing returned value with
         I2C_BUSY
************************************************************************/
extern unsigned char i2c_receive
  (
  unsigned char address    // address of device to receive from
  );

/***********************************************************************
DESC:    returns the current status of the I2C peripheral.
         allows polling to be used to determine if a transfer
         has been completed
RETURNS: I2C_BUSYTX if I2C is already busy transmitting data
         I2C_BUSYRX if I2C is already busy receiving data
         I2C_OK if no transfer in progress and last transfer
         was successful
         I2C_ERROR if no transfer in progress and last transfer
         encountered an error
         I2C_IDLE if no transfer in progress
NOTES:   Can check if I2C busy by ANDing returned value with
         I2C_BUSY. Example:
         i2c_transmit(0x00);
         while (i2c_getstatus() & I2C_BUSY);
         if (i2c_getstatus() == I2C_OK)
         ...
************************************************************************/
extern unsigned char i2c_getstatus
  (
  void
  );

#endif // _IC2H_

