Browse Source

sys/auto_init: added auto init for SAUL devices

cc430
Hauke Petersen 7 years ago
parent
commit
4950650c19
  1. 4
      sys/auto_init/Makefile
  2. 27
      sys/auto_init/auto_init.c
  3. 3
      sys/auto_init/saul/Makefile
  4. 73
      sys/auto_init/saul/auto_init_gpio.c
  5. 74
      sys/auto_init/saul/auto_init_isl29020.c
  6. 74
      sys/auto_init/saul/auto_init_l3g4200d.c
  7. 74
      sys/auto_init/saul/auto_init_lps331ap.c
  8. 82
      sys/auto_init/saul/auto_init_lsm303dlhc.c

4
sys/auto_init/Makefile

@ -4,4 +4,8 @@ ifneq (,$(filter auto_init_gnrc_netif,$(USEMODULE)))
DIRS += netif
endif
ifneq (,$(filter auto_init_saul,$(USEMODULE)))
DIRS += saul
endif
include $(RIOTBASE)/Makefile.base

27
sys/auto_init/auto_init.c

@ -183,4 +183,31 @@ void auto_init(void)
#ifdef MODULE_GNRC_IPV6_NETIF
gnrc_ipv6_netif_init_by_dev();
#endif
/* initialize sensors and actuators */
#ifdef MODULE_AUTO_INIT_SAUL
DEBUG("auto_init SAUL\n");
#ifdef MODULE_SAUL_GPIO
extern void auto_init_gpio(void);
auto_init_gpio();
#endif
#ifdef MODULE_LSM303DLHC
extern void auto_init_lsm303dlhc(void);
auto_init_lsm303dlhc();
#endif
#ifdef MODULE_LPS331AP
extern void auto_init_lps331ap(void);
auto_init_lps331ap();
#endif
#ifdef MODULE_ISL29020
extern void auto_init_isl29020(void);
auto_init_isl29020();
#endif
#ifdef MODULE_L3G4200D
extern void auto_init_l3g4200d(void);
auto_init_l3g4200d();
#endif
#endif /* MODULE_AUTO_INIT_SAUL */
}

3
sys/auto_init/saul/Makefile

@ -0,0 +1,3 @@
MODULE = auto_init_saul
include $(RIOTBASE)/Makefile.base

73
sys/auto_init/saul/auto_init_gpio.c

@ -0,0 +1,73 @@
/*
* Copyright (C) 2015 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 auto_init_saul
* @{
*
* @file
* @brief Auto initialization of GPIO pins directly mapped to SAUL reg
*
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
*
* @}
*/
#ifdef MODULE_SAUL_GPIO
#include "saul_reg.h"
#include "saul/periph.h"
#include "gpio_params.h"
#include "periph/gpio.h"
#define ENABLE_DEBUG (0)
#include "debug.h"
/**
* @brief Define the number of configured sensors
*/
#define SAUL_GPIO_NUMOF (sizeof(saul_gpio_params)/sizeof(saul_gpio_params[0]))
/**
* @brief Allocate memory for the device descriptors
*/
static gpio_t saul_gpios[SAUL_GPIO_NUMOF];
/**
* @brief Memory for the registry entries
*/
static saul_reg_t saul_reg_entries[SAUL_GPIO_NUMOF];
/**
* @brief Reference the driver struct
*/
extern saul_driver_t gpio_saul_driver;
void auto_init_gpio(void)
{
DEBUG("auto init gpio SAUL\n");
for (int i = 0; i < SAUL_GPIO_NUMOF; i++) {
const saul_gpio_params_t *p = &saul_gpio_params[i];
DEBUG("[auto_init_saul] initializing direct GPIO\n");
saul_gpios[i] = p->pin;
saul_reg_entries[i].dev = &(saul_gpios[i]);
saul_reg_entries[i].name = p->name;
saul_reg_entries[i].driver = &gpio_saul_driver;
/* initialize the GPIO pin */
gpio_init(p->pin, p->dir, GPIO_NOPULL);
/* add to registry */
saul_reg_add(&(saul_reg_entries[i]));
}
}
#else
typedef int dont_be_pedantic;
#endif /* MODULE_SAUL_GPIO */

