2017-03-16 16:44:04 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2017 OTA keys S.A.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2017-07-02 13:21:42 +02:00
|
|
|
* @ingroup drivers_lsm6dsl
|
|
|
|
* @{
|
|
|
|
*
|
2017-03-16 16:44:04 +01:00
|
|
|
* @file
|
2017-03-31 16:03:33 +02:00
|
|
|
* @brief SAUL implementation for the LSM6DSL 3D accelerometer/gyroscope.
|
2017-03-16 16:44:04 +01:00
|
|
|
*
|
|
|
|
* @author Vincent Dupont <vincent@otakeys.com>
|
2017-07-02 13:21:42 +02:00
|
|
|
* @author Sebastian Meiling <s@mlng.net>
|
|
|
|
*
|
|
|
|
* @}
|
2017-03-16 16:44:04 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "lsm6dsl.h"
|
|
|
|
#include "saul.h"
|
|
|
|
|
2017-06-26 16:00:34 +02:00
|
|
|
static int read_acc(const void *dev, phydat_t *res)
|
2017-03-16 16:44:04 +01:00
|
|
|
{
|
2019-01-06 16:56:17 +01:00
|
|
|
int ret = lsm6dsl_read_acc((const lsm6dsl_t *)dev, (lsm6dsl_3d_data_t *)res->val);
|
2017-03-16 16:44:04 +01:00
|
|
|
if (ret < 0) {
|
|
|
|
return -ECANCELED;
|
|
|
|
}
|
|
|
|
|
|
|
|
res->scale = -3;
|
2023-02-21 12:19:50 +01:00
|
|
|
res->unit = UNIT_G_FORCE;
|
2017-03-16 16:44:04 +01:00
|
|
|
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
|
2017-06-26 16:00:34 +02:00
|
|
|
static int read_gyro(const void *dev, phydat_t *res)
|
2017-03-16 16:44:04 +01:00
|
|
|
{
|
2019-01-06 16:56:17 +01:00
|
|
|
int ret = lsm6dsl_read_gyro((const lsm6dsl_t *)dev, (lsm6dsl_3d_data_t *)res->val);
|
2017-03-16 16:44:04 +01:00
|
|
|
if (ret < 0) {
|
|
|
|
return -ECANCELED;
|
|
|
|
}
|
|
|
|
|
|
|
|
res->scale = -1;
|
|
|
|
res->unit = UNIT_DPS;
|
|
|
|
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
|
2017-07-02 16:19:52 +02:00
|
|
|
static int read_temp(const void *dev, phydat_t *res)
|
|
|
|
{
|
2019-01-06 16:56:17 +01:00
|
|
|
if (lsm6dsl_read_temp((const lsm6dsl_t *)dev, &res->val[0]) < 0) {
|
2017-07-02 16:19:52 +02:00
|
|
|
return -ECANCELED;
|
|
|
|
}
|
|
|
|
res->scale = -2;
|
|
|
|
res->unit = UNIT_TEMP_C;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-03-16 16:44:04 +01:00
|
|
|
const saul_driver_t lsm6dsl_saul_acc_driver = {
|
|
|
|
.read = read_acc,
|
2022-05-02 21:31:03 +02:00
|
|
|
.write = saul_write_notsup,
|
2017-03-16 16:44:04 +01:00
|
|
|
.type = SAUL_SENSE_ACCEL,
|
|
|
|
};
|
|
|
|
|
|
|
|
const saul_driver_t lsm6dsl_saul_gyro_driver = {
|
|
|
|
.read = read_gyro,
|
2022-05-02 21:31:03 +02:00
|
|
|
.write = saul_write_notsup,
|
2017-03-16 16:44:04 +01:00
|
|
|
.type = SAUL_SENSE_GYRO,
|
|
|
|
};
|
2017-07-02 16:19:52 +02:00
|
|
|
|
|
|
|
const saul_driver_t lsm6dsl_saul_temp_driver = {
|
|
|
|
.read = read_temp,
|
2022-05-02 21:31:03 +02:00
|
|
|
.write = saul_write_notsup,
|
2017-07-02 16:19:52 +02:00
|
|
|
.type = SAUL_SENSE_TEMP,
|
|
|
|
};
|