Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions drivers/sensor/lsm9ds0_gyro/lsm9ds0_gyro.c
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ static const struct lsm9ds0_gyro_config lsm9ds0_gyro_config = {
#if defined(CONFIG_LSM9DS0_GYRO_TRIGGER_DRDY)
.gpio_drdy_dev_name = DT_INST_0_ST_LSM9DS0_GYRO_IRQ_GPIOS_CONTROLLER,
.gpio_drdy_int_pin = DT_INST_0_ST_LSM9DS0_GYRO_IRQ_GPIOS_PIN,
.gpio_drdy_int_flags = DT_INST_0_ST_LSM9DS0_GYRO_IRQ_GPIOS_FLAGS,
#endif
};

Expand Down
3 changes: 2 additions & 1 deletion drivers/sensor/lsm9ds0_gyro/lsm9ds0_gyro.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ struct lsm9ds0_gyro_config {

#if CONFIG_LSM9DS0_GYRO_TRIGGER_DRDY
char *gpio_drdy_dev_name;
u8_t gpio_drdy_int_pin;
gpio_pin_t gpio_drdy_int_pin;
gpio_devicetree_flags_t gpio_drdy_int_flags;
#endif
};

Expand Down
31 changes: 18 additions & 13 deletions drivers/sensor/lsm9ds0_gyro/lsm9ds0_gyro_trigger.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ extern struct lsm9ds0_gyro_data lsm9ds0_gyro_data;

LOG_MODULE_DECLARE(LSM9DS0_GYRO, CONFIG_SENSOR_LOG_LEVEL);

static inline void setup_drdy(struct device *dev,
bool enable)
{
struct lsm9ds0_gyro_data *data = dev->driver_data;
const struct lsm9ds0_gyro_config *cfg = dev->config->config_info;

gpio_pin_interrupt_configure(data->gpio_drdy,
cfg->gpio_drdy_int_pin,
enable
? GPIO_INT_EDGE_TO_ACTIVE
: GPIO_INT_DISABLE);
}

int lsm9ds0_gyro_trigger_set(struct device *dev,
const struct sensor_trigger *trig,
sensor_trigger_handler_t handler)
Expand All @@ -30,8 +43,7 @@ int lsm9ds0_gyro_trigger_set(struct device *dev,
u8_t state;

if (trig->type == SENSOR_TRIG_DATA_READY) {
gpio_pin_disable_callback(data->gpio_drdy,
config->gpio_drdy_int_pin);
setup_drdy(dev, false);

state = 0U;
if (handler) {
Expand All @@ -51,8 +63,7 @@ int lsm9ds0_gyro_trigger_set(struct device *dev,
return -EIO;
}

gpio_pin_enable_callback(data->gpio_drdy,
config->gpio_drdy_int_pin);
setup_drdy(dev, true);
return 0;
}

Expand All @@ -64,10 +75,8 @@ static void lsm9ds0_gyro_gpio_drdy_callback(struct device *dev,
{
struct lsm9ds0_gyro_data *data =
CONTAINER_OF(cb, struct lsm9ds0_gyro_data, gpio_cb);
const struct lsm9ds0_gyro_config * const config =
data->dev->config->config_info;

gpio_pin_disable_callback(dev, config->gpio_drdy_int_pin);
setup_drdy(data->dev, false);

k_sem_give(&data->sem);
}
Expand All @@ -76,9 +85,6 @@ static void lsm9ds0_gyro_thread_main(void *arg1, void *arg2, void *arg3)
{
struct device *dev = (struct device *) arg1;
struct lsm9ds0_gyro_data *data = dev->driver_data;
const struct lsm9ds0_gyro_config *config = dev->config->config_info;

int gpio_pin = config->gpio_drdy_int_pin;

while (1) {
k_sem_take(&data->sem, K_FOREVER);
Expand All @@ -87,7 +93,7 @@ static void lsm9ds0_gyro_thread_main(void *arg1, void *arg2, void *arg3)
data->handler_drdy(dev, &data->trigger_drdy);
}

gpio_pin_enable_callback(data->gpio_drdy, gpio_pin);
setup_drdy(dev, true);
}
}

Expand All @@ -112,8 +118,7 @@ int lsm9ds0_gyro_init_interrupt(struct device *dev)
}

gpio_pin_configure(data->gpio_drdy, config->gpio_drdy_int_pin,
GPIO_DIR_IN | GPIO_INT |
GPIO_INT_ACTIVE_HIGH | GPIO_INT_DEBOUNCE);
GPIO_INPUT | config->gpio_drdy_int_flags);

gpio_init_callback(&data->gpio_cb,
lsm9ds0_gyro_gpio_drdy_callback,
Expand Down
1 change: 1 addition & 0 deletions tests/drivers/build_all/dts_fixup.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@
#define DT_INST_0_ST_LSM9DS0_GYRO_BASE_ADDRESS 0x1d
#define DT_INST_0_ST_LSM9DS0_GYRO_IRQ_GPIOS_CONTROLLER ""
#define DT_INST_0_ST_LSM9DS0_GYRO_IRQ_GPIOS_PIN 1
#define DT_INST_0_ST_LSM9DS0_GYRO_IRQ_GPIOS_FLAGS 0
#endif

#ifndef DT_INST_0_ST_STTS751_LABEL
Expand Down