Skip to content
Permalink
Browse files

drivers: adxl362: clear status independently and before mapping

Clear status bits before mapping them to the interrupt pin, so the
interrupt will occur on the next event instead of a pending event. Also
the status bits are cleared independently, because the threshold and
data ready functions can be enabled simultaneously.

Signed-off-by: Brett Witherspoon <spoonb@cdspooner.com>
  • Loading branch information...
bwitherspoon authored and MaureenHelm committed May 5, 2019
1 parent ed474e8 commit a5327b000395574ccac7a5950247bcd14f657d66
Showing with 13 additions and 11 deletions.
  1. +7 −0 drivers/sensor/adxl362/adxl362.c
  2. +2 −0 drivers/sensor/adxl362/adxl362.h
  3. +4 −11 drivers/sensor/adxl362/adxl362_trigger.c
@@ -135,6 +135,13 @@ int adxl362_get_status(struct device *dev, u8_t *status)
{
return adxl362_get_reg(dev, status, ADXL362_REG_STATUS, 1);
}

int adxl362_clear_data_ready(struct device *dev)
{
u8_t buf;
/* Reading any data register clears the data ready interrupt */
return adxl362_get_reg(dev, &buf, ADXL362_REG_XDATA, 1);
}
#endif

static int adxl362_software_reset(struct device *dev)
@@ -249,6 +249,8 @@ int adxl362_trigger_set(struct device *dev,
int adxl362_init_interrupt(struct device *dev);

int adxl362_set_interrupt_mode(struct device *dev, u8_t mode);

int adxl362_clear_data_ready(struct device *dev);
#endif /* CONFIG_ADT7420_TRIGGER */

#endif /* ZEPHYR_DRIVERS_SENSOR_ADXL362_ADXL362_H_ */
@@ -85,7 +85,6 @@ int adxl362_trigger_set(struct device *dev,
{
struct adxl362_data *drv_data = dev->driver_data;
u8_t int_mask, int_en, status_buf;
int ret;

switch (trig->type) {
case SENSOR_TRIG_THRESHOLD:
@@ -95,13 +94,16 @@ int adxl362_trigger_set(struct device *dev,
k_mutex_unlock(&drv_data->trigger_mutex);
int_mask = ADXL362_INTMAP1_ACT |
ADXL362_INTMAP1_INACT;
/* Clear activity and inactivity interrupts */
adxl362_get_status(dev, &status_buf);
break;
case SENSOR_TRIG_DATA_READY:
k_mutex_lock(&drv_data->trigger_mutex, K_FOREVER);
drv_data->drdy_handler = handler;
drv_data->drdy_trigger = *trig;
k_mutex_unlock(&drv_data->trigger_mutex);
int_mask = ADXL362_INTMAP1_DATA_READY;
adxl362_clear_data_ready(dev);
break;
default:
LOG_ERR("Unsupported sensor trigger");
@@ -114,16 +116,7 @@ int adxl362_trigger_set(struct device *dev,
int_en = 0U;
}

ret = adxl362_reg_write_mask(dev, ADXL362_REG_INTMAP1,
int_mask, int_en);

if (ret) {
return -EFAULT;
}

ret = adxl362_get_status(dev, &status_buf);

return ret;
return adxl362_reg_write_mask(dev, ADXL362_REG_INTMAP1, int_mask, int_en);
}

int adxl362_init_interrupt(struct device *dev)

0 comments on commit a5327b0

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