Skip to content

Commit 9538b4f

Browse files
eHammarstromnashif
authored andcommitted
drivers: sensor: lsm6dso: Add support for Accel LP filter
Add device tree support for enabling the second low pass filter (LPF2) for the accelerometer output. This adds additional low pass on top of the default ODR/2 from the LPF1 output. Signed-off-by: Emil Hammarström <[email protected]>
1 parent 54cd6a3 commit 9538b4f

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed

drivers/sensor/st/lsm6dso/lsm6dso.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ LOG_MODULE_REGISTER(LSM6DSO, CONFIG_SENSOR_LOG_LEVEL);
2222

2323
static const uint16_t lsm6dso_odr_map[] = {0, 12, 26, 52, 104, 208, 417, 833,
2424
1667, 3333, 6667};
25+
static const uint8_t lsm6dso_lp_filter_map[] = {0,
26+
LSM6DSO_LP_ODR_DIV_10,
27+
LSM6DSO_LP_ODR_DIV_20,
28+
LSM6DSO_LP_ODR_DIV_45,
29+
LSM6DSO_LP_ODR_DIV_100,
30+
LSM6DSO_LP_ODR_DIV_200,
31+
LSM6DSO_LP_ODR_DIV_400,
32+
LSM6DSO_LP_ODR_DIV_800};
2533

2634
static int lsm6dso_freq_to_odr_val(uint16_t freq)
2735
{
@@ -813,6 +821,19 @@ static int lsm6dso_init_chip(const struct device *dev)
813821
return -EIO;
814822
}
815823

824+
if (cfg->accel_lp_filter) {
825+
if (lsm6dso_xl_filter_lp2_set(ctx, 1)) {
826+
LOG_ERR("failed to enable low pass filter (LPF2)");
827+
return -EIO;
828+
}
829+
830+
if (lsm6dso_xl_hp_path_on_out_set(ctx,
831+
lsm6dso_lp_filter_map[cfg->accel_lp_filter])) {
832+
LOG_ERR("failed to configure low pass filter (LPF2)");
833+
return -EIO;
834+
}
835+
}
836+
816837
return 0;
817838
}
818839

@@ -898,6 +919,7 @@ static int lsm6dso_init(const struct device *dev)
898919
#define LSM6DSO_CONFIG_COMMON(inst) \
899920
.accel_pm = DT_INST_PROP(inst, accel_pm), \
900921
.accel_odr = DT_INST_PROP(inst, accel_odr), \
922+
.accel_lp_filter = DT_INST_PROP(inst, accel_lp_filter), \
901923
.accel_range = DT_INST_PROP(inst, accel_range) | \
902924
(DT_INST_NODE_HAS_COMPAT(inst, st_lsm6dso32) ? \
903925
ACCEL_RANGE_DOUBLE : 0), \

drivers/sensor/st/lsm6dso/lsm6dso.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ struct lsm6dso_config {
5252
} stmemsc_cfg;
5353
uint8_t accel_pm;
5454
uint8_t accel_odr;
55+
uint8_t accel_lp_filter;
5556
#define ACCEL_RANGE_DOUBLE BIT(7)
5657
#define ACCEL_RANGE_MASK BIT_MASK(6)
5758
uint8_t accel_range;

dts/bindings/sensor/st,lsm6dso-common.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,25 @@ properties:
9494
9595
enum: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
9696

97+
accel-lp-filter:
98+
type: int
99+
default: 0
100+
description: |
101+
Specify the amount of low pass filtering applied to the accelerometer values.
102+
Default is power-up configuration.
103+
This will enable the LPF2 lowpass filter via the lpf2_xl_en bit in the CTRL1_XL register.
104+
105+
- 0 # LSM6DSO_DT_LP_ODR_DIV_2
106+
- 1 # LSM6DSO_DT_LP_ODR_DIV_10
107+
- 2 # LSM6DSO_DT_LP_ODR_DIV_20
108+
- 3 # LSM6DSO_DT_LP_ODR_DIV_45
109+
- 4 # LSM6DSO_DT_LP_ODR_DIV_100
110+
- 5 # LSM6DSO_DT_LP_ODR_DIV_200
111+
- 6 # LSM6DSO_DT_LP_ODR_DIV_400
112+
- 7 # LSM6DSO_DT_LP_ODR_DIV_800
113+
114+
enum: [0, 1, 2, 3, 4, 5, 6, 7]
115+
97116
gyro-pm:
98117
type: int
99118
default: 0

include/zephyr/dt-bindings/sensor/lsm6dso.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@
4242
#define LSM6DSO_DT_ODR_6667Hz 0xa
4343
#define LSM6DSO_DT_ODR_1Hz6 0xb
4444

45+
/* Low pass filter dividers */
46+
#define LSM6DSO_DT_LP_ODR_DIV_2 0
47+
#define LSM6DSO_DT_LP_ODR_DIV_10 1
48+
#define LSM6DSO_DT_LP_ODR_DIV_20 2
49+
#define LSM6DSO_DT_LP_ODR_DIV_45 3
50+
#define LSM6DSO_DT_LP_ODR_DIV_100 4
51+
#define LSM6DSO_DT_LP_ODR_DIV_200 5
52+
#define LSM6DSO_DT_LP_ODR_DIV_400 6
53+
#define LSM6DSO_DT_LP_ODR_DIV_800 7
54+
4555
/* Tap mode */
4656
#define LSM6DSO_DT_SINGLE_TAP 0
4757
#define LSM6DSO_DT_SINGLE_DOUBLE_TAP 1

0 commit comments

Comments
 (0)