sys/auto_init/saul: add saul adaptation
This commit is contained in:
parent
3a6a3b8b14
commit
5c7cc50698
@ -33,7 +33,7 @@ extern "C" {
|
|||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
#ifndef SI114X_PARAM_I2C_DEV
|
#ifndef SI114X_PARAM_I2C_DEV
|
||||||
#define SI114X_PARAM_I2C_DEV I2C_DEV(1)
|
#define SI114X_PARAM_I2C_DEV I2C_DEV(0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef SI114X_PARAMS
|
#ifndef SI114X_PARAMS
|
||||||
|
|||||||
@ -14,12 +14,11 @@
|
|||||||
* @brief SAUL adaption for Si114x devices family
|
* @brief SAUL adaption for Si114x devices family
|
||||||
*
|
*
|
||||||
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
||||||
|
* Bas Stottelaar <basstottelaar@gmail.com>
|
||||||
*
|
*
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "saul.h"
|
#include "saul.h"
|
||||||
#include "si114x.h"
|
#include "si114x.h"
|
||||||
#include "xtimer.h"
|
#include "xtimer.h"
|
||||||
@ -59,7 +58,7 @@ static int read_distance(const void *dev, phydat_t *res)
|
|||||||
si114x_t *d = (si114x_t *)dev;
|
si114x_t *d = (si114x_t *)dev;
|
||||||
|
|
||||||
res->val[0] = si114x_read_distance(d);
|
res->val[0] = si114x_read_distance(d);
|
||||||
res->unit = UNIT_M;
|
res->unit = UNIT_NONE;
|
||||||
res->scale = 0;
|
res->scale = 0;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -67,23 +66,23 @@ static int read_distance(const void *dev, phydat_t *res)
|
|||||||
const saul_driver_t si114x_uv_saul_driver = {
|
const saul_driver_t si114x_uv_saul_driver = {
|
||||||
.read = read_uv,
|
.read = read_uv,
|
||||||
.write = saul_notsup,
|
.write = saul_notsup,
|
||||||
.type = SAUL_SENSE_ANY
|
.type = SAUL_SENSE_UV
|
||||||
};
|
};
|
||||||
|
|
||||||
const saul_driver_t si114x_ir_saul_driver = {
|
const saul_driver_t si114x_ir_saul_driver = {
|
||||||
.read = read_ir,
|
.read = read_ir,
|
||||||
.write = saul_notsup,
|
.write = saul_notsup,
|
||||||
.type = SAUL_SENSE_ANY
|
.type = SAUL_SENSE_LIGHT
|
||||||
};
|
};
|
||||||
|
|
||||||
const saul_driver_t si114x_visible_saul_driver = {
|
const saul_driver_t si114x_visible_saul_driver = {
|
||||||
.read = read_visible,
|
.read = read_visible,
|
||||||
.write = saul_notsup,
|
.write = saul_notsup,
|
||||||
.type = SAUL_SENSE_ANY
|
.type = SAUL_SENSE_LIGHT
|
||||||
};
|
};
|
||||||
|
|
||||||
const saul_driver_t si114x_distance_saul_driver = {
|
const saul_driver_t si114x_distance_saul_driver = {
|
||||||
.read = read_distance,
|
.read = read_distance,
|
||||||
.write = saul_notsup,
|
.write = saul_notsup,
|
||||||
.type = SAUL_SENSE_ANY
|
.type = SAUL_SENSE_DISTANCE
|
||||||
};
|
};
|
||||||
|
|||||||
@ -375,6 +375,10 @@ auto_init_mpu9150();
|
|||||||
extern void auto_init_lis2dh12(void);
|
extern void auto_init_lis2dh12(void);
|
||||||
auto_init_lis2dh12();
|
auto_init_lis2dh12();
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef MODULE_SI114X
|
||||||
|
extern void auto_init_si114x(void);
|
||||||
|
auto_init_si114x();
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* MODULE_AUTO_INIT_SAUL */
|
#endif /* MODULE_AUTO_INIT_SAUL */
|
||||||
|
|
||||||
|
|||||||
100
sys/auto_init/saul/auto_init_si114x.c
Normal file
100
sys/auto_init/saul/auto_init_si114x.c
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017-2018 Inria
|
||||||
|
*
|
||||||
|
* 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 Si114x driver.
|
||||||
|
*
|
||||||
|
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
||||||
|
* Bas Stottelaar <basstottelaar@gmail.com>
|
||||||
|
*
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef MODULE_SI114X
|
||||||
|
|
||||||
|
#include "log.h"
|
||||||
|
#include "saul_reg.h"
|
||||||
|
#include "si114x.h"
|
||||||
|
#include "si114x_params.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Define the number of configured sensors
|
||||||
|
*/
|
||||||
|
#define SI114X_NUMOF (sizeof(si114x_params) / sizeof(si114x_params[0]))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Allocation of memory for device descriptors
|
||||||
|
*/
|
||||||
|
static si114x_t si114x_devs[SI114X_NUMOF];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Memory for the SAUL registry entries
|
||||||
|
*/
|
||||||
|
static saul_reg_t saul_entries[SI114X_NUMOF * 4];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Define the number of saul info
|
||||||
|
*/
|
||||||
|
#define SI114X_INFO_NUMOF (sizeof(si114x_saul_reg_info) / sizeof(si114x_saul_reg_info[0]))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @name Reference the driver structs
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
extern const saul_driver_t si114x_uv_saul_driver;
|
||||||
|
extern const saul_driver_t si114x_ir_saul_driver;
|
||||||
|
extern const saul_driver_t si114x_visible_saul_driver;
|
||||||
|
extern const saul_driver_t si114x_distance_saul_driver;
|
||||||
|
/** @} */
|
||||||
|
|
||||||
|
void auto_init_si114x(void)
|
||||||
|
{
|
||||||
|
assert(SI114X_INFO_NUMOF == SI114X_NUMOF);
|
||||||
|
|
||||||
|
for (unsigned i = 0; i < SI114X_NUMOF; i++) {
|
||||||
|
LOG_DEBUG("[auto_init_saul] initializing Si114x #%u\n", i);
|
||||||
|
|
||||||
|
if (si114x_init(&si114x_devs[i], &si114x_params[i]) != SI114X_OK) {
|
||||||
|
LOG_ERROR("[auto_init_saul] error initializing Si114x #%i\n", i);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* UV index */
|
||||||
|
saul_entries[i * 4].dev = &si114x_devs[i];
|
||||||
|
saul_entries[i * 4].name = si114x_saul_reg_info[i].name;
|
||||||
|
saul_entries[i * 4].driver = &si114x_uv_saul_driver;
|
||||||
|
|
||||||
|
/* Infra red */
|
||||||
|
saul_entries[(i * 4) + 1].dev = &si114x_devs[i];
|
||||||
|
saul_entries[(i * 4) + 1].name = si114x_saul_reg_info[i].name;
|
||||||
|
saul_entries[(i * 4) + 1].driver = &si114x_ir_saul_driver;
|
||||||
|
|
||||||
|
/* Visible */
|
||||||
|
saul_entries[(i * 4) + 2].dev = &si114x_devs[i];
|
||||||
|
saul_entries[(i * 4) + 2].name = si114x_saul_reg_info[i].name;
|
||||||
|
saul_entries[(i * 4) + 2].driver = &si114x_visible_saul_driver;
|
||||||
|
|
||||||
|
/* Distance */
|
||||||
|
saul_entries[(i * 4) + 3].dev = &si114x_devs[i];
|
||||||
|
saul_entries[(i * 4) + 3].name = si114x_saul_reg_info[i].name;
|
||||||
|
saul_entries[(i * 4) + 3].driver = &si114x_distance_saul_driver;
|
||||||
|
|
||||||
|
saul_reg_add(&saul_entries[i * 4]);
|
||||||
|
saul_reg_add(&saul_entries[(i * 4) + 1]);
|
||||||
|
saul_reg_add(&saul_entries[(i * 4) + 2]);
|
||||||
|
saul_reg_add(&saul_entries[(i * 4) + 3]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
typedef int dont_be_pedantic;
|
||||||
|
#endif /* MODULE_SI114X */
|
||||||
Loading…
x
Reference in New Issue
Block a user