mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-17 05:12:57 +01:00
drivers/saul: add ST L3Gxxxx 3-axis gyroscope family
This commit is contained in:
parent
1569299c92
commit
24106edde9
42
drivers/l3gxxxx/l3gxxxx_saul.c
Normal file
42
drivers/l3gxxxx/l3gxxxx_saul.c
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Gunar Schorcht
|
||||
*
|
||||
* 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_l3gxxxx
|
||||
* @brief L3Gxxxx adaption to the RIOT actuator/sensor interface
|
||||
* @author Gunar Schorcht <gunar@schorcht.net>
|
||||
* @file
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "saul.h"
|
||||
#include "l3gxxxx.h"
|
||||
|
||||
static int read(const void *dev, phydat_t *res)
|
||||
{
|
||||
l3gxxxx_data_t data;
|
||||
int ret = l3gxxxx_read((const l3gxxxx_t *)dev, &data);
|
||||
if (ret < 0) {
|
||||
return -ECANCELED;
|
||||
}
|
||||
|
||||
res->val[0] = data.x / 100;
|
||||
res->val[1] = data.y / 100;
|
||||
res->val[2] = data.z / 100;
|
||||
res->unit = UNIT_DPS;
|
||||
res->scale = -1;
|
||||
|
||||
return 3;
|
||||
}
|
||||
|
||||
const saul_driver_t l3gxxxx_saul_driver = {
|
||||
.read = read,
|
||||
.write = saul_notsup,
|
||||
.type = SAUL_SENSE_GYRO,
|
||||
};
|
65
drivers/saul/init_devs/auto_init_l3gxxxx.c
Normal file
65
drivers/saul/init_devs/auto_init_l3gxxxx.c
Normal file
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Gunar Schorcht
|
||||
*
|
||||
* 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 sys_auto_init_saul
|
||||
* @brief Auto initialization of ST L3Gxxxx 3-axis gyroscope sensor
|
||||
* @author Gunar Schorcht <gunar@schorcht.net>
|
||||
* @file
|
||||
*/
|
||||
|
||||
#include "assert.h"
|
||||
#include "log.h"
|
||||
#include "saul_reg.h"
|
||||
|
||||
#include "l3gxxxx.h"
|
||||
#include "l3gxxxx_params.h"
|
||||
|
||||
/**
|
||||
* @brief Define the number of configured sensors
|
||||
*/
|
||||
#define L3GXXXX_NUM ARRAY_SIZE(l3gxxxx_params)
|
||||
|
||||
/**
|
||||
* @brief Allocate memory for the device descriptors
|
||||
*/
|
||||
static l3gxxxx_t l3gxxxx_devs[L3GXXXX_NUM];
|
||||
|
||||
/**
|
||||
* @brief Memory for the SAUL registry entries
|
||||
*/
|
||||
static saul_reg_t saul_entries[L3GXXXX_NUM];
|
||||
|
||||
/**
|
||||
* @brief Define the number of saul info
|
||||
*/
|
||||
#define L3GXXXX_INFO_NUM ARRAY_SIZE(l3gxxxx_saul_info)
|
||||
|
||||
/**
|
||||
* @brief Reference the driver struct
|
||||
*/
|
||||
extern saul_driver_t l3gxxxx_saul_driver;
|
||||
|
||||
void auto_init_l3gxxxx(void)
|
||||
{
|
||||
assert(L3GXXXX_NUM == L3GXXXX_INFO_NUM);
|
||||
|
||||
for (unsigned int i = 0; i < L3GXXXX_NUM; i++) {
|
||||
LOG_DEBUG("[auto_init_saul] initializing l3gd20h #%u\n", i);
|
||||
|
||||
if (l3gxxxx_init(&l3gxxxx_devs[i], &l3gxxxx_params[i]) < 0) {
|
||||
LOG_ERROR("[auto_init_saul] error initializing l3gd20h #%u\n", i);
|
||||
continue;
|
||||
}
|
||||
|
||||
saul_entries[i].dev = &(l3gxxxx_devs[i]);
|
||||
saul_entries[i].name = l3gxxxx_saul_info[i].name;
|
||||
saul_entries[i].driver = &l3gxxxx_saul_driver;
|
||||
saul_reg_add(&(saul_entries[i]));
|
||||
}
|
||||
}
|
@ -163,6 +163,10 @@ void saul_init_devs(void)
|
||||
extern void auto_init_l3g4200d(void);
|
||||
auto_init_l3g4200d();
|
||||
}
|
||||
if (IS_USED(MODULE_L3GXXXX)) {
|
||||
extern void auto_init_l3gxxxx(void);
|
||||
auto_init_l3gxxxx();
|
||||
}
|
||||
if (IS_USED(MODULE_LIS2DH12)) {
|
||||
extern void auto_init_lis2dh12(void);
|
||||
auto_init_lis2dh12();
|
||||
|
Loading…
Reference in New Issue
Block a user