Skip to content

Commit

Permalink
drivers: sensors: lis2dh: added full high-pass filter capabilities
Browse files Browse the repository at this point in the history
The lis2dh driver has the ability to enable the hp filter.
However it was only possible to set the first 2 bits of the hp register.
These bits indicate wether the hp filter is enabled for the interrupts.
This commit moves lis2dh_acc_hp_filter_set to lis2dh.
 It also removes the mask so that all bits are able to be set.

Signed-off-by: Maarten Nieuwenhuize <maarten.nieuwenhuize@picoo.nl>
  • Loading branch information
Maartenwn authored and kartben committed Jan 16, 2025
1 parent e7e6cb9 commit 86a7e29
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 23 deletions.
15 changes: 15 additions & 0 deletions drivers/sensor/st/lis2dh/lis2dh.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,21 @@ static int lis2dh_acc_range_set(const struct device *dev, int32_t range)
}
#endif

#ifdef CONFIG_LIS2DH_ACCEL_HP_FILTERS
static int lis2dh_acc_hp_filter_set(const struct device *dev, int32_t val)
{
struct lis2dh_data *lis2dh = dev->data;
int status;

status = lis2dh->hw_tf->write_reg(dev, LIS2DH_REG_CTRL2, val);
if (status < 0) {
LOG_ERR("Failed to set high pass filters");
}

return status;
}
#endif

static int lis2dh_acc_config(const struct device *dev,
enum sensor_channel chan,
enum sensor_attribute attr,
Expand Down
12 changes: 5 additions & 7 deletions drivers/sensor/st/lis2dh/lis2dh.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,12 @@
#define LIS2DH_REG_CTRL2 0x21
#define LIS2DH_HPIS1_EN_BIT BIT(0)
#define LIS2DH_HPIS2_EN_BIT BIT(1)
#define LIS2DH_HPCLICK_EN_BIT BIT(2)
#define LIS2DH_FDS_EN_BIT BIT(3)

#define LIS2DH_HPIS_EN_MASK BIT_MASK(2)
#define LIS2DH_HPCF0_EN_BIT BIT(4)
#define LIS2DH_HPCF1_EN_BIT BIT(5)
#define LIS2DH_HPM0_EN_BIT BIT(6)
#define LIS2DH_HPM1_EN_BIT BIT(7)

#define LIS2DH_REG_CTRL3 0x22
#define LIS2DH_EN_CLICK_INT1 BIT(7)
Expand Down Expand Up @@ -305,11 +308,6 @@ int lis2dh_acc_slope_config(const struct device *dev,
const struct sensor_value *val);
#endif

#ifdef CONFIG_LIS2DH_ACCEL_HP_FILTERS
int lis2dh_acc_hp_filter_set(const struct device *dev,
int32_t val);
#endif

int lis2dh_spi_init(const struct device *dev);
int lis2dh_i2c_init(const struct device *dev);

Expand Down
16 changes: 0 additions & 16 deletions drivers/sensor/st/lis2dh/lis2dh_trigger.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,22 +361,6 @@ int lis2dh_acc_slope_config(const struct device *dev,
return status;
}

#ifdef CONFIG_LIS2DH_ACCEL_HP_FILTERS
int lis2dh_acc_hp_filter_set(const struct device *dev, int32_t val)
{
struct lis2dh_data *lis2dh = dev->data;
int status;

status = lis2dh->hw_tf->update_reg(dev, LIS2DH_REG_CTRL2,
LIS2DH_HPIS_EN_MASK, val);
if (status < 0) {
LOG_ERR("Failed to set high pass filters");
}

return status;
}
#endif

static void lis2dh_gpio_int1_callback(const struct device *dev,
struct gpio_callback *cb, uint32_t pins)
{
Expand Down

0 comments on commit 86a7e29

Please sign in to comment.