Skip to content

Commit

Permalink
drivers/saul: add auto_init for BME680
Browse files Browse the repository at this point in the history
  • Loading branch information
gschorcht committed Mar 12, 2020
1 parent c4325e4 commit a1e2f36
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
91 changes: 91 additions & 0 deletions drivers/saul/init_devs/auto_init_bme680.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Copyright (C) 2020 Gunar Schorcht
*
* 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 sys_auto_init_saul
* @brief Auto initialization of Bosch BME680 device driver
* @author Gunar Schorcht <gunar@schorcht.net>
* @file
*/

#ifdef MODULE_BME680

#include "assert.h"
#include "log.h"
#include "saul_reg.h"
#include "bme680.h"
#include "bme680_params.h"

/**
* @brief Allocation of memory for device descriptors
*/
bme680_t bme680_devs_saul[BME680_NUMOF];

/**
* @brief Memory for the SAUL registry entries
*/
static saul_reg_t saul_entries[BME680_NUMOF * 4];

/**
* @brief Define the number of saul info
*/
#define BME680_INFO_NUMOF ARRAY_SIZE(bme680_saul_info)

/**
* @name Reference the driver structs.
* @{
*/
extern const saul_driver_t bme680_saul_driver_temperature;
extern const saul_driver_t bme680_saul_driver_pressure;
extern const saul_driver_t bme680_saul_driver_humidity;
extern const saul_driver_t bme680_saul_driver_gas;
/** @} */

void auto_init_bme680(void)
{
assert(BME680_INFO_NUMOF == BME680_NUMOF);

for (unsigned i = 0; i < BME680_NUMOF; i++) {
LOG_DEBUG("[auto_init_saul] initializing BME680 #%u\n", i);

if (bme680_init(&bme680_devs_saul[i],
&bme680_params[i]) != BME680_OK) {
LOG_ERROR("[auto_init_saul] error initializing BME680 #%u\n", i);
continue;
}

/* temperature */
saul_entries[(i * 4)].dev = &(bme680_devs_saul[i]);
saul_entries[(i * 4)].name = bme680_saul_info[i].name;
saul_entries[(i * 4)].driver = &bme680_saul_driver_temperature;

/* pressure */
saul_entries[(i * 4) + 1].dev = &(bme680_devs_saul[i]);
saul_entries[(i * 4) + 1].name = bme680_saul_info[i].name;
saul_entries[(i * 4) + 1].driver = &bme680_saul_driver_pressure;

/* relative humidity */
saul_entries[(i * 4) + 2].dev = &(bme680_devs_saul[i]);
saul_entries[(i * 4) + 2].name = bme680_saul_info[i].name;
saul_entries[(i * 4) + 2].driver = &bme680_saul_driver_humidity;

/* relative humidity */
saul_entries[(i * 4) + 3].dev = &(bme680_devs_saul[i]);
saul_entries[(i * 4) + 3].name = bme680_saul_info[i].name;
saul_entries[(i * 4) + 3].driver = &bme680_saul_driver_gas;

/* register to saul */
saul_reg_add(&(saul_entries[(i * 4)]));
saul_reg_add(&(saul_entries[(i * 4) + 1]));
saul_reg_add(&(saul_entries[(i * 4) + 2]));
saul_reg_add(&(saul_entries[(i * 4) + 3]));
}
}
#else
typedef int dont_be_pedantic;
#endif /* MODULE_BME680 */
4 changes: 4 additions & 0 deletions drivers/saul/init_devs/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ void saul_init_devs(void)
extern void auto_init_apds99xx(void);
auto_init_apds99xx();
}
if (IS_USED(MODULE_BME680)) {
extern void auto_init_bme680(void);
auto_init_bme680();
}
if (IS_USED(MODULE_BMP180)) {
extern void auto_init_bmp180(void);
auto_init_bmp180();
Expand Down

0 comments on commit a1e2f36

Please sign in to comment.