#if defined(__PIC24F__)
#include <p24Fxxxx.h>
#endif
#include "adc.h"

#ifdef _ADC_10B_V3

/*********************************************************************
* Function Name     : OpenADC10
* Description       : Configures the ADC. This includes :
                    · Operating mode      // AD1CON1<15> ADON bit
                    · Data o/p format     // AD1CON1<9:8> FORM bits
                    · Sample Clk Source   // AD1CON1<7:5> SSRC<2:0>bits
                    · Vref source         // AD1CON2<15:13> VCFG<2:0> bits
                    . Channels utilized   // AD1CON2<9:8> CHPS<1:0>bits
                    · No of samples/int   // AD1CON2<4:2> SMPI<2:0>bits
                    · Buffer fill mode    // AD1CON2<1> BUFM bit
                    · Alternate i/p sample mode // AD1CON2<0> ALTS
                    · Auto sample time   //AD1CON3<12:8> SAMC<4:0>bits
                    · Conv clock source  //AD1CON3<7> ADRC
                    · Conv clock select bits //AD1CON3<5:0> ADCS<5:0>
            . Select number of DMA buffer locations per analog input // AD1CON4
                    · Port config control bits.  //AD1CSSH and AD1CSSL

* Parameters        : config1, config2, config3, configscan,configport
* Return Value      : None
*********************************************************************/

void OpenADC10(unsigned int config1, unsigned int config2, unsigned int
               config3, unsigned int configport, unsigned int configscan)
{

    /* digital/analog mode selection on the port bits */
    AD1PCFG = configport;

    /* configures the input scan selection bits */
    AD1CSSL = configscan;

    /* config AD1CON3 */
    AD1CON3 = config3;
    
    /* config AD1CON2 */
    AD1CON2 = config2;

    /* config AD1CON1 */
    AD1CON1 = config1;

    /* assign SAMP bit */
    AD1CON1bits.SAMP = config1 >> 1;
}

#else
#warning "Does not build on this target"
#endif
