drivers: sensor: lsm9ds0_gyro: convert to new GPIO API
Use the new pin and interrupt configuration API. NOTE: Because hardware is not available this has been build-tested only. Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
This commit is contained in:
parent
64f5e23b47
commit
6ccaef981c
4 changed files with 22 additions and 14 deletions
|
@ -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
|
||||
};
|
||||
|
||||
|
|
|
@ -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
|
||||
};
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue