1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-20 20:13:50 +01:00

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 * @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 * need to be set according to the application purposes
* @{ * @{
*/ */

View File

@ -18,6 +18,7 @@
#include "periph/i2c.h" #include "periph/i2c.h"
#include "xtimer.h" #include "xtimer.h"
#include "fxos8700.h" #include "fxos8700.h"
#include "kernel_defines.h"
#define ENABLE_DEBUG (0) #define ENABLE_DEBUG (0)
#include "debug.h" #include "debug.h"
@ -161,11 +162,12 @@ int fxos8700_read(const fxos8700_t* dev, fxos8700_measurement_t* acc,
/* Read accelerometer */ /* Read accelerometer */
if (acc) { if (acc) {
#if FXOS8700_USE_ACC_RAW_VALUES if (IS_ACTIVE(CONFIG_FXOS8700_USE_ACC_RAW_VALUES)) {
acc->x = (int16_t) ((data[0] << 8) | data[1]) >> 2; acc->x = (int16_t) ((data[0] << 8) | data[1]) >> 2;
acc->y = (int16_t) ((data[2] << 8) | data[3]) >> 2; acc->y = (int16_t) ((data[2] << 8) | data[3]) >> 2;
acc->z = (int16_t) ((data[4] << 8) | data[5]) >> 2; acc->z = (int16_t) ((data[4] << 8) | data[5]) >> 2;
#else }
else {
int32_t acc_raw_x = (int16_t) ((data[0] << 8) | data[1]) >> 2; 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_y = (int16_t) ((data[2] << 8) | data[3]) >> 2;
int32_t acc_raw_z = (int16_t) ((data[4] << 8) | data[5]) >> 2; int32_t acc_raw_z = (int16_t) ((data[4] << 8) | data[5]) >> 2;
@ -188,7 +190,7 @@ int fxos8700_read(const fxos8700_t* dev, fxos8700_measurement_t* acc,
default: default:
return FXOS8700_NODEV; return FXOS8700_NODEV;
} }
#endif }
} }
/* Read magnetometer */ /* Read magnetometer */
if (mag) { if (mag) {

View File

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

View File

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