Skip to content

Commit 08b6936

Browse files
miri64crasbe
andcommitted
feather-m0: add support for saul_bat_voltage
Co-authored-by: crasbe <[email protected]>
1 parent 406fef2 commit 08b6936

File tree

4 files changed

+85
-0
lines changed

4 files changed

+85
-0
lines changed

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+
/** @} */

0 commit comments

Comments
 (0)