1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

Merge pull request #16003 from benpicco/cpu/nrf52/saul-vddh

cpu/nrf52: add SAUL driver for VDDH sensor
This commit is contained in:
benpicco 2021-08-25 20:31:53 +02:00 committed by GitHub
commit dde4772aa4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 72 additions and 0 deletions

View File

@ -1,6 +1,7 @@
ifneq (,$(filter saul_default,$(USEMODULE)))
USEMODULE += saul_gpio
USEMODULE += saul_pwm
USEMODULE += saul_nrf_vddh
endif
include $(RIOTBOARD)/common/nrf52/bootloader_nrfutil.dep.mk

View File

@ -20,5 +20,9 @@ ifneq (,$(filter periph_uart_nonblocking,$(USEMODULE)))
USEMODULE += tsrb
endif
ifneq (,$(filter saul_nrf_vddh,$(USEMODULE)))
FEATURES_REQUIRED += periph_adc
endif
include $(RIOTCPU)/nrf5x_common/Makefile.dep
include $(RIOTCPU)/cortexm_common/Makefile.dep

View File

@ -0,0 +1,62 @@
/*
* Copyright (C) 2021 ML!PA Consulting GmbH
*
* 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 sys_auto_init_saul
* @{
*
* @file
* @brief Auto initialization of internal voltage sensor directly mapped to SAUL reg
*
* @author Benjamin Valentin <benjamin.valentin@ml-pa.com>
*
* @}
*/
#include "cpu.h"
#include "log.h"
#include "saul_reg.h"
#include "saul/periph.h"
#include "periph/adc.h"
static int _read_voltage(const void *dev, phydat_t *res)
{
(void)dev;
/* GPIO reference voltage / external output supply voltage in high voltage mode */
const uint8_t vref_deci_volt[] = { 18, 21, 24, 27, 30, 33, 0, 18 };
uint8_t idx = NRF_UICR->REGOUT0 & UICR_REGOUT0_VOUT_Msk;
int raw = adc_sample(NRF52_VDDHDIV5, ADC_RES_12BIT) * 5 * vref_deci_volt[idx] * 100;
res->val[0] = raw >> 12;
res->unit = UNIT_V;
res->scale = -3;
return 1;
}
static saul_driver_t nrf_vddh_saul_driver = {
.read = _read_voltage,
.write = saul_notsup,
.type = SAUL_SENSE_VOLTAGE,
};
void auto_init_nrf_vddh(void)
{
static saul_reg_t saul_reg_entry = {
.dev = NULL,
.name = "NRF_VDDH",
.driver = &nrf_vddh_saul_driver,
};
adc_init(NRF52_VDDHDIV5);
/* add to registry */
saul_reg_add(&(saul_reg_entry));
}

View File

@ -43,6 +43,10 @@ void saul_init_devs(void)
extern void auto_init_nrf_temperature(void);
auto_init_nrf_temperature();
}
if (IS_USED(MODULE_SAUL_NRF_VDDH)) {
extern void auto_init_nrf_vddh(void);
auto_init_nrf_vddh();
}
if (IS_USED(MODULE_AD7746)) {
extern void auto_init_ad7746(void);
auto_init_ad7746();

View File

@ -129,6 +129,7 @@ PSEUDOMODULES += saul_adc
PSEUDOMODULES += saul_default
PSEUDOMODULES += saul_gpio
PSEUDOMODULES += saul_nrf_temperature
PSEUDOMODULES += saul_nrf_vddh
PSEUDOMODULES += saul_pwm
PSEUDOMODULES += scanf_float
PSEUDOMODULES += sched_cb