forked from RIOT-OS/RIOT
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request RIOT-OS#21018 from miri64/saul_bat_voltage/feat/in…
…itial saul: initial import of saul_bat_voltage module
- Loading branch information
Showing
24 changed files
with
468 additions
and
1 deletion.
There are no files selected for viewing
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
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,31 @@ | ||
/* | ||
* Copyright (C) 2024 TU Dresden | ||
* | ||
* 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 boards_feather-nrf52840 | ||
* @ingroup saul_bat_voltage | ||
* @{ | ||
* @file | ||
* @brief Implementation of battery voltage convert function | ||
* | ||
* @author Martine S. Lenders <[email protected]> | ||
* | ||
* @} | ||
*/ | ||
|
||
#ifdef MODULE_SAUL_BAT_VOLTAGE | ||
#include "saul/bat_voltage.h" | ||
|
||
int16_t saul_bat_voltage_convert(int32_t adc_sample) | ||
{ | ||
/* See https://community.particle.io/t/can-argon-or-xenon-read-the-battery-state/45554/6 | ||
* and https://docs.particle.io/assets/images/xenon/schematic-main.png */ | ||
return (int16_t)((adc_sample * 33L * 1403L) / 10000L); | ||
} | ||
|
||
#endif /* MODULE_SAUL_BAT_VOLTAGE */ |
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,56 @@ | ||
/* | ||
* Copyright (C) 2024 TU Dresden | ||
* | ||
* 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 boards_common_particle-mesh | ||
* @{ | ||
* | ||
* @file | ||
* @brief Configuration of SAUL mapped battery voltage information | ||
* | ||
* @author Martine S. Lenders <[email protected]> | ||
*/ | ||
|
||
#ifndef BAT_VOLTAGE_PARAMS_H | ||
#define BAT_VOLTAGE_PARAMS_H | ||
|
||
#include "saul/bat_voltage.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/** | ||
* @brief Conversion function to convert ADC sample to battery voltage | ||
* | ||
* @param[in] adc_sample The raw ADC sample. | ||
* | ||
* @return Voltage value for phydat. | ||
*/ | ||
int16_t saul_bat_voltage_convert(int32_t adc_sample); | ||
|
||
/** | ||
* @brief Battery voltage configuration | ||
*/ | ||
static const saul_bat_voltage_params_t saul_bat_voltage_params[] = | ||
{ | ||
{ | ||
.name = "BAT", | ||
.phydat_scale = -3, | ||
.line = ADC_LINE(3), | ||
.res = ADC_RES_10BIT, | ||
.convert = saul_bat_voltage_convert, | ||
}, | ||
}; | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* BAT_VOLTAGE_PARAMS_H */ | ||
/** @} */ |
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
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,35 @@ | ||
/* | ||
* Copyright (C) 2024 TU Dresden | ||
* | ||
* 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 boards_feather-nrf52840 | ||
* @ingroup saul_bat_voltage | ||
* @{ | ||
* @file | ||
* @brief Implementation of battery voltage convert function | ||
* | ||
* @author Martine S. Lenders <[email protected]> | ||
* | ||
* @} | ||
*/ | ||
|
||
#ifdef MODULE_SAUL_BAT_VOLTAGE | ||
#include "saul/bat_voltage.h" | ||
|
||
int16_t saul_bat_voltage_convert(int32_t adc_sample) | ||
{ | ||
/* See | ||
* https://learn.adafruit.com/introducing-the-adafruit-nrf52840-feather/power-management-2 | ||
* | ||
* but the reference voltage is actually 3.3V (determined empirically)... | ||
* we return in millivolt so we set the reference voltage to 3300 | ||
* instead of 3.3 */ | ||
return (int16_t)((adc_sample * 2L * 3300L) / 1024L); | ||
} | ||
|
||
#endif /* MODULE_SAUL_BAT_VOLTAGE */ |
56 changes: 56 additions & 0 deletions
56
boards/feather-nrf52840-sense/include/bat_voltage_params.h
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,56 @@ | ||
/* | ||
* Copyright (C) 2024 TU Dresden | ||
* | ||
* 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 boards_feather-nrf52840-sense | ||
* @{ | ||
* | ||
* @file | ||
* @brief Configuration of SAUL mapped battery voltage information | ||
* | ||
* @author Martine S. Lenders <[email protected]> | ||
*/ | ||
|
||
#ifndef BAT_VOLTAGE_PARAMS_H | ||
#define BAT_VOLTAGE_PARAMS_H | ||
|
||
#include "saul/bat_voltage.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/** | ||
* @brief Conversion function to convert ADC sample to battery voltage | ||
* | ||
* @param[in] adc_sample The raw ADC sample. | ||
* | ||
* @return Voltage value for phydat. | ||
*/ | ||
int16_t saul_bat_voltage_convert(int32_t adc_sample); | ||
|
||
/** | ||
* @brief Battery voltage configuration | ||
*/ | ||
static const saul_bat_voltage_params_t saul_bat_voltage_params[] = | ||
{ | ||
{ | ||
.name = "BAT", | ||
.phydat_scale = -3, | ||
.line = ADC_LINE(5), | ||
.res = ADC_RES_10BIT, | ||
.convert = saul_bat_voltage_convert, | ||
}, | ||
}; | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* BAT_VOLTAGE_PARAMS_H */ | ||
/** @} */ |
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
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,35 @@ | ||
/* | ||
* Copyright (C) 2024 TU Dresden | ||
* | ||
* 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 boards_feather-nrf52840 | ||
* @ingroup saul_bat_voltage | ||
* @{ | ||
* @file | ||
* @brief Implementation of battery voltage convert function | ||
* | ||
* @author Martine S. Lenders <[email protected]> | ||
* | ||
* @} | ||
*/ | ||
|
||
#ifdef MODULE_SAUL_BAT_VOLTAGE | ||
#include "saul/bat_voltage.h" | ||
|
||
int16_t saul_bat_voltage_convert(int32_t adc_sample) | ||
{ | ||
/* See | ||
* https://learn.adafruit.com/introducing-the-adafruit-nrf52840-feather/power-management-2 | ||
* | ||
* but the reference voltage is actually 3.3V (determined empirically)... | ||
* we return in millivolt so we set the reference voltage to 3300 | ||
* instead of 3.3 */ | ||
return (int16_t)((adc_sample * 2L * 3300L) / 1024L); | ||
} | ||
|
||
#endif /* MODULE_SAUL_BAT_VOLTAGE */ |
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,56 @@ | ||
/* | ||
* Copyright (C) 2024 TU Dresden | ||
* | ||
* 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 boards_feather-nrf52840 | ||
* @{ | ||
* | ||
* @file | ||
* @brief Configuration of SAUL mapped battery voltage information | ||
* | ||
* @author Martine S. Lenders <[email protected]> | ||
*/ | ||
|
||
#ifndef BAT_VOLTAGE_PARAMS_H | ||
#define BAT_VOLTAGE_PARAMS_H | ||
|
||
#include "saul/bat_voltage.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/** | ||
* @brief Conversion function to convert ADC sample to battery voltage | ||
* | ||
* @param[in] adc_sample The raw ADC sample. | ||
* | ||
* @return Voltage value for phydat. | ||
*/ | ||
int16_t saul_bat_voltage_convert(int32_t adc_sample); | ||
|
||
/** | ||
* @brief Battery voltage configuration | ||
*/ | ||
static const saul_bat_voltage_params_t saul_bat_voltage_params[] = | ||
{ | ||
{ | ||
.name = "BAT", | ||
.phydat_scale = -3, | ||
.line = ADC_LINE(5), | ||
.res = ADC_RES_10BIT, | ||
.convert = saul_bat_voltage_convert, | ||
}, | ||
}; | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* BAT_VOLTAGE_PARAMS_H */ | ||
/** @} */ |
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
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
Oops, something went wrong.