diff --git a/drivers/si114x/include/si114x_params.h b/drivers/si114x/include/si114x_params.h index d261613b10..8f5ee3fd05 100644 --- a/drivers/si114x/include/si114x_params.h +++ b/drivers/si114x/include/si114x_params.h @@ -33,7 +33,7 @@ extern "C" { * @{ */ #ifndef SI114X_PARAM_I2C_DEV -#define SI114X_PARAM_I2C_DEV I2C_DEV(1) +#define SI114X_PARAM_I2C_DEV I2C_DEV(0) #endif #ifndef SI114X_PARAMS diff --git a/drivers/si114x/si114x_saul.c b/drivers/si114x/si114x_saul.c index 96f48c5eaf..b5bc5d93f1 100644 --- a/drivers/si114x/si114x_saul.c +++ b/drivers/si114x/si114x_saul.c @@ -14,12 +14,11 @@ * @brief SAUL adaption for Si114x devices family * * @author Alexandre Abadie + * Bas Stottelaar * * @} */ -#include - #include "saul.h" #include "si114x.h" #include "xtimer.h" @@ -59,7 +58,7 @@ static int read_distance(const void *dev, phydat_t *res) si114x_t *d = (si114x_t *)dev; res->val[0] = si114x_read_distance(d); - res->unit = UNIT_M; + res->unit = UNIT_NONE; res->scale = 0; return 1; } @@ -67,23 +66,23 @@ static int read_distance(const void *dev, phydat_t *res) const saul_driver_t si114x_uv_saul_driver = { .read = read_uv, .write = saul_notsup, - .type = SAUL_SENSE_ANY + .type = SAUL_SENSE_UV }; const saul_driver_t si114x_ir_saul_driver = { .read = read_ir, .write = saul_notsup, - .type = SAUL_SENSE_ANY + .type = SAUL_SENSE_LIGHT }; const saul_driver_t si114x_visible_saul_driver = { .read = read_visible, .write = saul_notsup, - .type = SAUL_SENSE_ANY + .type = SAUL_SENSE_LIGHT }; const saul_driver_t si114x_distance_saul_driver = { .read = read_distance, .write = saul_notsup, - .type = SAUL_SENSE_ANY + .type = SAUL_SENSE_DISTANCE }; diff --git a/sys/auto_init/auto_init.c b/sys/auto_init/auto_init.c index fd96540a22..098b9cd554 100644 --- a/sys/auto_init/auto_init.c +++ b/sys/auto_init/auto_init.c @@ -375,6 +375,10 @@ auto_init_mpu9150(); extern void auto_init_lis2dh12(void); auto_init_lis2dh12(); #endif +#ifdef MODULE_SI114X + extern void auto_init_si114x(void); + auto_init_si114x(); +#endif #endif /* MODULE_AUTO_INIT_SAUL */ diff --git a/sys/auto_init/saul/auto_init_si114x.c b/sys/auto_init/saul/auto_init_si114x.c new file mode 100644 index 0000000000..f905d33a21 --- /dev/null +++ b/sys/auto_init/saul/auto_init_si114x.c @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2017-2018 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 Si114x driver. + * + * @author Alexandre Abadie + * Bas Stottelaar + * + * @} + */ + +#ifdef MODULE_SI114X + +#include "log.h" +#include "saul_reg.h" +#include "si114x.h" +#include "si114x_params.h" + +/** + * @brief Define the number of configured sensors + */ +#define SI114X_NUMOF (sizeof(si114x_params) / sizeof(si114x_params[0])) + +/** + * @brief Allocation of memory for device descriptors + */ +static si114x_t si114x_devs[SI114X_NUMOF]; + +/** + * @brief Memory for the SAUL registry entries + */ +static saul_reg_t saul_entries[SI114X_NUMOF * 4]; + +/** + * @brief Define the number of saul info + */ +#define SI114X_INFO_NUMOF (sizeof(si114x_saul_reg_info) / sizeof(si114x_saul_reg_info[0])) + +/** + * @name Reference the driver structs + * @{ + */ +extern const saul_driver_t si114x_uv_saul_driver; +extern const saul_driver_t si114x_ir_saul_driver; +extern const saul_driver_t si114x_visible_saul_driver; +extern const saul_driver_t si114x_distance_saul_driver; +/** @} */ + +void auto_init_si114x(void) +{ + assert(SI114X_INFO_NUMOF == SI114X_NUMOF); + + for (unsigned i = 0; i < SI114X_NUMOF; i++) { + LOG_DEBUG("[auto_init_saul] initializing Si114x #%u\n", i); + + if (si114x_init(&si114x_devs[i], &si114x_params[i]) != SI114X_OK) { + LOG_ERROR("[auto_init_saul] error initializing Si114x #%i\n", i); + continue; + } + + /* UV index */ + saul_entries[i * 4].dev = &si114x_devs[i]; + saul_entries[i * 4].name = si114x_saul_reg_info[i].name; + saul_entries[i * 4].driver = &si114x_uv_saul_driver; + + /* Infra red */ + saul_entries[(i * 4) + 1].dev = &si114x_devs[i]; + saul_entries[(i * 4) + 1].name = si114x_saul_reg_info[i].name; + saul_entries[(i * 4) + 1].driver = &si114x_ir_saul_driver; + + /* Visible */ + saul_entries[(i * 4) + 2].dev = &si114x_devs[i]; + saul_entries[(i * 4) + 2].name = si114x_saul_reg_info[i].name; + saul_entries[(i * 4) + 2].driver = &si114x_visible_saul_driver; + + /* Distance */ + saul_entries[(i * 4) + 3].dev = &si114x_devs[i]; + saul_entries[(i * 4) + 3].name = si114x_saul_reg_info[i].name; + saul_entries[(i * 4) + 3].driver = &si114x_distance_saul_driver; + + 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_SI114X */