Skip to content

Commit

Permalink
drivers: sensor: lis2dw12: add interrupt status fetch
Browse files Browse the repository at this point in the history
INT status can be fetched if the feature can't trigger via interrupt

Signed-off-by: Andrew Sonzogni <[email protected]>
  • Loading branch information
andy3469 authored and fabiobaltieri committed Oct 3, 2024
1 parent 70de35d commit 44d101a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
15 changes: 15 additions & 0 deletions drivers/sensor/st/lis2dw12/lis2dw12.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,18 @@ static inline void lis2dw12_channel_get_acc(const struct device *dev,
}
}

static inline void lis2dw12_channel_get_status(const struct device *dev,
struct sensor_value *val)
{
const struct lis2dw12_device_config *cfg = dev->config;
stmdev_ctx_t *ctx = (stmdev_ctx_t *)&cfg->ctx;
lis2dw12_status_t status;

/* fetch manually the interrupt status reg */
lis2dw12_status_reg_get(ctx, &status);
val->val1 = (int32_t)*(uint8_t *)&status;
}

static int lis2dw12_channel_get(const struct device *dev,
enum sensor_channel chan,
struct sensor_value *val)
Expand All @@ -149,6 +161,9 @@ static int lis2dw12_channel_get(const struct device *dev,
case SENSOR_CHAN_DIE_TEMP:
lis2dw12_channel_get_temp(dev, val);
return 0;
case SENSOR_CHAN_LIS2DW12_INT_STATUS:
lis2dw12_channel_get_status(dev, val);
return 0;
default:
LOG_DBG("Channel not supported");
break;
Expand Down
5 changes: 5 additions & 0 deletions drivers/sensor/st/lis2dw12/lis2dw12.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,9 @@ int lis2dw12_trigger_set(const struct device *dev,
sensor_trigger_handler_t handler);
#endif /* CONFIG_LIS2DW12_TRIGGER */

/* LIS2DW12 specific channels */
enum sensor_channel_lis2dw12 {
SENSOR_CHAN_LIS2DW12_INT_STATUS = SENSOR_CHAN_PRIV_START,
};

#endif /* ZEPHYR_DRIVERS_SENSOR_LIS2DW12_LIS2DW12_H_ */

0 comments on commit 44d101a

Please sign in to comment.