From 345e69346056fde8e9a806b03a71c1ad78e5784b Mon Sep 17 00:00:00 2001 From: gdisirio Date: Thu, 5 Nov 2009 09:53:48 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1267 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/io/adc.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ os/io/adc.h | 55 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 138 insertions(+) create mode 100644 os/io/adc.c create mode 100644 os/io/adc.h (limited to 'os/io') diff --git a/os/io/adc.c b/os/io/adc.c new file mode 100644 index 000000000..8b4123bcd --- /dev/null +++ b/os/io/adc.c @@ -0,0 +1,83 @@ +/* + ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT 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 3 of the License, or + (at your option) any later version. + + ChibiOS/RT 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, see . +*/ + +/** + * @file adc.c + * @brief ADC Driver code. + * @addtogroup ADC + * @{ + */ + +#include +#include + +/** + * @brief ADC Driver initialization. + */ +void adcInit(void) { + + adc_lld_init(); +} + +/** + * @brief Initializes the standard part of a @p ADCDriver structure. + * + * @param[in] adcp pointer to the @p ADCDriver object + */ +void adcObjectInit(ADCDriver *adcp) { + + adcp->adc_state = ADC_STOP; + adcp->adc_config = NULL; +} + +/** + * @brief Configures and activates the ADC peripheral. + * + * @param[in] adcp pointer to the @p ADCDriver object + * @param config pointer to the @p ADCConfig object + */ +void adcStart(ADCDriver *adcp, const ADCConfig *config) { + + chDbgCheck((adcp != NULL) && (config != NULL), "adcStart"); + chDbgAssert((adcp->adc_state == ADC_STOP) || (adcp->adc_state == ADC_READY), + "adcStart(), #1", + "invalid state"); + + adcp->adc_config = config; + adc_lld_start(adcp); + adcp->adc_state = ADC_READY; +} + +/** + * @brief Deactivates the ADC peripheral. + * + * @param[in] adcp pointer to the @p ADCDriver object + */ +void adcStop(ADCDriver *adcp) { + + chDbgCheck(adcp != NULL, "adcStop"); + chDbgAssert((adcp->spd_state == ADC_STOP) || (adcp->spd_state == ADC_READY), + "adcStop(), #1", + "invalid state"); + + adc_lld_stop(adcp); + adcp->spd_state = ADC_STOP; +} + +/** @} */ diff --git a/os/io/adc.h b/os/io/adc.h new file mode 100644 index 000000000..628191c4f --- /dev/null +++ b/os/io/adc.h @@ -0,0 +1,55 @@ +/* + ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT 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 3 of the License, or + (at your option) any later version. + + ChibiOS/RT 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, see . +*/ + +/** + * @file adc.h + * @brief ADC Driver macros and structures. + * @addtogroup ADC + * @{ + */ + +#ifndef _ADC_H_ +#define _ADC_H_ + +/** + * @brief Driver state machine possible states. + */ +typedef enum { + ADC_UNINIT = 0, /**< @brief Not initialized. */ + ADC_STOP = 1, /**< @brief Stopped. */ + ADC_READY = 2, /**< @brief Ready. */ + ADC_ACTIVE = 3 /**< @brief Conversion running. */ +} adcstate_t; + +#include "adc_lld.h" + +#ifdef __cplusplus +extern "C" { +#endif + void adcInit(void); + void adcObjectInit(ADCDriver *adcp); + void adcStart(ADCDriver *adcp, const ADCDriver *config); + void adcStop(ADCDriver *adcp); +#ifdef __cplusplus +} +#endif + +#endif /* _ADC_H_ */ + +/** @} */ -- cgit v1.2.3