diff --git a/drivers/sensor/lis2dw12/lis2dw12.c b/drivers/sensor/lis2dw12/lis2dw12.c index 126595aab0b..4cfa07b94bc 100644 --- a/drivers/sensor/lis2dw12/lis2dw12.c +++ b/drivers/sensor/lis2dw12/lis2dw12.c @@ -236,6 +236,22 @@ static int lis2dw12_set_power_mode(const struct device *dev, return lis2dw12_write_reg(ctx, LIS2DW12_CTRL1, ®val, 1); } +static int lis2dw12_set_low_noise(const struct device *dev, + bool low_noise) +{ + const struct lis2dw12_device_config *cfg = dev->config; + stmdev_ctx_t *ctx = (stmdev_ctx_t *)&cfg->ctx; + lis2dw12_ctrl6_t ctrl6; + int ret; + + ret = lis2dw12_read_reg(ctx, LIS2DW12_CTRL6, (uint8_t *)&ctrl6, 1); + if (ret < 0) { + return ret; + } + ctrl6.low_noise = low_noise; + return lis2dw12_write_reg(ctx, LIS2DW12_CTRL6, (uint8_t *)&ctrl6, 1); +} + static int lis2dw12_init(const struct device *dev) { const struct lis2dw12_device_config *cfg = dev->config; @@ -271,8 +287,16 @@ static int lis2dw12_init(const struct device *dev) /* set power mode */ LOG_DBG("power-mode is %d", cfg->pm); - if (lis2dw12_set_power_mode(dev, cfg->pm)) { - return -EIO; + ret = lis2dw12_set_power_mode(dev, cfg->pm); + if (ret < 0) { + return ret; + } + + LOG_DBG("low noise is %d", cfg->low_noise); + ret = lis2dw12_set_low_noise(dev, cfg->low_noise); + if (ret < 0) { + LOG_ERR("Failed to configure low_noise"); + return ret; } /* set default odr to 12.5Hz acc */ @@ -293,9 +317,10 @@ static int lis2dw12_init(const struct device *dev) lis2dw12_filter_bandwidth_set(ctx, cfg->bw_filt); #ifdef CONFIG_LIS2DW12_TRIGGER - if (lis2dw12_init_interrupt(dev) < 0) { + ret = lis2dw12_init_interrupt(dev); + if (ret < 0) { LOG_ERR("Failed to initialize interrupts"); - return -EIO; + return ret; } #endif /* CONFIG_LIS2DW12_TRIGGER */ @@ -367,6 +392,7 @@ static int lis2dw12_init(const struct device *dev) .pm = DT_INST_PROP(inst, power_mode), \ .range = DT_INST_PROP(inst, range), \ .bw_filt = DT_INST_PROP(inst, bw_filt), \ + .low_noise = DT_INST_PROP(inst, low_noise), \ LIS2DW12_CONFIG_TAP(inst) \ COND_CODE_1(DT_INST_NODE_HAS_PROP(inst, irq_gpios), \ (LIS2DW12_CFG_IRQ(inst)), ()) \ @@ -392,6 +418,7 @@ static int lis2dw12_init(const struct device *dev) .pm = DT_INST_PROP(inst, power_mode), \ .range = DT_INST_PROP(inst, range), \ .bw_filt = DT_INST_PROP(inst, bw_filt), \ + .low_noise = DT_INST_PROP(inst, low_noise), \ 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 ff8f4516ec7..da6f8b84e9e 100644 --- a/drivers/sensor/lis2dw12/lis2dw12.h +++ b/drivers/sensor/lis2dw12/lis2dw12.h @@ -69,6 +69,7 @@ struct lis2dw12_device_config { lis2dw12_mode_t pm; uint8_t range; uint8_t bw_filt; + bool low_noise; #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 2bba8006afb..8fac0dfa959 100644 --- a/dts/bindings/sensor/st,lis2dw12-common.yaml +++ b/dts/bindings/sensor/st,lis2dw12-common.yaml @@ -156,3 +156,11 @@ properties: This register represents the time after the first detected tap in which there must not be any overthreshold event. Where 0 equals 2*1/ODR and 1LSB = 4*1/ODR. + + low-noise: + type: boolean + required: false + description: | + Enables the LOW_NOISE flag in the CTRL6 register. + This influences the noise density and the current consumption. + See the datasheet for more information.