diff --git a/drivers/tsl4531x/tsl4531x_saul.c b/drivers/tsl4531x/tsl4531x_saul.c index ee719ac230e8097541afa99671140e305eb786ad..c21b09a62c389dfcce9830f7ea12de893fc69ac7 100644 --- a/drivers/tsl4531x/tsl4531x_saul.c +++ b/drivers/tsl4531x/tsl4531x_saul.c @@ -27,7 +27,7 @@ static int _read(const void *dev, phydat_t *data) { memset(data, 0, sizeof(phydat_t)); - data->val[0] = tsl4531x_simple_read((const tsl4531x_t *)dev); + data->val[0] = tsl4531x_simple_read(*(tsl4531x_t * const*)dev); data->unit = UNIT_LUX; data->scale = 0; return 1; diff --git a/sys/auto_init/auto_init.c b/sys/auto_init/auto_init.c index d81277d478d78782add9ec3e1a06269261ceef8a..2bda5b71935803e57875340c07c65c019e8dec61 100644 --- a/sys/auto_init/auto_init.c +++ b/sys/auto_init/auto_init.c @@ -448,6 +448,10 @@ void auto_init(void) extern void auto_init_tsl2561(void); auto_init_tsl2561(); #endif +#ifdef MODULE_TSL4531X + extern void auto_init_tsl4531x(void); + auto_init_tsl4531x(); +#endif #ifdef MODULE_VCNL40X0 extern void auto_init_vcnl40x0(void); auto_init_vcnl40x0(); diff --git a/sys/auto_init/saul/auto_init_tsl4531x.c b/sys/auto_init/saul/auto_init_tsl4531x.c new file mode 100644 index 0000000000000000000000000000000000000000..0496666df186d61a31ce26d0d55b77399c46f75b --- /dev/null +++ b/sys/auto_init/saul/auto_init_tsl4531x.c @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2016 Inria + * Copyright (C) 2018 Freie Universität Berlin + * + * 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 + * @{ + * + * @file + * @brief Auto initialization of TSL4531x driver. + * + * @author Alexandre Abadie <alexandre.abadie@inria.fr> + * @author Daniel Petry <daniel.petry@fu-berlin.de> + * + * Adapted from auto_init for the TSL2561 driver. + * + * @} + */ + +#ifdef MODULE_TSL4531X + +#include "log.h" +#include "saul_reg.h" +#include "tsl4531x.h" +#include "tsl4531x_params.h" + +/** + * @brief Define the number of configured sensors + */ +#define TSL4531X_NUMOF (sizeof(tsl4531x_params) / sizeof(tsl4531x_params[0])) + +/** + * @brief Allocation of memory for device descriptors + */ +static tsl4531x_t tsl4531x_devs[TSL4531X_NUMOF]; +static tsl4531x_t *tsl4531x_devs_p[TSL4531X_NUMOF]; + +/** + * @brief Memory for the SAUL registry entries + */ +static saul_reg_t saul_entries[TSL4531X_NUMOF]; + +/** + * @brief Define the number of saul info + */ +#define TSL4531X_INFO_NUMOF (sizeof(tsl4531x_saul_info) / sizeof(tsl4531x_saul_info[0])) + +/** + * @brief Reference the driver structs. + */ +extern const saul_driver_t tsl4531x_saul_driver; + +void auto_init_tsl4531x(void) +{ + assert(TSL4531X_NUMOF == TSL4531X_INFO_NUMOF); + + for (unsigned i = 0; i < TSL4531X_NUMOF; i++) { + printf("[auto_init_saul] initializing tsl4531x #%u\n", i); + + tsl4531x_devs_p[i] = &tsl4531x_devs[i]; + + if (tsl4531x_init(&tsl4531x_devs[i], + &tsl4531x_params[i]) != 0) { + LOG_ERROR("[auto_init_saul] error initializing tsl4531x #%u\n", i); + continue; + } + + /* Fill the saul_entries struct */ + saul_entries[i].dev = &(tsl4531x_devs_p[i]); + saul_entries[i].name = tsl4531x_saul_info[i].name; + saul_entries[i].driver = &tsl4531x_saul_driver; + + /* register to saul */ + saul_reg_add(&(saul_entries[i])); + } +} +#else +typedef int dont_be_pedantic; +#endif /* MODULE_TSL4531X */