mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
feather-m0: add support for saul_bat_voltage
This commit is contained in:
parent
745aca6674
commit
291858dfc1
@ -1,5 +1,6 @@
|
||||
ifneq (,$(filter saul_default,$(USEMODULE)))
|
||||
USEMODULE += saul_gpio
|
||||
USEMODULE += saul_bat_voltage
|
||||
endif
|
||||
|
||||
# setup the samd21 arduino bootloader related dependencies
|
||||
|
@ -15,4 +15,5 @@ FEATURES_PROVIDED += periph_usbdev
|
||||
# Put other features for this board (in alphabetical order)
|
||||
FEATURES_PROVIDED += arduino_analog
|
||||
FEATURES_PROVIDED += arduino_pins
|
||||
FEATURES_PROVIDED += board_bat_voltage
|
||||
FEATURES_PROVIDED += highlevel_stdio
|
||||
|
35
boards/feather-m0/bat_voltage.c
Normal file
35
boards/feather-m0/bat_voltage.c
Normal file
@ -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-m0
|
||||
* @ingroup saul_bat_voltage
|
||||
* @{
|
||||
* @file
|
||||
* @brief Implementation of battery voltage convert function
|
||||
*
|
||||
* @author Martine S. Lenders <martine.lenders@tu-dresden.de>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#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/adafruit-feather-m0-basic-proto/power-management
|
||||
*
|
||||
* 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
boards/feather-m0/include/bat_voltage_params.h
Normal file
56
boards/feather-m0/include/bat_voltage_params.h
Normal file
@ -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 <martine.lenders@tu-dresden.de>
|
||||
*/
|
||||
|
||||
#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(7),
|
||||
.res = ADC_RES_10BIT,
|
||||
.convert = saul_bat_voltage_convert,
|
||||
},
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* BAT_VOLTAGE_PARAMS_H */
|
||||
/** @} */
|
Loading…
Reference in New Issue
Block a user