From 17e78f7d81ac8dde43257550a442db3765b47058 Mon Sep 17 00:00:00 2001 From: smlng Date: Tue, 11 Apr 2017 15:07:43 +0200 Subject: [PATCH] driver, mag3110: add saul auto init --- drivers/mag3110/mag3110_saul.c | 4 +- sys/auto_init/auto_init.c | 4 ++ sys/auto_init/saul/auto_init_mag3110.c | 71 ++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 sys/auto_init/saul/auto_init_mag3110.c diff --git a/drivers/mag3110/mag3110_saul.c b/drivers/mag3110/mag3110_saul.c index f6d76d3bef..c890ab4f56 100644 --- a/drivers/mag3110/mag3110_saul.c +++ b/drivers/mag3110/mag3110_saul.c @@ -24,7 +24,7 @@ #include "saul.h" #include "mag3110.h" -static int read_acc(void *dev, phydat_t *res) +static int read_mag(void *dev, phydat_t *res) { mag3110_read((mag3110_t *)dev, (mag3110_data_t *)res); @@ -35,7 +35,7 @@ static int read_acc(void *dev, phydat_t *res) } const saul_driver_t mag3110_saul_driver = { - .read = read_acc, + .read = read_mag, .write = saul_notsup, .type = SAUL_SENSE_MAG, }; diff --git a/sys/auto_init/auto_init.c b/sys/auto_init/auto_init.c index 251b5bf1bf..30fc3be9de 100644 --- a/sys/auto_init/auto_init.c +++ b/sys/auto_init/auto_init.c @@ -271,6 +271,10 @@ void auto_init(void) extern void auto_init_lis3dh(void); auto_init_lis3dh(); #endif +#ifdef MODULE_MAG3110 + extern void auto_init_mag3110(void); + auto_init_mag3110(); +#endif #ifdef MODULE_MMA8X5X extern void auto_init_mma8x5x(void); auto_init_mma8x5x(); diff --git a/sys/auto_init/saul/auto_init_mag3110.c b/sys/auto_init/saul/auto_init_mag3110.c new file mode 100644 index 0000000000..ac08bae1ae --- /dev/null +++ b/sys/auto_init/saul/auto_init_mag3110.c @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2017 HAW Hamburg + * + * 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 MAG3110 magnetometers + * + * @author Sebastian Meiling + * + * @} + */ + +#ifdef MODULE_MAG3110 + +#include "log.h" +#include "saul_reg.h" + +#include "mag3110.h" +#include "mag3110_params.h" + +/** + * @brief Define the number of configured sensors + */ +#define MAG3110_NUM (sizeof(mag3110_params) / sizeof(mag3110_params[0])) + +/** + * @brief Allocate memory for the device descriptors + */ +static mag3110_t mag3110_devs[MAG3110_NUM]; + +/** + * @brief Memory for the SAUL registry entries + */ +static saul_reg_t saul_entries[MAG3110_NUM]; + +/** + * @brief Reference the driver struct + * @{ + */ +extern const saul_driver_t mag3110_saul_driver; +/** @} */ + +void auto_init_mag3110(void) +{ + for (unsigned i = 0; i < MAG3110_NUM; i++) { + LOG_DEBUG("[auto_init_saul] initializing mag3110 #%u\n", i); + + if (mag3110_init(&mag3110_devs[i], &mag3110_params[i]) != MAG3110_OK) { + LOG_ERROR("[auto_init_saul] error initializing mag3110 #%u\n", i); + continue; + } + + saul_entries[i].dev = &(mag3110_devs[i]); + saul_entries[i].name = mag3110_saul_info[i].name; + saul_entries[i].driver = &mag3110_saul_driver; + saul_reg_add(&(saul_entries[i])); + } +} + +#else +typedef int dont_be_pedantic; +#endif /* MODULE_MAG3110 */