1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-30 00:41:17 +01:00

Merge pull request #11139 from aabadie/pr/cpu/nrf5x_temperature

cpu/nrf5x: add driver for internal temperature sensor
This commit is contained in:
Marian Buschsieweke 2019-03-10 16:42:28 +01:00 committed by GitHub
commit 0f587e04f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 135 additions and 0 deletions

View File

@ -602,6 +602,10 @@ ifneq (,$(filter saul,$(USEMODULE)))
USEMODULE += phydat
endif
ifneq (,$(filter saul_nrf_temperature,$(USEMODULE)))
FEATURES_REQUIRED += periph_temperature
endif
ifneq (,$(filter phydat,$(USEMODULE)))
USEMODULE += fmt
endif

View File

@ -1,3 +1,7 @@
ifneq (,$(filter gnrc_netdev_default netdev_default,$(USEMODULE)))
USEMODULE += nrfmin
endif
ifneq (,$(filter saul_default,$(USEMODULE)))
USEMODULE += saul_nrf_temperature
endif

View File

@ -3,3 +3,7 @@ include $(RIOTCPU)/nrf52/Makefile.dep
ifneq (,$(filter skald,$(USEMODULE)))
USEMODULE += nrfble
endif
ifneq (,$(filter saul_default,$(USEMODULE)))
USEMODULE += saul_nrf_temperature
endif

View File

@ -3,6 +3,7 @@ FEATURES_PROVIDED += periph_cpuid
FEATURES_PROVIDED += periph_flashpage
FEATURES_PROVIDED += periph_gpio periph_gpio_irq
FEATURES_PROVIDED += periph_hwrng
FEATURES_PROVIDED += periph_temperature
# Various other features (if any)
FEATURES_PROVIDED += radio_nrfmin

View File

@ -0,0 +1,62 @@
/*
* Copyright (C) 2019 Inria
*
* 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 cpu_nrf5x_common
* @{
*
* @file
* @brief Implementation of the temperature peripheral internal driver
*
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
*
* @}
*/
#include "cpu.h"
#include "saul.h"
#include "saul_reg.h"
#include "phydat.h"
void temperature_read(int16_t *temp)
{
/* Start temperature measurement task */
NRF_TEMP->TASKS_START = 1;
/* Wait for temperature measurement to be ready */
while (!NRF_TEMP->EVENTS_DATARDY); /* takes 36us according to manual */
/* temperature is in 0.25°C step, so just divide by 4 */
*temp = (int16_t)NRF_TEMP->TEMP >> 2;
/* Clear data ready bit and stop temperature measurement task */
NRF_TEMP->EVENTS_DATARDY = 0;
NRF_TEMP->TASKS_STOP = 1;
}
static int _read_temperature(const void *dev, phydat_t *res)
{
(void) dev;
temperature_read(&res->val[0]);
res->val[1] = 0;
res->val[2] = 0;
res->unit = UNIT_TEMP_C;
res->scale = 0;
return 1;
}
const saul_reg_info_t nrf_temperature_saul_info = {
.name = "NRF_TEMP"
};
const saul_driver_t nrf_temperature_saul_driver = {
.read = _read_temperature,
.write = saul_notsup,
.type = SAUL_SENSE_TEMP,
};

View File

@ -62,6 +62,7 @@ PSEUDOMODULES += riotboot_%
PSEUDOMODULES += saul_adc
PSEUDOMODULES += saul_default
PSEUDOMODULES += saul_gpio
PSEUDOMODULES += saul_nrf_temperature
PSEUDOMODULES += schedstatistics
PSEUDOMODULES += sock
PSEUDOMODULES += sock_ip

View File

@ -326,6 +326,10 @@ void auto_init(void)
extern void auto_init_gpio(void);
auto_init_gpio();
#endif
#ifdef MODULE_SAUL_NRF_TEMPERATURE
extern void auto_init_nrf_temperature(void);
auto_init_nrf_temperature();
#endif
#ifdef MODULE_AD7746
extern void auto_init_ad7746(void);
auto_init_ad7746();

View File

@ -0,0 +1,55 @@
/*
* Copyright (C) 2019 Inria
*
* 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 temperature sensor directly mapped to SAUL reg
*
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
*
* @}
*/
#ifdef MODULE_SAUL_NRF_TEMPERATURE
#include "cpu.h"
#include "log.h"
#include "saul_reg.h"
#include "saul/periph.h"
/**
* @brief Memory for the registry entries
*/
static saul_reg_t saul_reg_entry;
/**
* @brief Reference the driver struct
*/
extern saul_driver_t nrf_temperature_saul_driver;
/**
* @brief Reference the information for saul registry
*/
extern saul_reg_info_t nrf_temperature_saul_info;
void auto_init_nrf_temperature(void)
{
saul_reg_entry.dev = NULL;
saul_reg_entry.name = nrf_temperature_saul_info.name;
saul_reg_entry.driver = &nrf_temperature_saul_driver;
/* add to registry */
saul_reg_add(&(saul_reg_entry));
}
#else
typedef int dont_be_pedantic;
#endif /* MODULE_SAUL_NRF_TEMPERATURE */