#ifndef PCAL6416_INC
#define PCAL6416_INC			1

#include	<io_regs.h>
#include	<io_i2c.h>
#include	<my_defs.h>


// PCAL6416 I2C ADDRESS BYTES
#define PCAL6416_ADDR_WR         0x40
#define PCAL6416_ADDR_RD         0x41

// PCAL6416 COMMAND BYTE REGISTER ADDRESSES
#define PCAL6416_INPUT_PORT0     0x00
#define PCAL6416_INPUT_PORT1     0x01
#define PCAL6416_OUTPUT_PORT0    0x02
#define PCAL6416_OUTPUT_PORT1    0x03
#define PCAL6416_INVERT_REG0     0x04
#define PCAL6416_INVERT_REG1     0x05
#define PCAL6416_CONFIG_REG0     0x06
#define PCAL6416_CONFIG_REG1     0x07
#define PCAL6416_DRIVE_REG0      0x40
#define PCAL6416_DRIVE_REG1      0x41
#define PCAL6416_DRIVE_REG2      0x42
#define PCAL6416_DRIVE_REG3      0x43
#define PCAL6416_LATCH_REG0      0x44
#define PCAL6416_LATCH_REG1      0x45
#define PCAL6416_PULLENB_REG0    0x46
#define PCAL6416_PULLENB_REG1    0x47
#define PCAL6416_PULLDIR_REG0    0x48
#define PCAL6416_PULLDIR_REG1    0x49
#define PCAL6416_INTMASK_REG0    0x4A
#define PCAL6416_INTMASK_REG1    0x4B
#define PCAL6416_INTSTAT_REG0    0x4C
#define PCAL6416_INTSTAT_REG1    0x4D
#define PCAL6416_OUTCONFIG_REG   0x4F

// PCAL6416 DEFAULT OUTPUT PORT DATA VALUES
#define PCAL6416_OUTPUT_VAL0     0x00
#define PCAL6416_OUTPUT_VAL1     0x00

// PCAL6416 DEFAULT INVERT PORT BYTE VALUES
#define PCAL6416_INVERT_VAL0     0x00				//disable all inversion
#define PCAL6416_INVERT_VAL1     0x00				//disable all inversion

// PCAL6416 DEFAULT CONFIG PORT BYTE VALUES  (PIN DATA DIRECTION)
#define PCAL6416_CONFIG_VAL0     0x00				//set to outputs
#define PCAL6416_CONFIG_VAL1     0xFF				//set to inputs

// PCAL6416 DEFAULT PULL-UP/DOWN ENABLE VALUES  
#define PCAL6416_PULLENB_VAL0    0x00				//disable pull-up/down resistors on port 0
#define PCAL6416_PULLENB_VAL1    0xFF				//enable  pull-up/down resistros on port 1

// PCAL6416 DEFAULT OUTPUT PORT CONFIGURATION VALUE (PUSH-PULL OR OPEN-DRAIN)
#define PCAL6416_OUTCONFIG_VAL   0x00				//set to push-pull, per datasheet this value should be set prior to writing to the config regs

// PCAL6416 READ REGISTER OFFSET FROM ASSOCIATED WRITE REGISTER
#define PCAL6416_RD_OFFSET       0x02

// PCAL6416 APF CONTROLLER BOARD PIN ASSIGNMENTS
// IO_PORT_0
#define DURA_PWR_ON              0x01
#define SPEC_PWR_ON              0x02
#define REFD_PWR_ON              0x04
#define PUMP_PWR_ON              0x08
#define LAMP_PWR_ON              0x10
#define LAMP_DU_ENABLE           0x20
#define LAMP_W_ENABLE            0x40
#define LAMP_SHUT_ENABLE         0x80
// IO_PORT_1
#define DURA_PWR_FDBK            0x01
#define SPEC_PWR_FDBK            0x02
#define REFD_PWR_FDBK            0x04
#define PUMP_PWR_FDBK            0x08
#define LAMP_PWR_FDBK            0x10
#define LAMP_CTR_ALARM           0x20
#define TH_HI_ALARM              0x40
#define TH_LO_ALARM              0x80


// PCAL6416 high level function prototypes
int   PCAL6416_Init( void );
int   PCAL6416_WritePortDefaults( void );
int   PCAL6416_ReadPort(uchar Port, uchar *Data);
int   PCAL6416_ReadPorts(uchar Port0, uchar *Data0, uchar *Data1);
int   PCAL6416_WritePort(uchar Port, uchar Data);
int   PCAL6416_WritePortBit(uchar Port, uchar Bitval, uchar State);
void  PCAL6416_Reset( void );

#endif

