drivers/fxos8700 : Add CONFIG_

Add CONFIG_ Prefix for FXOS8700_USE_ACC_RAW_VALUES and model
it as a bool

Co-Authored-By: Leandro Lanzieri <leandro.lanzieri@haw-hamburg.de>
This commit is contained in:
Akshai M 2020-04-21 16:11:26 +05:30
parent 549d7ff24f
commit e5fe525711
4 changed files with 47 additions and 42 deletions

View File

@ -75,7 +75,7 @@ extern "C" {
/**
* @name FXOS8700 configuration
* Note that another fxos8700 operation option, FXOS8700_USE_ACC_RAW_VALUES,
* Note that another fxos8700 operation option, CONFIG_FXOS8700_USE_ACC_RAW_VALUES,
* need to be set according to the application purposes
* @{
*/

View File

@ -18,6 +18,7 @@
#include "periph/i2c.h"
#include "xtimer.h"
#include "fxos8700.h"
#include "kernel_defines.h"
#define ENABLE_DEBUG (0)
#include "debug.h"
@ -161,34 +162,35 @@ int fxos8700_read(const fxos8700_t* dev, fxos8700_measurement_t* acc,
/* Read accelerometer */
if (acc) {
#if FXOS8700_USE_ACC_RAW_VALUES
acc->x = (int16_t) ((data[0] << 8) | data[1]) >> 2;
acc->y = (int16_t) ((data[2] << 8) | data[3]) >> 2;
acc->z = (int16_t) ((data[4] << 8) | data[5]) >> 2;
#else
int32_t acc_raw_x = (int16_t) ((data[0] << 8) | data[1]) >> 2;
int32_t acc_raw_y = (int16_t) ((data[2] << 8) | data[3]) >> 2;
int32_t acc_raw_z = (int16_t) ((data[4] << 8) | data[5]) >> 2;
switch(dev->p.acc_range) {
case FXOS8700_REG_XYZ_DATA_CFG_FS__2G:
acc->x = (int16_t) ((acc_raw_x * 244) / 100);
acc->y = (int16_t) ((acc_raw_y * 244) / 100);
acc->z = (int16_t) ((acc_raw_z * 244) / 100);
break;
case FXOS8700_REG_XYZ_DATA_CFG_FS__4G:
acc->x = (int16_t) ((acc_raw_x * 488) / 1000);
acc->y = (int16_t) ((acc_raw_y * 488) / 1000);
acc->z = (int16_t) ((acc_raw_z * 488) / 1000);
break;
case FXOS8700_REG_XYZ_DATA_CFG_FS__8G:
acc->x = (int16_t) ((acc_raw_x * 976) / 1000);
acc->y = (int16_t) ((acc_raw_y * 976) / 1000);
acc->z = (int16_t) ((acc_raw_z * 976) / 1000);
break;
default:
return FXOS8700_NODEV;
if (IS_ACTIVE(CONFIG_FXOS8700_USE_ACC_RAW_VALUES)) {
acc->x = (int16_t) ((data[0] << 8) | data[1]) >> 2;
acc->y = (int16_t) ((data[2] << 8) | data[3]) >> 2;
acc->z = (int16_t) ((data[4] << 8) | data[5]) >> 2;
}
#endif
else {
int32_t acc_raw_x = (int16_t) ((data[0] << 8) | data[1]) >> 2;
int32_t acc_raw_y = (int16_t) ((data[2] << 8) | data[3]) >> 2;
int32_t acc_raw_z = (int16_t) ((data[4] << 8) | data[5]) >> 2;
switch(dev->p.acc_range) {
case FXOS8700_REG_XYZ_DATA_CFG_FS__2G:
acc->x = (int16_t) ((acc_raw_x * 244) / 100);
acc->y = (int16_t) ((acc_raw_y * 244) / 100);
acc->z = (int16_t) ((acc_raw_z * 244) / 100);
break;
case FXOS8700_REG_XYZ_DATA_CFG_FS__4G:
acc->x = (int16_t) ((acc_raw_x * 488) / 1000);
acc->y = (int16_t) ((acc_raw_y * 488) / 1000);
acc->z = (int16_t) ((acc_raw_z * 488) / 1000);
break;
case FXOS8700_REG_XYZ_DATA_CFG_FS__8G:
acc->x = (int16_t) ((acc_raw_x * 976) / 1000);
acc->y = (int16_t) ((acc_raw_y * 976) / 1000);
acc->z = (int16_t) ((acc_raw_z * 976) / 1000);
break;
default:
return FXOS8700_NODEV;
}
}
}
/* Read magnetometer */
if (mag) {

View File

@ -22,6 +22,7 @@
#include "saul.h"
#include "fxos8700.h"
#include "kernel_defines.h"
static int read_mag(const void *dev, phydat_t *res)
{
@ -42,17 +43,19 @@ static int read_acc(const void *dev, phydat_t *res)
/* Read failure */
return -ECANCELED;
}
#if FXOS8700_USE_ACC_RAW_VALUES
res->unit = UNIT_NONE;
res->scale = 0;
#else
res->unit = UNIT_G;
if (((fxos8700_t *)dev)->p.acc_range == FXOS8700_REG_XYZ_DATA_CFG_FS__2G) {
res->scale = -4;
} else {
res->scale = -3;
if (IS_ACTIVE(CONFIG_FXOS8700_USE_ACC_RAW_VALUES)) {
res->unit = UNIT_NONE;
res->scale = 0;
}
else {
res->unit = UNIT_G;
if (((fxos8700_t *)dev)->p.acc_range == FXOS8700_REG_XYZ_DATA_CFG_FS__2G) {
res->scale = -4;
}
else {
res->scale = -3;
}
}
#endif
return 3;
}

View File

@ -44,11 +44,11 @@ extern "C" {
/**
* @brief Default raw value mode for accelerator
*
* If set to 0, measurements will be converted to mg.
* If set to 1, raw adc readings will be returned.
* Set this to 1 to return raw ADC readings. Otherwise measurements
* will be converted to mg.
*/
#ifndef FXOS8700_USE_ACC_RAW_VALUES
#define FXOS8700_USE_ACC_RAW_VALUES (0)
#ifdef DOXYGEN
#define CONFIG_FXOS8700_USE_ACC_RAW_VALUES
#endif
/** @} */