mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-18 12:52:44 +01:00
Merge pull request #5477 from aabadie/bmp_180_saul
drivers/bmp180: add saul adaptation
This commit is contained in:
commit
cd66ac0091
@ -19,14 +19,22 @@
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "log.h"
|
||||
#include "bmp180.h"
|
||||
#include "bmp180_internals.h"
|
||||
#include "bmp180_params.h"
|
||||
#include "periph/i2c.h"
|
||||
#include "xtimer.h"
|
||||
|
||||
#define ENABLE_DEBUG (0)
|
||||
#include "debug.h"
|
||||
|
||||
/**
|
||||
* @brief Allocation of memory for device descriptors
|
||||
*/
|
||||
bmp180_t bmp180_devs[BMP180_NUMOF];
|
||||
|
||||
/* Internal function prototypes */
|
||||
static int _read_ut(bmp180_t *dev, int32_t *ut);
|
||||
static int _read_up(bmp180_t *dev, int32_t *up);
|
||||
@ -99,6 +107,21 @@ int bmp180_init(bmp180_t *dev, i2c_t i2c, uint8_t mode)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void bmp180_auto_init(void)
|
||||
{
|
||||
for (unsigned i = 0; i < BMP180_NUMOF; i++) {
|
||||
if (bmp180_init(&bmp180_devs[i], bmp180_params[i].i2c_dev, bmp180_params[i].mode) < 0) {
|
||||
LOG_ERROR("Unable to initialize BMP180 sensor #%i\n", i);
|
||||
}
|
||||
#ifdef MODULE_SAUL_REG
|
||||
for (int j = 0; j < 2; j++) {
|
||||
bmp180_saul_reg[i][j].dev = &bmp180_devs[i];
|
||||
saul_reg_add(&bmp180_saul_reg[i][j]);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
int bmp180_read_temperature(bmp180_t *dev, int32_t *temperature)
|
||||
{
|
||||
int32_t ut, b5;
|
||||
|
73
drivers/bmp180/bmp180_saul.c
Normal file
73
drivers/bmp180/bmp180_saul.c
Normal file
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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_bmp180
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief SAUL adaption for BMP180 device
|
||||
*
|
||||
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
||||
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "saul.h"
|
||||
#include "bmp180.h"
|
||||
#include "xtimer.h"
|
||||
|
||||
static int32_t temperature, pressure;
|
||||
|
||||
static int check_and_read_temperature(void *dev, phydat_t *res)
|
||||
{
|
||||
bmp180_t *d = (bmp180_t *)dev;
|
||||
|
||||
bmp180_read_temperature(d, &temperature);
|
||||
res->val[0] = temperature;
|
||||
res->unit = UNIT_TEMP_C;
|
||||
res->scale = -1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int check_and_read_pressure(void *dev, phydat_t *res)
|
||||
{
|
||||
bmp180_t *d = (bmp180_t *)dev;
|
||||
|
||||
bmp180_read_pressure(d, &pressure);
|
||||
|
||||
res->val[0] = pressure/10;
|
||||
res->unit = UNIT_PA;
|
||||
res->scale = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int read_temperature(void *dev, phydat_t *res)
|
||||
{
|
||||
return check_and_read_temperature(dev, res);
|
||||
}
|
||||
|
||||
static int read_pressure(void *dev, phydat_t *res)
|
||||
{
|
||||
return check_and_read_pressure(dev, res);
|
||||
}
|
||||
|
||||
const saul_driver_t bmp180_temperature_saul_driver = {
|
||||
.read = read_temperature,
|
||||
.write = saul_notsup,
|
||||
.type = SAUL_SENSE_TEMP
|
||||
};
|
||||
|
||||
const saul_driver_t bmp180_pressure_saul_driver = {
|
||||
.read = read_pressure,
|
||||
.write = saul_notsup,
|
||||
.type = SAUL_SENSE_PRESS
|
||||
};
|
87
drivers/bmp180/include/bmp180_params.h
Normal file
87
drivers/bmp180/include/bmp180_params.h
Normal file
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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_bmp180
|
||||
*
|
||||
* @{
|
||||
* @file
|
||||
* @brief Default configuration for BMP180
|
||||
*
|
||||
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
||||
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
||||
*/
|
||||
|
||||
#ifndef BMP180_PARAMS_H
|
||||
#define BMP180_PARAMS_H
|
||||
|
||||
#include "board.h"
|
||||
#include "bmp180.h"
|
||||
#include "saul_reg.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Set default configuration parameters for the BMP180
|
||||
* @{
|
||||
*/
|
||||
#ifndef BMP180_PARAM_I2C_DEV
|
||||
#define BMP180_PARAM_I2C_DEV (0)
|
||||
#endif
|
||||
#ifndef BMP180_PARAM_MODE
|
||||
#define BMP180_PARAM_MODE BMP180_ULTRALOWPOWER
|
||||
#endif
|
||||
|
||||
#define BMP180_PARAMS_DEFAULT {.i2c_dev = BMP180_PARAM_I2C_DEV, \
|
||||
.mode = BMP180_PARAM_MODE }
|
||||
/**@}*/
|
||||
|
||||
/**
|
||||
* @brief Configure BMP180
|
||||
*/
|
||||
static const bmp180_params_t bmp180_params[] =
|
||||
{
|
||||
#ifdef BMP180_PARAMS_BOARD
|
||||
BMP180_PARAMS_BOARD,
|
||||
#else
|
||||
BMP180_PARAMS_DEFAULT,
|
||||
#endif
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Get the number of configured BMP180 devices
|
||||
*/
|
||||
#define BMP180_NUMOF (sizeof(bmp180_params) / sizeof(bmp180_params[0]))
|
||||
|
||||
#ifdef MODULE_SAUL_REG
|
||||
/**
|
||||
* @brief Allocate and configure entries to the SAUL registry
|
||||
*/
|
||||
saul_reg_t bmp180_saul_reg[][2] =
|
||||
{
|
||||
{
|
||||
{
|
||||
.name = "bmp180-temp",
|
||||
.driver = &bmp180_temperature_saul_driver
|
||||
},
|
||||
{
|
||||
.name = "bmp180-press",
|
||||
.driver = &bmp180_pressure_saul_driver
|
||||
},
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* BMP180_PARAMS_H */
|
||||
/** @} */
|
@ -21,6 +21,7 @@
|
||||
#ifndef BMP180_H_
|
||||
#define BMP180_H_
|
||||
|
||||
#include "saul.h"
|
||||
#include "periph/i2c.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
@ -63,6 +64,28 @@ typedef struct {
|
||||
uint8_t oversampling; /**< Oversampling mode */
|
||||
} bmp180_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Device initialization parameters
|
||||
*/
|
||||
typedef struct {
|
||||
i2c_t i2c_dev;
|
||||
uint8_t mode;
|
||||
} bmp180_params_t;
|
||||
|
||||
/**
|
||||
* @brief export SAUL endpoints
|
||||
* @{
|
||||
*/
|
||||
extern const saul_driver_t bmp180_temperature_saul_driver;
|
||||
extern const saul_driver_t bmp180_pressure_saul_driver;
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @brief auto-initialize all configured BMP180 devices
|
||||
*/
|
||||
void bmp180_auto_init(void);
|
||||
|
||||
/**
|
||||
* @brief Initialize the given BMP180 device
|
||||
*
|
||||
|
@ -24,6 +24,10 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#ifdef MODULE_BMP180
|
||||
#include "bmp180.h"
|
||||
#endif
|
||||
|
||||
#ifdef MODULE_SHT11
|
||||
#include "sht11.h"
|
||||
#endif
|
||||
@ -109,6 +113,10 @@ void auto_init(void)
|
||||
DEBUG("Auto init rtc module.\n");
|
||||
rtc_init();
|
||||
#endif
|
||||
#ifdef MODULE_BMP180
|
||||
DEBUG("Auto init BMP180 module.\n");
|
||||
bmp180_auto_init();
|
||||
#endif
|
||||
#ifdef MODULE_SHT11
|
||||
DEBUG("Auto init SHT11 module.\n");
|
||||
sht11_init();
|
||||
|
Loading…
Reference in New Issue
Block a user