74
sys/auto_init/saul/auto_init_isl29020.c

@ -0,0 +1,74 @@
/*
* Copyright (C) 2015 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 auto_init_saul
* @{
*
* @file
* @brief Auto initialization of ISL29020 light sensors
*
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
*
* @}
*/
#ifdef MODULE_ISL29020
#include "saul_reg.h"
#include "isl29020.h"
#include "isl29020_params.h"
#define ENABLE_DEBUG (0)
#include "debug.h"
/**
* @brief Define the number of configured sensors
*/
#define ISL29020_NUM (sizeof(isl29020_params)/sizeof(isl29020_params[0]))
/**
* @brief Allocate memory for the device descriptors
*/
static isl29020_t isl29020_devs[ISL29020_NUM];
/**
* @brief Memory for the SAUL registry entries
*/
static saul_reg_t saul_entries[ISL29020_NUM];
/**
* @brief Reference the driver struct
*/
extern saul_driver_t isl29020_saul_driver;
void auto_init_isl29020(void)
{
for (int i = 0; i < ISL29020_NUM; i++) {
const isl29020_params_t *p = &isl29020_params[i];
DEBUG("[auto_init_saul] initializing isl29020 light sensor\n");
int res = isl29020_init(&isl29020_devs[i], p->i2c, p->addr,
p->range, p->mode);
if (res < 0) {
DEBUG("[auto_init_saul] error during initialization\n");
}
else {
saul_entries[i].dev = &(isl29020_devs[i]);
saul_entries[i].name = isl29020_saul_info[i].name;
saul_entries[i].driver = &isl29020_saul_driver;
saul_reg_add(&(saul_entries[i]));
}
}
}
#else
typedef int dont_be_pedantic;
#endif /* MODULE_ISL29020 */

74
sys/auto_init/saul/auto_init_l3g4200d.c

@ -0,0 +1,74 @@
/*
* Copyright (C) 2015 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 auto_init_saul
* @{
*
* @file
* @brief Auto initialization of L3G4200D pressure sensors
*
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
*
* @}
*/
#ifdef MODULE_L3G4200D
#include "saul_reg.h"
#include "l3g4200d.h"
#include "l3g4200d_params.h"
#define ENABLE_DEBUG (0)
#include "debug.h"
/**
* @brief Define the number of configured sensors
*/
#define L3G4200D_NUM (sizeof(l3g4200d_params)/sizeof(l3g4200d_params[0]))
/**
* @brief Allocate memory for the device descriptors
*/
static l3g4200d_t l3g4200d_devs[L3G4200D_NUM];
/**
* @brief Memory for the SAUL registry entries
*/
static saul_reg_t saul_entries[L3G4200D_NUM];
/**
* @brief Reference the driver struct
*/
extern saul_driver_t l3g4200d_saul_driver;
void auto_init_l3g4200d(void)
{
for (int i = 0; i < L3G4200D_NUM; i++) {
const l3g4200d_params_t *p = &l3g4200d_params[i];
DEBUG("[auto_init_saul] initializing l3g4200d gyroscope\n");
int res = l3g4200d_init(&l3g4200d_devs[i], p->i2c, p->addr,
p->int1_pin, p->int2_pin, p->mode, p->scale);
if (res < 0) {
DEBUG("[auto_init_saul] error during initialization\n");
}
else {
saul_entries[i].dev = &(l3g4200d_devs[i]);
saul_entries[i].name = l3g4200d_saul_info[i].name;
saul_entries[i].driver = &l3g4200d_saul_driver;
saul_reg_add(&(saul_entries[i]));
}
}
}
#else
typedef int dont_be_pedantic;
#endif /* MODULE_L3G4200D */

74
sys/auto_init/saul/auto_init_lps331ap.c

