Re: [PATCH 8/9] iio: imu: st_lsm6dsx: add event configurability on a per axis basis
From: Andy Shevchenko
Date: Thu Oct 30 2025 - 04:24:43 EST
On Thu, Oct 30, 2025 at 08:27:51AM +0100, Francesco Lavra wrote:
> In order to be able to configure event detection on a per axis
> basis (for either setting an event threshold/sensitivity value, or
> enabling/disabling event detection), add new axis-specific fields
> to struct st_lsm6dsx_event_src, and modify the logic that handles
> event configuration to properly handle axis-specific settings when
> supported by a given event source.
> A future commit will add actual event sources with per-axis
> configurability.
...
> + old_enable = hw->enable_event[event];
> + new_enable = state ? (old_enable | BIT(axis)) : (old_enable & ~BIT(axis));
> + if (!!old_enable == !!new_enable)
This is an interesting check. So, old_enable and new_enable are _not_ booleans, right?
So, this means the check test if _any_ of the bit was set and kept set or none were set
and non is going to be set. Correct? I think a short comment would be good to have.
> + return 0;
...
> +static const struct st_lsm6dsx_reg *st_lsm6dsx_get_event_reg(struct st_lsm6dsx_hw *hw,
> + enum st_lsm6dsx_event_id event,
> + const struct iio_chan_spec *chan)
> +{
> + const struct st_lsm6dsx_event_src *src = &hw->settings->event_settings.sources[event];
> + const struct st_lsm6dsx_reg *reg;
> +
> + switch (chan->channel2) {
> + case IIO_MOD_X:
> + reg = &src->x_value;
> + break;
> + case IIO_MOD_Y:
> + reg = &src->y_value;
> + break;
> + case IIO_MOD_Z:
> + reg = &src->z_value;
> + break;
> + default:
> + return NULL;
> + }
> + if (!reg->addr)
> + reg = &src->value;
> + return reg;
if (reg->addr)
return reg;
/* Perhaps a comment here to explain the choice */
return &src->value;
> +}
--
With Best Regards,
Andy Shevchenko