Code cleanup for non-trigger mode.

This commit is contained in:
Pete Johanson 2020-07-21 13:29:21 -04:00
parent aa7c74fe07
commit ac9ba3ae7d
3 changed files with 17 additions and 24 deletions

View file

@ -92,7 +92,7 @@ int ec11_init(struct device *dev)
struct ec11_data *drv_data = dev->driver_data;
const struct ec11_config *drv_cfg = dev->config_info;
LOG_DBG("resolution %d", drv_cfg->resolution);
LOG_DBG("A: %s %d B: %s %d resolution %d", drv_cfg->a_label, drv_cfg->a_pin, drv_cfg->b_label, drv_cfg->b_pin, drv_cfg->resolution);
drv_data->a = device_get_binding(drv_cfg->a_label);
if (drv_data->a == NULL) {
@ -106,6 +106,22 @@ int ec11_init(struct device *dev)
return -EINVAL;
}
if (gpio_pin_configure(drv_data->a, drv_cfg->a_pin,
drv_cfg->a_flags
| GPIO_INPUT)) {
LOG_DBG("Failed to configure A pin");
return -EIO;
}
if (gpio_pin_configure(drv_data->b, drv_cfg->b_pin,
drv_cfg->b_flags
| GPIO_INPUT)) {
LOG_DBG("Failed to configure B pin");
return -EIO;
}
#ifdef CONFIG_EC11_TRIGGER
if (ec11_init_interrupt(dev) < 0) {
LOG_DBG("Failed to initialize interrupt!");

View file

@ -22,11 +22,6 @@ struct ec11_config {
const u8_t resolution;
};
enum ec11_pin_state {
EC11_A_PIN_STATE,
EC11_B_PIN_STATE
};
struct ec11_data {
struct device *a;
struct device *b;
@ -36,7 +31,6 @@ struct ec11_data {
s8_t delta;
#ifdef CONFIG_EC11_TRIGGER
struct device *gpio;
struct gpio_callback a_gpio_cb;
struct gpio_callback b_gpio_cb;
struct device *dev;

View file

@ -141,14 +141,6 @@ int ec11_init_interrupt(struct device *dev)
drv_data->dev = dev;
/* setup gpio interrupt */
LOG_DBG("A: %s %d B: %s %d", drv_cfg->a_label, drv_cfg->a_pin, drv_cfg->b_label, drv_cfg->b_pin);
if (gpio_pin_configure(drv_data->a, drv_cfg->a_pin,
drv_cfg->a_flags
| GPIO_INPUT)) {
LOG_DBG("Failed to configure B pin");
return -EIO;
}
gpio_init_callback(&drv_data->a_gpio_cb,
ec11_a_gpio_callback,
@ -159,13 +151,6 @@ int ec11_init_interrupt(struct device *dev)
return -EIO;
}
if (gpio_pin_configure(drv_data->b, drv_cfg->b_pin,
drv_cfg->b_flags
| GPIO_INPUT)) {
LOG_DBG("Failed to configure B pin");
return -EIO;
}
gpio_init_callback(&drv_data->b_gpio_cb,
ec11_b_gpio_callback,
BIT(drv_cfg->b_pin));
@ -175,8 +160,6 @@ int ec11_init_interrupt(struct device *dev)
return -EIO;
}
LOG_DBG("A Pin? %d, B Pin? %d", gpio_pin_get(drv_data->a, drv_cfg->a_pin), gpio_pin_get(drv_data->b, drv_cfg->b_pin));
#if defined(CONFIG_EC11_TRIGGER_OWN_THREAD)
k_sem_init(&drv_data->gpio_sem, 0, UINT_MAX);