diff --git a/drivers/sensor/mc3419/Kconfig b/drivers/sensor/mc3419/Kconfig index 81e0665c3e0..5332e8c61ec 100644 --- a/drivers/sensor/mc3419/Kconfig +++ b/drivers/sensor/mc3419/Kconfig @@ -35,14 +35,4 @@ config MC3419_THREAD_STACK_SIZE endif # MC3419_TRIGGER -config MC3419_DECIMATION_RATE - int "Enable decimation rate" - range 0 15 - default 15 - help - This helps in producing slower interrupt. Internal Data - Rate is divide by this decimation rate. If decimation rate - is 0 then internal data rate is equal to output data rate, - then it produce interrupt floods. - endif # MC3419 diff --git a/drivers/sensor/mc3419/mc3419.c b/drivers/sensor/mc3419/mc3419.c index 0282bff02b4..a5a0fcae4d2 100644 --- a/drivers/sensor/mc3419/mc3419.c +++ b/drivers/sensor/mc3419/mc3419.c @@ -143,8 +143,7 @@ static int mc3419_set_odr(const struct device *dev, } LOG_DBG("Set ODR Rate to 0x%x", data_rate); - ret = i2c_reg_write_byte_dt(&cfg->i2c, MC3419_REG_SAMPLE_RATE_2, - CONFIG_MC3419_DECIMATION_RATE); + ret = i2c_reg_write_byte_dt(&cfg->i2c, MC3419_REG_SAMPLE_RATE_2, cfg->decimation_rate); if (ret < 0) { LOG_ERR("Failed to set decimation rate (%d)", ret); return ret; @@ -304,9 +303,11 @@ static const struct sensor_driver_api mc3419_api = { #endif #define MC3419_DEFINE(idx) \ + \ static const struct mc3419_config mc3419_config_##idx = { \ .i2c = I2C_DT_SPEC_INST_GET(idx), \ .lpf_fc_sel = DT_INST_PROP(idx, lpf_fc_sel), \ + .decimation_rate = DT_INST_PROP(idx, decimation_rate), \ MC3419_CFG_IRQ(idx)}; \ static struct mc3419_driver_data mc3419_data_##idx; \ SENSOR_DEVICE_DT_INST_DEFINE(idx, mc3419_init, NULL, &mc3419_data_##idx, \ diff --git a/drivers/sensor/mc3419/mc3419.h b/drivers/sensor/mc3419/mc3419.h index c4417222bf7..e7165c8c739 100644 --- a/drivers/sensor/mc3419/mc3419.h +++ b/drivers/sensor/mc3419/mc3419.h @@ -73,6 +73,7 @@ struct mc3419_config { bool int_cfg; #endif uint8_t lpf_fc_sel; + uint8_t decimation_rate; }; struct mc3419_driver_data { diff --git a/dts/bindings/sensor/memsic,mc3419.yaml b/dts/bindings/sensor/memsic,mc3419.yaml index 55753234a8a..d6c2fe5c7cf 100644 --- a/dts/bindings/sensor/memsic,mc3419.yaml +++ b/dts/bindings/sensor/memsic,mc3419.yaml @@ -11,6 +11,7 @@ description: | ... lpf-fc-sel = ; + decimation-rate = ; }; compatible: "memsic,mc3419" @@ -49,3 +50,32 @@ properties: | 13 | MC3419_LPF_EN_WITH_IDR_BY_16_FC | +-----------+-------------------------------------+ Default is LPF disabled (reset value of the register). + + decimation-rate: + type: int + default: 0 + enum: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] + description: | + This helps in producing slower Output Data Rate (ODR) from given Input Data Rate (IDR). + Possible values are listed below. Either use Int value or Macro Name in node definition. + +-----------+-------------------------------+ + | Int value | Macro Name | + +-----------+-------------------------------+ + | 0 | MC3419_DECIMATE_IDR_BY_1 | + | 1 | MC3419_DECIMATE_IDR_BY_2 | + | 2 | MC3419_DECIMATE_IDR_BY_4 | + | 3 | MC3419_DECIMATE_IDR_BY_5 | + | 4 | MC3419_DECIMATE_IDR_BY_8 | + | 5 | MC3419_DECIMATE_IDR_BY_10 | + | 6 | MC3419_DECIMATE_IDR_BY_16 | + | 7 | MC3419_DECIMATE_IDR_BY_20 | + | 8 | MC3419_DECIMATE_IDR_BY_40 | + | 9 | MC3419_DECIMATE_IDR_BY_67 | + | 10 | MC3419_DECIMATE_IDR_BY_80 | + | 11 | MC3419_DECIMATE_IDR_BY_100 | + | 12 | MC3419_DECIMATE_IDR_BY_200 | + | 13 | MC3419_DECIMATE_IDR_BY_250 | + | 14 | MC3419_DECIMATE_IDR_BY_500 | + | 15 | MC3419_DECIMATE_IDR_BY_1000 | + +-----------+-------------------------------+ + Default is Decimation 0 (reset value of the register). diff --git a/include/zephyr/dt-bindings/sensor/mc3419.h b/include/zephyr/dt-bindings/sensor/mc3419.h index 3d58944da00..9219f5c9646 100644 --- a/include/zephyr/dt-bindings/sensor/mc3419.h +++ b/include/zephyr/dt-bindings/sensor/mc3419.h @@ -7,7 +7,7 @@ #define ZEPHYR_INCLUDE_DT_BINDINGS_MEMSIC_MC3419_H_ /** - * @defgroup MC3419 memsic DT Options + * @defgroup MC3419 Memsic DT Options * @ingroup sensor_interface * @{ */ @@ -23,6 +23,28 @@ #define MC3419_LPF_EN_WITH_IDR_BY_16_FC 13 /** @} */ +/** + * @defgroup MC3419_DECIMATION_RATES decimate sampling rate by provided rate + * @{ + */ +#define MC3419_DECIMATE_IDR_BY_1 0 +#define MC3419_DECIMATE_IDR_BY_2 1 +#define MC3419_DECIMATE_IDR_BY_4 2 +#define MC3419_DECIMATE_IDR_BY_5 3 +#define MC3419_DECIMATE_IDR_BY_8 4 +#define MC3419_DECIMATE_IDR_BY_10 5 +#define MC3419_DECIMATE_IDR_BY_16 6 +#define MC3419_DECIMATE_IDR_BY_20 7 +#define MC3419_DECIMATE_IDR_BY_40 8 +#define MC3419_DECIMATE_IDR_BY_67 9 +#define MC3419_DECIMATE_IDR_BY_80 10 +#define MC3419_DECIMATE_IDR_BY_100 11 +#define MC3419_DECIMATE_IDR_BY_200 12 +#define MC3419_DECIMATE_IDR_BY_250 13 +#define MC3419_DECIMATE_IDR_BY_500 14 +#define MC3419_DECIMATE_IDR_BY_1000 15 +/** @} */ + /** @} */ #endif /*ZEPHYR_INCLUDE_DT_BINDINGS_MEMSIC_MC3419_H_ */