Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions drivers/sensor/lis2dh/lis2dh.c
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,12 @@ static int lis2dh_pm_action(const struct device *dev,
#define ANYM_ON_INT1(inst) \
DT_INST_PROP(inst, anym_on_int1)

#define ANYM_LATCH(inst) \
!DT_INST_PROP(inst, anym_no_latch)

#define ANYM_MODE(inst) \
DT_INST_PROP(inst, anym_mode)

#ifdef CONFIG_LIS2DH_TRIGGER
#define GPIO_DT_SPEC_INST_GET_BY_IDX_COND(id, prop, idx) \
COND_CODE_1(DT_INST_PROP_HAS_IDX(id, prop, idx), \
Expand Down Expand Up @@ -548,9 +554,11 @@ static int lis2dh_pm_action(const struct device *dev,
SPI_MODE_CPOL | \
SPI_MODE_CPHA, \
0) }, \
.hw = { .is_lsm303agr_dev = IS_LSM303AGR_DEV(inst), \
.disc_pull_up = DISC_PULL_UP(inst), \
.anym_on_int1 = ANYM_ON_INT1(inst), }, \
.hw = { .is_lsm303agr_dev = IS_LSM303AGR_DEV(inst), \
.disc_pull_up = DISC_PULL_UP(inst), \
.anym_on_int1 = ANYM_ON_INT1(inst), \
.anym_latch = ANYM_LATCH(inst), \
.anym_mode = ANYM_MODE(inst), }, \
LIS2DH_CFG_TEMPERATURE(inst) \
LIS2DH_CFG_INT(inst) \
}
Expand All @@ -569,9 +577,11 @@ static int lis2dh_pm_action(const struct device *dev,
{ \
.bus_init = lis2dh_i2c_init, \
.bus_cfg = { .i2c = I2C_DT_SPEC_INST_GET(inst), }, \
.hw = { .is_lsm303agr_dev = IS_LSM303AGR_DEV(inst), \
.disc_pull_up = DISC_PULL_UP(inst), \
.anym_on_int1 = ANYM_ON_INT1(inst), }, \
.hw = { .is_lsm303agr_dev = IS_LSM303AGR_DEV(inst), \
.disc_pull_up = DISC_PULL_UP(inst), \
.anym_on_int1 = ANYM_ON_INT1(inst), \
.anym_latch = ANYM_LATCH(inst), \
.anym_mode = ANYM_MODE(inst), }, \
LIS2DH_CFG_TEMPERATURE(inst) \
LIS2DH_CFG_INT(inst) \
}
Expand Down
6 changes: 5 additions & 1 deletion drivers/sensor/lis2dh/lis2dh.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@
#define LIS2DH_REG_INT2_THS 0x36
#define LIS2DH_REG_INT2_DUR 0x37

#define LIS2DH_AOI_CFG BIT(7)
#define LIS2DH_INT_CFG_MODE_SHIFT 6
#define LIS2DH_INT_CFG_AOI_CFG BIT(LIS2DH_INT_CFG_MODE_SHIFT + 1)
#define LIS2DH_INT_CFG_6D_CFG BIT(LIS2DH_INT_CFG_MODE_SHIFT)
#define LIS2DH_INT_CFG_ZHIE_ZUPE BIT(5)
#define LIS2DH_INT_CFG_ZLIE_ZDOWNE BIT(4)
#define LIS2DH_INT_CFG_YHIE_YUPE BIT(3)
Expand Down Expand Up @@ -208,6 +210,8 @@ struct lis2dh_config {
bool is_lsm303agr_dev : 1;
bool disc_pull_up : 1;
bool anym_on_int1 : 1;
bool anym_latch : 1;
uint8_t anym_mode : 2;
} hw;
#ifdef CONFIG_LIS2DH_MEASURE_TEMPERATURE
const struct temperature temperature;
Expand Down
46 changes: 25 additions & 21 deletions drivers/sensor/lis2dh/lis2dh_trigger.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ static int lis2dh_start_trigger_int2(const struct device *dev)
return lis2dh->hw_tf->write_reg(
dev,
cfg->hw.anym_on_int1 ? LIS2DH_REG_INT1_CFG : LIS2DH_REG_INT2_CFG,
LIS2DH_ANYM_CFG);
(cfg->hw.anym_mode << LIS2DH_INT_CFG_MODE_SHIFT) | LIS2DH_ANYM_CFG);
}

