

10 changed files with 428 additions and 216 deletions
@ -0,0 +1,80 @@
|
||||
/*
|
||||
* 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 Default configuration for MPL3115A2 devices |
||||
* |
||||
* @author Sebastian Meiling <s@mlng.net> |
||||
*/ |
||||
|
||||
#ifndef MPL3115A2_PARAMS_H |
||||
#define MPL3115A2_PARAMS_H |
||||
|
||||
#include "board.h" |
||||
#include "saul_reg.h" |
||||
#include "mpl3115a2.h" |
||||
#include "mpl3115a2_reg.h" |
||||
|
||||
#ifdef __cplusplus |
||||
extern "C" { |
||||
#endif |
||||
|
||||
/**
|
||||
* @name Default configuration parameters for the MPL3115A2 driver |
||||
* @{ |
||||
*/ |
||||
#ifndef MPL3115A2_PARAM_I2C |
||||
#define MPL3115A2_PARAM_I2C I2C_DEV(0) |
||||
#endif |
||||
|
||||
#ifndef MPL3115A2_PARAM_ADDR |
||||
#define MPL3115A2_PARAM_ADDR MPL3115A2_I2C_ADDRESS |
||||
#endif |
||||
|
||||
#ifndef MPL3115A2_PARAM_RATIO |
||||
#define MPL3115A2_PARAM_RATIO MPL3115A2_OS_RATIO_DEFAULT |
||||
#endif |
||||
|
||||
#ifndef MPL3115A2_PARAMS_DEFAULT |
||||
#define MPL3115A2_PARAMS_DEFAULT { .i2c = MPL3115A2_PARAM_I2C, \ |
||||
.addr = MPL3115A2_PARAM_ADDR, \
|
||||
.ratio = MPL3115A2_PARAM_RATIO } |
||||
#endif |
||||
/**@}*/ |
||||
|
||||
/**
|
||||
* @brief MPL3115A2 configuration |
||||
*/ |
||||
static const mpl3115a2_params_t mpl3115a2_params[] = |
||||
{ |
||||
|
||||
#ifdef MPL3115A2_PARAMS_CUSTOM |
||||
MPL3115A2_PARAMS_CUSTOM |
||||
#else |
||||
MPL3115A2_PARAMS_DEFAULT |
||||
#endif |
||||
}; |
||||
|
||||
/**
|
||||
* @brief Additional meta information to keep in the SAUL registry |
||||
*/ |
||||
static const saul_reg_info_t mpl3115a2_saul_info[] = |
||||
{ |
||||
{ .name = "mpl3115a2" }, |
||||
}; |
||||
|
||||
#ifdef __cplusplus |
||||
} |
||||
#endif |
||||
|
||||
#endif /* MPL3115A2_PARAMS_H */ |
||||
/** @} */ |
@ -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, |
||||
}; |
@ -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…
Reference in new issue