|
| 1 | +/* |
| 2 | + * Copyright (C) 2016 Freie Universität Berlin |
| 3 | + * |
| 4 | + * This file is subject to the terms and conditions of the GNU Lesser |
| 5 | + * General Public License v2.1. See the file LICENSE in the top level |
| 6 | + * directory for more details. |
| 7 | + * |
| 8 | + */ |
| 9 | + |
| 10 | +/** |
| 11 | + * @ingroup auto_init_saul |
| 12 | + * @{ |
| 13 | + * |
| 14 | + * @file |
| 15 | + * @brief Auto initialization of MMA8652 accelerometer |
| 16 | + * |
| 17 | + * @author Cenk Gündoğan <mail@cgundogan.de> |
| 18 | + * |
| 19 | + * @} |
| 20 | + */ |
| 21 | + |
| 22 | +#ifdef MODULE_MMA8652 |
| 23 | + |
| 24 | +#include "saul_reg.h" |
| 25 | +#include "mma8652.h" |
| 26 | +#include "mma8652_params.h" |
| 27 | + |
| 28 | +#define ENABLE_DEBUG (0) |
| 29 | +#include "debug.h" |
| 30 | + |
| 31 | +/** |
| 32 | + * @brief Define the number of configured sensors |
| 33 | + */ |
| 34 | +#define MMA8652_NUM (sizeof(mma8652_params)/sizeof(mma8652_params[0])) |
| 35 | + |
| 36 | +/** |
| 37 | + * @brief Allocate memory for the device descriptors |
| 38 | + */ |
| 39 | +static mma8652_t mma8652_devs[MMA8652_NUM]; |
| 40 | + |
| 41 | +/** |
| 42 | + * @brief Memory for the SAUL registry entries |
| 43 | + */ |
| 44 | +static saul_reg_t saul_entries[MMA8652_NUM]; |
| 45 | + |
| 46 | +/** |
| 47 | + * @brief Reference the driver struct |
| 48 | + * @{ |
| 49 | + */ |
| 50 | +extern saul_driver_t mma8652_saul_driver; |
| 51 | +/** @} */ |
| 52 | + |
| 53 | +void auto_init_mma8652(void) |
| 54 | +{ |
| 55 | + for (int i = 0; i < MMA8652_NUM; i++) { |
| 56 | + const mma8652_params_t *p = &mma8652_params[i]; |
| 57 | + |
| 58 | + DEBUG("[auto_init_saul] initializing mma8652 acc sensor\n"); |
| 59 | + |
| 60 | + if (mma8652_init(&mma8652_devs[i], p->i2c, p->addr, p->rate, p->scale) < 0) { |
| 61 | + DEBUG("[auto_init_saul] error during initialization\n"); |
| 62 | + return; |
| 63 | + } |
| 64 | + |
| 65 | + if (mma8652_set_active(&mma8652_devs[i]) < 0) { |
| 66 | + DEBUG("[auto_init_saul] error activating mma8652\n"); |
| 67 | + return; |
| 68 | + } |
| 69 | + |
| 70 | + saul_entries[i].dev = &(mma8652_devs[i]); |
| 71 | + saul_entries[i].name = mma8652_saul_info[i].name; |
| 72 | + saul_entries[i].driver = &mma8652_saul_driver; |
| 73 | + saul_reg_add(&(saul_entries[i])); |
| 74 | + } |
| 75 | +} |
| 76 | + |
| 77 | +#else |
| 78 | +typedef int dont_be_pedantic; |
| 79 | +#endif /* MODULE_MMA8652 */ |
0 commit comments