Re: [PATCH v5 05/11] iio: accel: adxl345: add freefall feature
From: Jonathan Cameron
Date: Mon Mar 31 2025 - 06:28:52 EST
On Tue, 18 Mar 2025 23:08:37 +0000
Lothar Rubusch <l.rubusch@xxxxxxxxx> wrote:
> Add the freefall detection of the sensor together with a threshold and
> time parameter. A freefall event is detected if the measuring signal
> falls below the threshold.
>
> Introduce a freefall threshold stored in regmap cache, and a freefall
> time, having the scaled time value stored as a member variable in the
> state instance.
>
> Signed-off-by: Lothar Rubusch <l.rubusch@xxxxxxxxx>
Hi Lothar,
Apologies for the slow review! Just catching up after travel
and I did it reverse order.
> +
> +static int adxl345_set_ff_en(struct adxl345_state *st, bool cmd_en)
> +{
> + unsigned int regval, ff_threshold;
> + const unsigned int freefall_mask = 0x02;
Where did this mask come from? Feels like it should be a define
(just use ADXL345_INT_FREE_FALL probably)
or if not that at lest use BIT(1) to make it clear it's a bit rather
than the number 2.
> + bool en;
> + int ret;
> +
> + ret = regmap_read(st->regmap, ADXL345_REG_THRESH_FF, &ff_threshold);
> + if (ret)
> + return ret;
> +
> + en = cmd_en && ff_threshold > 0 && st->ff_time_ms > 0;
> +
> + regval = en ? ADXL345_INT_FREE_FALL : 0x00;
> +
> + return regmap_update_bits(st->regmap, ADXL345_REG_INT_ENABLE,
> + freefall_mask, regval);
> +}
Jonathan