Skip to content

Commit d892c2c

Browse files
committed
common/particle-mesh: add support for saul_bat_voltage
1 parent 7698aca commit d892c2c

File tree

4 files changed

+89
-0
lines changed

4 files changed

+89
-0
lines changed

boards/common/particle-mesh/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
USEMODULE += saul_pwm
45
endif
56

boards/common/particle-mesh/Makefile.features

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
CPU_MODEL = nrf52840xxaa
22

33
# Put defined MCU peripherals here (in alphabetical order)
4+
FEATURES_PROVIDED += board_bat_voltage
45
FEATURES_PROVIDED += periph_i2c
56
FEATURES_PROVIDED += periph_pwm
67
FEATURES_PROVIDED += periph_spi
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright (C) 2024 TU Dresden
3+
*
4+
* This file is subject to the terms and conditions of the GNU Lesser
5+
* General Public License v2.1. See the file LICENSE in the top level
6+
* directory for more details.
7+
*/
8+
9+
/**
10+
* @ingroup boards_feather-nrf52840
11+
* @ingroup saul_bat_voltage
12+
* @{
13+
* @file
14+
* @brief Implementation of battery voltage convert function
15+
*
16+
* @author Martine S. Lenders <[email protected]>
17+
*
18+
* @}
19+
*/
20+
21+
#ifdef MODULE_SAUL_BAT_VOLTAGE
22+
#include "saul/bat_voltage.h"
23+
24+
int16_t saul_bat_voltage_convert(int32_t adc_sample)
25+
{
26+
/* See https://community.particle.io/t/can-argon-or-xenon-read-the-battery-state/45554/6
27+
* and https://docs.particle.io/assets/images/xenon/schematic-main.png */
28+
return (int16_t)((adc_sample * 33L * 1403L) / 10000L);
29+
}
30+
31+
#endif /* MODULE_SAUL_BAT_VOLTAGE */
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright (C) 2024 TU Dresden
3+
*
4+
* This file is subject to the terms and conditions of the GNU Lesser
5+
* General Public License v2.1. See the file LICENSE in the top level
6+
* directory for more details.
7+
*/
8+
9+
/**
10+
* @ingroup boards_common_particle-mesh
11+
* @{
12+
*
13+
* @file
14+
* @brief Configuration of SAUL mapped battery voltage information
15+
*
16+
* @author Martine S. Lenders <[email protected]>
17+
*/
18+
19+
#ifndef BAT_VOLTAGE_PARAMS_H
20+
#define BAT_VOLTAGE_PARAMS_H
21+
22+
#include "saul/bat_voltage.h"
23+
24+
#ifdef __cplusplus
25+
extern "C" {
26+
#endif
27+
28+
/**
29+
* @brief Conversion function to convert ADC sample to battery voltage
30+
*
31+
* @param[in] adc_sample The raw ADC sample.
32+
*
33+
* @return Voltage value for phydat.
34+
*/
35+
int16_t saul_bat_voltage_convert(int32_t adc_sample);
36+
37+
/**
38+
* @brief Battery voltage configuration
39+
*/
40+
static const saul_bat_voltage_params_t saul_bat_voltage_params[] =
41+
{
42+
{
43+
.name = "BAT",
44+
.phydat_scale = -3,
45+
.line = ADC_LINE(3),
46+
.res = ADC_RES_10BIT,
47+
.convert = saul_bat_voltage_convert,
48+
},
49+
};
50+
51+
#ifdef __cplusplus
52+
}
53+
#endif
54+
55+
#endif /* BAT_VOLTAGE_PARAMS_H */
56+
/** @} */

0 commit comments

Comments
 (0)