Skip to content

Commit 2d2a708

Browse files
maximevincenashif
authored andcommitted
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 <[email protected]>
1 parent 47021a6 commit 2d2a708

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

drivers/sensor/lis2dw12/lis2dw12.c

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,22 @@ static int lis2dw12_set_power_mode(const struct device *dev,
236236
return lis2dw12_write_reg(ctx, LIS2DW12_CTRL1, &regval, 1);
237237
}
238238

239+
static int lis2dw12_set_low_noise(const struct device *dev,
240+
bool low_noise)
241+
{
242+
const struct lis2dw12_device_config *cfg = dev->config;
243+
stmdev_ctx_t *ctx = (stmdev_ctx_t *)&cfg->ctx;
244+
lis2dw12_ctrl6_t ctrl6;
245+
int ret;
246+
247+
ret = lis2dw12_read_reg(ctx, LIS2DW12_CTRL6, (uint8_t *)&ctrl6, 1);
248+
if (ret < 0) {
249+
return ret;
250+
}
251+
ctrl6.low_noise = low_noise;
252+
return lis2dw12_write_reg(ctx, LIS2DW12_CTRL6, (uint8_t *)&ctrl6, 1);
253+
}
254+
239255
static int lis2dw12_init(const struct device *dev)
240256
{
241257
const struct lis2dw12_device_config *cfg = dev->config;
@@ -271,8 +287,16 @@ static int lis2dw12_init(const struct device *dev)
271287

272288
/* set power mode */
273289
LOG_DBG("power-mode is %d", cfg->pm);
274-
if (lis2dw12_set_power_mode(dev, cfg->pm)) {
275-
return -EIO;
290+
ret = lis2dw12_set_power_mode(dev, cfg->pm);
291+
if (ret < 0) {
292+
return ret;
293+
}
294+
295+
LOG_DBG("low noise is %d", cfg->low_noise);
296+
ret = lis2dw12_set_low_noise(dev, cfg->low_noise);
297+
if (ret < 0) {
298+
LOG_ERR("Failed to configure low_noise");
299+
return ret;
276300
}
277301

278302
/* set default odr to 12.5Hz acc */
@@ -293,9 +317,10 @@ static int lis2dw12_init(const struct device *dev)
293317
lis2dw12_filter_bandwidth_set(ctx, cfg->bw_filt);
294318

295319
#ifdef CONFIG_LIS2DW12_TRIGGER
296-
if (lis2dw12_init_interrupt(dev) < 0) {
320+
ret = lis2dw12_init_interrupt(dev);
321+
if (ret < 0) {
297322
LOG_ERR("Failed to initialize interrupts");
298-
return -EIO;
323+
return ret;
299324
}
300325
#endif /* CONFIG_LIS2DW12_TRIGGER */
301326

@@ -367,6 +392,7 @@ static int lis2dw12_init(const struct device *dev)
367392
.pm = DT_INST_PROP(inst, power_mode), \
368393
.range = DT_INST_PROP(inst, range), \
369394
.bw_filt = DT_INST_PROP(inst, bw_filt), \
395+
.low_noise = DT_INST_PROP(inst, low_noise), \
370396
LIS2DW12_CONFIG_TAP(inst) \
371397
COND_CODE_1(DT_INST_NODE_HAS_PROP(inst, irq_gpios), \
372398
(LIS2DW12_CFG_IRQ(inst)), ()) \
@@ -392,6 +418,7 @@ static int lis2dw12_init(const struct device *dev)
392418
.pm = DT_INST_PROP(inst, power_mode), \
393419
.range = DT_INST_PROP(inst, range), \
394420
.bw_filt = DT_INST_PROP(inst, bw_filt), \
421+
.low_noise = DT_INST_PROP(inst, low_noise), \
395422
LIS2DW12_CONFIG_TAP(inst) \
396423
COND_CODE_1(DT_INST_NODE_HAS_PROP(inst, irq_gpios), \
397424
(LIS2DW12_CFG_IRQ(inst)), ()) \

drivers/sensor/lis2dw12/lis2dw12.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ struct lis2dw12_device_config {
6969
lis2dw12_mode_t pm;
7070
uint8_t range;
7171
uint8_t bw_filt;
72+
bool low_noise;
7273
#ifdef CONFIG_LIS2DW12_TRIGGER
7374
struct gpio_dt_spec gpio_int;
7475
uint8_t int_pin;

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,11 @@ properties:
156156
This register represents the time after the first detected tap in which
157157
there must not be any overthreshold event. Where 0 equals 2*1/ODR
158158
and 1LSB = 4*1/ODR.
159+
160+
low-noise:
161+
type: boolean
162+
required: false
163+
description: |
164+
Enables the LOW_NOISE flag in the CTRL6 register.
165+
This influences the noise density and the current consumption.
166+
See the datasheet for more information.

0 commit comments

Comments
 (0)