Skip to content
Snippets Groups Projects
Commit 17e78f7d authored by Sebastian Meiling's avatar Sebastian Meiling
Browse files

driver, mag3110: add saul auto init

parent 36526f8a
Branches
No related tags found
No related merge requests found
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
#include "saul.h" #include "saul.h"
#include "mag3110.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); mag3110_read((mag3110_t *)dev, (mag3110_data_t *)res);
...@@ -35,7 +35,7 @@ static int read_acc(void *dev, phydat_t *res) ...@@ -35,7 +35,7 @@ static int read_acc(void *dev, phydat_t *res)
} }
const saul_driver_t mag3110_saul_driver = { const saul_driver_t mag3110_saul_driver = {
.read = read_acc, .read = read_mag,
.write = saul_notsup, .write = saul_notsup,
.type = SAUL_SENSE_MAG, .type = SAUL_SENSE_MAG,
}; };
...@@ -271,6 +271,10 @@ void auto_init(void) ...@@ -271,6 +271,10 @@ void auto_init(void)
extern void auto_init_lis3dh(void); extern void auto_init_lis3dh(void);
auto_init_lis3dh(); auto_init_lis3dh();
#endif #endif
#ifdef MODULE_MAG3110
extern void auto_init_mag3110(void);
auto_init_mag3110();
#endif
#ifdef MODULE_MMA8X5X #ifdef MODULE_MMA8X5X
extern void auto_init_mma8x5x(void); extern void auto_init_mma8x5x(void);
auto_init_mma8x5x(); auto_init_mma8x5x();
......
/*
* 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 <s@mlng.net>
*
* @}
*/
#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 */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment