Browse Source

saul: add mpl3115a2

master
smlng 6 years ago
parent
commit
addf64349c
  1. 3
      boards/pba-d-01-kw2x/Makefile.dep
  2. 4
      drivers/mpl3115a2/include/mpl3115a2_params.h
  3. 70
      drivers/mpl3115a2/mpl3115a2_saul.c
  4. 4
      sys/auto_init/auto_init.c
  5. 82
      sys/auto_init/saul/auto_init_mpl3115a2.c

3
boards/pba-d-01-kw2x/Makefile.dep

@ -7,6 +7,7 @@ ifneq (,$(filter saul_default,$(USEMODULE)))
USEMODULE += hdc1000
USEMODULE += mag3110
USEMODULE += mma8x5x
USEMODULE += tmp006
USEMODULE += mpl3115a2
USEMODULE += tcs37727
USEMODULE += tmp006
endif

4
drivers/mpl3115a2/include/mpl3115a2_params.h

@ -69,9 +69,7 @@ static const mpl3115a2_params_t mpl3115a2_params[] =
*/
static const saul_reg_info_t mpl3115a2_saul_info[] =
{
{
.name = "mpl3115a2"
}
{ .name = "mpl3115a2" },
};
#ifdef __cplusplus

70
drivers/mpl3115a2/mpl3115a2_saul.c

@ -0,0 +1,70 @@
/*
* 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_mpl3115a2
* @{
*
* @file
* @brief MPL3115A2 adaption to the RIOT actuator/sensor interface
*
* @author Sebastian Meiling <s@mlng.net>
*
* @}
*/
#include <string.h>
#include <stdio.h>
#include "log.h"
#include "saul.h"
#include "mpl3115a2.h"
static int read_pressure(const void *dev, phydat_t *res)
{
uint8_t state;
uint32_t pressure;
if (mpl3115a2_read_pressure((const mpl3115a2_t *)dev,
&pressure, &state) != MPL3115A2_OK) {
LOG_ERROR("[SAUL] mpl3115a2_read_pressure failed!\n");
return -1;
}
/* pressure values > 100000, so /100 for int16_t which matches unit hPA */
res->val[0] = (int16_t)(pressure/100);
res->unit = UNIT_PA;
res->scale = 2;
return 1;
}
static int read_temperature(const void *dev, phydat_t *res)
{
int16_t temperature;
if (mpl3115a2_read_temp((const mpl3115a2_t *)dev, &temperature) != MPL3115A2_OK) {
LOG_ERROR("[SAUL] mpl3115a2_read_temp failed!\n");
return -1;
}
res->val[0] = temperature;
res->unit = UNIT_TEMP_C;
res->scale = -1;
return 1;
}
const saul_driver_t mpl3115a2_pressure_saul_driver = {
.read = read_pressure,
.write = saul_notsup,
.type = SAUL_SENSE_PRESS,
};
const saul_driver_t mpl3115a2_temperature_saul_driver = {
.read = read_temperature,
.write = saul_notsup,
.type = SAUL_SENSE_TEMP,
};

4
sys/auto_init/auto_init.c

@ -287,6 +287,10 @@ void auto_init(void)
extern void auto_init_mma8x5x(void);
auto_init_mma8x5x();
#endif
#ifdef MODULE_MPL3115A2
extern void auto_init_mpl3115a2(void);
auto_init_mpl3115a2();
#endif
#ifdef MODULE_SI70XX
extern void auto_init_si70xx(void);
auto_init_si70xx();

82
sys/auto_init/saul/auto_init_mpl3115a2.c

@ -0,0 +1,82 @@
/*
* 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 of MPL3115A2 pressure sensor
*
* @author Sebastian Meiling <s@mlng.net>
*
* @}
*/
#ifdef MODULE_MPL3115A2
#include "log.h"
#include "saul_reg.h"
#include "mpl3115a2.h"
#include "mpl3115a2_params.h"
/**
* @brief Define the number of configured sensors
*/
#define MPL3115A2_NUM (sizeof(mpl3115a2_params) / sizeof(mpl3115a2_params[0]))
/**
* @brief Allocate memory for the device descriptors
*/
static mpl3115a2_t mpl3115a2_devs[MPL3115A2_NUM];
/**
* @brief Memory for the SAUL registry entries
*/
static saul_reg_t saul_entries[MPL3115A2_NUM * 2];
/**
* @name Reference the driver struct
* @{
*/
extern const saul_driver_t mpl3115a2_pressure_saul_driver;
extern const saul_driver_t mpl3115a2_temperature_saul_driver;
/** @} */
void auto_init_mpl3115a2(void)
{
for (unsigned i = 0; i < MPL3115A2_NUM; i++) {
LOG_DEBUG("[auto_init_saul] initializing mpl3115a2 #%u\n", i);
if ((mpl3115a2_init(&mpl3115a2_devs[i], &mpl3115a2_params[i]) |
mpl3115a2_set_active(&mpl3115a2_devs[i])) != MPL3115A2_OK) {
LOG_ERROR("[auto_init_saul] error initializing mpl3115a2 #%u\n", i);
continue;
}
/* temperature */
saul_entries[(i * 2)].dev = &(mpl3115a2_devs[i]);
saul_entries[(i * 2)].name = mpl3115a2_saul_info[i].name;
saul_entries[(i * 2)].driver = &mpl3115a2_temperature_saul_driver;
/* atmospheric pressure */
saul_entries[(i * 2) + 1].dev = &(mpl3115a2_devs[i]);
saul_entries[(i * 2) + 1].name = mpl3115a2_saul_info[i].name;
saul_entries[(i * 2) + 1].driver = &mpl3115a2_pressure_saul_driver;
/* register to saul */
saul_reg_add(&(saul_entries[(i * 2)]));
saul_reg_add(&(saul_entries[(i * 2) + 1]));
}
}
#else
typedef int dont_be_pedantic;
#endif /* MODULE_MPL3115A2 */
Loading…
Cancel
Save