2014-11-01 17:01:38 +00:00
|
|
|
/*
|
2016-03-18 10:29:35 +00:00
|
|
|
ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio
|
2014-11-01 17:01:38 +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
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2014-11-02 16:38:13 +00:00
|
|
|
* @file adc_lld.h
|
|
|
|
* @brief PLATFORM ADC subsystem low level driver header.
|
2014-11-01 17:01:38 +00:00
|
|
|
*
|
|
|
|
* @addtogroup ADC
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _ADC_LLD_H_
|
|
|
|
#define _ADC_LLD_H_
|
|
|
|
|
2015-03-09 10:48:08 +00:00
|
|
|
#if (HAL_USE_ADC == TRUE) || defined(__DOXYGEN__)
|
2014-11-01 17:01:38 +00:00
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver constants. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver pre-compile time settings. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/**
|
2014-12-11 14:45:16 +00:00
|
|
|
* @name PLATFORM configuration options
|
2014-11-01 17:01:38 +00:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @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__)
|
2014-11-02 10:06:54 +00:00
|
|
|
#define PLATFORM_ADC_USE_ADC1 FALSE
|
2014-11-01 17:01:38 +00:00
|
|
|
#endif
|
|
|
|
/** @} */
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Derived constants and error checks. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver data structures and types. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief ADC sample data type.
|
|
|
|
*/
|
|
|
|
typedef uint16_t adcsample_t;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Channels number in a conversion group.
|
|
|
|
*/
|
|
|
|
typedef uint16_t adc_channels_num_t;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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. */
|
2014-11-02 10:06:54 +00:00
|
|
|
ADC_ERR_OVERFLOW = 1, /**< ADC overflow condition. */
|
|
|
|
ADC_ERR_AWD = 2 /**< Analog watchdog triggered. */
|
2014-11-01 17:01:38 +00:00
|
|
|
} adcerror_t;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Type of a structure representing an ADC driver.
|
|
|
|
*/
|
|
|
|
typedef struct ADCDriver ADCDriver;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief ADC notification callback type.
|
|
|
|
*
|
|
|
|
* @param[in] adcp pointer to the @p ADCDriver object triggering the
|
|
|
|
* callback
|
|
|
|
* @param[in] buffer pointer to the most recent samples data
|
|
|
|
* @param[in] n number of buffer rows available starting from @p buffer
|
|
|
|
*/
|
|
|
|
typedef void (*adccallback_t)(ADCDriver *adcp, adcsample_t *buffer, size_t n);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Conversion group configuration structure.
|
|
|
|
* @details This implementation-dependent structure describes a conversion
|
|
|
|
* operation.
|
2014-11-02 10:06:54 +00:00
|
|
|
* @note The use of this configuration structure requires knowledge of
|
|
|
|
* PLATFORM ADC cell registers interface, please refer to the PLATFORM
|
|
|
|
* reference manual for details.
|
2014-11-01 17:01:38 +00:00
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
/**
|
|
|
|
* @brief Enables the circular buffer mode for the group.
|
|
|
|
*/
|
2014-11-02 10:06:54 +00:00
|
|
|
bool circular;
|
2014-11-01 17:01:38 +00:00
|
|
|
/**
|
|
|
|
* @brief Number of the analog channels belonging to the conversion group.
|
|
|
|
*/
|
|
|
|
adc_channels_num_t num_channels;
|
|
|
|
/**
|
|
|
|
* @brief Callback function associated to the group or @p NULL.
|
|
|
|
*/
|
|
|
|
adccallback_t end_cb;
|
|
|
|
/**
|
|
|
|
* @brief Error callback or @p NULL.
|
|
|
|
*/
|
|
|
|
adcerrorcallback_t error_cb;
|
|
|
|
/* End of the mandatory fields.*/
|
|
|
|
} ADCConversionGroup;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Driver configuration structure.
|
|
|
|
* @note It could be empty on some architectures.
|
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
uint32_t dummy;
|
|
|
|
} ADCConfig;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Structure representing an ADC driver.
|
|
|
|
*/
|
|
|
|
struct ADCDriver {
|
|
|
|
/**
|
2014-11-02 10:06:54 +00:00
|
|
|
* @brief Driver state.
|
2014-11-01 17:01:38 +00:00
|
|
|
*/
|
|
|
|
adcstate_t state;
|
|
|
|
/**
|
2014-11-02 10:06:54 +00:00
|
|
|
* @brief Current configuration data.
|
2014-11-01 17:01:38 +00:00
|
|
|
*/
|
|
|
|
const ADCConfig *config;
|
|
|
|
/**
|
2014-11-02 10:06:54 +00:00
|
|
|
* @brief Current samples buffer pointer or @p NULL.
|
2014-11-01 17:01:38 +00:00
|
|
|
*/
|
|
|
|
adcsample_t *samples;
|
|
|
|
/**
|
2014-11-02 10:06:54 +00:00
|
|
|
* @brief Current samples buffer depth or @p 0.
|
2014-11-01 17:01:38 +00:00
|
|
|
*/
|
|
|
|
size_t depth;
|
|
|
|
/**
|
2014-11-02 10:06:54 +00:00
|
|
|
* @brief Current conversion group pointer or @p NULL.
|
2014-11-01 17:01:38 +00:00
|
|
|
*/
|
|
|
|
const ADCConversionGroup *grpp;
|
2015-03-09 10:48:08 +00:00
|
|
|
#if (ADC_USE_WAIT == TRUE) || defined(__DOXYGEN__)
|
2014-11-01 17:01:38 +00:00
|
|
|
/**
|
2014-11-02 10:06:54 +00:00
|
|
|
* @brief Waiting thread.
|
2014-11-01 17:01:38 +00:00
|
|
|
*/
|
2014-11-02 10:06:54 +00:00
|
|
|
thread_reference_t thread;
|
2014-11-01 17:01:38 +00:00
|
|
|
#endif
|
2015-03-09 10:48:08 +00:00
|
|
|
#if (ADC_USE_MUTUAL_EXCLUSION == TRUE) || defined(__DOXYGEN__)
|
2014-11-01 17:01:38 +00:00
|
|
|
/**
|
2014-11-02 10:06:54 +00:00
|
|
|
* @brief Mutex protecting the peripheral.
|
2014-11-01 17:01:38 +00:00
|
|
|
*/
|
2014-11-02 10:06:54 +00:00
|
|
|
mutex_t mutex;
|
2015-03-09 10:48:08 +00:00
|
|
|
#endif
|
2014-11-01 17:01:38 +00:00
|
|
|
#if defined(ADC_DRIVER_EXT_FIELDS)
|
|
|
|
ADC_DRIVER_EXT_FIELDS
|
|
|
|
#endif
|
|
|
|
/* End of the mandatory fields.*/
|
|
|
|
};
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver macros. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* External declarations. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2015-03-09 10:48:08 +00:00
|
|
|
#if (PLATFORM_ADC_USE_ADC1 == TRUE) && !defined(__DOXYGEN__)
|
2014-11-01 17:01:38 +00:00
|
|
|
extern ADCDriver ADCD1;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
2015-03-09 10:48:08 +00:00
|
|
|
#endif /* HAL_USE_ADC == TRUE */
|
2014-11-01 17:01:38 +00:00
|
|
|
|
|
|
|
#endif /* _ADC_LLD_H_ */
|
|
|
|
|
|
|
|
/** @} */
|