Drivers: Sensor: mc3419: Added LPF CutOff select using dt
For applications that rely on low noise/variance in accelerometer sample reading. Application can take advantage of integrated LPF Thus this PR adds LPF configuration capability to the mc3419 driver Signed-off-by: Anuj Pathak <anuj@croxel.com>
This commit is contained in:
parent
4ab8073b87
commit
932e207741
4 changed files with 74 additions and 14 deletions
|
|
@ -271,6 +271,12 @@ static int mc3419_init(const struct device *dev)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
ret = i2c_reg_update_byte_dt(&cfg->i2c, MC3419_REG_RANGE_SELECT_CTRL, MC3419_LPF_MASK,
|
||||||
|
cfg->lpf_fc_sel);
|
||||||
|
if (ret < 0) {
|
||||||
|
LOG_ERR("Failed to configure LPF (%d)", ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
/* Leave the sensor in default power on state, will be
|
/* Leave the sensor in default power on state, will be
|
||||||
* enabled by configure attr or setting trigger.
|
* enabled by configure attr or setting trigger.
|
||||||
*/
|
*/
|
||||||
|
|
@ -297,18 +303,14 @@ static const struct sensor_driver_api mc3419_api = {
|
||||||
#define MC3419_CFG_IRQ(idx)
|
#define MC3419_CFG_IRQ(idx)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define MC3419_DEFINE(idx) \
|
#define MC3419_DEFINE(idx) \
|
||||||
static const struct mc3419_config mc3419_config_##idx = { \
|
static const struct mc3419_config mc3419_config_##idx = { \
|
||||||
.i2c = I2C_DT_SPEC_INST_GET(idx), \
|
.i2c = I2C_DT_SPEC_INST_GET(idx), \
|
||||||
MC3419_CFG_IRQ(idx) \
|
.lpf_fc_sel = DT_INST_PROP(idx, lpf_fc_sel), \
|
||||||
}; \
|
MC3419_CFG_IRQ(idx)}; \
|
||||||
static struct mc3419_driver_data mc3419_data_##idx; \
|
static struct mc3419_driver_data mc3419_data_##idx; \
|
||||||
SENSOR_DEVICE_DT_INST_DEFINE(idx, \
|
SENSOR_DEVICE_DT_INST_DEFINE(idx, mc3419_init, NULL, &mc3419_data_##idx, \
|
||||||
mc3419_init, NULL, \
|
&mc3419_config_##idx, POST_KERNEL, \
|
||||||
&mc3419_data_##idx, \
|
CONFIG_SENSOR_INIT_PRIORITY, &mc3419_api);
|
||||||
&mc3419_config_##idx, \
|
|
||||||
POST_KERNEL, \
|
|
||||||
CONFIG_SENSOR_INIT_PRIORITY, \
|
|
||||||
&mc3419_api);
|
|
||||||
|
|
||||||
DT_INST_FOREACH_STATUS_OKAY(MC3419_DEFINE)
|
DT_INST_FOREACH_STATUS_OKAY(MC3419_DEFINE)
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@
|
||||||
#define MC3419_REG_ANY_MOTION_THRES 0x43
|
#define MC3419_REG_ANY_MOTION_THRES 0x43
|
||||||
|
|
||||||
#define MC3419_RANGE_MASK GENMASK(6, 4)
|
#define MC3419_RANGE_MASK GENMASK(6, 4)
|
||||||
|
#define MC3419_LPF_MASK GENMASK(3, 0)
|
||||||
#define MC3419_DATA_READY_MASK BIT(7)
|
#define MC3419_DATA_READY_MASK BIT(7)
|
||||||
#define MC3419_ANY_MOTION_MASK BIT(2)
|
#define MC3419_ANY_MOTION_MASK BIT(2)
|
||||||
#define MC3419_INT_CLEAR 0x00
|
#define MC3419_INT_CLEAR 0x00
|
||||||
|
|
@ -71,6 +72,7 @@ struct mc3419_config {
|
||||||
struct gpio_dt_spec int_gpio;
|
struct gpio_dt_spec int_gpio;
|
||||||
bool int_cfg;
|
bool int_cfg;
|
||||||
#endif
|
#endif
|
||||||
|
uint8_t lpf_fc_sel;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mc3419_driver_data {
|
struct mc3419_driver_data {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,17 @@
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
# Copyright (c) 2023 Linumiz
|
# Copyright (c) 2023 Linumiz
|
||||||
|
|
||||||
description: MC3419 3-axis accel sensor
|
description: |
|
||||||
|
MC3419 3-axis accel sensor
|
||||||
|
|
||||||
|
Example:
|
||||||
|
#include <zephyr/dt-bindings/sensor/mc3419.h>
|
||||||
|
|
||||||
|
mc3419: mc3419@0 {
|
||||||
|
...
|
||||||
|
|
||||||
|
lpf-fc-sel = <MC3419_LPF_DISABLE>;
|
||||||
|
};
|
||||||
|
|
||||||
compatible: "memsic,mc3419"
|
compatible: "memsic,mc3419"
|
||||||
|
|
||||||
|
|
@ -21,3 +31,21 @@ properties:
|
||||||
has two interrupt pins.By default the interrupt are routed
|
has two interrupt pins.By default the interrupt are routed
|
||||||
to interrupt pin 1, by enabled this property interrupt are
|
to interrupt pin 1, by enabled this property interrupt are
|
||||||
routed to interrupt pin 2.
|
routed to interrupt pin 2.
|
||||||
|
|
||||||
|
lpf-fc-sel:
|
||||||
|
type: int
|
||||||
|
default: 0
|
||||||
|
enum: [0, 9, 10, 11, 13]
|
||||||
|
description: |
|
||||||
|
Enable and select LPF cutoff frequency for a given IDR (Input Data Rate).
|
||||||
|
Possible values are listed below. Either use Int value or Macro Name in node definition.
|
||||||
|
+-----------+-------------------------------------+
|
||||||
|
| int value | Macro Name |
|
||||||
|
+-----------+-------------------------------------+
|
||||||
|
| 0 | MC3419_LPF_DISABLE |
|
||||||
|
| 9 | MC3419_LPF_EN_WITH_IDR_BY_4p255_FC |
|
||||||
|
| 10 | MC3419_LPF_EN_WITH_IDR_BY_6_FC |
|
||||||
|
| 11 | MC3419_LPF_EN_WITH_IDR_BY_12_FC |
|
||||||
|
| 13 | MC3419_LPF_EN_WITH_IDR_BY_16_FC |
|
||||||
|
+-----------+-------------------------------------+
|
||||||
|
Default is LPF disabled (reset value of the register).
|
||||||
|
|
|
||||||
28
include/zephyr/dt-bindings/sensor/mc3419.h
Normal file
28
include/zephyr/dt-bindings/sensor/mc3419.h
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2024 Croxel Inc
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_MEMSIC_MC3419_H_
|
||||||
|
#define ZEPHYR_INCLUDE_DT_BINDINGS_MEMSIC_MC3419_H_
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @defgroup MC3419 memsic DT Options
|
||||||
|
* @ingroup sensor_interface
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @defgroup MC3419_LPF_CONFIGS Lowe pass filter configurations
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define MC3419_LPF_DISABLE 0
|
||||||
|
#define MC3419_LPF_EN_WITH_IDR_BY_4p255_FC 9
|
||||||
|
#define MC3419_LPF_EN_WITH_IDR_BY_6_FC 10
|
||||||
|
#define MC3419_LPF_EN_WITH_IDR_BY_12_FC 11
|
||||||
|
#define MC3419_LPF_EN_WITH_IDR_BY_16_FC 13
|
||||||
|
/** @} */
|
||||||
|
|
||||||
|
/** @} */
|
||||||
|
|
||||||
|
#endif /*ZEPHYR_INCLUDE_DT_BINDINGS_MEMSIC_MC3419_H_ */
|
||||||
Loading…
Reference in a new issue