2017-11-07 22:57:03 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2017 Inria
|
2019-08-23 13:06:13 +02:00
|
|
|
* 2019 HAW Hamburg
|
2017-11-07 22:57:03 +01:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2019-08-23 13:06:13 +02:00
|
|
|
* @ingroup drivers_mpu9x50
|
2017-11-07 22:57:03 +01:00
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file
|
2019-08-23 13:06:13 +02:00
|
|
|
* @brief MPU9X50 adaption to the RIOT actuator/sensor interface
|
2017-11-07 22:57:03 +01:00
|
|
|
*
|
|
|
|
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
2019-08-23 13:06:13 +02:00
|
|
|
* @author Jannes Volkens <jannes.volkens@haw-hamburg.de>
|
2017-11-07 22:57:03 +01:00
|
|
|
*
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "saul.h"
|
2019-08-23 13:06:13 +02:00
|
|
|
#include "mpu9x50.h"
|
2017-11-07 22:57:03 +01:00
|
|
|
|
|
|
|
static int read_acc(const void *dev, phydat_t *res)
|
|
|
|
{
|
2019-08-23 13:06:13 +02:00
|
|
|
int ret = mpu9x50_read_accel((const mpu9x50_t *)dev, (mpu9x50_results_t *)res->val);
|
2017-11-07 22:57:03 +01:00
|
|
|
if (ret < 0) {
|
|
|
|
return -ECANCELED;
|
|
|
|
}
|
|
|
|
|
|
|
|
res->scale = -3;
|
2023-02-21 12:19:50 +01:00
|
|
|
res->unit = UNIT_G_FORCE;
|
2017-11-07 22:57:03 +01:00
|
|
|
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int read_gyro(const void *dev, phydat_t *res)
|
|
|
|
{
|
2019-08-23 13:06:13 +02:00
|
|
|
int ret = mpu9x50_read_gyro((const mpu9x50_t *)dev, (mpu9x50_results_t *)res->val);
|
2017-11-07 22:57:03 +01:00
|
|
|
if (ret < 0) {
|
|
|
|
return -ECANCELED;
|
|
|
|
}
|
|
|
|
|
|
|
|
res->scale = -1;
|
|
|
|
res->unit = UNIT_DPS;
|
|
|
|
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int read_mag(const void *dev, phydat_t *res)
|
|
|
|
{
|
2019-08-23 13:06:13 +02:00
|
|
|
int ret = mpu9x50_read_compass((const mpu9x50_t *)dev, (mpu9x50_results_t *)res->val);
|
2017-11-07 22:57:03 +01:00
|
|
|
if (ret < 0) {
|
|
|
|
return -ECANCELED;
|
|
|
|
}
|
|
|
|
|
|
|
|
res->scale = -2;
|
2023-02-21 12:19:50 +01:00
|
|
|
res->unit = UNIT_GAUSS;
|
2017-11-07 22:57:03 +01:00
|
|
|
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
|
2019-08-23 13:06:13 +02:00
|
|
|
const saul_driver_t mpu9x50_saul_acc_driver = {
|
2017-11-07 22:57:03 +01:00
|
|
|
.read = read_acc,
|
2022-05-02 21:31:03 +02:00
|
|
|
.write = saul_write_notsup,
|
2017-11-07 22:57:03 +01:00
|
|
|
.type = SAUL_SENSE_ACCEL,
|
|
|
|
};
|
|
|
|
|
2019-08-23 13:06:13 +02:00
|
|
|
const saul_driver_t mpu9x50_saul_gyro_driver = {
|
2017-11-07 22:57:03 +01:00
|
|
|
.read = read_gyro,
|
2022-05-02 21:31:03 +02:00
|
|
|
.write = saul_write_notsup,
|
2017-11-07 22:57:03 +01:00
|
|
|
.type = SAUL_SENSE_GYRO,
|
|
|
|
};
|
|
|
|
|
2019-08-23 13:06:13 +02:00
|
|
|
const saul_driver_t mpu9x50_saul_mag_driver = {
|
2017-11-07 22:57:03 +01:00
|
|
|
.read = read_mag,
|
2022-05-02 21:31:03 +02:00
|
|
|
.write = saul_write_notsup,
|
2017-11-07 22:57:03 +01:00
|
|
|
.type = SAUL_SENSE_MAG,
|
|
|
|
};
|