/****************************************************************************/
/* Copyright 2016 MBARI                                                     */
/****************************************************************************/
/* Summary  : Definitions for ADC Routines for OASIS5 on PIC32MX470F512L    */
/* Filename : adc.h                                                         */
/* Author   : Robert Herlien (rah)                                          */
/* Project  : OASIS Mooring Replacement (OASIS5)                            */
/* Revision: 1.0                                                            */
/* Created  : 02/23/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:                                                    */
/* 23feb2016 rah - created                                                  */
/****************************************************************************/

#ifndef ADC_H
#define ADC_H

#include <mbariTypes.h>


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

typedef enum
{
    ADC_PRESS = 0, ADC_BATT, ADC_GF, ADC_TEMP, ADC_HUMID
} ADC_ChanNum;

#define ADC_CHANS       5
#define ADC_CHAN_OFFSET 6				/* Actual A/D chans start at 6	*/
#define ADC_CHAN_MIN	ADC_PRESS
#define ADC_CHAN_MAX    ADC_HUMID

#define DFLT_ADC_STARTUP_MS	100

#define AdcVolts(cnt)    ((double)(cnt) * 3.3 / 65536.0)
/* A/D conversions are averaged and normalized to 16 bits,	*/
/* thus the divisor of 65536 rather than 1024				*/


typedef struct                  /****************************************/
{                               /* Analog channel descriptors           */
    char  *name;                /* Channel name                         */
    char  *units;               /* Name of engineering units            */
    double mult;                /* Multiplier                           */
    double offset;              /* Offset                               */
} AnalogDesc;                   /****************************************/


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

Errno   adcInit(void);
void    adcSetupSingle(int chan);
void    adcSetupMult(int chan, int nchans);
Nat16	adcConvertSingle(void);
void    adcConvertMult(void);
Nat16	adcGetResult(Nat16 chanOfs);
void    adcStop(void);
Errno	adcConvertChans(int stChan, int numChans, int numAvg, Nat16 *result);
AnalogDesc *getAnalogDesc(void);
void	printAnalogChan(Nat32 chan, Nat16 cnt);

#endif
