2014-02-03 19:34:57 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 Freie Universität Berlin
|
|
|
|
*
|
2014-08-27 18:47:31 +02:00
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
2014-02-03 19:34:57 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2014-10-25 15:37:04 +02:00
|
|
|
* @defgroup driver_periph_adc ADC
|
2014-02-03 19:34:57 +01:00
|
|
|
* @ingroup driver_periph
|
|
|
|
* @brief Low-level ADC peripheral driver
|
|
|
|
* @{
|
|
|
|
*
|
2014-07-17 00:52:00 +02:00
|
|
|
* @file
|
2014-02-03 19:34:57 +01:00
|
|
|
* @brief Low-level ADC peripheral driver interface definitions
|
|
|
|
*
|
|
|
|
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
|
|
|
*/
|
|
|
|
|
2015-03-23 21:07:50 +01:00
|
|
|
#ifndef ADC_H
|
|
|
|
#define ADC_H
|
2014-02-03 19:34:57 +01:00
|
|
|
|
|
|
|
#include "periph_conf.h"
|
|
|
|
|
2014-10-13 15:49:17 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2014-07-17 00:52:00 +02:00
|
|
|
/* guard file in case no ADC device is defined */
|
|
|
|
#if ADC_NUMOF
|
2014-02-03 19:34:57 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Definition available ADC devices
|
2014-05-14 10:46:15 +02:00
|
|
|
*
|
2014-02-03 19:34:57 +01:00
|
|
|
* Each ADC device is based on a hardware ADC which can have one or more
|
|
|
|
* multiplexed channels.
|
|
|
|
*/
|
|
|
|
typedef enum {
|
|
|
|
#if ADC_0_EN
|
2014-07-17 00:52:00 +02:00
|
|
|
ADC_0 = 0, /**< ADC device 0 */
|
2014-02-03 19:34:57 +01:00
|
|
|
#endif
|
|
|
|
#if ADC_1_EN
|
2014-07-17 00:52:00 +02:00
|
|
|
ADC_1, /**< ADC device 1 */
|
2014-02-03 19:34:57 +01:00
|
|
|
#endif
|
|
|
|
#if ADC_2_EN
|
2014-07-17 00:52:00 +02:00
|
|
|
ADC_2, /**< ADC device 2 */
|
2014-02-03 19:34:57 +01:00
|
|
|
#endif
|
|
|
|
#if ADC_3_EN
|
2014-07-17 00:52:00 +02:00
|
|
|
ADC_3, /**< ADC device 3 */
|
2014-02-03 19:34:57 +01:00
|
|
|
#endif
|
|
|
|
} adc_t;
|
|
|
|
|
2014-07-17 00:52:00 +02:00
|
|
|
/**
|
|
|
|
* @brief Possible ADC precision settings
|
|
|
|
*/
|
|
|
|
typedef enum {
|
|
|
|
ADC_RES_6BIT = 0, /**< ADC precision: 6 bit */
|
|
|
|
ADC_RES_8BIT, /**< ADC precision: 8 bit */
|
|
|
|
ADC_RES_10BIT, /**< ADC precision: 10 bit */
|
|
|
|
ADC_RES_12BIT, /**< ADC precision: 12 bit */
|
|
|
|
ADC_RES_14BIT, /**< ADC precision: 14 bit */
|
|
|
|
ADC_RES_16BIT, /**< ADC precision: 16 bit */
|
|
|
|
} adc_precision_t;
|
|
|
|
|
2014-02-03 19:34:57 +01:00
|
|
|
/**
|
|
|
|
* @brief Initialization of a given ADC device
|
2014-05-14 10:46:15 +02:00
|
|
|
*
|
2014-02-03 19:34:57 +01:00
|
|
|
* The ADC will be initialized in synchronous, blocking mode, so no callbacks for finished
|
|
|
|
* conversions are required as conversions are presumed to be very fast (somewhere in the
|
|
|
|
* range of some us).
|
|
|
|
*
|
|
|
|
* @param[in] dev the device to initialize
|
2014-07-17 00:52:00 +02:00
|
|
|
* @param[in] precision the precision to use for conversion
|
2014-02-03 19:34:57 +01:00
|
|
|
*
|
2014-07-17 00:52:00 +02:00
|
|
|
* @return 0 on success
|
|
|
|
* @return -1 on precision not available
|
2014-02-03 19:34:57 +01:00
|
|
|
*/
|
2014-07-17 00:52:00 +02:00
|
|
|
int adc_init(adc_t dev, adc_precision_t precision);
|
2014-02-03 19:34:57 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Start a new conversion by using the given channel.
|
2014-05-14 10:46:15 +02:00
|
|
|
*
|
2014-02-03 19:34:57 +01:00
|
|
|
* If a conversion on any channel on the given ADC core is in progress, it is aborted.
|
2014-05-14 10:46:15 +02:00
|
|
|
*
|
2014-02-03 19:34:57 +01:00
|
|
|
* @param[in] dev the ADC device to use for the conversion
|
|
|
|
* @param[in] channel the channel to convert from
|
|
|
|
*
|
2014-07-17 00:52:00 +02:00
|
|
|
* @return the converted value
|
|
|
|
* @return -1 on invalid channel
|
2014-02-03 19:34:57 +01:00
|
|
|
*/
|
|
|
|
int adc_sample(adc_t dev, int channel);
|
|
|
|
|
2014-07-17 00:52:00 +02:00
|
|
|
/**
|
|
|
|
* @brief Enable the power for the given ADC device
|
|
|
|
*
|
|
|
|
* @param[in] dev the ADC device to power up
|
|
|
|
*/
|
|
|
|
void adc_poweron(adc_t dev);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Disable the power for the given ADC device
|
|
|
|
*
|
|
|
|
* @param[in] dev the ADC device to power down
|
|
|
|
*/
|
|
|
|
void adc_poweroff(adc_t dev);
|
|
|
|
|
2014-02-03 19:34:57 +01:00
|
|
|
/**
|
|
|
|
* @brief Helper function to map a converted value to the given integer range.
|
2014-05-14 10:46:15 +02:00
|
|
|
*
|
2014-02-03 19:34:57 +01:00
|
|
|
* This function is useful for converting sampled ADC values into their physical representation.
|
2014-05-14 10:46:15 +02:00
|
|
|
*
|
2014-02-03 19:34:57 +01:00
|
|
|
* The min value is asserted to be smaller than the max value.
|
2014-05-14 10:46:15 +02:00
|
|
|
*
|
2014-02-03 19:34:57 +01:00
|
|
|
* @param[in] dev the ADC device to read the precision value from (as input interval)
|
|
|
|
* @param[in] value the value to map
|
|
|
|
* @param[in] min the lower bound of the target interval
|
|
|
|
* @param[in] max the upper bound of the target interval
|
|
|
|
*
|
|
|
|
* @return the mapped value
|
|
|
|
*/
|
|
|
|
int adc_map(adc_t dev, int value, int min, int max);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Helper function to map a converted value to the given float range
|
2014-05-14 10:46:15 +02:00
|
|
|
*
|
2014-02-03 19:34:57 +01:00
|
|
|
* @see adc_map
|
2014-05-14 10:46:15 +02:00
|
|
|
*
|
2014-02-03 19:34:57 +01:00
|
|
|
* @param[in] dev the ADC device to read the precision value from (as input interval)
|
|
|
|
* @param[in] value the value to map
|
|
|
|
* @param[in] min the lower bound of the target interval
|
|
|
|
* @param[in] max the upper bound of the target interval
|
|
|
|
*
|
|
|
|
* @return the mapped value
|
|
|
|
*/
|
|
|
|
float adc_mapf(adc_t dev, int value, float min, float max);
|
|
|
|
|
2014-07-17 00:52:00 +02:00
|
|
|
#endif /* ADC_NUMOF */
|
|
|
|
|
2014-10-13 15:49:17 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-03-23 21:07:50 +01:00
|
|
|
#endif /* ADC_H */
|
2014-02-03 19:34:57 +01:00
|
|
|
/** @} */
|