drivers/sensor: iis2iclx: Move range Kconfig property into dts

Converts iis2iclx range options (500mg, 1g, 2g, 3g) from Kconfigs
to Device Tree.

Signed-off-by: Armando Visconti <armando.visconti@st.com>
This commit is contained in:
Armando Visconti 2021-02-05 14:58:17 +01:00 committed by Anas Nashif
commit 5ebada58a7
4 changed files with 20 additions and 40 deletions

View file

@ -88,19 +88,6 @@ 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

View file

@ -52,7 +52,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};
@ -68,7 +67,6 @@ static int iis2iclx_accel_range_to_fs_val(int32_t range)
return -EINVAL;
}
#endif
static inline int iis2iclx_reboot(const struct device *dev)
{
@ -129,7 +127,6 @@ static int iis2iclx_accel_odr_set(const struct device *dev, uint16_t freq)
}
#endif
#ifdef IIS2ICLX_ACCEL_FS_RUNTIME
static int iis2iclx_accel_range_set(const struct device *dev, int32_t range)
{
int fs;
@ -148,7 +145,6 @@ 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,
@ -156,10 +152,8 @@ static int iis2iclx_accel_config(const struct device *dev,
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);
@ -544,8 +538,10 @@ 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 fs = cfg->range;
iis2iclx->dev = dev;
@ -568,12 +564,12 @@ 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) {
@ -709,6 +705,7 @@ 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) }, \
.range = DT_INST_PROP(inst, range), \
COND_CODE_1(DT_INST_NODE_HAS_PROP(inst, drdy_gpios), \
(IIS2ICLX_CFG_IRQ(inst)), ()) \
}
@ -729,6 +726,7 @@ 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), }, \
.range = DT_INST_PROP(inst, range), \
COND_CODE_1(DT_INST_NODE_HAS_PROP(inst, drdy_gpios), \
(IIS2ICLX_CFG_IRQ(inst)), ()) \
}

View file

@ -35,24 +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
@ -78,6 +60,7 @@ struct iis2iclx_config {
char *bus_name;
int (*bus_init)(const struct device *dev);
const union iis2iclx_bus_cfg bus_cfg;
uint8_t range;
#ifdef CONFIG_IIS2ICLX_TRIGGER
const char *irq_dev_name;
uint8_t irq_pin;

View file

@ -20,3 +20,15 @@ properties:
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.
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)