int lis2dh_trigger_set(const struct device *dev,
Expand Down Expand Up @@ -275,7 +275,7 @@ static void lis2dh_gpio_int1_callback(const struct device *dev,

atomic_set_bit(&lis2dh->trig_flags, TRIGGED_INT1);

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

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

atomic_set_bit(&lis2dh->trig_flags, TRIGGED_INT2);

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

#if defined(CONFIG_LIS2DH_TRIGGER_OWN_THREAD)
Expand Down Expand Up @@ -365,15 +365,17 @@ static void lis2dh_thread_cb(const struct device *dev)
};
uint8_t reg_val;

/* clear interrupt to de-assert int line */
status = lis2dh->hw_tf->read_reg(dev,
cfg->hw.anym_on_int1 ?
LIS2DH_REG_INT1_SRC :
LIS2DH_REG_INT2_SRC,
&reg_val);
if (status < 0) {
LOG_ERR("clearing interrupt 2 failed: %d", status);
return;
if (cfg->hw.anym_latch) {
/* clear interrupt to de-assert int line */
status = lis2dh->hw_tf->read_reg(dev,
cfg->hw.anym_on_int1 ?
LIS2DH_REG_INT1_SRC :
LIS2DH_REG_INT2_SRC,
&reg_val);
if (status < 0) {
LOG_ERR("clearing interrupt 2 failed: %d", status);
return;
}
}

if (likely(lis2dh->handler_anymotion != NULL)) {
Expand Down Expand Up @@ -538,23 +540,25 @@ int lis2dh_init_interrupt(const struct device *dev)
status = lis2dh->hw_tf->update_reg(dev, LIS2DH_REG_CTRL3,
LIS2DH_EN_INT1_INT1,
LIS2DH_EN_INT1_INT1);

/* latch int1 line interrupt */
status = lis2dh->hw_tf->write_reg(dev, LIS2DH_REG_CTRL5,
LIS2DH_EN_LIR_INT1);
if (cfg->hw.anym_latch) {
/* latch int1 line interrupt */
status = lis2dh->hw_tf->write_reg(dev, LIS2DH_REG_CTRL5,
LIS2DH_EN_LIR_INT1);
}
} else {
/* enable interrupt 2 on int2 line */
status = lis2dh->hw_tf->update_reg(dev, LIS2DH_REG_CTRL6,
LIS2DH_EN_INT2_INT2,
LIS2DH_EN_INT2_INT2);

/* latch int2 line interrupt */
status = lis2dh->hw_tf->write_reg(dev, LIS2DH_REG_CTRL5,
LIS2DH_EN_LIR_INT2);
if (cfg->hw.anym_latch) {
/* latch int2 line interrupt */
status = lis2dh->hw_tf->write_reg(dev, LIS2DH_REG_CTRL5,
LIS2DH_EN_LIR_INT2);
}
}

if (status < 0) {
LOG_ERR("latch enable reg write failed (%d)", status);
LOG_ERR("enable reg write failed (%d)", status);
return status;
}

Expand Down
26 changes: 24 additions & 2 deletions dts/bindings/sensor/st,lis2dh-common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ properties:

disconnect-sdo-sa0-pull-up:
type: boolean
required: false
description: |
Indicates the device driver should disconnect SDO/SA0 pull-up
during device initialization (e.g. to save current
Expand All @@ -20,8 +19,31 @@ properties:

anym-on-int1:
type: boolean
required: false
description: |
Indicates that the device driver should use interrupt 1
for any movement. This is for boards that only have one
interrupt line connected from the sensor to the processor.

anym-no-latch:
type: boolean
description: |
Disable the latching of interrupts for any movement.

anym-mode:
type: int
required: false
default: 0
description: |
Select the interrupt mode for any movement.

0 = OR combination of interrupt events
1 = 6D movement recognition
2 = AND combination of interrupt events
3 = 6D position recognition

The default of 0 is the power-on-reset value.
enum:
- 0
- 1
- 2
- 3
4 changes: 0 additions & 4 deletions dts/bindings/sensor/st,lis2dw12-common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,13 @@ properties:

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.

hp-filter-path:
type: boolean
required: false
description: |
Sets the Filtered Data Selection bit in the CTRL6 register.
When enabled, the high-pass filter path is selected.
Expand All @@ -177,7 +175,6 @@ properties:

hp-ref-mode:
type: boolean
required: false
description: |
Enables the high-pass filter reference mode in the CTRL7 register.
When the high-pass filter is configured in reference mode,
Expand All @@ -190,7 +187,6 @@ properties:

drdy-pulsed:
type: boolean
required: false
description: |
Selects the pulsed mode for data-ready interrupt when enabled,
and the latched mode when disabled.
Expand Down
3 changes: 0 additions & 3 deletions dts/bindings/sensor/st,lis2mdl-common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,17 @@ properties:

single-mode:
type: boolean
required: false
description: |
Set to config the sensor in single measurement mode. Leave
unset to configure the sensor in continious measurement mode.

cancel-offset:
type: boolean
required: false
description: |
Set to enable the offset cancellation. Otherwise it would be
disabled as default.

spi-full-duplex:
type: boolean
required: false
description: |
Enable SPI 4wires mode with separated MISO and MOSI lines