driver, hts221: add SAUL adaption
This commit is contained in:
parent
697ff44ce1
commit
df2b65a1dd
58
drivers/hts221/hts221_saul.c
Normal file
58
drivers/hts221/hts221_saul.c
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 HAW Hamburg
|
||||||
|
*
|
||||||
|
* 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_hts221
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
* @file
|
||||||
|
* @brief HTS221 adaption to the RIOT SAUL interface
|
||||||
|
*
|
||||||
|
* @author Sebastian Meiling <s@mlng.net>
|
||||||
|
*
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "saul.h"
|
||||||
|
#include "hts221.h"
|
||||||
|
|
||||||
|
static int read_temp(const void *dev, phydat_t *res)
|
||||||
|
{
|
||||||
|
if (hts221_read_temperature((const hts221_t *)dev, &res->val[0]) != HTS221_OK) {
|
||||||
|
return -ECANCELED;
|
||||||
|
}
|
||||||
|
res->unit = UNIT_TEMP_C;
|
||||||
|
res->scale = -1;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int read_hum(const void *dev, phydat_t *res)
|
||||||
|
{
|
||||||
|
if (hts221_read_humidity((const hts221_t *)dev, (uint16_t *)&res->val[0]) != HTS221_OK) {
|
||||||
|
return -ECANCELED;
|
||||||
|
}
|
||||||
|
res->unit = UNIT_PERCENT;
|
||||||
|
res->scale = -1;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const saul_driver_t hts221_saul_temp_driver = {
|
||||||
|
.read = read_temp,
|
||||||
|
.write = saul_notsup,
|
||||||
|
.type = SAUL_SENSE_TEMP,
|
||||||
|
};
|
||||||
|
|
||||||
|
const saul_driver_t hts221_saul_hum_driver = {
|
||||||
|
.read = read_hum,
|
||||||
|
.write = saul_notsup,
|
||||||
|
.type = SAUL_SENSE_HUM,
|
||||||
|
};
|
||||||
@ -51,6 +51,10 @@ extern "C" {
|
|||||||
.avgx = HTS221_PARAM_AVGX, \
|
.avgx = HTS221_PARAM_AVGX, \
|
||||||
.rate = HTS221_PARAM_RATE }
|
.rate = HTS221_PARAM_RATE }
|
||||||
#endif /* HTS221_PARAMS */
|
#endif /* HTS221_PARAMS */
|
||||||
|
|
||||||
|
#ifndef HTS221_SAULINFO
|
||||||
|
#define HTS221_SAULINFO { .name = "hts221" }
|
||||||
|
#endif
|
||||||
/**@}*/
|
/**@}*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -61,6 +65,14 @@ static const hts221_params_t hts221_params[] =
|
|||||||
HTS221_PARAMS,
|
HTS221_PARAMS,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Additional meta information to keep in the SAUL registry
|
||||||
|
*/
|
||||||
|
static const saul_reg_info_t hts221_saul_info[] =
|
||||||
|
{
|
||||||
|
HTS221_SAULINFO
|
||||||
|
};
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -317,6 +317,10 @@ void auto_init(void)
|
|||||||
extern void auto_init_hdc1000(void);
|
extern void auto_init_hdc1000(void);
|
||||||
auto_init_hdc1000();
|
auto_init_hdc1000();
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef MODULE_HTS221
|
||||||
|
extern void auto_init_hts221(void);
|
||||||
|
auto_init_hts221();
|
||||||
|
#endif
|
||||||
#ifdef MODULE_DHT
|
#ifdef MODULE_DHT
|
||||||
extern void auto_init_dht(void);
|
extern void auto_init_dht(void);
|
||||||
auto_init_dht();
|
auto_init_dht();
|
||||||
|
|||||||
88
sys/auto_init/saul/auto_init_hts221.c
Normal file
88
sys/auto_init/saul/auto_init_hts221.c
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 HAW Hamburg
|
||||||
|
*
|
||||||
|
* 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 auto_init_saul
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
* @file
|
||||||
|
* @brief Auto initialization for HTS221 devices
|
||||||
|
*
|
||||||
|
* @author Sebastian Meiling <s@mlng.net>
|
||||||
|
*
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef MODULE_HTS221
|
||||||
|
|
||||||
|
#include "log.h"
|
||||||
|
#include "saul_reg.h"
|
||||||
|
#include "hts221.h"
|
||||||
|
#include "hts221_params.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Define the number of configured sensors
|
||||||
|
*/
|
||||||
|
#define HTS221_NUM (sizeof(hts221_params)/sizeof(hts221_params[0]))
|
||||||
|
|
||||||
|
#define HTS221_SAUL_NUM (sizeof(hts221_saul_info)/sizeof(hts221_saul_info[0]))
|
||||||
|
/**
|
||||||
|
* @brief Allocate memory for the device descriptors
|
||||||
|
*/
|
||||||
|
static hts221_t hts221_devs[HTS221_NUM];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Memory for the SAUL registry entries
|
||||||
|
*/
|
||||||
|
static saul_reg_t saul_entries[HTS221_NUM * 2];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Reference the driver struct
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
extern saul_driver_t hts221_saul_temp_driver;
|
||||||
|
extern saul_driver_t hts221_saul_hum_driver;
|
||||||
|
/** @} */
|
||||||
|
|
||||||
|
|
||||||
|
void auto_init_hts221(void)
|
||||||
|
{
|
||||||
|
assert(HTS221_NUM == HTS221_SAUL_NUM);
|
||||||
|
|
||||||
|
for (unsigned i = 0; i < HTS221_NUM; i++) {
|
||||||
|
LOG_DEBUG("[auto_init_saul] initializing hts221 #%u\n", i);
|
||||||
|
|
||||||
|
hts221_t *dev = &hts221_devs[i];
|
||||||
|
if (hts221_init(dev, &hts221_params[i]) != HTS221_OK) {
|
||||||
|
LOG_ERROR("[auto_init_saul] error initializing hts221 (#%u)\n", i);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (hts221_power_on(dev) != HTS221_OK) {
|
||||||
|
LOG_ERROR("[auto_init_saul] error set power on (#%u)!\n", i);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (hts221_set_rate(dev, dev->p.rate) != HTS221_OK) {
|
||||||
|
LOG_ERROR("[auto_init_saul] error set continuous mode (#%u)!\n", i);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
saul_entries[(i * 2)].dev = &(hts221_devs[i]);
|
||||||
|
saul_entries[(i * 2)].name = hts221_saul_info[i].name;
|
||||||
|
saul_entries[(i * 2)].driver = &hts221_saul_temp_driver;
|
||||||
|
saul_entries[(i * 2) + 1].dev = &(hts221_devs[i]);
|
||||||
|
saul_entries[(i * 2) + 1].name = hts221_saul_info[i].name;
|
||||||
|
saul_entries[(i * 2) + 1].driver = &hts221_saul_hum_driver;
|
||||||
|
saul_reg_add(&(saul_entries[(i * 2)]));
|
||||||
|
saul_reg_add(&(saul_entries[(i * 2) + 1]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
typedef int dont_be_pedantic;
|
||||||
|
#endif /* MODULE_HTS221 */
|
||||||
Loading…
x
Reference in New Issue
Block a user