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

Converts lis2ds12 range options (2g, 4g, 8g, 16g) from Kconfig
to Device Tree.

Signed-off-by: Armando Visconti <armando.visconti@st.com>
This commit is contained in:
Armando Visconti 2021-09-01 15:53:46 +02:00 committed by Maureen Helm
commit e0f06e23ef
4 changed files with 19 additions and 15 deletions

View file

@ -57,19 +57,6 @@ config LIS2DS12_ENABLE_TEMP
menu "Attributes" menu "Attributes"
config LIS2DS12_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
2: +/- 2g
4: +/- 4g
8: +/- 8g
16: +/- 16g
config LIS2DS12_ODR config LIS2DS12_ODR
int "Accelerometer Output data rate frequency" int "Accelerometer Output data rate frequency"
range 0 10 range 0 10

View file

@ -258,9 +258,10 @@ static int lis2ds12_init(const struct device *dev)
} }
/* set sensor default scale */ /* set sensor default scale */
ret = lis2ds12_set_range(dev, CONFIG_LIS2DS12_FS); LOG_DBG("%s: range is %d", dev->name, cfg->range);
ret = lis2ds12_set_range(dev, cfg->range);
if (ret < 0) { if (ret < 0) {
LOG_ERR("%s: range init error %d", dev->name, CONFIG_LIS2DS12_FS); LOG_ERR("%s: range init error %d", dev->name, cfg->range);
return ret; return ret;
} }
@ -317,6 +318,7 @@ static int lis2ds12_init(const struct device *dev)
LIS2DS12_SPI_OPERATION, \ LIS2DS12_SPI_OPERATION, \
0), \ 0), \
}, \ }, \
.range = DT_INST_PROP(inst, range), \
COND_CODE_1(DT_INST_NODE_HAS_PROP(inst, irq_gpios), \ COND_CODE_1(DT_INST_NODE_HAS_PROP(inst, irq_gpios), \
(LIS2DS12_CFG_IRQ(inst)), ()) \ (LIS2DS12_CFG_IRQ(inst)), ()) \
} }
@ -338,6 +340,7 @@ static int lis2ds12_init(const struct device *dev)
.stmemsc_cfg = { \ .stmemsc_cfg = { \
.i2c = I2C_DT_SPEC_INST_GET(inst), \ .i2c = I2C_DT_SPEC_INST_GET(inst), \
}, \ }, \
.range = DT_INST_PROP(inst, range), \
COND_CODE_1(DT_INST_NODE_HAS_PROP(inst, irq_gpios), \ COND_CODE_1(DT_INST_NODE_HAS_PROP(inst, irq_gpios), \
(LIS2DS12_CFG_IRQ(inst)), ()) \ (LIS2DS12_CFG_IRQ(inst)), ()) \
} }

View file

@ -40,6 +40,7 @@ struct lis2ds12_config {
const struct spi_dt_spec spi; const struct spi_dt_spec spi;
#endif #endif
} stmemsc_cfg; } stmemsc_cfg;
uint8_t range;
#ifdef CONFIG_LIS2DS12_TRIGGER #ifdef CONFIG_LIS2DS12_TRIGGER
struct gpio_dt_spec gpio_int; struct gpio_dt_spec gpio_int;
#endif #endif

View file

@ -11,3 +11,16 @@ properties:
This pin defaults to active high when produced by the sensor. This pin defaults to active high when produced by the sensor.
The property value should ensure the flags properly describe The property value should ensure the flags properly describe
the signal that is presented to the driver. the signal that is presented to the driver.
range:
type: int
required: false
default: 2
description: |
Range in g. Default is power-up configuration.
enum:
- 16 # 16g (0.488 mg/LSB)
- 8 # 8g (0.244 mg/LSB)
- 4 # 4g (0.122 mg/LSB)
- 2 # 2g (0.061 mg/LSB)