Skip to content

Commit 1be70cf

Browse files
authored
Merge pull request #21022 from miri64/saul_bat_voltage/enh/feather-m0-config
feather-m0: add support for saul_bat_voltage
2 parents 39c68a7 + 08b6936 commit 1be70cf

File tree

8 files changed

+89
-4
lines changed

8 files changed

+89
-4
lines changed

boards/adafruit-feather-nrf52840-express/include/bat_voltage_params.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ extern "C" {
2626
*
2727
* @param[in] adc_sample The raw ADC sample.
2828
*
29-
* @return Voltage value for phydat.
29+
* @return Voltage value in mV for phydat.
3030
*/
3131
int16_t saul_bat_voltage_convert(int32_t adc_sample);
3232

boards/adafruit-feather-nrf52840-sense/include/bat_voltage_params.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ extern "C" {
2626
*
2727
* @param[in] adc_sample The raw ADC sample.
2828
*
29-
* @return Voltage value for phydat.
29+
* @return Voltage value in mV for phydat.
3030
*/
3131
int16_t saul_bat_voltage_convert(int32_t adc_sample);
3232

boards/common/particle-mesh/include/bat_voltage_params.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ extern "C" {
2626
*
2727
* @param[in] adc_sample The raw ADC sample.
2828
*
29-
* @return Voltage value for phydat.
29+
* @return Voltage value in mV for phydat.
3030
*/
3131
int16_t saul_bat_voltage_convert(int32_t adc_sample);
3232

boards/feather-m0/Makefile.dep

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
ifneq (,$(filter saul_default,$(USEMODULE)))
22
USEMODULE += saul_gpio
3+
USEMODULE += saul_bat_voltage
34
endif
45

56
# setup the samd21 arduino bootloader related dependencies

boards/feather-m0/Makefile.features

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ FEATURES_PROVIDED += periph_usbdev
1515
# Put other features for this board (in alphabetical order)
1616
FEATURES_PROVIDED += arduino_analog
1717
FEATURES_PROVIDED += arduino_pins
18+
FEATURES_PROVIDED += board_bat_voltage
1819
FEATURES_PROVIDED += feather_shield
1920
FEATURES_PROVIDED += highlevel_stdio

boards/feather-m0/bat_voltage.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2024 TU Dresden
3+
* SPDX-License-Identifier: LGPL-2.1-only
4+
*/
5+
6+
/**
7+
* @ingroup boards_feather-m0
8+
* @ingroup saul_bat_voltage
9+
* @{
10+
* @file
11+
* @brief Implementation of battery voltage convert function
12+
*
13+
* @author Martine S. Lenders <[email protected]>
14+
*
15+
* @}
16+
*/
17+
18+
#ifdef MODULE_SAUL_BAT_VOLTAGE
19+
#include "saul/bat_voltage.h"
20+
21+
int16_t saul_bat_voltage_convert(int32_t adc_sample)
22+
{
23+
/* See
24+
* https://learn.adafruit.com/adafruit-feather-m0-basic-proto/power-management
25+
*
26+
* we return in millivolt so we set the reference voltage to 3300
27+
* instead of 3.3
28+
*/
29+
return (int16_t)((adc_sample * 2L * 3300L) / 1024L);
30+
}
31+
32+
#endif /* MODULE_SAUL_BAT_VOLTAGE */
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2024 TU Dresden
3+
* SPDX-License-Identifier: LGPL-2.1-only
4+
*/
5+
6+
#pragma once
7+
8+
/**
9+
* @ingroup boards_feather-m0
10+
* @{
11+
*
12+
* @file
13+
* @brief Configuration of SAUL mapped battery voltage information
14+
*
15+
* @author Martine S. Lenders <[email protected]>
16+
*/
17+
18+
#include "saul/bat_voltage.h"
19+
20+
#ifdef __cplusplus
21+
extern "C" {
22+
#endif
23+
24+
/**
25+
* @brief Conversion function to convert ADC sample to battery voltage
26+
*
27+
* @param[in] adc_sample The raw ADC sample.
28+
*
29+
* @return Voltage value in mV for phydat.
30+
*/
31+
int16_t saul_bat_voltage_convert(int32_t adc_sample);
32+
33+
/**
34+
* @brief Battery voltage configuration
35+
*/
36+
static const saul_bat_voltage_params_t saul_bat_voltage_params[] =
37+
{
38+
{
39+
.name = "BAT",
40+
.phydat_scale = -3,
41+
.line = ADC_LINE(6),
42+
.res = ADC_RES_10BIT,
43+
.convert = saul_bat_voltage_convert,
44+
},
45+
};
46+
47+
#ifdef __cplusplus
48+
}
49+
#endif
50+
51+
/** @} */

drivers/include/saul/bat_voltage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ typedef struct {
3939
*
4040
* @param[in] adc_sample The raw ADC sample.
4141
*
42-
* @return Voltage value for phydat.
42+
* @return Voltage value in 10^phydat_scale*V for phydat.
4343
*/
4444
int16_t (*convert)(int32_t adc_sample);
4545
} saul_bat_voltage_params_t;

0 commit comments

Comments
 (0)