summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--driver/accel_lis2dh.c12
-rw-r--r--driver/accel_lis2dh.h31
2 files changed, 7 insertions, 36 deletions
diff --git a/driver/accel_lis2dh.c b/driver/accel_lis2dh.c
index a02b1df1b0..3bba013b71 100644
--- a/driver/accel_lis2dh.c
+++ b/driver/accel_lis2dh.c
@@ -53,25 +53,25 @@ static int enable_fifo(const struct motion_sensor_t *s, int mode, int en_dis)
*/
static int set_range(const struct motion_sensor_t *s, int range, int rnd)
{
- int err, normalized_rate;
+ int err, normalized_range;
struct stprivate_data *data = s->drv_data;
int val;
val = LIS2DH_FS_TO_REG(range);
- normalized_rate = LIS2DH_FS_TO_NORMALIZE(range);
+ normalized_range = ST_NORMALIZE_RATE(range);
- if (rnd && (range < normalized_rate))
+ if (rnd && (range < normalized_range))
val++;
/* Adjust rounded values */
if (val > LIS2DH_FS_16G_VAL) {
val = LIS2DH_FS_16G_VAL;
- normalized_rate = 16;
+ normalized_range = 16;
}
if (val < LIS2DH_FS_2G_VAL) {
val = LIS2DH_FS_2G_VAL;
- normalized_rate = 2;
+ normalized_range = 2;
}
/* Lock accel resource to prevent another task from attempting
@@ -82,7 +82,7 @@ static int set_range(const struct motion_sensor_t *s, int range, int rnd)
/* Save Gain in range for speed up data path */
if (err == EC_SUCCESS)
- data->base.range = LIS2DH_FS_TO_GAIN(normalized_rate);
+ data->base.range = normalized_range;
mutex_unlock(s->mutex);
return EC_SUCCESS;
diff --git a/driver/accel_lis2dh.h b/driver/accel_lis2dh.h
index 48e5bb4fab..4a01cc995c 100644
--- a/driver/accel_lis2dh.h
+++ b/driver/accel_lis2dh.h
@@ -122,37 +122,8 @@ enum lis2dh_odr {
/* Full scale range Mask register */
#define LIS2DH_FS_MASK 0x30
-/* Acc FS value */
-enum lis2dh_fs {
- LIS2DH_FS_2G_VAL = 0x00,
- LIS2DH_FS_4G_VAL,
- LIS2DH_FS_8G_VAL,
- LIS2DH_FS_16G_VAL,
- LIS2DH_FS_LIST_NUM
-};
-
/* FS reg value from Full Scale */
-#define LIS2DH_FS_TO_REG(_fs) \
- (31 - __builtin_clz(_fs) - 1)
-
-/* Full Scale range real value normalized to sensor capabilities */
-#define LIS2DH_FS_TO_NORMALIZE(_fs) \
- (1 << (31 - __builtin_clz(_fs)))
-
-/* Acc Gain value */
-#define LIS2DH_FS_2G_GAIN 4
-#define LIS2DH_FS_4G_GAIN 8
-#define LIS2DH_FS_8G_GAIN 16
-#define LIS2DH_FS_16G_GAIN 48
-
-/* Return Gain from Full Scale range
- * TODO: This work only for 2, 4 and 8 G full scale */
-#define LIS2DH_FS_TO_GAIN(_fs) \
- (LIS2DH_FS_2G_GAIN << (30 - __builtin_clz(_fs)))
-
-/* Return Full Scale Range from normalized gain */
-#define LIS2DH_GAIN_TO_FS(_gain) \
- (1 << (30 - __builtin_clz(_gain)))
+#define LIS2DH_FS_TO_REG(_fs) (__fls(_fs) - 1)
/* Sensor resolution in number of bits
* This sensor has variable precision (8/10/12 bits) depending Power Mode