From 307a60e21754e7f4e92e2bbe11ebfc5ae0967349 Mon Sep 17 00:00:00 2001 From: Maxime Vincent Date: Sat, 19 Mar 2022 11:47:20 +0100 Subject: [PATCH] drivers/sensor: lis2dw12: add drdy pulsed/latched config Add DT option to configure the data ready interrupt mode. Latched is the default; pulsed can be enabled through the drdy-pulsed DT, if desired. Signed-off-by: Maxime Vincent --- drivers/sensor/lis2dw12/lis2dw12.c | 2 ++ drivers/sensor/lis2dw12/lis2dw12.h | 1 + drivers/sensor/lis2dw12/lis2dw12_trigger.c | 11 ++++++++--- dts/bindings/sensor/st,lis2dw12-common.yaml | 8 ++++++++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/drivers/sensor/lis2dw12/lis2dw12.c b/drivers/sensor/lis2dw12/lis2dw12.c index fc0a914622b..0bd288a15e3 100644 --- a/drivers/sensor/lis2dw12/lis2dw12.c +++ b/drivers/sensor/lis2dw12/lis2dw12.c @@ -503,6 +503,7 @@ static int lis2dw12_init(const struct device *dev) .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), \ + .drdy_pulsed = DT_INST_PROP(inst, drdy_pulsed), \ LIS2DW12_CONFIG_TAP(inst) \ COND_CODE_1(DT_INST_NODE_HAS_PROP(inst, irq_gpios), \ (LIS2DW12_CFG_IRQ(inst)), ()) \ @@ -531,6 +532,7 @@ static int lis2dw12_init(const struct device *dev) .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), \ + .drdy_pulsed = DT_INST_PROP(inst, drdy_pulsed), \ 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 74f6b2a55db..f4578b4f59c 100644 --- a/drivers/sensor/lis2dw12/lis2dw12.h +++ b/drivers/sensor/lis2dw12/lis2dw12.h @@ -72,6 +72,7 @@ struct lis2dw12_device_config { bool low_noise; bool hp_filter_path; bool hp_ref_mode; + bool drdy_pulsed; #ifdef CONFIG_LIS2DW12_TRIGGER struct gpio_dt_spec gpio_int; uint8_t int_pin; diff --git a/drivers/sensor/lis2dw12/lis2dw12_trigger.c b/drivers/sensor/lis2dw12/lis2dw12_trigger.c index 87b780cacbf..a3f2a9f1d3d 100644 --- a/drivers/sensor/lis2dw12/lis2dw12_trigger.c +++ b/drivers/sensor/lis2dw12/lis2dw12_trigger.c @@ -422,9 +422,14 @@ int lis2dw12_init_interrupt(const struct device *dev) return -EIO; } - /* enable interrupt on int1/int2 in pulse mode */ - if (lis2dw12_int_notification_set(ctx, LIS2DW12_INT_PULSED)) { - return -EIO; + /* set interrupt notification mode on int1/int2 */ + LOG_DBG("drdy_pulsed is %d", (int)cfg->drdy_pulsed); + lis2dw12_lir_t mode = cfg->drdy_pulsed ? LIS2DW12_INT_PULSED : LIS2DW12_INT_LATCHED; + + ret = lis2dw12_int_notification_set(ctx, mode); + if (ret < 0) { + LOG_ERR("drdy_pulsed config error %d", (int)cfg->drdy_pulsed); + return ret; } #ifdef CONFIG_LIS2DW12_TAP diff --git a/dts/bindings/sensor/st,lis2dw12-common.yaml b/dts/bindings/sensor/st,lis2dw12-common.yaml index 0e684e610f3..9c149d390bc 100644 --- a/dts/bindings/sensor/st,lis2dw12-common.yaml +++ b/dts/bindings/sensor/st,lis2dw12-common.yaml @@ -187,3 +187,11 @@ properties: of the LIS2DW12. Note that this influences both the OUT_REG / FIFO values, as well as the Wakeup function. + + drdy-pulsed: + type: boolean + required: false + description: | + Selects the pulsed mode for data-ready interrupt when enabled, + and the latched mode when disabled. + Sets the corresponding DRDY_PULSED bit in the CTRL7 register.