Browse Source

sys/auto_init: use new bmx280 implementation for bme280 and bmp280

master
Alexandre Abadie 6 years ago
parent
commit
d7543ccf31
  1. 6
      sys/auto_init/auto_init.c
  2. 74
      sys/auto_init/saul/auto_init_bme280.c
  3. 95
      sys/auto_init/saul/auto_init_bmx280.c

6
sys/auto_init/auto_init.c

@ -295,9 +295,9 @@ void auto_init(void)
extern void auto_init_bmp180(void);
auto_init_bmp180();
#endif
#ifdef MODULE_BME280
extern void auto_init_bme280(void);
auto_init_bme280();
#if defined(MODULE_BME280) || defined(MODULE_BMP280)
extern void auto_init_bmx280(void);
auto_init_bmx280();
#endif
#ifdef MODULE_JC42
extern void auto_init_jc42(void);

74
sys/auto_init/saul/auto_init_bme280.c

@ -1,74 +0,0 @@
/*
* Copyright (C) 2016 Kees Bakker, SODAQ
*
* 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 BME280 driver.
*
* @author Kees Bakker <kees@sodaq.com>
*
* @}
*/
#ifdef MODULE_BME280
#include "log.h"
#include "saul_reg.h"
#include "bme280.h"
#include "bme280_params.h"
/**
* @brief Allocation of memory for device descriptors
*/
static bme280_t bme280_devs[BME280_NUMOF];
/**
* @brief Memory for the SAUL registry entries
*/
static saul_reg_t saul_entries[BME280_NUMOF * 3];
void auto_init_bme280(void)
{
size_t se_ix = 0;
for (size_t i = 0; i < BME280_NUMOF; i++) {
LOG_DEBUG("[auto_init_saul] initializing BME280 #%u\n", i);
int res = bme280_init(&bme280_devs[i], &bme280_params[i]);
if (res < 0) {
LOG_ERROR("[auto_init_saul] error initializing BME280 #%i\n", i);
continue;
}
/* temperature */
saul_entries[se_ix].dev = &bme280_devs[i];
saul_entries[se_ix].name = bme280_saul_reg_info[i][0].name;
saul_entries[se_ix].driver = &bme280_temperature_saul_driver;
saul_reg_add(&saul_entries[se_ix]);
se_ix++;
/* relative humidity */
saul_entries[se_ix].dev = &bme280_devs[i];
saul_entries[se_ix].name = bme280_saul_reg_info[i][1].name;
saul_entries[se_ix].driver = &bme280_relative_humidity_saul_driver;
saul_reg_add(&saul_entries[se_ix]);
se_ix++;
/* pressure */
saul_entries[se_ix].dev = &bme280_devs[i];
saul_entries[se_ix].name = bme280_saul_reg_info[i][2].name;
saul_entries[se_ix].driver = &bme280_pressure_saul_driver;
saul_reg_add(&saul_entries[se_ix]);
se_ix++;
}
}
#else
typedef int dont_be_pedantic;
#endif /* MODULE_BME280 */

95
sys/auto_init/saul/auto_init_bmx280.c

@ -0,0 +1,95 @@
/*
* Copyright (C) 2016 Kees Bakker, SODAQ
* 2017 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 auto_init_saul
* @{
*
* @file
* @brief Auto initialization of BMX280 driver.
*
* @author Kees Bakker <kees@sodaq.com>
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
*
* @}
*/
#if defined(MODULE_BME280) || defined(MODULE_BMP280)
#include "log.h"
#include "saul_reg.h"
#include "bmx280_params.h"
#include "bmx280.h"
/**
* @brief Allocation of memory for device descriptors
*/
static bmx280_t bmx280_devs[BMX280_NUMOF];
/**
* @brief Reference the driver structs.
* @{
*/
extern const saul_driver_t bmx280_temperature_saul_driver;
extern const saul_driver_t bmx280_pressure_saul_driver;
#if defined(MODULE_BME280)
extern const saul_driver_t bme280_relative_humidity_saul_driver;
#endif
/** @} */
/**
* @brief Memory for the SAUL registry entries
*/
#if defined(MODULE_BME280)
#define SENSORS_NUMOF 3
#else
#define SENSORS_NUMOF 2
#endif
static saul_reg_t saul_entries[BMX280_NUMOF * SENSORS_NUMOF];
void auto_init_bmx280(void)
{
size_t se_ix = 0;
for (size_t i = 0; i < BMX280_NUMOF; i++) {
LOG_DEBUG("[auto_init_saul] initializing BMX280 #%u\n", i);
int res = bmx280_init(&bmx280_devs[i], &bmx280_params[i]);
if (res < 0) {
LOG_ERROR("[auto_init_saul] error initializing BMX280 #%i\n", i);
continue;
}
/* temperature */
saul_entries[se_ix].dev = &bmx280_devs[i];
saul_entries[se_ix].name = bmx280_saul_reg_info[i][0].name;
saul_entries[se_ix].driver = &bmx280_temperature_saul_driver;
saul_reg_add(&saul_entries[se_ix]);
se_ix++;
/* pressure */
saul_entries[se_ix].dev = &bmx280_devs[i];
saul_entries[se_ix].name = bmx280_saul_reg_info[i][1].name;
saul_entries[se_ix].driver = &bmx280_pressure_saul_driver;
saul_reg_add(&saul_entries[se_ix]);
se_ix++;
#if defined(MODULE_BME280)
/* relative humidity */
saul_entries[se_ix].dev = &bmx280_devs[i];
saul_entries[se_ix].name = bmx280_saul_reg_info[i][2].name;
saul_entries[se_ix].driver = &bme280_relative_humidity_saul_driver;
saul_reg_add(&saul_entries[se_ix]);
se_ix++;
#endif
}
}
#else
typedef int dont_be_pedantic;
#endif /* MODULE_BMX280 */
Loading…
Cancel
Save