// ----------------------------------------------------------------------------------------
//
//  avr/device/adc.h
//    
//  Bob Cook Development, Robotics Library
//  http://www.bobcookdev.com/rl/
//    
//  This file provides a basic Analog to Digitial Conversion (ADC) library.
//
//  Copyright (C) 2007 Bob Cook
//
//      This program is free software; you can redistribute it and/or modify it
//      under the terms of the GNU General Public License as published by the
//      Free Software Foundation; either version 2 of the License, or (at your
//      option) any later version.
//    
//      This program is distributed in the hope that it will be useful, but 
//      WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
//      or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License 
//      for more details.
//    
//      You should have received a copy of the GNU General Public License along
//      with this program; if not, write to the Free Software Foundation, Inc., 
//      51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
//
// ----------------------------------------------------------------------------------------


#if !defined( BCDRL_AVR_DEVICE_ADC_H )
#define BCDRL_AVR_DEVICE_ADC_H


#include <stdint.h>


// ----------------------------------------------------------------------------------------
//  definitions from "project_defs.h"
//
//  enable adc by defining:
//  
//      + PRJ_ADC_ENABLED
//
//  select the adc clock prescalar with one (and only one) of:
//
//      + PRJ_ADC_CLOCK_FACTOR_DIV_2
//      + PRJ_ADC_CLOCK_FACTOR_DIV_4
//      + PRJ_ADC_CLOCK_FACTOR_DIV_8
//      + PRJ_ADC_CLOCK_FACTOR_DIV_16
//      + PRJ_ADC_CLOCK_FACTOR_DIV_32
//      + PRJ_ADC_CLOCK_FACTOR_DIV_64
//      + PRJ_ADC_CLOCK_FACTOR_DIV_128
//
//  select the analog voltage reference with one (and only one) of:
//
//      + PRJ_ADC_REFERENCE_EXTERNAL_AREF
//      + PRJ_ADC_REFERENCE_INTERNAL_2.56V
//      + PRJ_ADC_REFERENCE_AREF_IS_AVCC
//
//  optional library functions:
//
//      + PRJ_ADC_EXTENDED_READ
//      + PRJ_ADC_USE_NOISE_REDUCTION
//
// ----------------------------------------------------------------------------------------


// ----------------------------------------------------------------------------------------
//  adc_init
//
//      Initialize the ADC h/w; call this once, before reading samples.
//

void adc_init();


// ----------------------------------------------------------------------------------------
//  adc_stop
//
//      Shut down the ADC h/w.
//

void adc_stop();


// ----------------------------------------------------------------------------------------
//  adc_read
//
//      Read a sample from the specified ADC channel. Blocks until a sample is available.
//

uint16_t adc_read( uint8_t channel );


// ----------------------------------------------------------------------------------------
//  adc_read
//
//      Read a series of values from a given channel, optionally delay between each.
//
//      This function is only available if PRJ_ADC_EXTENDED_READ is defined.
//      

void adc_read
    (
        uint8_t   channel,
        uint16_t* data,
        uint8_t   count,
        uint8_t   delay_ms = 10
    );


#endif  // #if !defined( BCDRL_AVR_DEVICE_ADC_H )
// ----------------------------------------------------------------------------------------
//  end of adc.h
// ----------------------------------------------------------------------------------------

