drivers/sensor: ism330dhcx: Move accel/gyro odr Kconfig attr into DT

Convert ism330dhcx accel and gyro odr attributes from Kconfigs to Device
Tree binding properties.

Signed-off-by: Armando Visconti <armando.visconti@st.com>
This commit is contained in:
Armando Visconti 2021-02-24 15:17:37 +01:00 committed by Anas Nashif
commit e97424e23d
4 changed files with 75 additions and 63 deletions

View file

@ -100,45 +100,4 @@ config ISM330DHCX_EXT_LPS22HB
endif # ISM330DHCX_SENSORHUB
menu "Attributes"
config ISM330DHCX_GYRO_ODR
int "Gyroscope 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
config ISM330DHCX_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 # ISM330DHCX

View file

@ -26,7 +26,6 @@ LOG_MODULE_REGISTER(ISM330DHCX, CONFIG_SENSOR_LOG_LEVEL);
static const uint16_t ism330dhcx_odr_map[] = {0, 12, 26, 52, 104, 208, 416, 833,
1660, 3330, 6660};
#if defined(ISM330DHCX_ACCEL_ODR_RUNTIME) || defined(ISM330DHCX_GYRO_ODR_RUNTIME)
static int ism330dhcx_freq_to_odr_val(uint16_t freq)
{
size_t i;
@ -39,7 +38,6 @@ static int ism330dhcx_freq_to_odr_val(uint16_t freq)
return -EINVAL;
}
#endif
static int ism330dhcx_odr_to_freq_val(uint16_t odr)
{
@ -146,7 +144,6 @@ static int ism330dhcx_gyro_set_odr_raw(const struct device *dev, uint8_t odr)
return 0;
}
#ifdef ISM330DHCX_ACCEL_ODR_RUNTIME
static int ism330dhcx_accel_odr_set(const struct device *dev, uint16_t freq)
{
int odr;
@ -163,7 +160,6 @@ static int ism330dhcx_accel_odr_set(const struct device *dev, uint16_t freq)
return 0;
}
#endif
static int ism330dhcx_accel_range_set(const struct device *dev, int32_t range)
{
@ -192,10 +188,8 @@ static int ism330dhcx_accel_config(const struct device *dev,
switch (attr) {
case SENSOR_ATTR_FULL_SCALE:
return ism330dhcx_accel_range_set(dev, sensor_ms2_to_g(val));
#ifdef ISM330DHCX_ACCEL_ODR_RUNTIME
case SENSOR_ATTR_SAMPLING_FREQUENCY:
return ism330dhcx_accel_odr_set(dev, val->val1);
#endif
default:
LOG_DBG("Accel attribute not supported.");
return -ENOTSUP;
@ -204,7 +198,6 @@ static int ism330dhcx_accel_config(const struct device *dev,
return 0;
}
#ifdef ISM330DHCX_GYRO_ODR_RUNTIME
static int ism330dhcx_gyro_odr_set(const struct device *dev, uint16_t freq)
{
int odr;
@ -221,7 +214,6 @@ static int ism330dhcx_gyro_odr_set(const struct device *dev, uint16_t freq)
return 0;
}
#endif
static int ism330dhcx_gyro_range_set(const struct device *dev, int32_t range)
{
@ -250,10 +242,8 @@ static int ism330dhcx_gyro_config(const struct device *dev,
switch (attr) {
case SENSOR_ATTR_FULL_SCALE:
return ism330dhcx_gyro_range_set(dev, sensor_rad_to_degrees(val));
#ifdef ISM330DHCX_GYRO_ODR_RUNTIME
case SENSOR_ATTR_SAMPLING_FREQUENCY:
return ism330dhcx_gyro_odr_set(dev, val->val1);
#endif
default:
LOG_DBG("Gyro attribute not supported.");
return -ENOTSUP;
@ -709,8 +699,8 @@ static int ism330dhcx_init_chip(const struct device *dev)
return -EIO;
}
ism330dhcx->accel_freq = ism330dhcx_odr_to_freq_val(CONFIG_ISM330DHCX_ACCEL_ODR);
if (ism330dhcx_accel_set_odr_raw(dev, CONFIG_ISM330DHCX_ACCEL_ODR) < 0) {
LOG_DBG("accel odr is %d", cfg->accel_odr);
if (ism330dhcx_accel_set_odr_raw(dev, cfg->accel_odr) < 0) {
LOG_DBG("failed to set accelerometer sampling rate");
return -EIO;
}
@ -721,8 +711,9 @@ static int ism330dhcx_init_chip(const struct device *dev)
return -EIO;
}
ism330dhcx->gyro_freq = ism330dhcx_odr_to_freq_val(CONFIG_ISM330DHCX_GYRO_ODR);
if (ism330dhcx_gyro_set_odr_raw(dev, CONFIG_ISM330DHCX_GYRO_ODR) < 0) {
LOG_DBG("gyro odr is %d", cfg->gyro_odr);
ism330dhcx->gyro_freq = ism330dhcx_odr_to_freq_val(cfg->gyro_odr);
if (ism330dhcx_gyro_set_odr_raw(dev, cfg->gyro_odr) < 0) {
LOG_DBG("failed to set gyroscope sampling rate");
return -EIO;
}
@ -745,7 +736,9 @@ static struct ism330dhcx_data ism330dhcx_data;
static const struct ism330dhcx_config ism330dhcx_config = {
.bus_name = DT_INST_BUS_LABEL(0),
.accel_odr = DT_INST_PROP(0, accel_odr),
.accel_range = DT_INST_PROP(0, accel_range),
.gyro_odr = DT_INST_PROP(0, gyro_odr),
.gyro_range = DT_INST_PROP(0, gyro_range),
#if DT_ANY_INST_ON_BUS_STATUS_OKAY(spi)
.bus_init = ism330dhcx_spi_init,

View file

@ -41,17 +41,11 @@ union axis1bit16_t {
#define SENSOR_DEG2RAD_DOUBLE (SENSOR_PI_DOUBLE / 180)
#define SENSOR_G_DOUBLE (SENSOR_G / 1000000.0)
#if (CONFIG_ISM330DHCX_ACCEL_ODR == 0)
#define ISM330DHCX_ACCEL_ODR_RUNTIME 1
#endif
#if (CONFIG_ISM330DHCX_GYRO_ODR == 0)
#define ISM330DHCX_GYRO_ODR_RUNTIME 1
#endif
struct ism330dhcx_config {
char *bus_name;
int (*bus_init)(const struct device *dev);
uint8_t accel_odr;
uint16_t gyro_odr;
uint8_t accel_range;
uint16_t gyro_range;
#ifdef CONFIG_ISM330DHCX_TRIGGER

View file

@ -12,6 +12,39 @@ properties:
The property value should ensure the flags properly describe
the signal that is presented to the driver.
accel-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.
Selection
0 Power-Down
1 12.5Hz
2 26Hz
3 52Hz
4 104Hz
5 208Hz
6 416Hz
7 833Hz
8 1660Hz
9 3330Hz
10 6660Hz
enum:
- 0
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
accel-range:
type: int
required: false
@ -30,6 +63,39 @@ properties:
- 4
- 2
gyro-odr:
type: int
required: false
default: 0
description: |
Specify the default gyro output data rate expressed in samples per second (Hz).
Default is power-up configuration.
Selection
0 Power-Down
1 12.5Hz
2 26Hz
3 52Hz
4 104Hz
5 208Hz
6 416Hz
7 833Hz
8 1660Hz
9 3330Hz
10 6660Hz
enum:
- 0
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
gyro-range:
type: int
required: false