summaryrefslogtreecommitdiff
path: root/app/drivers
diff options
context:
space:
mode:
authorPete Johanson <peter@peterjohanson.com>2020-07-21 13:16:15 -0400
committerPete Johanson <peter@peterjohanson.com>2020-07-21 13:16:15 -0400
commit7da9a1039f453d549318737d85603a7a8c87b1d9 (patch)
tree644451be2cb3e4c2c2af0cf801d35c756e11b75c /app/drivers
parentb6b982fcef50938fcd271d41452a6c3e86a0c5c9 (diff)
Working encoder detection.
Diffstat (limited to 'app/drivers')
-rw-r--r--app/drivers/zephyr/ec11.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/app/drivers/zephyr/ec11.c b/app/drivers/zephyr/ec11.c
index 3e09cd6..74c8f9b 100644
--- a/app/drivers/zephyr/ec11.c
+++ b/app/drivers/zephyr/ec11.c
@@ -18,6 +18,13 @@
LOG_MODULE_REGISTER(EC11, CONFIG_SENSOR_LOG_LEVEL);
+static int ec11_get_ab_state(struct device *dev)
+{
+ struct ec11_data *drv_data = dev->driver_data;
+ const struct ec11_config *drv_cfg = dev->config_info;
+
+ return (gpio_pin_get(drv_data->a, drv_cfg->a_pin) << 1) | gpio_pin_get(drv_data->b, drv_cfg->b_pin);
+}
static int ec11_sample_fetch(struct device *dev, enum sensor_channel chan)
{
@@ -28,15 +35,15 @@ static int ec11_sample_fetch(struct device *dev, enum sensor_channel chan)
__ASSERT_NO_MSG(chan == SENSOR_CHAN_ALL || chan == SENSOR_CHAN_ROTATION);
- val = (gpio_pin_get(drv_data->a, drv_cfg->a_pin) << 1) | gpio_pin_get(drv_data->b, drv_cfg->b_pin);
+ val = ec11_get_ab_state(dev);
LOG_DBG("prev: %d, new: %d", drv_data->ab_state, val);
switch(val | (drv_data->ab_state << 2)) {
- case 0b0001: case 0b0111: case 0b1110: case 0b1000:
+ case 0b0010: case 0b0100: case 0b1101: case 0b1011:
delta = 1;
break;
- case 0b0010: case 0b0100: case 0b1101: case 0b1011:
+ case 0b0001: case 0b0111: case 0b1110: case 0b1000:
delta = -1;
break;
default:
@@ -106,6 +113,8 @@ int ec11_init(struct device *dev)
}
#endif
+ drv_data->ab_state = ec11_get_ab_state(dev);
+
return 0;
}