drivers/saul: add auto_init for BME680
This commit is contained in:
parent
c4325e4d5e
commit
a1e2f36adb
91
drivers/saul/init_devs/auto_init_bme680.c
Normal file
91
drivers/saul/init_devs/auto_init_bme680.c
Normal file
@ -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 */
|
||||||
@ -59,6 +59,10 @@ void saul_init_devs(void)
|
|||||||
extern void auto_init_apds99xx(void);
|
extern void auto_init_apds99xx(void);
|
||||||
auto_init_apds99xx();
|
auto_init_apds99xx();
|
||||||
}
|
}
|
||||||
|
if (IS_USED(MODULE_BME680)) {
|
||||||
|
extern void auto_init_bme680(void);
|
||||||
|
auto_init_bme680();
|
||||||
|
}
|
||||||
if (IS_USED(MODULE_BMP180)) {
|
if (IS_USED(MODULE_BMP180)) {
|
||||||
extern void auto_init_bmp180(void);
|
extern void auto_init_bmp180(void);
|
||||||
auto_init_bmp180();
|
auto_init_bmp180();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user