Skip to content

Commit 70e99fe

Browse files
pdgendtcarlescufi
authored andcommitted
drivers: sensor: lis2dh: Configurable latch and mode for any movement
Add 2 properties to configure the "any movement" event. * Ability to disable the interrupt latch * Select movement mode Signed-off-by: Pieter De Gendt <[email protected]>
1 parent 46045e6 commit 70e99fe

File tree

4 files changed

+70
-28
lines changed

4 files changed

+70
-28
lines changed

drivers/sensor/lis2dh/lis2dh.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,12 @@ static int lis2dh_pm_action(const struct device *dev,
496496
#define ANYM_ON_INT1(inst) \
497497
DT_INST_PROP(inst, anym_on_int1)
498498

499+
#define ANYM_LATCH(inst) \
500+
!DT_INST_PROP(inst, anym_no_latch)
501+
502+
#define ANYM_MODE(inst) \
503+
DT_INST_PROP(inst, anym_mode)
504+
499505
#ifdef CONFIG_LIS2DH_TRIGGER
500506
#define GPIO_DT_SPEC_INST_GET_BY_IDX_COND(id, prop, idx) \
501507
COND_CODE_1(DT_INST_PROP_HAS_IDX(id, prop, idx), \
@@ -548,9 +554,11 @@ static int lis2dh_pm_action(const struct device *dev,
548554
SPI_MODE_CPOL | \
549555
SPI_MODE_CPHA, \
550556
0) }, \
551-
.hw = { .is_lsm303agr_dev = IS_LSM303AGR_DEV(inst), \
552-
.disc_pull_up = DISC_PULL_UP(inst), \
553-
.anym_on_int1 = ANYM_ON_INT1(inst), }, \
557+
.hw = { .is_lsm303agr_dev = IS_LSM303AGR_DEV(inst), \
558+
.disc_pull_up = DISC_PULL_UP(inst), \
559+
.anym_on_int1 = ANYM_ON_INT1(inst), \
560+
.anym_latch = ANYM_LATCH(inst), \
561+
.anym_mode = ANYM_MODE(inst), }, \
554562
LIS2DH_CFG_TEMPERATURE(inst) \
555563
LIS2DH_CFG_INT(inst) \
556564
}
@@ -569,9 +577,11 @@ static int lis2dh_pm_action(const struct device *dev,
569577
{ \
570578
.bus_init = lis2dh_i2c_init, \
571579
.bus_cfg = { .i2c = I2C_DT_SPEC_INST_GET(inst), }, \
572-
.hw = { .is_lsm303agr_dev = IS_LSM303AGR_DEV(inst), \
573-
.disc_pull_up = DISC_PULL_UP(inst), \
574-
.anym_on_int1 = ANYM_ON_INT1(inst), }, \
580+
.hw = { .is_lsm303agr_dev = IS_LSM303AGR_DEV(inst), \
581+
.disc_pull_up = DISC_PULL_UP(inst), \
582+
.anym_on_int1 = ANYM_ON_INT1(inst), \
583+
.anym_latch = ANYM_LATCH(inst), \
584+
.anym_mode = ANYM_MODE(inst), }, \
575585
LIS2DH_CFG_TEMPERATURE(inst) \
576586
LIS2DH_CFG_INT(inst) \
577587
}

drivers/sensor/lis2dh/lis2dh.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@
159159
#define LIS2DH_REG_INT2_THS 0x36
160160
#define LIS2DH_REG_INT2_DUR 0x37
161161

162-
#define LIS2DH_AOI_CFG BIT(7)
162+
#define LIS2DH_INT_CFG_MODE_SHIFT 6
163+
#define LIS2DH_INT_CFG_AOI_CFG BIT(LIS2DH_INT_CFG_MODE_SHIFT + 1)
164+
#define LIS2DH_INT_CFG_6D_CFG BIT(LIS2DH_INT_CFG_MODE_SHIFT)
163165
#define LIS2DH_INT_CFG_ZHIE_ZUPE BIT(5)
164166
#define LIS2DH_INT_CFG_ZLIE_ZDOWNE BIT(4)
165167
#define LIS2DH_INT_CFG_YHIE_YUPE BIT(3)
@@ -208,6 +210,8 @@ struct lis2dh_config {
208210
bool is_lsm303agr_dev : 1;
209211
bool disc_pull_up : 1;
210212
bool anym_on_int1 : 1;
213+
bool anym_latch : 1;
214+
uint8_t anym_mode : 2;
211215
} hw;
212216
#ifdef CONFIG_LIS2DH_MEASURE_TEMPERATURE
213217
const struct temperature temperature;

drivers/sensor/lis2dh/lis2dh_trigger.c

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ static int lis2dh_start_trigger_int2(const struct device *dev)
187187
return lis2dh->hw_tf->write_reg(
188188
dev,
189189
cfg->hw.anym_on_int1 ? LIS2DH_REG_INT1_CFG : LIS2DH_REG_INT2_CFG,
190-
LIS2DH_ANYM_CFG);
190+
(cfg->hw.anym_mode << LIS2DH_INT_CFG_MODE_SHIFT) | LIS2DH_ANYM_CFG);
191191
}
192192