@ -0,0 +1,74 @@
/*
* Copyright (C) 2015 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 auto_init_saul
* @{
*
* @file
* @brief Auto initialization of LPS331AP pressure sensors
*
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
*
* @}
*/
#ifdef MODULE_LPS331AP
#include "saul_reg.h"
#include "lps331ap.h"
#include "lps331ap_params.h"
#define ENABLE_DEBUG (0)
#include "debug.h"
/**
* @brief Define the number of configured sensors
*/
#define LPS331AP_NUM (sizeof(lps331ap_params)/sizeof(lps331ap_params[0]))
/**
* @brief Allocate memory for the device descriptors
*/
static lps331ap_t lps331ap_devs[LPS331AP_NUM];
/**
* @brief Memory for the SAUL registry entries
*/
static saul_reg_t saul_entries[LPS331AP_NUM];
/**
* @brief Reference the driver struct
*/
extern saul_driver_t lps331ap_saul_driver;
void auto_init_lps331ap(void)
{
for (int i = 0; i < LPS331AP_NUM; i++) {
const lps331ap_params_t *p = &lps331ap_params[i];
DEBUG("[auto_init_saul] initializing lps331ap pressure sensor\n");
int res = lps331ap_init(&lps331ap_devs[i], p->i2c, p->addr, p->rate);
DEBUG("not done\n");
if (res < 0) {
DEBUG("[auto_init_saul] error during initialization\n");
}
else {
saul_entries[i].dev = &(lps331ap_devs[i]);
saul_entries[i].name = lps331ap_saul_info[i].name;
saul_entries[i].driver = &lps331ap_saul_driver;
saul_reg_add(&(saul_entries[i]));
}
}
}
#else
typedef int dont_be_pedantic;
#endif /* MODULE_LPS331AP */

82
sys/auto_init/saul/auto_init_lsm303dlhc.c

@ -0,0 +1,82 @@
/*
* Copyright (C) 2015 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 auto_init_saul
* @{
*
* @file
* @brief Auto initialization of LSM303DLHC accelerometer/magnetometer
*
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
*
* @}
*/
#ifdef MODULE_LSM303DLHC
#include "saul_reg.h"
#include "lsm303dlhc.h"
#include "lsm303dlhc_params.h"
#define ENABLE_DEBUG (0)
#include "debug.h"
/**
* @brief Define the number of configured sensors
*/
#define LSM303DLHC_NUM (sizeof(lsm303dlhc_params)/sizeof(lsm303dlhc_params[0]))
/**
* @brief Allocate memory for the device descriptors
*/
static lsm303dlhc_t lsm303dlhc_devs[LSM303DLHC_NUM];
/**
* @brief Memory for the SAUL registry entries
*/
static saul_reg_t saul_entries[LSM303DLHC_NUM * 2];
/**
* @brief Reference the driver structs
* @{
*/
extern saul_driver_t lsm303dlhc_saul_acc_driver;
extern saul_driver_t lsm303dlhc_saul_mag_driver;
/** @} */
void auto_init_lsm303dlhc(void)
{
for (int i = 0; i < LSM303DLHC_NUM; i++) {
const lsm303dlhc_params_t *p = &lsm303dlhc_params[i];
DEBUG("[auto_init_saul] initializing lsm303dlhc acc/mag sensor\n");
int res = lsm303dlhc_init(&lsm303dlhc_devs[i], p->i2c,
p->acc_pin, p->mag_pin,
p->acc_addr, p->acc_rate, p->acc_scale,
p->mag_addr, p->mag_rate, p->mag_gain);
if (res < 0) {
DEBUG("[auto_init_saul] error during initialization\n");
}
else {
saul_entries[(i * 2)].dev = &(lsm303dlhc_devs[i]);
saul_entries[(i * 2)].name = lsm303dlhc_saul_info[i].name;
saul_entries[(i * 2)].driver = &lsm303dlhc_saul_acc_driver;
saul_entries[(i * 2) + 1].dev = &(lsm303dlhc_devs[i]);
saul_entries[(i * 2) + 1].name = lsm303dlhc_saul_info[i].name;
saul_entries[(i * 2) + 1].driver = &lsm303dlhc_saul_mag_driver;
saul_reg_add(&(saul_entries[(i * 2)]));
saul_reg_add(&(saul_entries[(i * 2) + 1]));
}
}
}
#else
typedef int dont_be_pedantic;
#endif /* MODULE_LSM303DLHC */
Loading…
Cancel
Save