From: bernie Date: Mon, 27 Jun 2005 21:28:31 +0000 (+0000) Subject: Import ADC driver. X-Git-Tag: 1.0.0~822 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=4e5ed47bad71f6730e6a041cbe00418d458d0c9c;p=bertos.git Import ADC driver. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@419 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/drv/adc.c b/drv/adc.c new file mode 100755 index 00000000..c775e161 --- /dev/null +++ b/drv/adc.c @@ -0,0 +1,58 @@ +/*! + * \file + * + * + * \version $Id$ + * + * \brief ADC driver (implementation) + * + * \version $Id$ + * \author Francesco Sacchi + */ + +/*#* + *#* $Log$ + *#* Revision 1.1 2005/06/27 21:28:31 bernie + *#* Import ADC driver. + *#* + *#*/ + + +#include +#include +#include + +#include +#include +#include + +DB(bool adc_initialized = false;) + +/*! + * Read the ADC channel \a ch. + */ +adcread_t adc_read(uint16_t ch) +{ + ASSERT(ch <= (uint16_t)ADC_MUX_MAXCH); + ch = MIN(ch, (uint16_t)ADC_MUX_MAXCH); + + adc_hw_select_ch(ch); + + return(adc_hw_read()); +} + +/*! + * Initialize the ADC hardware. + */ +void adc_init(void) +{ + cpuflags_t flags; + IRQ_SAVE_DISABLE(flags); + + ADC_HW_INIT; + DB(adc_initialized = true;) + IRQ_RESTORE(flags); +} diff --git a/drv/adc.h b/drv/adc.h new file mode 100755 index 00000000..d87a2687 --- /dev/null +++ b/drv/adc.h @@ -0,0 +1,38 @@ +/*! + * \file + * + * + * \version $Id$ + * + * \brief ADC driver (interface) + * + * \version $Id$ + * \author Francesco Sacchi + */ + +/*#* + *#* $Log$ + *#* Revision 1.1 2005/06/27 21:28:31 bernie + *#* Import ADC driver. + *#* + *#*/ + +#ifndef DRV_ADC_H +#define DRV_ADC_H + +#include +#include +#include + +/*!Type for ADC return value. */ +typedef uint16_t adcread_t; + +#define adc_bits() ADC_BITS + +adcread_t adc_read(uint16_t ch); +void adc_init(void); +DB(extern bool adc_initialized;) +#endif /* DRV_ADC_H */