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
35 changes: 0 additions & 35 deletions drivers/sensor/iis2iclx/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -86,39 +86,4 @@ config IIS2ICLX_EXT_LPS22HB

endif # IIS2ICLX_SENSORHUB

menu "Attributes"

config IIS2ICLX_ACCEL_FS
int "Accelerometer full-scale range"
default 0
help
Specify the default accelerometer full-scale range.
An X value for the config represents a range of +/- X G. Valid values
are:
0: Full Scale selected at runtime
500: +/- 500mg
1000: +/- 1g
2000: +/- 2g
3000: +/- 3g

config IIS2ICLX_ACCEL_ODR
int "Accelerometer Output data rate frequency"
range 0 10
default 0
help
Specify the default accelerometer output data rate expressed in
samples per second (Hz).
0: ODR selected at runtime
1: 12.5Hz
2: 26Hz
3: 52Hz
4: 104Hz
5: 208Hz
6: 416Hz
7: 833Hz
8: 1660Hz
9: 3330Hz
10: 6660Hz
endmenu

endif # IIS2ICLX
29 changes: 12 additions & 17 deletions drivers/sensor/iis2iclx/iis2iclx.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ LOG_MODULE_REGISTER(IIS2ICLX, CONFIG_SENSOR_LOG_LEVEL);
static const uint16_t iis2iclx_odr_map[] = {0, 12, 26, 52, 104, 208, 416, 833,
1660, 3330, 6660};

#if defined(IIS2ICLX_ACCEL_ODR_RUNTIME)
static int iis2iclx_freq_to_odr_val(uint16_t freq)
{
size_t i;
Expand All @@ -39,7 +38,6 @@ static int iis2iclx_freq_to_odr_val(uint16_t freq)

return -EINVAL;
}
#endif

static int iis2iclx_odr_to_freq_val(uint16_t odr)
{
Expand All @@ -52,7 +50,6 @@ static int iis2iclx_odr_to_freq_val(uint16_t odr)
return iis2iclx_odr_map[ARRAY_SIZE(iis2iclx_odr_map) - 1];
}

#ifdef IIS2ICLX_ACCEL_FS_RUNTIME
static const uint16_t iis2iclx_accel_fs_map[] = {500, 3000, 1000, 2000};
static const uint16_t iis2iclx_accel_fs_sens[] = {1, 8, 2, 4};

Expand All @@ -68,7 +65,6 @@ static int iis2iclx_accel_range_to_fs_val(int32_t range)

return -EINVAL;
}
#endif

static inline int iis2iclx_reboot(const struct device *dev)
{
Expand Down Expand Up @@ -110,7 +106,6 @@ static int iis2iclx_accel_set_odr_raw(const struct device *dev, uint8_t odr)
return 0;
}

#ifdef IIS2ICLX_ACCEL_ODR_RUNTIME
static int iis2iclx_accel_odr_set(const struct device *dev, uint16_t freq)
{
int odr;
Expand All @@ -127,9 +122,7 @@ static int iis2iclx_accel_odr_set(const struct device *dev, uint16_t freq)

return 0;
}
#endif

#ifdef IIS2ICLX_ACCEL_FS_RUNTIME
static int iis2iclx_accel_range_set(const struct device *dev, int32_t range)
{
int fs;
Expand All @@ -148,22 +141,17 @@ static int iis2iclx_accel_range_set(const struct device *dev, int32_t range)
data->acc_gain = (iis2iclx_accel_fs_sens[fs] * GAIN_UNIT_XL);
return 0;
}
#endif

