Browse Source

sys: s/adc_util/analog_util/ and added DAC mapping

pr/gpio
Hauke Petersen 7 years ago
parent
commit
a1e3bb1bfc
  1. 0
      sys/analog_util/Makefile
  2. 6
      sys/analog_util/adc_util.c
  3. 33
      sys/analog_util/dac_util.c
  4. 39
      sys/include/analog_util.h

0
sys/adc_util/Makefile → sys/analog_util/Makefile

6
sys/adc_util/adc_util.c → sys/analog_util/adc_util.c

@ -7,7 +7,7 @@
*/
/**
* @ingroup sys_adc_util
* @ingroup sys_analog_util
* @{
*
* @file
@ -18,7 +18,7 @@
* @}
*/
#include "adc_util.h"
#include "analog_util.h"
/* keep a max value to ADC resolution mapping for quick access in the ROM */
static const int val_max[] = {
@ -28,7 +28,7 @@ static const int val_max[] = {
[ADC_RES_12BIT] = 0x0fff,
[ADC_RES_14BIT] = 0x3fff,
[ADC_RES_16BIT] = 0xffff
}
};
int adc_util_map(int sample, adc_res_t res, int min, int max)
{

33
sys/analog_util/dac_util.c

@ -0,0 +1,33 @@
/*
* Copyright (C) 2015 Freie Universität Berlin
*
* 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.
*/
/**
* @ingroup sys_analog_util
* @{
*
* @file
* @brief DAC utility function implementation
*
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
*
* @}
*/
#include <limits.h>
#include "analog_util.h"
uint16_t dac_util_map(int value, int min, int max)
{
return (uint16_t)((value - min) * UINT16_MAX) / (max - min);
}
uint16_t dac_util_mapf(float value, float min, float max)
{
return (uint16_t)(((value - min) * UINT16_MAX) / (max - min));
}

39
sys/include/adc_util.h → sys/include/analog_util.h

@ -7,19 +7,19 @@
*/
/**
* @defgroup sys_adc_util ADC utilities
* @defgroup sys_analog_util Analog data conversion utilities
* @ingroup sys
* @brief Utility functions for handling ADC samples
* @brief Utility functions for converting analog data samples
*
* @{
* @file
* @brief ADC utility function interfaces
* @brief Analog utility function interfaces
*
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
*/
#ifndef ADC_UTIL_H
#define ADC_UTIL_H
#ifndef ANALOG_UTIL_H
#define ANALOG_UTIL_H
#include "periph/adc.h"
@ -59,9 +59,36 @@ int adc_util_map(int sample, adc_res_t res, int min, int max);
*/
float adc_util_mapf(int sample, adc_res_t res, float min, float max);
/**
* @brief Map a value out of the given range to a 16-bit unsigned int
*
* The min value is assumed to be smaller than max value and value is assumed
* to be between min and max.
*
* @param[in] value value to map to a DAC set value
* @param[in] min the lower bound of the source interval
* @param[in] max the upper bound of the source interval
*
* @return the mapped value
*/
uint16_t dac_util_map(int value, int min, int max);
/**
* @brief Helper function to map a given float value range to a valid DAC value.
*
* @see dac_util_map
*
* @param[in] value value to map to a DAC set value
* @param[in] min the lower bound of the source interval
* @param[in] max the upper bound of the source interval
*
* @return the mapped value
*/
uint16_t dac_util_mapf(float value, float min, float max);
#ifdef __cplusplus
}
#endif
#endif /* ADC_UTIL_H */
#endif /* ANALOG_UTIL_H */
/** @} */
Loading…
Cancel
Save