Drivers: Sensor: mc3419: Moved Decimation Rate config to DT

- Similar to LPF settings decimation rate could be applied to
per instance basis, thus moved to DT prop

Signed-off-by: Anuj Pathak <anuj@croxel.com>
This commit is contained in:
Anuj Pathak 2024-08-07 19:50:58 +05:30 committed by Carles Cufí
parent 932e207741
commit 1f05d03489
5 changed files with 57 additions and 13 deletions

View file

@ -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

View file

@ -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, \

View file

@ -73,6 +73,7 @@ struct mc3419_config {
bool int_cfg;
#endif
uint8_t lpf_fc_sel;
uint8_t decimation_rate;
};
struct mc3419_driver_data {

View file

@ -11,6 +11,7 @@ description: |
...
lpf-fc-sel = <MC3419_LPF_DISABLE>;
decimation-rate = <MC3419_DECIMATE_IDR_BY_1>;
};
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).

View file

@ -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_ */