From e97424e23d4b73e47b90ed2a8c428966b0c60888 Mon Sep 17 00:00:00 2001 From: Armando Visconti Date: Wed, 24 Feb 2021 15:17:37 +0100 Subject: [PATCH] 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 --- drivers/sensor/ism330dhcx/Kconfig | 41 ------------ drivers/sensor/ism330dhcx/ism330dhcx.c | 21 ++---- drivers/sensor/ism330dhcx/ism330dhcx.h | 10 +-- dts/bindings/sensor/st,ism330dhcx-common.yaml | 66 +++++++++++++++++++ 4 files changed, 75 insertions(+), 63 deletions(-) diff --git a/drivers/sensor/ism330dhcx/Kconfig b/drivers/sensor/ism330dhcx/Kconfig index 25480e59c8c..5fe9b80a503 100644 --- a/drivers/sensor/ism330dhcx/Kconfig +++ b/drivers/sensor/ism330dhcx/Kconfig @@ -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 diff --git a/drivers/sensor/ism330dhcx/ism330dhcx.c b/drivers/sensor/ism330dhcx/ism330dhcx.c index 85dba6fce8c..cb125dbcb89 100644 --- a/drivers/sensor/ism330dhcx/ism330dhcx.c +++ b/drivers/sensor/ism330dhcx/ism330dhcx.c @@ -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, diff --git a/drivers/sensor/ism330dhcx/ism330dhcx.h b/drivers/sensor/ism330dhcx/ism330dhcx.h index c21a59ca339..3d4e9ccc7f6 100644 --- a/drivers/sensor/ism330dhcx/ism330dhcx.h +++ b/drivers/sensor/ism330dhcx/ism330dhcx.h @@ -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 diff --git a/dts/bindings/sensor/st,ism330dhcx-common.yaml b/dts/bindings/sensor/st,ism330dhcx-common.yaml index 9add7e247f2..4fe71ab08bb 100644 --- a/dts/bindings/sensor/st,ism330dhcx-common.yaml +++ b/dts/bindings/sensor/st,ism330dhcx-common.yaml @@ -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