2009-11-29 08:50:13 +00:00
|
|
|
/*
|
2013-03-30 10:32:37 +00:00
|
|
|
ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio
|
2009-11-29 08:50:13 +00:00
|
|
|
|
2013-03-30 10:32:37 +00:00
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
2009-11-29 08:50:13 +00:00
|
|
|
|
2013-03-30 10:32:37 +00:00
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
2009-11-29 08:50:13 +00:00
|
|
|
|
2013-03-30 10:32:37 +00:00
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-02-07 11:11:45 +00:00
|
|
|
* @file templates/adc_lld.h
|
|
|
|
* @brief ADC Driver subsystem low level driver header template.
|
|
|
|
*
|
2010-10-25 18:48:13 +00:00
|
|
|
* @addtogroup ADC
|
2009-11-29 08:50:13 +00:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _ADC_LLD_H_
|
|
|
|
#define _ADC_LLD_H_
|
|
|
|
|
2010-11-01 17:29:56 +00:00
|
|
|
#if HAL_USE_ADC || defined(__DOXYGEN__)
|
2009-11-29 08:50:13 +00:00
|
|
|
|
2009-12-19 10:08:08 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver constants. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2009-11-29 08:50:13 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver pre-compile time settings. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2013-02-24 15:35:53 +00:00
|
|
|
/**
|
|
|
|
* @name Configuration options
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @brief ADC1 driver enable switch.
|
|
|
|
* @details If set to @p TRUE the support for ADC1 is included.
|
|
|
|
* @note The default is @p FALSE.
|
|
|
|
*/
|
|
|
|
#if !defined(PLATFORM_ADC_USE_ADC1) || defined(__DOXYGEN__)
|
2013-02-25 13:10:39 +00:00
|
|
|
#define PLATFORM_ADC_USE_ADC1 FALSE
|
2013-02-24 15:35:53 +00:00
|
|
|
#endif
|
|
|
|
/** @} */
|
|
|
|
|
2009-11-29 08:50:13 +00:00
|
|
|
/*===========================================================================*/
|
2009-12-19 10:08:08 +00:00
|
|
|
/* Derived constants and error checks. */
|
2009-11-29 08:50:13 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver data structures and types. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/**
|
2010-02-21 07:24:53 +00:00
|
|
|
* @brief ADC sample data type.
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
|
|
|
typedef uint16_t adcsample_t;
|
|
|
|
|
|
|
|
/**
|
2010-02-07 11:11:45 +00:00
|
|
|
* @brief Channels number in a conversion group.
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
|
|
|
typedef uint16_t adc_channels_num_t;
|
|
|
|
|
2013-02-24 15:35:53 +00:00
|
|
|
/**
|
|
|
|
* @brief Possible ADC failure causes.
|
|
|
|
* @note Error codes are architecture dependent and should not relied
|
|
|
|
* upon.
|
|
|
|
*/
|
|
|
|
typedef enum {
|
|
|
|
ADC_ERR_DMAFAILURE = 0, /**< DMA operations failure. */
|
|
|
|
ADC_ERR_OVERFLOW = 1 /**< ADC overflow condition. */
|
|
|
|
} adcerror_t;
|
|
|
|
|
2010-10-08 18:16:38 +00:00
|
|
|
/**
|
|
|
|
* @brief Type of a structure representing an ADC driver.
|
|
|
|
*/
|
|
|
|
typedef struct ADCDriver ADCDriver;
|
|
|
|
|
2009-11-29 08:50:13 +00:00
|
|
|
/**
|
2010-02-07 11:11:45 +00:00
|
|
|
* @brief ADC notification callback type.
|
|
|
|
*
|
2010-10-08 18:16:38 +00:00
|
|
|
* @param[in] adcp pointer to the @p ADCDriver object triggering the
|
|
|
|
* callback
|
2010-02-07 11:11:45 +00:00
|
|
|
* @param[in] buffer pointer to the most recent samples data
|
2010-02-21 07:24:53 +00:00
|
|
|
* @param[in] n number of buffer rows available starting from @p buffer
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
2010-10-08 18:16:38 +00:00
|
|
|
typedef void (*adccallback_t)(ADCDriver *adcp, adcsample_t *buffer, size_t n);
|
2009-11-29 08:50:13 +00:00
|
|
|
|
2013-02-24 15:35:53 +00:00
|
|
|
/**
|
|
|
|
* @brief ADC error callback type.
|
|
|
|
*
|
|
|
|
* @param[in] adcp pointer to the @p ADCDriver object triggering the
|
|
|
|
* callback
|
|
|
|
* @param[in] err ADC error code
|
|
|
|
*/
|
|
|
|
typedef void (*adcerrorcallback_t)(ADCDriver *adcp, adcerror_t err);
|
|
|
|
|
2009-11-29 08:50:13 +00:00
|
|
|
/**
|
2010-02-07 11:11:45 +00:00
|
|
|
* @brief Conversion group configuration structure.
|
2009-11-29 08:50:13 +00:00
|
|
|
* @details This implementation-dependent structure describes a conversion
|
2010-02-21 07:24:53 +00:00
|
|
|
* operation.
|
2010-09-07 13:37:22 +00:00
|
|
|
* @note Implementations may extend this structure to contain more,
|
|
|
|
* architecture dependent, fields.
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
/**
|
2013-02-24 15:35:53 +00:00
|
|
|
* @brief Enables the circular buffer mode for the group.
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
2011-03-08 10:09:57 +00:00
|
|
|
bool_t circular;
|
2009-11-29 08:50:13 +00:00
|
|
|
/**
|
2013-02-24 15:35:53 +00:00
|
|
|
* @brief Number of the analog channels belonging to the conversion group.
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
2011-03-08 10:09:57 +00:00
|
|
|
adc_channels_num_t num_channels;
|
2010-10-08 18:16:38 +00:00
|
|
|
/**
|
2013-02-24 15:35:53 +00:00
|
|
|
* @brief Callback function associated to the group or @p NULL.
|
2010-10-08 18:16:38 +00:00
|
|
|
*/
|
2011-03-08 10:09:57 +00:00
|
|
|
adccallback_t end_cb;
|
2013-02-24 15:35:53 +00:00
|
|
|
/**
|
|
|
|
* @brief Error callback or @p NULL.
|
|
|
|
*/
|
|
|
|
adcerrorcallback_t error_cb;
|
2009-11-29 08:50:13 +00:00
|
|
|
/* End of the mandatory fields.*/
|
|
|
|
} ADCConversionGroup;
|
|
|
|
|
|
|
|
/**
|
2010-02-07 11:11:45 +00:00
|
|
|
* @brief Driver configuration structure.
|
|
|
|
* @note It could be empty on some architectures.
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
|
|
|
typedef struct {
|
2013-02-24 15:35:53 +00:00
|
|
|
uint32_t dummy;
|
2009-11-29 08:50:13 +00:00
|
|
|
} ADCConfig;
|
|
|
|
|
|
|
|
/**
|
2010-02-07 11:11:45 +00:00
|
|
|
* @brief Structure representing an ADC driver.
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
2010-10-08 18:16:38 +00:00
|
|
|
struct ADCDriver {
|
2009-11-29 08:50:13 +00:00
|
|
|
/**
|
2013-02-24 15:35:53 +00:00
|
|
|
* @brief Driver state.
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
2011-03-08 10:09:57 +00:00
|
|
|
adcstate_t state;
|
2009-11-29 08:50:13 +00:00
|
|
|
/**
|
2013-02-24 15:35:53 +00:00
|
|
|
* @brief Current configuration data.
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
2011-03-08 10:09:57 +00:00
|
|
|
const ADCConfig *config;
|
2009-11-29 08:50:13 +00:00
|
|
|
/**
|
2013-02-24 15:35:53 +00:00
|
|
|
* @brief Current samples buffer pointer or @p NULL.
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
2011-03-08 10:09:57 +00:00
|
|
|
adcsample_t *samples;
|
2009-11-29 08:50:13 +00:00
|
|
|
/**
|
2013-02-24 15:35:53 +00:00
|
|
|
* @brief Current samples buffer depth or @p 0.
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
2011-03-08 10:09:57 +00:00
|
|
|
size_t depth;
|
2009-11-29 08:50:13 +00:00
|
|
|
/**
|
2013-02-24 15:35:53 +00:00
|
|
|
* @brief Current conversion group pointer or @p NULL.
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
2011-03-08 10:09:57 +00:00
|
|
|
const ADCConversionGroup *grpp;
|
2010-10-08 18:16:38 +00:00
|
|
|
#if ADC_USE_WAIT || defined(__DOXYGEN__)
|
2010-09-11 10:57:11 +00:00
|
|
|
/**
|
2013-02-24 15:35:53 +00:00
|
|
|
* @brief Waiting thread.
|
2010-09-11 10:57:11 +00:00
|
|
|
*/
|
2011-03-08 10:09:57 +00:00
|
|
|
Thread *thread;
|
2013-02-24 15:35:53 +00:00
|
|
|
#endif
|
2010-10-12 15:19:15 +00:00
|
|
|
#if ADC_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__)
|
2013-07-20 18:04:21 +00:00
|
|
|
#if CH_CFG_USE_MUTEXES || defined(__DOXYGEN__)
|
2010-10-12 15:19:15 +00:00
|
|
|
/**
|
2013-02-24 15:35:53 +00:00
|
|
|
* @brief Mutex protecting the peripheral.
|
2010-10-12 15:19:15 +00:00
|
|
|
*/
|
2011-03-08 10:09:57 +00:00
|
|
|
Mutex mutex;
|
2013-07-20 18:04:21 +00:00
|
|
|
#elif CH_CFG_USE_SEMAPHORES
|
2011-03-08 10:09:57 +00:00
|
|
|
Semaphore semaphore;
|
2010-10-08 18:16:38 +00:00
|
|
|
#endif
|
2010-10-12 15:19:15 +00:00
|
|
|
#endif /* ADC_USE_MUTUAL_EXCLUSION */
|
2010-10-08 18:16:38 +00:00
|
|
|
#if defined(ADC_DRIVER_EXT_FIELDS)
|
|
|
|
ADC_DRIVER_EXT_FIELDS
|
2010-09-11 10:57:11 +00:00
|
|
|
#endif
|
2009-11-29 08:50:13 +00:00
|
|
|
/* End of the mandatory fields.*/
|
2010-10-08 18:16:38 +00:00
|
|
|
};
|
2009-11-29 08:50:13 +00:00
|
|
|
|
2009-12-29 11:12:05 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver macros. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2009-11-29 08:50:13 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* External declarations. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2013-02-24 15:35:53 +00:00
|
|
|
#if PLATFORM_ADC_USE_ADC1 && !defined(__DOXYGEN__)
|
|
|
|
extern ADCDriver ADCD1;
|
|
|
|
#endif
|
|
|
|
|
2009-11-29 08:50:13 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
void adc_lld_init(void);
|
|
|
|
void adc_lld_start(ADCDriver *adcp);
|
|
|
|
void adc_lld_stop(ADCDriver *adcp);
|
|
|
|
void adc_lld_start_conversion(ADCDriver *adcp);
|
|
|
|
void adc_lld_stop_conversion(ADCDriver *adcp);
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-11-01 17:29:56 +00:00
|
|
|
#endif /* HAL_USE_ADC */
|
2009-11-29 08:50:13 +00:00
|
|
|
|
|
|
|
#endif /* _ADC_LLD_H_ */
|
|
|
|
|
|
|
|
/** @} */
|