drivers/sensor: lis2dw12: add low_noise support

Add low_noise support. (LOW_NOISE in CTRL6)
Value is configurable through DT per instance.

Signed-off-by: Maxime Vincent <maxime@veemax.be>
This commit is contained in:
Maxime Vincent 2022-03-18 18:56:55 +01:00 committed by Anas Nashif
commit 2d2a708bc8
3 changed files with 40 additions and 4 deletions

View file

@ -236,6 +236,22 @@ static int lis2dw12_set_power_mode(const struct device *dev,
return lis2dw12_write_reg(ctx, LIS2DW12_CTRL1, &regval, 1); return lis2dw12_write_reg(ctx, LIS2DW12_CTRL1, &regval, 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) static int lis2dw12_init(const struct device *dev)
{ {
const struct lis2dw12_device_config *cfg = dev->config; const struct lis2dw12_device_config *cfg = dev->config;
@ -271,8 +287,16 @@ static int lis2dw12_init(const struct device *dev)
/* set power mode */ /* set power mode */
LOG_DBG("power-mode is %d", cfg->pm); LOG_DBG("power-mode is %d", cfg->pm);
if (lis2dw12_set_power_mode(dev, cfg->pm)) { ret = lis2dw12_set_power_mode(dev, cfg->pm);
return -EIO; 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 */ /* 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); lis2dw12_filter_bandwidth_set(ctx, cfg->bw_filt);
#ifdef CONFIG_LIS2DW12_TRIGGER #ifdef CONFIG_LIS2DW12_TRIGGER
if (lis2dw12_init_interrupt(dev) < 0) { ret = lis2dw12_init_interrupt(dev);
if (ret < 0) {
LOG_ERR("Failed to initialize interrupts"); LOG_ERR("Failed to initialize interrupts");
return -EIO; return ret;
} }
#endif /* CONFIG_LIS2DW12_TRIGGER */ #endif /* CONFIG_LIS2DW12_TRIGGER */
@ -367,6 +392,7 @@ static int lis2dw12_init(const struct device *dev)
.pm = DT_INST_PROP(inst, power_mode), \ .pm = DT_INST_PROP(inst, power_mode), \
.range = DT_INST_PROP(inst, range), \ .range = DT_INST_PROP(inst, range), \
.bw_filt = DT_INST_PROP(inst, bw_filt), \ .bw_filt = DT_INST_PROP(inst, bw_filt), \
.low_noise = DT_INST_PROP(inst, low_noise), \
LIS2DW12_CONFIG_TAP(inst) \ LIS2DW12_CONFIG_TAP(inst) \
COND_CODE_1(DT_INST_NODE_HAS_PROP(inst, irq_gpios), \ COND_CODE_1(DT_INST_NODE_HAS_PROP(inst, irq_gpios), \
(LIS2DW12_CFG_IRQ(inst)), ()) \ (LIS2DW12_CFG_IRQ(inst)), ()) \
@ -392,6 +418,7 @@ static int lis2dw12_init(const struct device *dev)
.pm = DT_INST_PROP(inst, power_mode), \ .pm = DT_INST_PROP(inst, power_mode), \
.range = DT_INST_PROP(inst, range), \ .range = DT_INST_PROP(inst, range), \
.bw_filt = DT_INST_PROP(inst, bw_filt), \ .bw_filt = DT_INST_PROP(inst, bw_filt), \
.low_noise = DT_INST_PROP(inst, low_noise), \
LIS2DW12_CONFIG_TAP(inst) \ LIS2DW12_CONFIG_TAP(inst) \
COND_CODE_1(DT_INST_NODE_HAS_PROP(inst, irq_gpios), \ COND_CODE_1(DT_INST_NODE_HAS_PROP(inst, irq_gpios), \
(LIS2DW12_CFG_IRQ(inst)), ()) \ (LIS2DW12_CFG_IRQ(inst)), ()) \

View file

@ -69,6 +69,7 @@ struct lis2dw12_device_config {
lis2dw12_mode_t pm; lis2dw12_mode_t pm;
uint8_t range; uint8_t range;
uint8_t bw_filt; uint8_t bw_filt;
bool low_noise;
#ifdef CONFIG_LIS2DW12_TRIGGER #ifdef CONFIG_LIS2DW12_TRIGGER
struct gpio_dt_spec gpio_int; struct gpio_dt_spec gpio_int;
uint8_t int_pin; uint8_t int_pin;

View file

@ -156,3 +156,11 @@ properties:
This register represents the time after the first detected tap in which 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 there must not be any overthreshold event. Where 0 equals 2*1/ODR
and 1LSB = 4*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.