Skip to content

Commit

Permalink
sys/autoinit: add VL53L1X ToF ranging sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
gschorcht committed Nov 12, 2018
1 parent a471513 commit b64d549
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
4 changes: 4 additions & 0 deletions sys/auto_init/auto_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,10 @@ void auto_init(void)
extern void auto_init_veml6070(void);
auto_init_veml6070();
#endif
#ifdef MODULE_VL53L1X
extern void auto_init_vl53l1x(void);
auto_init_vl53l1x();
#endif

#endif /* MODULE_AUTO_INIT_SAUL */

Expand Down
72 changes: 72 additions & 0 deletions sys/auto_init/saul/auto_init_vl53l1x.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright (C) 2017 Mesotic SAS
*
* 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 drivers_vl53l1x
* @ingroup sys_auto_init_saul
* @brief Auto initialization of ST VL53L1X Time-of-Flight (ToF) ranging sensor
* @author Gunar Schorcht <gunar@schorcht.net>
* @file
*/

#ifdef MODULE_VL53L1X

#include "assert.h"
#include "log.h"
#include "saul_reg.h"
#include "vl53l1x.h"
#include "vl53l1x_params.h"

/**
* @brief Define the number of configured sensors
*/
#define VL53L1X_NUM (sizeof(vl53l1x_params) / sizeof(vl53l1x_params[0]))

/**
* @brief Allocate memory for the device descriptors
*/
static vl53l1x_t vl53l1x_devs[VL53L1X_NUM];

/**
* @brief Memory for the SAUL registry entries
*/
static saul_reg_t saul_entries[VL53L1X_NUM];

/**
* @brief Define the number of saul info
*/
#define VL53L1X_INFO_NUM (sizeof(vl53l1x_saul_info) / sizeof(vl53l1x_saul_info[0]))

/**
* @brief Reference the driver structs
*/
extern saul_driver_t vl53l1x_saul_driver;

void auto_init_vl53l1x(void)
{
assert(VL53L1X_INFO_NUM == VL53L1X_NUM);

for (unsigned i = 0; i < VL53L1X_NUM; i++) {
LOG_DEBUG("[auto_init_saul] initializing vl53l1x #%u\n", i);

if (vl53l1x_init(&vl53l1x_devs[i], &vl53l1x_params[i]) != VL53L1X_OK) {
LOG_ERROR("[auto_init_saul] error initializing vl53l1x #%u\n", i);
continue;
}

saul_entries[i].dev = &(vl53l1x_devs[i]);
saul_entries[i].name = vl53l1x_saul_info[i].name;
saul_entries[i].driver = &vl53l1x_saul_driver;
saul_reg_add(&(saul_entries[i]));
}
}

#else
typedef int dont_be_pedantic;
#endif /* MODULE_VL53L1X */

0 comments on commit b64d549

Please sign in to comment.