193193
int lis2dh_trigger_set(const struct device *dev,
@@ -275,7 +275,7 @@ static void lis2dh_gpio_int1_callback(const struct device *dev,
275275

276276
atomic_set_bit(&lis2dh->trig_flags, TRIGGED_INT1);
277277

278-
/* int is level triggered so disable until we clear it */
278+
/* int is level triggered so disable until processed */
279279
setup_int1(lis2dh->dev, false);
280280

281281
#if defined(CONFIG_LIS2DH_TRIGGER_OWN_THREAD)
@@ -295,7 +295,7 @@ static void lis2dh_gpio_int2_callback(const struct device *dev,
295295

296296
atomic_set_bit(&lis2dh->trig_flags, TRIGGED_INT2);
297297

298-
/* int is level triggered so disable until we clear it */
298+
/* int is level triggered so disable until processed */
299299
setup_int2(lis2dh->dev, false);
300300

301301
#if defined(CONFIG_LIS2DH_TRIGGER_OWN_THREAD)
@@ -365,15 +365,17 @@ static void lis2dh_thread_cb(const struct device *dev)
365365
};
366366
uint8_t reg_val;
367367

368-
/* clear interrupt to de-assert int line */
369-
status = lis2dh->hw_tf->read_reg(dev,
370-
cfg->hw.anym_on_int1 ?
371-
LIS2DH_REG_INT1_SRC :
372-
LIS2DH_REG_INT2_SRC,
373-
&reg_val);
374-
if (status < 0) {
375-
LOG_ERR("clearing interrupt 2 failed: %d", status);
376-
return;
368+
if (cfg->hw.anym_latch) {
369+
/* clear interrupt to de-assert int line */
370+
status = lis2dh->hw_tf->read_reg(dev,
371+
cfg->hw.anym_on_int1 ?
372+
LIS2DH_REG_INT1_SRC :
373+
LIS2DH_REG_INT2_SRC,
374+
&reg_val);
375+
if (status < 0) {
376+
LOG_ERR("clearing interrupt 2 failed: %d", status);
377+
return;
378+
}
377379
}
378380

379381
if (likely(lis2dh->handler_anymotion != NULL)) {
@@ -538,23 +540,25 @@ int lis2dh_init_interrupt(const struct device *dev)
538540
status = lis2dh->hw_tf->update_reg(dev, LIS2DH_REG_CTRL3,
539541
LIS2DH_EN_INT1_INT1,
540542
LIS2DH_EN_INT1_INT1);
541-
542-
/* latch int1 line interrupt */
543-
status = lis2dh->hw_tf->write_reg(dev, LIS2DH_REG_CTRL5,
544-
LIS2DH_EN_LIR_INT1);
543+
if (cfg->hw.anym_latch) {
544+
/* latch int1 line interrupt */
545+
status = lis2dh->hw_tf->write_reg(dev, LIS2DH_REG_CTRL5,
546+
LIS2DH_EN_LIR_INT1);
547+
}
545548
} else {
546549
/* enable interrupt 2 on int2 line */
547550
status = lis2dh->hw_tf->update_reg(dev, LIS2DH_REG_CTRL6,
548551
LIS2DH_EN_INT2_INT2,
549552
LIS2DH_EN_INT2_INT2);
550-
551-
/* latch int2 line interrupt */
552-
status = lis2dh->hw_tf->write_reg(dev, LIS2DH_REG_CTRL5,
553-
LIS2DH_EN_LIR_INT2);
553+
if (cfg->hw.anym_latch) {
554+
/* latch int2 line interrupt */
555+
status = lis2dh->hw_tf->write_reg(dev, LIS2DH_REG_CTRL5,
556+
LIS2DH_EN_LIR_INT2);
557+
}
554558
}
555559

556560
if (status < 0) {
557-
LOG_ERR("latch enable reg write failed (%d)", status);
561+
LOG_ERR("enable reg write failed (%d)", status);
558562
return status;
559563
}
560564

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,27 @@ properties:
2525
Indicates that the device driver should use interrupt 1
2626
for any movement. This is for boards that only have one
2727
interrupt line connected from the sensor to the processor.
28+
29+
anym-no-latch:
30+
type: boolean
31+
description: |
32+
Disable the latching of interrupts for any movement.
33+
34+
anym-mode:
35+
type: int
36+
required: false
37+
default: 0
38+
description: |
39+
Select the interrupt mode for any movement.
40+
41+
0 = OR combination of interrupt events
42+
1 = 6D movement recognition
43+
2 = AND combination of interrupt events
44+
3 = 6D position recognition
45+
46+
The default of 0 is the power-on-reset value.
47+
enum:
48+
- 0
49+
- 1
50+
- 2
51+
- 3

0 commit comments

Comments
 (0)