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
12 changes: 10 additions & 2 deletions drivers/sensor/lis2dh/lis2dh.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ int lis2dh_spi_access(struct lis2dh_data *ctx, u8_t cmd,
}
#endif

#if defined(CONFIG_LIS2DH_TRIGGER) || defined(CONFIG_LIS2DH_ACCEL_RANGE_RUNTIME)
int lis2dh_reg_field_update(struct device *dev, u8_t reg_addr,
u8_t pos, u8_t mask, u8_t val)
{
Expand All @@ -63,7 +62,6 @@ int lis2dh_reg_field_update(struct device *dev, u8_t reg_addr,
return lis2dh_reg_write_byte(dev, reg_addr,
(old_val & ~mask) | ((val << pos) & mask));
}
#endif

static void lis2dh_convert(s16_t raw_val, u16_t scale,
struct sensor_value *val)
Expand Down Expand Up @@ -322,6 +320,16 @@ int lis2dh_init(struct device *dev)
return status;
}

if (IS_ENABLED(DT_INST_0_ST_LIS2DH_DISCONNECT_SDO_SA0_PULL_UP)) {
status = lis2dh_reg_field_update(dev, LIS2DH_REG_CTRL0,
LIS2DH_SDO_PU_DISC_SHIFT,
LIS2DH_SDO_PU_DISC_MASK, 1);
if (status < 0) {
LOG_ERR("Failed to disconnect SDO/SA0 pull-up.");
return status;
}
}

/* Initialize control register ctrl1 to ctrl 6 to default boot values
* to avoid warm start/reset issues as the accelerometer has no reset
* pin. Register values are retained if power is not removed.
Expand Down
10 changes: 7 additions & 3 deletions drivers/sensor/lis2dh/lis2dh.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@

#define LIS2DH_AUTOINCREMENT_ADDR BIT(7)

#define LIS2DH_REG_CTRL0 0x1e
#define LIS2DH_SDO_PU_DISC_SHIFT 7
#define LIS2DH_SDO_PU_DISC_MASK BIT(LIS2DH_SDO_PU_DISC_SHIFT)

#define LIS2DH_REG_CTRL1 0x20
#define LIS2DH_ACCEL_XYZ_SHIFT 0
#define LIS2DH_ACCEL_X_EN_BIT BIT(0)
Expand Down Expand Up @@ -330,16 +334,16 @@ static inline int lis2dh_reg_write_byte(struct device *dev, u8_t reg_addr,
#endif
}

int lis2dh_reg_field_update(struct device *dev, u8_t reg_addr,
u8_t pos, u8_t mask, u8_t val);

#ifdef CONFIG_LIS2DH_TRIGGER
int lis2dh_trigger_set(struct device *dev,
const struct sensor_trigger *trig,
sensor_trigger_handler_t handler);

int lis2dh_init_interrupt(struct device *dev);

int lis2dh_reg_field_update(struct device *dev, u8_t reg_addr,
u8_t pos, u8_t mask, u8_t val);

int lis2dh_acc_slope_config(struct device *dev, enum sensor_attribute attr,
const struct sensor_value *val);
#endif
Expand Down
15 changes: 15 additions & 0 deletions dts/bindings/sensor/st,lis2dh-common.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright (c) 2018 STMicroelectronics
# SPDX-License-Identifier: Apache-2.0

properties:
irq-gpios:
type: phandle-array
required: false

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
leakage). Note that only subset of devices supported by this
binding have SDO/SA0 pull-up (e.g. LIS2DH12, LIS3DH).
10 changes: 3 additions & 7 deletions dts/bindings/sensor/st,lis2dh-i2c.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
# Copyright (c) 2018 STMicroelectronics
# SPDX-License-Identifier: Apache-2.0

title: STMicroelectronics MEMS sensors LIS2DH
title: STMicroelectronics MEMS sensors LIS2DH I2C

description: >
This binding gives a base representation of LIS2DH 3-axis accelerometer
accessed through I2C bus

compatible: "st,lis2dh"

include: i2c-device.yaml

properties:
irq-gpios:
type: phandle-array
required: false
include: ["i2c-device.yaml", "st,lis2dh-common.yaml"]
7 changes: 1 addition & 6 deletions dts/bindings/sensor/st,lis2dh-spi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,4 @@ description: >

compatible: "st,lis2dh"

include: spi-device.yaml

properties:
irq-gpios:
type: phandle-array
required: false
include: ["spi-device.yaml", "st,lis2dh-common.yaml"]
2 changes: 1 addition & 1 deletion dts/bindings/sensor/st,lsm303dlhc-accel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ description: >

compatible: "st,lsm303dlhc-accel"

include: i2c-device.yaml
include: ["i2c-device.yaml", "st,lis2dh-common.yaml"]