/****************************************************************************/
/* Copyright 2013 MBARI.                                                    */
/* MBARI Proprietary Information. All rights reserved.                      */
/****************************************************************************/
/* Written by Bob Herlien for SensorNode for xFOCE, May 2013                */
/****************************************************************************/
#ifndef ADC_H
#define ADC_H

#include <mb.h>
#include <port.h>

#define ADC_HOLDING_START 0x0020

#define ADC_CHANS	   14
#define ADC_CONVERT_START ADC_HOLDING_START
#define ADC_CONVERT_END1   (ADC_CONVERT_START+ADC_CHANS)
#define ADC_CONVERT_END    (ADC_CONVERT_START+ADC_CHANS-1)

#define ADC_NUM_AVG	  0x0030
#define ADC_AVG_MS        0x0031
#define ADC_PARM_START    ADC_NUM_AVG
#define ADC_PARM_END      ADC_AVG_MS
#define ADC_HOLDING_END   ADC_PARM_END


/* ADS8344 Bit Definitions	*/
#define ADS8344START	0x8000
#define ADS8344SGL	0x0400
#define ADS8344EXT	0x0300
#define ADS8344INT	0x0200
#define ADS8344PDFull	0x0000

#define GF_CH_SEL	0x3000		/* Selects channel 6 for GF detector*/

typedef struct				/************************************/
{					/* Structure to describe ADC chans  */
    unsigned short	converter;	/* Which convert it's on	    */
    unsigned short	chan;		/* Which channel on converter       */
} ADCDesc;				/************************************/

typedef enum
{ ADC_01=0, ADC_02, ADC_48V_01, ADC_48V_02 } AdcConverter;


/************* Function Declarations **************/
void adcInit(); 
void adcConvert(USHORT address, USHORT nRegs);
USHORT adcReadReg(USHORT address);
eMBErrorCode adcWriteRegs(UCHAR *pRegBuffer, USHORT address, USHORT nRegs);
USHORT ads834xConvert(USHORT chan);
USHORT adsConvertGFchan(void);

#endif

