Skip to content
Permalink
Browse files

drivers: adxl362: check interrupt status

Check the status and only execute the callback if the event has
occurred.

Signed-off-by: Brett Witherspoon <spoonb@cdspooner.com>
  • Loading branch information...
bwitherspoon authored and MaureenHelm committed May 5, 2019
1 parent 0e92570 commit ed474e88bd91dbf4dffea2ca3e8f7839fd2c8b6c
Showing with 9 additions and 8 deletions.
  1. +1 −0 drivers/sensor/adxl362/adxl362.h
  2. +8 −8 drivers/sensor/adxl362/adxl362_trigger.c
@@ -157,6 +157,7 @@
#define ADXL362_RESET_KEY 0x52

/* ADXL362 Status check */
#define ADXL362_STATUS_CHECK_DATA_READY(x) (((x) >> 0) & 0x1)
#define ADXL362_STATUS_CHECK_INACT(x) (((x) >> 5) & 0x1)
#define ADXL362_STATUS_CHECK_ACTIVITY(x) (((x) >> 4) & 0x1)

@@ -21,23 +21,23 @@ static void adxl362_thread_cb(void *arg)
struct device *dev = arg;
struct adxl362_data *drv_data = dev->driver_data;
u8_t status_buf;
int ret;

/* Clears activity and inactivity interrupt */
if (adxl362_get_status(dev, &status_buf)) {
LOG_ERR("Unable to get status.");
return;
}

k_mutex_lock(&drv_data->trigger_mutex, K_FOREVER);
if (drv_data->th_handler != NULL) {
ret = adxl362_get_status(dev, &status_buf);

if (ret) {
LOG_ERR("Unable to get status from ADXL362.\n");
}

if (ADXL362_STATUS_CHECK_INACT(status_buf) ||
ADXL362_STATUS_CHECK_ACTIVITY(status_buf)) {
drv_data->th_handler(dev, &drv_data->th_trigger);
}
}

if (drv_data->drdy_handler != NULL) {
if (drv_data->drdy_handler != NULL &&
ADXL362_STATUS_CHECK_DATA_READY(status_buf)) {
drv_data->drdy_handler(dev, &drv_data->drdy_trigger);
}
k_mutex_unlock(&drv_data->trigger_mutex);

0 comments on commit ed474e8

Please sign in to comment.
You can’t perform that action at this time.