static int iis2iclx_accel_config(const struct device *dev,
enum sensor_channel chan,
enum sensor_attribute attr,
const struct sensor_value *val)
{
switch (attr) {
#ifdef IIS2ICLX_ACCEL_FS_RUNTIME
case SENSOR_ATTR_FULL_SCALE:
return iis2iclx_accel_range_set(dev, sensor_ms2_to_g(val));
#endif
#ifdef IIS2ICLX_ACCEL_ODR_RUNTIME
case SENSOR_ATTR_SAMPLING_FREQUENCY:
return iis2iclx_accel_odr_set(dev, val->val1);
#endif
default:
LOG_ERR("Accel attribute not supported.");
return -ENOTSUP;
Expand Down Expand Up @@ -544,8 +532,11 @@ static const struct sensor_driver_api iis2iclx_driver_api = {

static int iis2iclx_init_chip(const struct device *dev)
{
const struct iis2iclx_config * const cfg = dev->config;
struct iis2iclx_data *iis2iclx = dev->data;
uint8_t chip_id;
uint8_t odr = cfg->odr;
uint8_t fs = cfg->range;

iis2iclx->dev = dev;

Expand All @@ -568,15 +559,15 @@ static int iis2iclx_init_chip(const struct device *dev)

k_usleep(100);

if (iis2iclx_accel_set_fs_raw(dev,
IIS2ICLX_DEFAULT_ACCEL_FULLSCALE) < 0) {
LOG_DBG("range is %d", fs);
if (iis2iclx_accel_set_fs_raw(dev, fs) < 0) {
LOG_ERR("failed to set accelerometer full-scale");
return -EIO;
}
iis2iclx->acc_gain = IIS2ICLX_DEFAULT_ACCEL_SENSITIVITY;
iis2iclx->acc_gain = (iis2iclx_accel_fs_sens[fs] * GAIN_UNIT_XL);

iis2iclx->accel_freq = iis2iclx_odr_to_freq_val(CONFIG_IIS2ICLX_ACCEL_ODR);
if (iis2iclx_accel_set_odr_raw(dev, CONFIG_IIS2ICLX_ACCEL_ODR) < 0) {
LOG_DBG("odr is %d", odr);
if (iis2iclx_accel_set_odr_raw(dev, odr) < 0) {
LOG_ERR("failed to set accelerometer sampling rate");
return -EIO;
}
Expand Down Expand Up @@ -709,6 +700,8 @@ static int iis2iclx_init(const struct device *dev)
.bus_name = DT_INST_BUS_LABEL(inst), \
.bus_init = iis2iclx_spi_init, \
.bus_cfg = { .spi_cfg = IIS2ICLX_SPI_CFG(inst) }, \
.odr = DT_INST_PROP(inst, odr), \
.range = DT_INST_PROP(inst, range), \
COND_CODE_1(DT_INST_NODE_HAS_PROP(inst, drdy_gpios), \
(IIS2ICLX_CFG_IRQ(inst)), ()) \
}
Expand All @@ -729,6 +722,8 @@ static int iis2iclx_init(const struct device *dev)
.bus_name = DT_INST_BUS_LABEL(inst), \
.bus_init = iis2iclx_i2c_init, \
.bus_cfg = { .i2c_slv_addr = DT_INST_REG_ADDR(inst), }, \
.odr = DT_INST_PROP(inst, odr), \
.range = DT_INST_PROP(inst, range), \
COND_CODE_1(DT_INST_NODE_HAS_PROP(inst, drdy_gpios), \
(IIS2ICLX_CFG_IRQ(inst)), ()) \
}
Expand Down
24 changes: 2 additions & 22 deletions drivers/sensor/iis2iclx/iis2iclx.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,6 @@
#define SENSOR_DEG2RAD_DOUBLE (SENSOR_PI_DOUBLE / 180)
#define SENSOR_G_DOUBLE (SENSOR_G / 1000000.0)

#if CONFIG_IIS2ICLX_ACCEL_FS == 0
#define IIS2ICLX_ACCEL_FS_RUNTIME 1
#define IIS2ICLX_DEFAULT_ACCEL_FULLSCALE 0
#define IIS2ICLX_DEFAULT_ACCEL_SENSITIVITY GAIN_UNIT_XL
#elif CONFIG_IIS2ICLX_ACCEL_FS == 500
#define IIS2ICLX_DEFAULT_ACCEL_FULLSCALE 0
#define IIS2ICLX_DEFAULT_ACCEL_SENSITIVITY GAIN_UNIT_XL
#elif CONFIG_IIS2ICLX_ACCEL_FS == 1000
#define IIS2ICLX_DEFAULT_ACCEL_FULLSCALE 2
#define IIS2ICLX_DEFAULT_ACCEL_SENSITIVITY (2.0 * GAIN_UNIT_XL)
#elif CONFIG_IIS2ICLX_ACCEL_FS == 2000
#define IIS2ICLX_DEFAULT_ACCEL_FULLSCALE 3
#define IIS2ICLX_DEFAULT_ACCEL_SENSITIVITY (4.0 * GAIN_UNIT_XL)
#elif CONFIG_IIS2ICLX_ACCEL_FS == 3000
#define IIS2ICLX_DEFAULT_ACCEL_FULLSCALE 1
#define IIS2ICLX_DEFAULT_ACCEL_SENSITIVITY (8.0 * GAIN_UNIT_XL)
#endif

#if (CONFIG_IIS2ICLX_ACCEL_ODR == 0)
#define IIS2ICLX_ACCEL_ODR_RUNTIME 1
#endif

#if DT_ANY_INST_ON_BUS_STATUS_OKAY(spi)
struct iis2iclx_spi_cfg {
struct spi_config spi_conf;
Expand All @@ -78,6 +56,8 @@ struct iis2iclx_config {
char *bus_name;
int (*bus_init)(const struct device *dev);
const union iis2iclx_bus_cfg bus_cfg;
uint8_t odr;
uint8_t range;
#ifdef CONFIG_IIS2ICLX_TRIGGER
const char *irq_dev_name;
uint8_t irq_pin;
Expand Down
57 changes: 57 additions & 0 deletions dts/bindings/sensor/st,iis2iclx-common.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Copyright (c) 2020 STMicroelectronics
# SPDX-License-Identifier: Apache-2.0

properties:
drdy-gpios:
type: phandle-array
required: false
description: DRDY pin

This pin defaults to active high when produced by the sensor.
The property value should ensure the flags properly describe
the signal that is presented to the driver.

int-pin:
type: int
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's out of the PR's intended scope, and the same problem occurs elsewhere so won't block on this, but:

In another PR please review all uses of similar properties in ST devicetree bindings and make this and the others you'll find an enum too, like st,iis2dlpc's drdy-int property.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pabigot
Yes, that's a good point. I'll do it in a separate PR.
Thanks

required: false
default: 1
enum:
- 1 # drdy is generated from INT1
- 2 # drdy is generated from INT2
description: Select DRDY pin number (1 or 2).

This number represents which of the two interrupt pins
(INT1 or INT2) the drdy line is attached to. This property is not
mandatory and if not present it defaults to 1 which is the
configuration at power-up.

range:
type: int
required: false
default: 3
description: Range in g. Default is power-up configuration.
enum:
- 0 # 500mg (0.015 mg/LSB)
- 1 # 3g (0.122 mg/LSB)
- 2 # 1g (0.031 mg/LSB)
- 3 # 2g (0.061 mg/LSB)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

git commit normally complains about empty last lines, not sure why it didn't here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it's corrected in the next commit.

odr:
type: int
required: false
default: 0
description:
Specify the default accelerometer output data rate expressed in samples per second (Hz).
Default is power-up configuration.
enum:
- 0 # Power-Down
- 1 # 12.5Hz
- 2 # 26Hz
- 3 # 52Hz
- 4 # 104Hz
- 5 # 208Hz
- 6 # 416Hz
- 7 # 833Hz
- 8 # 1660Hz
- 9 # 3330Hz
- 10 # 6660Hz
22 changes: 1 addition & 21 deletions dts/bindings/sensor/st,iis2iclx-i2c.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,4 @@ description: |

compatible: "st,iis2iclx"

include: i2c-device.yaml

properties:
drdy-gpios:
type: phandle-array
required: false
description: DRDY pin

This pin defaults to active high when produced by the sensor.
The property value should ensure the flags properly describe
the signal that is presented to the driver.

int-pin:
type: int
required: false
default: 1
description: Device INT pin number (1 or 2)

This number represents which of the two interrupt pins
(INT1 or INT2) the line is attached to. This property is not
mandatory and if not present it defaults to 1.
include: ["i2c-device.yaml", "st,iis2iclx-common.yaml"]
22 changes: 1 addition & 21 deletions dts/bindings/sensor/st,iis2iclx-spi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,4 @@ description: |

compatible: "st,iis2iclx"

include: spi-device.yaml

properties:
drdy-gpios:
type: phandle-array
required: false
description: DRDY pin

This pin defaults to active high when produced by the sensor.
The property value should ensure the flags properly describe
the signal that is presented to the driver.

int-pin:
type: int
required: false
default: 1
description: Device INT pin number (1 or 2)

This number represents which of the two interrupt pins
(INT1 or INT2) the line is attached to. This property is not
mandatory and if not present it defaults to 1.
include: ["spi-device.yaml", "st,iis2iclx-common.yaml"]