Skip to content

Commit 86a7e29

Browse files
Maartenwnkartben
authored andcommitted
drivers: sensors: lis2dh: added full high-pass filter capabilities
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 <[email protected]>
1 parent e7e6cb9 commit 86a7e29

File tree

3 files changed

+20
-23
lines changed

3 files changed

+20
-23
lines changed

drivers/sensor/st/lis2dh/lis2dh.c

+15
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,21 @@ static int lis2dh_acc_range_set(const struct device *dev, int32_t range)
271271
}
272272
#endif
273273

274+
#ifdef CONFIG_LIS2DH_ACCEL_HP_FILTERS
275+
static int lis2dh_acc_hp_filter_set(const struct device *dev, int32_t val)
276+
{
277+
struct lis2dh_data *lis2dh = dev->data;
278+
int status;
279+
280+
status = lis2dh->hw_tf->write_reg(dev, LIS2DH_REG_CTRL2, val);
281+
if (status < 0) {
282+
LOG_ERR("Failed to set high pass filters");
283+
}
284+
285+
return status;
286+
}
287+
#endif
288+
274289
static int lis2dh_acc_config(const struct device *dev,
275290
enum sensor_channel chan,
276291
enum sensor_attribute attr,

drivers/sensor/st/lis2dh/lis2dh.h

+5-7
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,12 @@
8787
#define LIS2DH_REG_CTRL2 0x21
8888
#define LIS2DH_HPIS1_EN_BIT BIT(0)
8989
#define LIS2DH_HPIS2_EN_BIT BIT(1)
90+
#define LIS2DH_HPCLICK_EN_BIT BIT(2)
9091
#define LIS2DH_FDS_EN_BIT BIT(3)
91-
92-
#define LIS2DH_HPIS_EN_MASK BIT_MASK(2)
92+
#define LIS2DH_HPCF0_EN_BIT BIT(4)
93+
#define LIS2DH_HPCF1_EN_BIT BIT(5)
94+
#define LIS2DH_HPM0_EN_BIT BIT(6)
95+
#define LIS2DH_HPM1_EN_BIT BIT(7)
9396

9497
#define LIS2DH_REG_CTRL3 0x22
9598
#define LIS2DH_EN_CLICK_INT1 BIT(7)
@@ -305,11 +308,6 @@ int lis2dh_acc_slope_config(const struct device *dev,
305308
const struct sensor_value *val);
306309
#endif
307310

308-
#ifdef CONFIG_LIS2DH_ACCEL_HP_FILTERS
309-
int lis2dh_acc_hp_filter_set(const struct device *dev,
310-
int32_t val);
311-
#endif
312-
313311
int lis2dh_spi_init(const struct device *dev);
314312
int lis2dh_i2c_init(const struct device *dev);
315313

drivers/sensor/st/lis2dh/lis2dh_trigger.c

-16
Original file line numberDiff line numberDiff line change
@@ -361,22 +361,6 @@ int lis2dh_acc_slope_config(const struct device *dev,
361361
return status;
362362
}
363363

364-
#ifdef CONFIG_LIS2DH_ACCEL_HP_FILTERS
365-
int lis2dh_acc_hp_filter_set(const struct device *dev, int32_t val)
366-
{
367-
struct lis2dh_data *lis2dh = dev->data;
368-
int status;
369-
370-
status = lis2dh->hw_tf->update_reg(dev, LIS2DH_REG_CTRL2,
371-
LIS2DH_HPIS_EN_MASK, val);
372-
if (status < 0) {
373-
LOG_ERR("Failed to set high pass filters");
374-
}
375-
376-
return status;
377-
}
378-
#endif
379-
380364
static void lis2dh_gpio_int1_callback(const struct device *dev,
381365
struct gpio_callback *cb, uint32_t pins)
382366
{

0 commit comments

Comments
 (0)