From 652ab7f2d4d2c89ab96c8850dfcf8dbe05526ebb Mon Sep 17 00:00:00 2001 From: Maxime Vincent Date: Fri, 18 Mar 2022 19:19:10 +0100 Subject: [PATCH] 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 --- drivers/sensor/lis2dw12/lis2dw12.c | 20 ++++++++++++++++++ drivers/sensor/lis2dw12/lis2dw12.h | 2 ++ dts/bindings/sensor/st,lis2dw12-common.yaml | 23 +++++++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/drivers/sensor/lis2dw12/lis2dw12.c b/drivers/sensor/lis2dw12/lis2dw12.c index 4cfa07b94bc..4b65d938962 100644 --- a/drivers/sensor/lis2dw12/lis2dw12.c +++ b/drivers/sensor/lis2dw12/lis2dw12.c @@ -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)), ()) \ diff --git a/drivers/sensor/lis2dw12/lis2dw12.h b/drivers/sensor/lis2dw12/lis2dw12.h index da6f8b84e9e..d3839999dea 100644 --- a/drivers/sensor/lis2dw12/lis2dw12.h +++ b/drivers/sensor/lis2dw12/lis2dw12.h @@ -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; diff --git a/dts/bindings/sensor/st,lis2dw12-common.yaml b/dts/bindings/sensor/st,lis2dw12-common.yaml index 8fac0dfa959..0e684e610f3 100644 --- a/dts/bindings/sensor/st,lis2dw12-common.yaml +++ b/dts/bindings/sensor/st,lis2dw12-common.yaml @@ -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.