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 <maxime@veemax.be>
This commit is contained in:
Maxime Vincent 2022-03-18 19:19:10 +01:00 committed by Anas Nashif
commit 652ab7f2d4
3 changed files with 45 additions and 0 deletions

View file

@ -324,6 +324,22 @@ static int lis2dw12_init(const struct device *dev)
}
#endif /* CONFIG_LIS2DW12_TRIGGER */
LOG_DBG("high pass reference mode is %d", (int)cfg->hp_ref_mode);
ret = lis2dw12_reference_mode_set(ctx, cfg->hp_ref_mode);
if (ret < 0) {
LOG_ERR("high pass reference mode config error %d", (int)cfg->hp_ref_mode);
return ret;
}
LOG_DBG("high pass filter path is %d", (int)cfg->hp_filter_path);
lis2dw12_fds_t fds = cfg->hp_filter_path ?
LIS2DW12_HIGH_PASS_ON_OUT : LIS2DW12_LPF_ON_OUT;
ret = lis2dw12_filter_path_set(ctx, fds);
if (ret < 0) {
LOG_ERR("filter path config error %d", (int)cfg->hp_filter_path);
return ret;
}
return 0;
}
@ -393,6 +409,8 @@ static int lis2dw12_init(const struct device *dev)
.range = DT_INST_PROP(inst, range), \
.bw_filt = DT_INST_PROP(inst, bw_filt), \
.low_noise = DT_INST_PROP(inst, low_noise), \
.hp_filter_path = DT_INST_PROP(inst, hp_filter_path), \
.hp_ref_mode = DT_INST_PROP(inst, hp_ref_mode), \
LIS2DW12_CONFIG_TAP(inst) \
COND_CODE_1(DT_INST_NODE_HAS_PROP(inst, irq_gpios), \
(LIS2DW12_CFG_IRQ(inst)), ()) \
@ -419,6 +437,8 @@ static int lis2dw12_init(const struct device *dev)
.range = DT_INST_PROP(inst, range), \
.bw_filt = DT_INST_PROP(inst, bw_filt), \
.low_noise = DT_INST_PROP(inst, low_noise), \
.hp_filter_path = DT_INST_PROP(inst, hp_filter_path), \
.hp_ref_mode = DT_INST_PROP(inst, hp_ref_mode), \
LIS2DW12_CONFIG_TAP(inst) \
COND_CODE_1(DT_INST_NODE_HAS_PROP(inst, irq_gpios), \
(LIS2DW12_CFG_IRQ(inst)), ()) \

View file

@ -70,6 +70,8 @@ struct lis2dw12_device_config {
uint8_t range;
uint8_t bw_filt;
bool low_noise;
bool hp_filter_path;
bool hp_ref_mode;
#ifdef CONFIG_LIS2DW12_TRIGGER
struct gpio_dt_spec gpio_int;
uint8_t int_pin;

View file

@ -164,3 +164,26 @@ properties:
Enables the LOW_NOISE flag in the CTRL6 register.
This influences the noise density and the current consumption.
See the datasheet for more information.
hp-filter-path:
type: boolean
required: false
description: |
Sets the Filtered Data Selection bit in the CTRL6 register.
When enabled, the high-pass filter path is selected.
When disabled, the low-pass filter path is selected.
Note that this influences the OUT_REG / FIFO values,
but not the Wakeup function.
hp-ref-mode:
type: boolean
required: false
description: |
Enables the high-pass filter reference mode in the CTRL7 register.
When the high-pass filter is configured in reference mode,
the output data is calculated as the difference between the input
acceleration and the values captured when reference mode was enabled.
In this way only the difference is applied without any filtering
of the LIS2DW12.
Note that this influences both the OUT_REG / FIFO values,
as well as the Wakeup function.