Skip to content

Commit 652ab7f

Browse files
maximevincenashif
authored andcommitted
drivers/sensor: lis2dw12: add fds + hp_ref support
Add FDS (Filtered Data Type Selection) + High-Pass reference mode support (FDS in CTRL6, HP_REF_MODE in CTRL7) Values are configurable through DT per instance. Signed-off-by: Maxime Vincent <[email protected]>
1 parent 2d2a708 commit 652ab7f

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

drivers/sensor/lis2dw12/lis2dw12.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,22 @@ static int lis2dw12_init(const struct device *dev)
324324
}
325325
#endif /* CONFIG_LIS2DW12_TRIGGER */
326326

327+
LOG_DBG("high pass reference mode is %d", (int)cfg->hp_ref_mode);
328+
ret = lis2dw12_reference_mode_set(ctx, cfg->hp_ref_mode);
329+
if (ret < 0) {
330+
LOG_ERR("high pass reference mode config error %d", (int)cfg->hp_ref_mode);
331+
return ret;
332+
}
333+
334+
LOG_DBG("high pass filter path is %d", (int)cfg->hp_filter_path);
335+
lis2dw12_fds_t fds = cfg->hp_filter_path ?
336+
LIS2DW12_HIGH_PASS_ON_OUT : LIS2DW12_LPF_ON_OUT;
337+
ret = lis2dw12_filter_path_set(ctx, fds);
338+
if (ret < 0) {
339+
LOG_ERR("filter path config error %d", (int)cfg->hp_filter_path);
340+
return ret;
341+
}
342+
327343
return 0;
328344
}
329345

@@ -393,6 +409,8 @@ static int lis2dw12_init(const struct device *dev)
393409
.range = DT_INST_PROP(inst, range), \
394410
.bw_filt = DT_INST_PROP(inst, bw_filt), \
395411
.low_noise = DT_INST_PROP(inst, low_noise), \
412+
.hp_filter_path = DT_INST_PROP(inst, hp_filter_path), \
413+
.hp_ref_mode = DT_INST_PROP(inst, hp_ref_mode), \
396414
LIS2DW12_CONFIG_TAP(inst) \
397415
COND_CODE_1(DT_INST_NODE_HAS_PROP(inst, irq_gpios), \
398416
(LIS2DW12_CFG_IRQ(inst)), ()) \
@@ -419,6 +437,8 @@ static int lis2dw12_init(const struct device *dev)
419437
.range = DT_INST_PROP(inst, range), \
420438
.bw_filt = DT_INST_PROP(inst, bw_filt), \
421439
.low_noise = DT_INST_PROP(inst, low_noise), \
440+
.hp_filter_path = DT_INST_PROP(inst, hp_filter_path), \
441+
.hp_ref_mode = DT_INST_PROP(inst, hp_ref_mode), \
422442
LIS2DW12_CONFIG_TAP(inst) \
423443
COND_CODE_1(DT_INST_NODE_HAS_PROP(inst, irq_gpios), \
424444
(LIS2DW12_CFG_IRQ(inst)), ()) \

drivers/sensor/lis2dw12/lis2dw12.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ struct lis2dw12_device_config {
7070
uint8_t range;
7171
uint8_t bw_filt;
7272
bool low_noise;
73+
bool hp_filter_path;
74+
bool hp_ref_mode;
7375
#ifdef CONFIG_LIS2DW12_TRIGGER
7476
struct gpio_dt_spec gpio_int;
7577
uint8_t int_pin;

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,26 @@ properties:
164164
Enables the LOW_NOISE flag in the CTRL6 register.
165165
This influences the noise density and the current consumption.
166166
See the datasheet for more information.
167+
168+
hp-filter-path:
169+
type: boolean
170+
required: false
171+
description: |
172+
Sets the Filtered Data Selection bit in the CTRL6 register.
173+
When enabled, the high-pass filter path is selected.
174+
When disabled, the low-pass filter path is selected.
175+
Note that this influences the OUT_REG / FIFO values,
176+
but not the Wakeup function.
177+
178+
hp-ref-mode:
179+
type: boolean
180+
required: false
181+
description: |
182+
Enables the high-pass filter reference mode in the CTRL7 register.
183+
When the high-pass filter is configured in reference mode,
184+
the output data is calculated as the difference between the input
185+
acceleration and the values captured when reference mode was enabled.
186+
In this way only the difference is applied without any filtering
187+
of the LIS2DW12.
188+
Note that this influences both the OUT_REG / FIFO values,
189+
as well as the Wakeup function.

0 commit comments

Comments
 (0)