diff --git a/sys/auto_init/auto_init.c b/sys/auto_init/auto_init.c index 755f5f0ec1..31a01675c0 100644 --- a/sys/auto_init/auto_init.c +++ b/sys/auto_init/auto_init.c @@ -433,6 +433,10 @@ void auto_init(void) extern void auto_init_tsl2561(void); auto_init_tsl2561(); #endif +#ifdef MODULE_VCNL40X0 + extern void auto_init_vcnl40x0(void); + auto_init_vcnl40x0(); +#endif #ifdef MODULE_VEML6070 extern void auto_init_veml6070(void); auto_init_veml6070(); diff --git a/sys/auto_init/saul/auto_init_vcnl40x0.c b/sys/auto_init/saul/auto_init_vcnl40x0.c new file mode 100644 index 0000000000..b8d1e3feda --- /dev/null +++ b/sys/auto_init/saul/auto_init_vcnl40x0.c @@ -0,0 +1,81 @@ +/* + * Copyright (C) 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 VCNL40X0 driver. + * + * @author Alexandre Abadie + * + * @} + */ + +#ifdef MODULE_VCNL40X0 + +#include "log.h" +#include "saul_reg.h" + +#include "vcnl40x0_params.h" + +#define ENABLE_DEBUG (0) + +/** + * @brief Define the number of configured sensors + */ +#define VCNL40X0_NUMOF (sizeof(vcnl40x0_params) / sizeof(vcnl40x0_params[0])) + +/** + * @brief Allocation of memory for device descriptors + */ +static vcnl40x0_t vcnl40x0_devs[VCNL40X0_NUMOF]; + +/** + * @brief Memory for the SAUL registry entries + */ +static saul_reg_t saul_entries[VCNL40X0_NUMOF * 2]; + +/** + * @brief Reference the driver structs. + * @{ + */ +extern const saul_driver_t vcnl40x0_proximity_saul_driver; +extern const saul_driver_t vcnl40x0_illuminance_saul_driver; +/** @} */ + +void auto_init_vcnl40x0(void) +{ + for (unsigned i = 0; i < VCNL40X0_NUMOF; i++) { + LOG_DEBUG("[auto_init_saul] initializing vcnl40x0 #%u\n", i); + + if (vcnl40x0_init(&vcnl40x0_devs[i], + &vcnl40x0_params[i]) != VCNL40X0_OK) { + LOG_ERROR("[auto_init_saul] error initializing vcnl40x0 #%u\n", i); + return; + } + + /* proximity */ + saul_entries[(i * 2)].dev = &(vcnl40x0_devs[i]); + saul_entries[(i * 2)].name = vcnl40x0_saul_reg_info[i].name; + saul_entries[(i * 2)].driver = &vcnl40x0_proximity_saul_driver; + + /* illuminance */ + saul_entries[(i * 2) + 1].dev = &(vcnl40x0_devs[i]); + saul_entries[(i * 2) + 1].name = vcnl40x0_saul_reg_info[i].name; + saul_entries[(i * 2) + 1].driver = &vcnl40x0_illuminance_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_VCNL40X0 */