mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
drivers: sys: add SAUL support for ds75lx sensor
This commit is contained in:
parent
69a38f8b7b
commit
a7f8182249
44
drivers/ds75lx/ds75lx_saul.c
Normal file
44
drivers/ds75lx/ds75lx_saul.c
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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 drivers_ds75lx
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief SAUL adaption for DS75LX device
|
||||
*
|
||||
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "saul.h"
|
||||
#include "ds75lx.h"
|
||||
|
||||
static int read_temperature(const void *dev, phydat_t *res)
|
||||
{
|
||||
ds75lx_wakeup((const ds75lx_t *)dev);
|
||||
if (ds75lx_read_temperature((const ds75lx_t *)dev, &res->val[0]) != DS75LX_OK) {
|
||||
ds75lx_shutdown((const ds75lx_t *)dev);
|
||||
return -ECANCELED;
|
||||
}
|
||||
ds75lx_shutdown((const ds75lx_t *)dev);
|
||||
|
||||
res->unit = UNIT_TEMP_C;
|
||||
res->scale = -2;
|
||||
return 1;
|
||||
}
|
||||
|
||||
const saul_driver_t ds75lx_temperature_saul_driver = {
|
||||
.read = read_temperature,
|
||||
.write = saul_notsup,
|
||||
.type = SAUL_SENSE_TEMP
|
||||
};
|
@ -47,6 +47,9 @@ extern "C" {
|
||||
.addr = DS75LX_PARAM_I2C_ADDR, \
|
||||
.resolution = DS75LX_PARAM_RESOLUTION }
|
||||
#endif
|
||||
#ifndef DS75LX_SAUL_INFO
|
||||
#define DS75LX_SAUL_INFO { .name = "ds75lx" }
|
||||
#endif
|
||||
/**@}*/
|
||||
|
||||
/**
|
||||
@ -57,6 +60,14 @@ static const ds75lx_params_t ds75lx_params[] =
|
||||
DS75LX_PARAMS
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Configure SAUL registry entries
|
||||
*/
|
||||
static const saul_reg_info_t ds75lx_saul_info[] =
|
||||
{
|
||||
DS75LX_SAUL_INFO
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -9,8 +9,10 @@
|
||||
/**
|
||||
* @defgroup drivers_ds75lx Maxim DS75LX temperature sensor
|
||||
* @ingroup drivers_sensors
|
||||
* @ingroup drivers_saul
|
||||
* @brief Device driver interface for the Maxim DS75LX temperature sensor
|
||||
*
|
||||
* This driver provides @ref drivers_saul capabilities.
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
|
@ -365,6 +365,10 @@ void auto_init(void)
|
||||
extern void auto_init_ds18(void);
|
||||
auto_init_ds18();
|
||||
#endif
|
||||
#ifdef MODULE_DS75LX
|
||||
extern void auto_init_ds75lx(void);
|
||||
auto_init_ds75lx();
|
||||
#endif
|
||||
#ifdef MODULE_FXOS8700
|
||||
extern void auto_init_fxos8700(void);
|
||||
auto_init_fxos8700();
|
||||
|
79
sys/auto_init/saul/auto_init_ds75lx.c
Normal file
79
sys/auto_init/saul/auto_init_ds75lx.c
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* 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 DS75LX driver.
|
||||
*
|
||||
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef MODULE_DS75LX
|
||||
|
||||
#include "assert.h"
|
||||
#include "log.h"
|
||||
#include "saul_reg.h"
|
||||
#include "ds75lx.h"
|
||||
#include "ds75lx_params.h"
|
||||
|
||||
/**
|
||||
* @brief Define the number of configured sensors
|
||||
*/
|
||||
#define DS75LX_NUM (sizeof(ds75lx_params) / sizeof(ds75lx_params[0]))
|
||||
|
||||
/**
|
||||
* @brief Allocation of memory for device descriptors
|
||||
*/
|
||||
static ds75lx_t ds75lx_devs[DS75LX_NUM];
|
||||
|
||||
/**
|
||||
* @brief Memory for the SAUL registry entries
|
||||
*/
|
||||
static saul_reg_t saul_entries[DS75LX_NUM];
|
||||
|
||||
/**
|
||||
* @brief Define the number of saul info
|
||||
*/
|
||||
#define DS75LX_INFO_NUM (sizeof(ds75lx_saul_info) / sizeof(ds75lx_saul_info[0]))
|
||||
|
||||
/**
|
||||
* @name Reference the driver structs.
|
||||
* @{
|
||||
*/
|
||||
extern const saul_driver_t ds75lx_temperature_saul_driver;
|
||||
/** @} */
|
||||
|
||||
void auto_init_ds75lx(void)
|
||||
{
|
||||
assert(DS75LX_INFO_NUM == DS75LX_NUM);
|
||||
|
||||
for (unsigned i = 0; i < DS75LX_NUM; i++) {
|
||||
LOG_DEBUG("[auto_init_saul] initializing ds75lx #%u\n", i);
|
||||
|
||||
if (ds75lx_init(&ds75lx_devs[i],
|
||||
&ds75lx_params[i]) != DS75LX_OK) {
|
||||
LOG_ERROR("[auto_init_saul] error initializing ds75lx #%u\n", i);
|
||||
continue;
|
||||
}
|
||||
|
||||
saul_entries[i].dev = &(ds75lx_devs[i]);
|
||||
saul_entries[i].name = ds75lx_saul_info[i].name;
|
||||
saul_entries[i].driver = &ds75lx_temperature_saul_driver;
|
||||
|
||||
/* register to saul */
|
||||
saul_reg_add(&(saul_entries[i]));
|
||||
}
|
||||
}
|
||||
#else
|
||||
typedef int dont_be_pedantic;
|
||||
#endif /* MODULE_DS75LX */
|
Loading…
Reference in New Issue
Block a user