forked from RIOT-OS/RIOT
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sys: s/adc_util/analog_util/ and added DAC mapping
- Loading branch information
1 parent
40ae604
commit a1e3bb1
Showing
4 changed files
with
69 additions
and
9 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <[email protected]> | ||
* | ||
* @} | ||
*/ | ||
|
||
#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)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 <[email protected]> | ||
*/ | ||
|
||
#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 */ | ||
/** @} */ |