Browse Source

Code cleanup for non-trigger mode.

xmkb
Pete Johanson 4 years ago
parent
commit
ac9ba3ae7d
  1. 18
      app/drivers/zephyr/ec11.c
  2. 6
      app/drivers/zephyr/ec11.h
  3. 17
      app/drivers/zephyr/ec11_trigger.c

18
app/drivers/zephyr/ec11.c

@ -92,7 +92,7 @@ int ec11_init(struct device *dev)
struct ec11_data *drv_data = dev->driver_data; struct ec11_data *drv_data = dev->driver_data;
const struct ec11_config *drv_cfg = dev->config_info; 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); drv_data->a = device_get_binding(drv_cfg->a_label);
if (drv_data->a == NULL) { if (drv_data->a == NULL) {
@ -106,6 +106,22 @@ int ec11_init(struct device *dev)
return -EINVAL; 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 #ifdef CONFIG_EC11_TRIGGER
if (ec11_init_interrupt(dev) < 0) { if (ec11_init_interrupt(dev) < 0) {
LOG_DBG("Failed to initialize interrupt!"); LOG_DBG("Failed to initialize interrupt!");

6
app/drivers/zephyr/ec11.h

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

17
app/drivers/zephyr/ec11_trigger.c

@ -141,14 +141,6 @@ int ec11_init_interrupt(struct device *dev)
drv_data->dev = dev; drv_data->dev = dev;
/* setup gpio interrupt */ /* 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, gpio_init_callback(&drv_data->a_gpio_cb,
ec11_a_gpio_callback, ec11_a_gpio_callback,
@ -159,13 +151,6 @@ int ec11_init_interrupt(struct device *dev)
return -EIO; 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, gpio_init_callback(&drv_data->b_gpio_cb,
ec11_b_gpio_callback, ec11_b_gpio_callback,
BIT(drv_cfg->b_pin)); BIT(drv_cfg->b_pin));
@ -175,8 +160,6 @@ int ec11_init_interrupt(struct device *dev)
return -EIO; 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) #if defined(CONFIG_EC11_TRIGGER_OWN_THREAD)
k_sem_init(&drv_data->gpio_sem, 0, UINT_MAX); k_sem_init(&drv_data->gpio_sem, 0, UINT_MAX);

Loading…
Cancel
Save