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

Move iis2iclx odr options from Kconfigs to Device Tree.

Signed-off-by: Armando Visconti <armando.visconti@st.com>
This commit is contained in:
Armando Visconti 2021-02-09 11:26:48 +01:00 committed by Anas Nashif
commit 69269c52e8
4 changed files with 25 additions and 34 deletions

View file

@ -86,26 +86,4 @@ config IIS2ICLX_EXT_LPS22HB
endif # IIS2ICLX_SENSORHUB
menu "Attributes"
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

View file

@ -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;
@ -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)
{
@ -108,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;
@ -125,7 +122,6 @@ static int iis2iclx_accel_odr_set(const struct device *dev, uint16_t freq)
return 0;
}
#endif
static int iis2iclx_accel_range_set(const struct device *dev, int32_t range)
{
@ -154,10 +150,8 @@ static int iis2iclx_accel_config(const struct device *dev,
switch (attr) {
case SENSOR_ATTR_FULL_SCALE:
return iis2iclx_accel_range_set(dev, sensor_ms2_to_g(val));
#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;
@ -541,6 +535,7 @@ 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;
@ -571,8 +566,8 @@ static int iis2iclx_init_chip(const struct device *dev)
}
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;
}
@ -705,6 +700,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) }, \
.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)), ()) \
@ -726,6 +722,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), }, \
.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)), ()) \

View file

@ -35,10 +35,6 @@
#define SENSOR_DEG2RAD_DOUBLE (SENSOR_PI_DOUBLE / 180)
#define SENSOR_G_DOUBLE (SENSOR_G / 1000000.0)
#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;
@ -60,6 +56,7 @@ 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;

View file

@ -32,3 +32,22 @@ properties:
- 2 # 1g (0.031 mg/LSB)
- 3 # 2g (0.061 mg/LSB)
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