From 893b99d907b85109c8cf8b00f381f36939f5ae3c Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Fri, 17 Jul 2020 22:43:19 -0400 Subject: [PATCH 01/16] Initial en11 exploration. --- app/boards/shields/kyria/kyria_left.overlay | 12 + app/drivers/zephyr/CMakeLists.txt | 3 + app/drivers/zephyr/Kconfig | 47 ++++ .../zephyr/dts/bindings/alps,en11.yaml | 17 ++ app/drivers/zephyr/en11.c | 110 +++++++++ app/drivers/zephyr/en11.h | 61 +++++ app/drivers/zephyr/en11_trigger.c | 210 ++++++++++++++++++ app/src/drivers/sensors/en11/CMakeLists.txt | 6 + app/src/drivers/sensors/en11/Kconfig | 52 +++++ app/src/main.c | 24 ++ 10 files changed, 542 insertions(+) create mode 100644 app/drivers/zephyr/dts/bindings/alps,en11.yaml create mode 100644 app/drivers/zephyr/en11.c create mode 100644 app/drivers/zephyr/en11.h create mode 100644 app/drivers/zephyr/en11_trigger.c create mode 100644 app/src/drivers/sensors/en11/CMakeLists.txt create mode 100644 app/src/drivers/sensors/en11/Kconfig diff --git a/app/boards/shields/kyria/kyria_left.overlay b/app/boards/shields/kyria/kyria_left.overlay index c6305bd8..393b9d8e 100644 --- a/app/boards/shields/kyria/kyria_left.overlay +++ b/app/boards/shields/kyria/kyria_left.overlay @@ -6,6 +6,18 @@ #include "kyria.dtsi" +/ { + sensors { + encoder: encoder0 { + compatible = "alps,en11"; + label = "Rotary Encoder"; + a-gpios = <&pro_micro_d 5 GPIO_ACTIVE_HIGH>; + b-gpios = <&pro_micro_d 9 GPIO_ACTIVE_HIGH>; + }; + }; + +}; + &kscan0 { col-gpios = <&pro_micro_a 3 GPIO_ACTIVE_HIGH> diff --git a/app/drivers/zephyr/CMakeLists.txt b/app/drivers/zephyr/CMakeLists.txt index 983828f5..59664195 100644 --- a/app/drivers/zephyr/CMakeLists.txt +++ b/app/drivers/zephyr/CMakeLists.txt @@ -6,4 +6,7 @@ if(CONFIG_ZMK_KSCAN_GPIO_DRIVER) kscan_gpio_matrix.c kscan_gpio_direct.c ) + + zephyr_library_sources_ifdef(CONFIG_EN11 en11.c) + zephyr_library_sources_ifdef(CONFIG_EN11_TRIGGER en11_trigger.c) endif() diff --git a/app/drivers/zephyr/Kconfig b/app/drivers/zephyr/Kconfig index cd526e86..00a43d27 100644 --- a/app/drivers/zephyr/Kconfig +++ b/app/drivers/zephyr/Kconfig @@ -17,3 +17,50 @@ config ZMK_KSCAN_INIT_PRIORITY help Keyboard scan device driver initialization priority. +menuconfig EN11 + bool "EN11 Incremental Encoder Sensor" + depends on GPIO + help + Enable driver for EN11 incremental encoder sensors. + +if EN11 + +choice + prompt "Trigger mode" + default EN11_TRIGGER_NONE + help + Specify the type of triggering to be used by the driver. + +config EN11_TRIGGER_NONE + bool "No trigger" + +config EN11_TRIGGER_GLOBAL_THREAD + bool "Use global thread" + depends on GPIO + select EN11_TRIGGER + +config EN11_TRIGGER_OWN_THREAD + bool "Use own thread" + depends on GPIO + select EN11_TRIGGER + +endchoice + +config EN11_TRIGGER + bool + +config EN11_THREAD_PRIORITY + int "Thread priority" + depends on EN11_TRIGGER_OWN_THREAD + default 10 + help + Priority of thread used by the driver to handle interrupts. + +config EN11_THREAD_STACK_SIZE + int "Thread stack size" + depends on EN11_TRIGGER_OWN_THREAD + default 1024 + help + Stack size of thread used by the driver to handle interrupts. + +endif # EN11 diff --git a/app/drivers/zephyr/dts/bindings/alps,en11.yaml b/app/drivers/zephyr/dts/bindings/alps,en11.yaml new file mode 100644 index 00000000..1d1de3aa --- /dev/null +++ b/app/drivers/zephyr/dts/bindings/alps,en11.yaml @@ -0,0 +1,17 @@ +description: | + Sensor driver for the Alps en11 rotary encoder + +compatible: "alps,en11" + +properties: + label: + type: string + required: true + a-gpios: + type: phandle-array + required: true + description: A pin for the encoder + b-gpios: + type: phandle-array + required: true + description: A pin for the encoder diff --git a/app/drivers/zephyr/en11.c b/app/drivers/zephyr/en11.c new file mode 100644 index 00000000..e6c6b740 --- /dev/null +++ b/app/drivers/zephyr/en11.c @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2020 Peter Johanson + * + * SPDX-License-Identifier: MIT + */ + +#define DT_DRV_COMPAT alps_en11 + +#include +#include +#include +#include +#include +#include +#include + +#include "en11.h" + +LOG_MODULE_REGISTER(EN11, CONFIG_SENSOR_LOG_LEVEL); + +static int en11_sample_fetch(struct device *dev, enum sensor_channel chan) +{ + struct en11_data *drv_data = dev->driver_data; + u16_t val; + + __ASSERT_NO_MSG(chan == SENSOR_CHAN_ALL || chan == SENSOR_CHAN_AMBIENT_TEMP); + + // if (en11_reg_read(drv_data, EN11_REG_TOBJ, &val) < 0) { + // return -EIO; + // } + + // if (val & EN11_DATA_INVALID_BIT) { + // return -EIO; + // } + + // drv_data->sample = arithmetic_shift_right((s16_t)val, 2); + + return 0; +} + +static int en11_channel_get(struct device *dev, + enum sensor_channel chan, + struct sensor_value *val) +{ + struct en11_data *drv_data = dev->driver_data; + // s32_t uval; + + // if (chan != SENSOR_CHAN_AMBIENT_TEMP) { + // return -ENOTSUP; + // } + + // uval = (s32_t)drv_data->sample * EN11_TEMP_SCALE; + // val->val1 = uval / 1000000; + // val->val2 = uval % 1000000; + + return 0; +} + +static const struct sensor_driver_api en11_driver_api = { +#ifdef CONFIG_EN11_TRIGGER + .trigger_set = en11_trigger_set, +#endif + .sample_fetch = en11_sample_fetch, + .channel_get = en11_channel_get, +}; + +int en11_init(struct device *dev) +{ + struct en11_data *drv_data = dev->driver_data; + const struct en11_config *drv_cfg = dev->config_info; + + LOG_DBG(""); + + drv_data->a = device_get_binding(drv_cfg->a_label); + if (drv_data->a == NULL) { + LOG_ERR("Failed to get pointer to A GPIO device"); + return -EINVAL; + } + + drv_data->b = device_get_binding(drv_cfg->b_label); + if (drv_data->b == NULL) { + LOG_ERR("Failed to get pointer to B GPIO device"); + return -EINVAL; + } + +#ifdef CONFIG_EN11_TRIGGER + if (en11_init_interrupt(dev) < 0) { + LOG_DBG("Failed to initialize interrupt!"); + return -EIO; + } +#endif + + return 0; +} + +struct en11_data en11_data; + +const struct en11_config en11_cfg = { + .a_label = DT_INST_GPIO_LABEL(0, a_gpios), + .a_pin = DT_INST_GPIO_PIN(0, a_gpios), + .a_flags = DT_INST_GPIO_FLAGS(0, a_gpios), + .b_label = DT_INST_GPIO_LABEL(0, b_gpios), + .b_pin = DT_INST_GPIO_PIN(0, b_gpios), + .b_flags = DT_INST_GPIO_FLAGS(0, b_gpios), +}; + +DEVICE_AND_API_INIT(en11, DT_INST_LABEL(0), en11_init, + &en11_data, + &en11_cfg, POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY, + &en11_driver_api); diff --git a/app/drivers/zephyr/en11.h b/app/drivers/zephyr/en11.h new file mode 100644 index 00000000..e8b2f21e --- /dev/null +++ b/app/drivers/zephyr/en11.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2020 Peter Johanson + * + * SPDX-License-Identifier: MIT + */ + +#pragma once + +#include +#include +#include + +struct en11_config { + const char *a_label; + const u8_t a_pin; + const u8_t a_flags; + + const char *b_label; + const u8_t b_pin; + const u8_t b_flags; +}; + +enum en11_pin_state { + EN11_A_PIN_STATE, + EN11_B_PIN_STATE +}; + +struct en11_data { + struct device *a; + struct device *b; + u8_t ab_state; + s16_t sample; + +#ifdef CONFIG_EN11_TRIGGER + struct device *gpio; + struct gpio_callback a_gpio_cb; + struct gpio_callback b_gpio_cb; + struct device *dev; + + sensor_trigger_handler_t handler; + struct sensor_trigger trigger; + +#if defined(CONFIG_EN11_TRIGGER_OWN_THREAD) + K_THREAD_STACK_MEMBER(thread_stack, CONFIG_EN11_THREAD_STACK_SIZE); + struct k_sem gpio_sem; + struct k_thread thread; +#elif defined(CONFIG_EN11_TRIGGER_GLOBAL_THREAD) + struct k_work work; +#endif + +#endif /* CONFIG_EN11_TRIGGER */ +}; + +#ifdef CONFIG_EN11_TRIGGER + +int en11_trigger_set(struct device *dev, + const struct sensor_trigger *trig, + sensor_trigger_handler_t handler); + +int en11_init_interrupt(struct device *dev); +#endif diff --git a/app/drivers/zephyr/en11_trigger.c b/app/drivers/zephyr/en11_trigger.c new file mode 100644 index 00000000..d210431f --- /dev/null +++ b/app/drivers/zephyr/en11_trigger.c @@ -0,0 +1,210 @@ +/* + * Copyright (c) 2016 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#define DT_DRV_COMPAT alps_en11 + +#include +#include +#include +#include +#include + +#include "en11.h" + +extern struct en11_data en11_driver; + +#include +LOG_MODULE_DECLARE(EN11, CONFIG_SENSOR_LOG_LEVEL); + +static inline void setup_int(struct device *dev, + bool enable) +{ + struct en11_data *data = dev->driver_data; + const struct en11_config *cfg = dev->config_info; + + LOG_DBG("enabled %s", (enable ? "true" : "false")); + + if (gpio_pin_interrupt_configure(data->a, + cfg->a_pin, + enable + ? GPIO_INT_EDGE_BOTH + : GPIO_INT_DISABLE)) { + LOG_WRN("Unable to set A pin GPIO interrupt"); + } + + if (gpio_pin_interrupt_configure(data->b, + cfg->b_pin, + enable + ? GPIO_INT_EDGE_BOTH + : GPIO_INT_DISABLE)) { + LOG_WRN("Unable to set A pin GPIO interrupt"); + } +} + +static void en11_a_gpio_callback(struct device *dev, + struct gpio_callback *cb, u32_t pins) +{ + struct en11_data *drv_data = + CONTAINER_OF(cb, struct en11_data, a_gpio_cb); + + LOG_DBG(""); + + setup_int(drv_data->dev, false); + +#if defined(CONFIG_EN11_TRIGGER_OWN_THREAD) + k_sem_give(&drv_data->gpio_sem); +#elif defined(CONFIG_EN11_TRIGGER_GLOBAL_THREAD) + k_work_submit(&drv_data->work); +#endif +} + +static void en11_b_gpio_callback(struct device *dev, + struct gpio_callback *cb, u32_t pins) +{ + struct en11_data *drv_data = + CONTAINER_OF(cb, struct en11_data, b_gpio_cb); + + LOG_DBG(""); + + setup_int(drv_data->dev, false); + +#if defined(CONFIG_EN11_TRIGGER_OWN_THREAD) + k_sem_give(&drv_data->gpio_sem); +#elif defined(CONFIG_EN11_TRIGGER_GLOBAL_THREAD) + k_work_submit(&drv_data->work); +#endif +} + +static void en11_thread_cb(void *arg) +{ + struct device *dev = arg; + struct en11_data *drv_data = dev->driver_data; + const struct en11_config *cfg = dev->config_info; + u16_t status; + + // gpio_pin_get(drv_data->a, cfg->a_pin) + + // if (en11_reg_read(drv_data, EN11_REG_STATUS, &status) < 0) { + // return; + // } + + // if (status & EN11_DATA_READY_INT_BIT && + // drv_data->drdy_handler != NULL) { + // drv_data->drdy_handler(dev, &drv_data->drdy_trigger); + // } + + // if (status & EN11_TOBJ_TH_INT_BITS && + // drv_data->th_handler != NULL) { + // drv_data->th_handler(dev, &drv_data->th_trigger); + // } + + setup_int(dev, true); +} + +#ifdef CONFIG_EN11_TRIGGER_OWN_THREAD +static void en11_thread(int dev_ptr, int unused) +{ + struct device *dev = INT_TO_POINTER(dev_ptr); + struct en11_data *drv_data = dev->driver_data; + + ARG_UNUSED(unused); + + while (1) { + k_sem_take(&drv_data->gpio_sem, K_FOREVER); + en11_thread_cb(dev); + } +} +#endif + +#ifdef CONFIG_EN11_TRIGGER_GLOBAL_THREAD +static void en11_work_cb(struct k_work *work) +{ + struct en11_data *drv_data = + CONTAINER_OF(work, struct en11_data, work); + + LOG_DBG(""); + + en11_thread_cb(drv_data->dev); +} +#endif + +int en11_trigger_set(struct device *dev, + const struct sensor_trigger *trig, + sensor_trigger_handler_t handler) +{ + struct en11_data *drv_data = dev->driver_data; + + setup_int(dev, false); + + drv_data->trigger = *trig; + drv_data->handler = handler; + + setup_int(dev, true); + + return 0; +} + +int en11_init_interrupt(struct device *dev) +{ + struct en11_data *drv_data = dev->driver_data; + const struct en11_config *drv_cfg = dev->config_info; + + /* 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); + + gpio_pin_configure(drv_data->a, drv_cfg->a_pin, + drv_cfg->a_flags + | GPIO_INPUT); + + if (gpio_pin_set(drv_data->a, drv_cfg->a_pin, 1)) { + LOG_DBG("Failed to set A active!"); + return -EIO; + } + + gpio_init_callback(&drv_data->a_gpio_cb, + en11_a_gpio_callback, + BIT(drv_cfg->a_pin)); + + if (gpio_add_callback(drv_data->a, &drv_data->a_gpio_cb) < 0) { + LOG_DBG("Failed to set A callback!"); + return -EIO; + } + + gpio_pin_configure(drv_data->b, drv_cfg->b_pin, + drv_cfg->b_flags + | GPIO_INPUT); + + if (gpio_pin_set(drv_data->b, drv_cfg->b_pin, 1)) { + LOG_DBG("Failed to set B active!"); + return -EIO; + } + + gpio_init_callback(&drv_data->b_gpio_cb, + en11_b_gpio_callback, + BIT(drv_cfg->b_pin)); + + if (gpio_add_callback(drv_data->b, &drv_data->b_gpio_cb) < 0) { + LOG_DBG("Failed to set B callback!"); + 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_EN11_TRIGGER_OWN_THREAD) + k_sem_init(&drv_data->gpio_sem, 0, UINT_MAX); + + k_thread_create(&drv_data->thread, drv_data->thread_stack, + CONFIG_EN11_THREAD_STACK_SIZE, + (k_thread_entry_t)en11_thread, dev, + 0, NULL, K_PRIO_COOP(CONFIG_EN11_THREAD_PRIORITY), + 0, K_NO_WAIT); +#elif defined(CONFIG_EN11_TRIGGER_GLOBAL_THREAD) + drv_data->work.handler = en11_work_cb; +#endif + + return 0; +} diff --git a/app/src/drivers/sensors/en11/CMakeLists.txt b/app/src/drivers/sensors/en11/CMakeLists.txt new file mode 100644 index 00000000..4c538ca8 --- /dev/null +++ b/app/src/drivers/sensors/en11/CMakeLists.txt @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: Apache-2.0 + +zephyr_library() + +zephyr_library_sources_ifdef(CONFIG_EN11 en11.c) +zephyr_library_sources_ifdef(CONFIG_EN11_TRIGGER en11_trigger.c) diff --git a/app/src/drivers/sensors/en11/Kconfig b/app/src/drivers/sensors/en11/Kconfig new file mode 100644 index 00000000..84fec95c --- /dev/null +++ b/app/src/drivers/sensors/en11/Kconfig @@ -0,0 +1,52 @@ +# EN11 incremental encoder sensor configuration options + +# Copyright (c) 2020 Peter Johanson +# SPDX-License-Identifier: MIT + +menuconfig EN11 + bool "EN11 Incremental Encoder Sensor" + depends on GPIO + help + Enable driver for EN11 incremental encoder sensors. + +if EN11 + +choice + prompt "Trigger mode" + default EN11_TRIGGER_NONE + help + Specify the type of triggering to be used by the driver. + +config EN11_TRIGGER_NONE + bool "No trigger" + +config EN11_TRIGGER_GLOBAL_THREAD + bool "Use global thread" + depends on GPIO + select EN11_TRIGGER + +config EN11_TRIGGER_OWN_THREAD + bool "Use own thread" + depends on GPIO + select EN11_TRIGGER + +endchoice + +config EN11_TRIGGER + bool + +config EN11_THREAD_PRIORITY + int "Thread priority" + depends on EN11_TRIGGER_OWN_THREAD + default 10 + help + Priority of thread used by the driver to handle interrupts. + +config EN11_THREAD_STACK_SIZE + int "Thread stack size" + depends on EN11_TRIGGER_OWN_THREAD + default 1024 + help + Stack size of thread used by the driver to handle interrupts. + +endif # EN11 diff --git a/app/src/main.c b/app/src/main.c index 92ecc8b1..f42c7c4d 100644 --- a/app/src/main.c +++ b/app/src/main.c @@ -8,6 +8,7 @@ #include #include #include +#include #include LOG_MODULE_REGISTER(zmk, CONFIG_ZMK_LOG_LEVEL); @@ -18,6 +19,27 @@ LOG_MODULE_REGISTER(zmk, CONFIG_ZMK_LOG_LEVEL); #define ZMK_KSCAN_DEV DT_LABEL(ZMK_MATRIX_NODE_ID) +static struct sensor_trigger trigger; + +void encoder_change(struct device *dev, struct sensor_trigger *trigger) +{ + LOG_DBG(""); +} + +void init_sensor() +{ + struct device *dev = device_get_binding("Rotary Encoder"); + if (!dev) { + LOG_DBG("NO ENCODER!"); + return; + } + + trigger.type = SENSOR_TRIG_DATA_READY; + trigger.chan = SENSOR_CHAN_ROTATION; + + sensor_trigger_set(dev, &trigger, encoder_change); +} + void main(void) { printk("Welcome to ZMK!\n"); @@ -31,4 +53,6 @@ void main(void) #ifdef CONFIG_SETTINGS settings_load(); #endif + + init_sensor(); } From 331bfa70521112759a4b553356a90eee8747644d Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Mon, 20 Jul 2020 10:27:44 -0400 Subject: [PATCH 02/16] Interrupt fixes. --- app/boards/shields/kyria/kyria_left.overlay | 7 ++----- app/drivers/zephyr/en11_trigger.c | 17 +++++++---------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/app/boards/shields/kyria/kyria_left.overlay b/app/boards/shields/kyria/kyria_left.overlay index 393b9d8e..d17548ff 100644 --- a/app/boards/shields/kyria/kyria_left.overlay +++ b/app/boards/shields/kyria/kyria_left.overlay @@ -7,15 +7,12 @@ #include "kyria.dtsi" / { - sensors { encoder: encoder0 { compatible = "alps,en11"; label = "Rotary Encoder"; - a-gpios = <&pro_micro_d 5 GPIO_ACTIVE_HIGH>; - b-gpios = <&pro_micro_d 9 GPIO_ACTIVE_HIGH>; + a-gpios = <&pro_micro_d 5 (GPIO_ACTIVE_HIGH | GPIO_PULL_UP)>; + b-gpios = <&pro_micro_d 9 (GPIO_ACTIVE_HIGH | GPIO_PULL_UP)>; }; - }; - }; &kscan0 { diff --git a/app/drivers/zephyr/en11_trigger.c b/app/drivers/zephyr/en11_trigger.c index d210431f..0f85e8e6 100644 --- a/app/drivers/zephyr/en11_trigger.c +++ b/app/drivers/zephyr/en11_trigger.c @@ -152,16 +152,15 @@ int en11_init_interrupt(struct device *dev) struct en11_data *drv_data = dev->driver_data; const struct en11_config *drv_cfg = dev->config_info; + 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); - gpio_pin_configure(drv_data->a, drv_cfg->a_pin, + if (gpio_pin_configure(drv_data->a, drv_cfg->a_pin, drv_cfg->a_flags - | GPIO_INPUT); - - if (gpio_pin_set(drv_data->a, drv_cfg->a_pin, 1)) { - LOG_DBG("Failed to set A active!"); + | GPIO_INPUT)) { + LOG_DBG("Failed to configure B pin"); return -EIO; } @@ -174,12 +173,10 @@ int en11_init_interrupt(struct device *dev) return -EIO; } - gpio_pin_configure(drv_data->b, drv_cfg->b_pin, + if (gpio_pin_configure(drv_data->b, drv_cfg->b_pin, drv_cfg->b_flags - | GPIO_INPUT); - - if (gpio_pin_set(drv_data->b, drv_cfg->b_pin, 1)) { - LOG_DBG("Failed to set B active!"); + | GPIO_INPUT)) { + LOG_DBG("Failed to configure B pin"); return -EIO; } From 109c69cbab0a417c97b20788b0fd3bcd720178f1 Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Mon, 20 Jul 2020 20:54:58 -0400 Subject: [PATCH 03/16] EN11 is actually EC11, some sample work. --- app/boards/shields/kyria/kyria_left.overlay | 3 +- app/drivers/zephyr/CMakeLists.txt | 4 +- app/drivers/zephyr/Kconfig | 32 ++--- .../zephyr/dts/bindings/alps,en11.yaml | 8 +- app/drivers/zephyr/ec11.c | 132 ++++++++++++++++++ app/drivers/zephyr/{en11.h => ec11.h} | 31 ++-- .../zephyr/{en11_trigger.c => ec11_trigger.c} | 91 ++++++------ app/drivers/zephyr/en11.c | 110 --------------- app/src/drivers/sensors/en11/CMakeLists.txt | 6 - app/src/drivers/sensors/en11/Kconfig | 52 ------- app/src/main.c | 15 ++ 11 files changed, 237 insertions(+), 247 deletions(-) create mode 100644 app/drivers/zephyr/ec11.c rename app/drivers/zephyr/{en11.h => ec11.h} (59%) rename app/drivers/zephyr/{en11_trigger.c => ec11_trigger.c} (60%) delete mode 100644 app/drivers/zephyr/en11.c delete mode 100644 app/src/drivers/sensors/en11/CMakeLists.txt delete mode 100644 app/src/drivers/sensors/en11/Kconfig diff --git a/app/boards/shields/kyria/kyria_left.overlay b/app/boards/shields/kyria/kyria_left.overlay index d17548ff..43c9d88d 100644 --- a/app/boards/shields/kyria/kyria_left.overlay +++ b/app/boards/shields/kyria/kyria_left.overlay @@ -8,10 +8,11 @@ / { encoder: encoder0 { - compatible = "alps,en11"; + compatible = "alps,ec11"; label = "Rotary Encoder"; a-gpios = <&pro_micro_d 5 (GPIO_ACTIVE_HIGH | GPIO_PULL_UP)>; b-gpios = <&pro_micro_d 9 (GPIO_ACTIVE_HIGH | GPIO_PULL_UP)>; + resolution = <4>; }; }; diff --git a/app/drivers/zephyr/CMakeLists.txt b/app/drivers/zephyr/CMakeLists.txt index 59664195..8778ded3 100644 --- a/app/drivers/zephyr/CMakeLists.txt +++ b/app/drivers/zephyr/CMakeLists.txt @@ -7,6 +7,6 @@ if(CONFIG_ZMK_KSCAN_GPIO_DRIVER) kscan_gpio_direct.c ) - zephyr_library_sources_ifdef(CONFIG_EN11 en11.c) - zephyr_library_sources_ifdef(CONFIG_EN11_TRIGGER en11_trigger.c) + zephyr_library_sources_ifdef(CONFIG_EC11 ec11.c) + zephyr_library_sources_ifdef(CONFIG_EC11_TRIGGER ec11_trigger.c) endif() diff --git a/app/drivers/zephyr/Kconfig b/app/drivers/zephyr/Kconfig index 00a43d27..0237846a 100644 --- a/app/drivers/zephyr/Kconfig +++ b/app/drivers/zephyr/Kconfig @@ -17,50 +17,50 @@ config ZMK_KSCAN_INIT_PRIORITY help Keyboard scan device driver initialization priority. -menuconfig EN11 - bool "EN11 Incremental Encoder Sensor" +menuconfig EC11 + bool "EC11 Incremental Encoder Sensor" depends on GPIO help - Enable driver for EN11 incremental encoder sensors. + Enable driver for EC11 incremental encoder sensors. -if EN11 +if EC11 choice prompt "Trigger mode" - default EN11_TRIGGER_NONE + default EC11_TRIGGER_NONE help Specify the type of triggering to be used by the driver. -config EN11_TRIGGER_NONE +config EC11_TRIGGER_NONE bool "No trigger" -config EN11_TRIGGER_GLOBAL_THREAD +config EC11_TRIGGER_GLOBAL_THREAD bool "Use global thread" depends on GPIO - select EN11_TRIGGER + select EC11_TRIGGER -config EN11_TRIGGER_OWN_THREAD +config EC11_TRIGGER_OWN_THREAD bool "Use own thread" depends on GPIO - select EN11_TRIGGER + select EC11_TRIGGER endchoice -config EN11_TRIGGER +config EC11_TRIGGER bool -config EN11_THREAD_PRIORITY +config EC11_THREAD_PRIORITY int "Thread priority" - depends on EN11_TRIGGER_OWN_THREAD + depends on EC11_TRIGGER_OWN_THREAD default 10 help Priority of thread used by the driver to handle interrupts. -config EN11_THREAD_STACK_SIZE +config EC11_THREAD_STACK_SIZE int "Thread stack size" - depends on EN11_TRIGGER_OWN_THREAD + depends on EC11_TRIGGER_OWN_THREAD default 1024 help Stack size of thread used by the driver to handle interrupts. -endif # EN11 +endif # EC11 diff --git a/app/drivers/zephyr/dts/bindings/alps,en11.yaml b/app/drivers/zephyr/dts/bindings/alps,en11.yaml index 1d1de3aa..5cbe77a2 100644 --- a/app/drivers/zephyr/dts/bindings/alps,en11.yaml +++ b/app/drivers/zephyr/dts/bindings/alps,en11.yaml @@ -1,7 +1,7 @@ description: | - Sensor driver for the Alps en11 rotary encoder + Sensor driver for the Alps EC11 rotary encoder -compatible: "alps,en11" +compatible: "alps,ec11" properties: label: @@ -15,3 +15,7 @@ properties: type: phandle-array required: true description: A pin for the encoder + resolution: + type: int + description: Number of pulses per tick + required: false diff --git a/app/drivers/zephyr/ec11.c b/app/drivers/zephyr/ec11.c new file mode 100644 index 00000000..ef0c5c39 --- /dev/null +++ b/app/drivers/zephyr/ec11.c @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2020 Peter Johanson + * + * SPDX-License-Identifier: MIT + */ + +#define DT_DRV_COMPAT alps_ec11 + +#include +#include +#include +#include +#include +#include +#include + +#include "ec11.h" + +LOG_MODULE_REGISTER(EC11, CONFIG_SENSOR_LOG_LEVEL); + + +static int ec11_sample_fetch(struct device *dev, enum sensor_channel chan) +{ + struct ec11_data *drv_data = dev->driver_data; + const struct ec11_config *drv_cfg = dev->config_info; + u8_t val; + u8_t delta; + + __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); + + LOG_DBG("prev: %d, new: %d", drv_data->ab_state, val); + + switch(val | (drv_data->ab_state << 2)) { + case 0b0001: case 0b0111: case 0b1110: + LOG_DBG("+1"); + delta = 1; + break; + default: + LOG_DBG("FIGURE IT OUT!"); + break; + } + + LOG_DBG("Delta: %d", delta); + + + // if (ec11_reg_read(drv_data, EC11_REG_TOBJ, &val) < 0) { + // return -EIO; + // } + + // if (val & EC11_DATA_INVALID_BIT) { + // return -EIO; + // } + + // drv_data->sample = arithmetic_shift_right((s16_t)val, 2); + + return 0; +} + +static int ec11_channel_get(struct device *dev, + enum sensor_channel chan, + struct sensor_value *val) +{ + struct ec11_data *drv_data = dev->driver_data; + + // s32_t uval; + + // if (chan != SENSOR_CHAN_AMBIENT_TEMP) { + // return -ENOTSUP; + // } + + // uval = (s32_t)drv_data->sample * EC11_TEMP_SCALE; + // val->val1 = uval / 1000000; + // val->val2 = uval % 1000000; + + return 0; +} + +static const struct sensor_driver_api ec11_driver_api = { +#ifdef CONFIG_EC11_TRIGGER + .trigger_set = ec11_trigger_set, +#endif + .sample_fetch = ec11_sample_fetch, + .channel_get = ec11_channel_get, +}; + +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); + + drv_data->a = device_get_binding(drv_cfg->a_label); + if (drv_data->a == NULL) { + LOG_ERR("Failed to get pointer to A GPIO device"); + return -EINVAL; + } + + drv_data->b = device_get_binding(drv_cfg->b_label); + if (drv_data->b == NULL) { + LOG_ERR("Failed to get pointer to B GPIO device"); + return -EINVAL; + } + +#ifdef CONFIG_EC11_TRIGGER + if (ec11_init_interrupt(dev) < 0) { + LOG_DBG("Failed to initialize interrupt!"); + return -EIO; + } +#endif + + return 0; +} + +struct ec11_data ec11_data; + +const struct ec11_config ec11_cfg = { + .a_label = DT_INST_GPIO_LABEL(0, a_gpios), + .a_pin = DT_INST_GPIO_PIN(0, a_gpios), + .a_flags = DT_INST_GPIO_FLAGS(0, a_gpios), + .b_label = DT_INST_GPIO_LABEL(0, b_gpios), + .b_pin = DT_INST_GPIO_PIN(0, b_gpios), + .b_flags = DT_INST_GPIO_FLAGS(0, b_gpios), + COND_CODE_0(DT_INST_NODE_HAS_PROP(0, resolution), (1), (DT_INST_PROP(0, resolution))), +}; + +DEVICE_AND_API_INIT(ec11, DT_INST_LABEL(0), ec11_init, + &ec11_data, + &ec11_cfg, POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY, + &ec11_driver_api); diff --git a/app/drivers/zephyr/en11.h b/app/drivers/zephyr/ec11.h similarity index 59% rename from app/drivers/zephyr/en11.h rename to app/drivers/zephyr/ec11.h index e8b2f21e..524af2c0 100644 --- a/app/drivers/zephyr/en11.h +++ b/app/drivers/zephyr/ec11.h @@ -10,7 +10,7 @@ #include #include -struct en11_config { +struct ec11_config { const char *a_label; const u8_t a_pin; const u8_t a_flags; @@ -18,20 +18,23 @@ struct en11_config { const char *b_label; const u8_t b_pin; const u8_t b_flags; + + const u8_t resolution; }; -enum en11_pin_state { - EN11_A_PIN_STATE, - EN11_B_PIN_STATE +enum ec11_pin_state { + EC11_A_PIN_STATE, + EC11_B_PIN_STATE }; -struct en11_data { +struct ec11_data { struct device *a; struct device *b; u8_t ab_state; - s16_t sample; + s16_t pulse_state; + s16_t tick_state; -#ifdef CONFIG_EN11_TRIGGER +#ifdef CONFIG_EC11_TRIGGER struct device *gpio; struct gpio_callback a_gpio_cb; struct gpio_callback b_gpio_cb; @@ -40,22 +43,22 @@ struct en11_data { sensor_trigger_handler_t handler; struct sensor_trigger trigger; -#if defined(CONFIG_EN11_TRIGGER_OWN_THREAD) - K_THREAD_STACK_MEMBER(thread_stack, CONFIG_EN11_THREAD_STACK_SIZE); +#if defined(CONFIG_EC11_TRIGGER_OWN_THREAD) + K_THREAD_STACK_MEMBER(thread_stack, CONFIG_EC11_THREAD_STACK_SIZE); struct k_sem gpio_sem; struct k_thread thread; -#elif defined(CONFIG_EN11_TRIGGER_GLOBAL_THREAD) +#elif defined(CONFIG_EC11_TRIGGER_GLOBAL_THREAD) struct k_work work; #endif -#endif /* CONFIG_EN11_TRIGGER */ +#endif /* CONFIG_EC11_TRIGGER */ }; -#ifdef CONFIG_EN11_TRIGGER +#ifdef CONFIG_EC11_TRIGGER -int en11_trigger_set(struct device *dev, +int ec11_trigger_set(struct device *dev, const struct sensor_trigger *trig, sensor_trigger_handler_t handler); -int en11_init_interrupt(struct device *dev); +int ec11_init_interrupt(struct device *dev); #endif diff --git a/app/drivers/zephyr/en11_trigger.c b/app/drivers/zephyr/ec11_trigger.c similarity index 60% rename from app/drivers/zephyr/en11_trigger.c rename to app/drivers/zephyr/ec11_trigger.c index 0f85e8e6..07493fbe 100644 --- a/app/drivers/zephyr/en11_trigger.c +++ b/app/drivers/zephyr/ec11_trigger.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#define DT_DRV_COMPAT alps_en11 +#define DT_DRV_COMPAT alps_ec11 #include #include @@ -12,18 +12,18 @@ #include #include -#include "en11.h" +#include "ec11.h" -extern struct en11_data en11_driver; +extern struct ec11_data ec11_driver; #include -LOG_MODULE_DECLARE(EN11, CONFIG_SENSOR_LOG_LEVEL); +LOG_MODULE_DECLARE(EC11, CONFIG_SENSOR_LOG_LEVEL); static inline void setup_int(struct device *dev, bool enable) { - struct en11_data *data = dev->driver_data; - const struct en11_config *cfg = dev->config_info; + struct ec11_data *data = dev->driver_data; + const struct ec11_config *cfg = dev->config_info; LOG_DBG("enabled %s", (enable ? "true" : "false")); @@ -44,59 +44,60 @@ static inline void setup_int(struct device *dev, } } -static void en11_a_gpio_callback(struct device *dev, +static void ec11_a_gpio_callback(struct device *dev, struct gpio_callback *cb, u32_t pins) { - struct en11_data *drv_data = - CONTAINER_OF(cb, struct en11_data, a_gpio_cb); + struct ec11_data *drv_data = + CONTAINER_OF(cb, struct ec11_data, a_gpio_cb); LOG_DBG(""); setup_int(drv_data->dev, false); -#if defined(CONFIG_EN11_TRIGGER_OWN_THREAD) +#if defined(CONFIG_EC11_TRIGGER_OWN_THREAD) k_sem_give(&drv_data->gpio_sem); -#elif defined(CONFIG_EN11_TRIGGER_GLOBAL_THREAD) +#elif defined(CONFIG_EC11_TRIGGER_GLOBAL_THREAD) k_work_submit(&drv_data->work); #endif } -static void en11_b_gpio_callback(struct device *dev, +static void ec11_b_gpio_callback(struct device *dev, struct gpio_callback *cb, u32_t pins) { - struct en11_data *drv_data = - CONTAINER_OF(cb, struct en11_data, b_gpio_cb); + struct ec11_data *drv_data = + CONTAINER_OF(cb, struct ec11_data, b_gpio_cb); LOG_DBG(""); setup_int(drv_data->dev, false); -#if defined(CONFIG_EN11_TRIGGER_OWN_THREAD) +#if defined(CONFIG_EC11_TRIGGER_OWN_THREAD) k_sem_give(&drv_data->gpio_sem); -#elif defined(CONFIG_EN11_TRIGGER_GLOBAL_THREAD) +#elif defined(CONFIG_EC11_TRIGGER_GLOBAL_THREAD) k_work_submit(&drv_data->work); #endif } -static void en11_thread_cb(void *arg) +static void ec11_thread_cb(void *arg) { struct device *dev = arg; - struct en11_data *drv_data = dev->driver_data; - const struct en11_config *cfg = dev->config_info; + struct ec11_data *drv_data = dev->driver_data; + const struct ec11_config *cfg = dev->config_info; u16_t status; + drv_data->handler(dev, &drv_data->trigger); // gpio_pin_get(drv_data->a, cfg->a_pin) - // if (en11_reg_read(drv_data, EN11_REG_STATUS, &status) < 0) { + // if (ec11_reg_read(drv_data, EC11_REG_STATUS, &status) < 0) { // return; // } - // if (status & EN11_DATA_READY_INT_BIT && + // if (status & EC11_DATA_READY_INT_BIT && // drv_data->drdy_handler != NULL) { // drv_data->drdy_handler(dev, &drv_data->drdy_trigger); // } - // if (status & EN11_TOBJ_TH_INT_BITS && + // if (status & EC11_TOBJ_TH_INT_BITS && // drv_data->th_handler != NULL) { // drv_data->th_handler(dev, &drv_data->th_trigger); // } @@ -104,41 +105,43 @@ static void en11_thread_cb(void *arg) setup_int(dev, true); } -#ifdef CONFIG_EN11_TRIGGER_OWN_THREAD -static void en11_thread(int dev_ptr, int unused) +#ifdef CONFIG_EC11_TRIGGER_OWN_THREAD +static void ec11_thread(int dev_ptr, int unused) { struct device *dev = INT_TO_POINTER(dev_ptr); - struct en11_data *drv_data = dev->driver_data; + struct ec11_data *drv_data = dev->driver_data; ARG_UNUSED(unused); while (1) { k_sem_take(&drv_data->gpio_sem, K_FOREVER); - en11_thread_cb(dev); + ec11_thread_cb(dev); } } #endif -#ifdef CONFIG_EN11_TRIGGER_GLOBAL_THREAD -static void en11_work_cb(struct k_work *work) +#ifdef CONFIG_EC11_TRIGGER_GLOBAL_THREAD +static void ec11_work_cb(struct k_work *work) { - struct en11_data *drv_data = - CONTAINER_OF(work, struct en11_data, work); + struct ec11_data *drv_data = + CONTAINER_OF(work, struct ec11_data, work); LOG_DBG(""); - en11_thread_cb(drv_data->dev); + ec11_thread_cb(drv_data->dev); } #endif -int en11_trigger_set(struct device *dev, +int ec11_trigger_set(struct device *dev, const struct sensor_trigger *trig, sensor_trigger_handler_t handler) { - struct en11_data *drv_data = dev->driver_data; + struct ec11_data *drv_data = dev->driver_data; setup_int(dev, false); + k_msleep(5); + drv_data->trigger = *trig; drv_data->handler = handler; @@ -147,10 +150,10 @@ int en11_trigger_set(struct device *dev, return 0; } -int en11_init_interrupt(struct device *dev) +int ec11_init_interrupt(struct device *dev) { - struct en11_data *drv_data = dev->driver_data; - const struct en11_config *drv_cfg = dev->config_info; + struct ec11_data *drv_data = dev->driver_data; + const struct ec11_config *drv_cfg = dev->config_info; drv_data->dev = dev; /* setup gpio interrupt */ @@ -165,7 +168,7 @@ int en11_init_interrupt(struct device *dev) } gpio_init_callback(&drv_data->a_gpio_cb, - en11_a_gpio_callback, + ec11_a_gpio_callback, BIT(drv_cfg->a_pin)); if (gpio_add_callback(drv_data->a, &drv_data->a_gpio_cb) < 0) { @@ -181,7 +184,7 @@ int en11_init_interrupt(struct device *dev) } gpio_init_callback(&drv_data->b_gpio_cb, - en11_b_gpio_callback, + ec11_b_gpio_callback, BIT(drv_cfg->b_pin)); if (gpio_add_callback(drv_data->b, &drv_data->b_gpio_cb) < 0) { @@ -191,16 +194,16 @@ int en11_init_interrupt(struct device *dev) 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_EN11_TRIGGER_OWN_THREAD) +#if defined(CONFIG_EC11_TRIGGER_OWN_THREAD) k_sem_init(&drv_data->gpio_sem, 0, UINT_MAX); k_thread_create(&drv_data->thread, drv_data->thread_stack, - CONFIG_EN11_THREAD_STACK_SIZE, - (k_thread_entry_t)en11_thread, dev, - 0, NULL, K_PRIO_COOP(CONFIG_EN11_THREAD_PRIORITY), + CONFIG_EC11_THREAD_STACK_SIZE, + (k_thread_entry_t)ec11_thread, dev, + 0, NULL, K_PRIO_COOP(CONFIG_EC11_THREAD_PRIORITY), 0, K_NO_WAIT); -#elif defined(CONFIG_EN11_TRIGGER_GLOBAL_THREAD) - drv_data->work.handler = en11_work_cb; +#elif defined(CONFIG_EC11_TRIGGER_GLOBAL_THREAD) + k_work_init(&drv_data->work, ec11_work_cb); #endif return 0; diff --git a/app/drivers/zephyr/en11.c b/app/drivers/zephyr/en11.c deleted file mode 100644 index e6c6b740..00000000 --- a/app/drivers/zephyr/en11.c +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (c) 2020 Peter Johanson - * - * SPDX-License-Identifier: MIT - */ - -#define DT_DRV_COMPAT alps_en11 - -#include -#include -#include -#include -#include -#include -#include - -#include "en11.h" - -LOG_MODULE_REGISTER(EN11, CONFIG_SENSOR_LOG_LEVEL); - -static int en11_sample_fetch(struct device *dev, enum sensor_channel chan) -{ - struct en11_data *drv_data = dev->driver_data; - u16_t val; - - __ASSERT_NO_MSG(chan == SENSOR_CHAN_ALL || chan == SENSOR_CHAN_AMBIENT_TEMP); - - // if (en11_reg_read(drv_data, EN11_REG_TOBJ, &val) < 0) { - // return -EIO; - // } - - // if (val & EN11_DATA_INVALID_BIT) { - // return -EIO; - // } - - // drv_data->sample = arithmetic_shift_right((s16_t)val, 2); - - return 0; -} - -static int en11_channel_get(struct device *dev, - enum sensor_channel chan, - struct sensor_value *val) -{ - struct en11_data *drv_data = dev->driver_data; - // s32_t uval; - - // if (chan != SENSOR_CHAN_AMBIENT_TEMP) { - // return -ENOTSUP; - // } - - // uval = (s32_t)drv_data->sample * EN11_TEMP_SCALE; - // val->val1 = uval / 1000000; - // val->val2 = uval % 1000000; - - return 0; -} - -static const struct sensor_driver_api en11_driver_api = { -#ifdef CONFIG_EN11_TRIGGER - .trigger_set = en11_trigger_set, -#endif - .sample_fetch = en11_sample_fetch, - .channel_get = en11_channel_get, -}; - -int en11_init(struct device *dev) -{ - struct en11_data *drv_data = dev->driver_data; - const struct en11_config *drv_cfg = dev->config_info; - - LOG_DBG(""); - - drv_data->a = device_get_binding(drv_cfg->a_label); - if (drv_data->a == NULL) { - LOG_ERR("Failed to get pointer to A GPIO device"); - return -EINVAL; - } - - drv_data->b = device_get_binding(drv_cfg->b_label); - if (drv_data->b == NULL) { - LOG_ERR("Failed to get pointer to B GPIO device"); - return -EINVAL; - } - -#ifdef CONFIG_EN11_TRIGGER - if (en11_init_interrupt(dev) < 0) { - LOG_DBG("Failed to initialize interrupt!"); - return -EIO; - } -#endif - - return 0; -} - -struct en11_data en11_data; - -const struct en11_config en11_cfg = { - .a_label = DT_INST_GPIO_LABEL(0, a_gpios), - .a_pin = DT_INST_GPIO_PIN(0, a_gpios), - .a_flags = DT_INST_GPIO_FLAGS(0, a_gpios), - .b_label = DT_INST_GPIO_LABEL(0, b_gpios), - .b_pin = DT_INST_GPIO_PIN(0, b_gpios), - .b_flags = DT_INST_GPIO_FLAGS(0, b_gpios), -}; - -DEVICE_AND_API_INIT(en11, DT_INST_LABEL(0), en11_init, - &en11_data, - &en11_cfg, POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY, - &en11_driver_api); diff --git a/app/src/drivers/sensors/en11/CMakeLists.txt b/app/src/drivers/sensors/en11/CMakeLists.txt deleted file mode 100644 index 4c538ca8..00000000 --- a/app/src/drivers/sensors/en11/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 - -zephyr_library() - -zephyr_library_sources_ifdef(CONFIG_EN11 en11.c) -zephyr_library_sources_ifdef(CONFIG_EN11_TRIGGER en11_trigger.c) diff --git a/app/src/drivers/sensors/en11/Kconfig b/app/src/drivers/sensors/en11/Kconfig deleted file mode 100644 index 84fec95c..00000000 --- a/app/src/drivers/sensors/en11/Kconfig +++ /dev/null @@ -1,52 +0,0 @@ -# EN11 incremental encoder sensor configuration options - -# Copyright (c) 2020 Peter Johanson -# SPDX-License-Identifier: MIT - -menuconfig EN11 - bool "EN11 Incremental Encoder Sensor" - depends on GPIO - help - Enable driver for EN11 incremental encoder sensors. - -if EN11 - -choice - prompt "Trigger mode" - default EN11_TRIGGER_NONE - help - Specify the type of triggering to be used by the driver. - -config EN11_TRIGGER_NONE - bool "No trigger" - -config EN11_TRIGGER_GLOBAL_THREAD - bool "Use global thread" - depends on GPIO - select EN11_TRIGGER - -config EN11_TRIGGER_OWN_THREAD - bool "Use own thread" - depends on GPIO - select EN11_TRIGGER - -endchoice - -config EN11_TRIGGER - bool - -config EN11_THREAD_PRIORITY - int "Thread priority" - depends on EN11_TRIGGER_OWN_THREAD - default 10 - help - Priority of thread used by the driver to handle interrupts. - -config EN11_THREAD_STACK_SIZE - int "Thread stack size" - depends on EN11_TRIGGER_OWN_THREAD - default 1024 - help - Stack size of thread used by the driver to handle interrupts. - -endif # EN11 diff --git a/app/src/main.c b/app/src/main.c index f42c7c4d..d04efae2 100644 --- a/app/src/main.c +++ b/app/src/main.c @@ -23,7 +23,22 @@ static struct sensor_trigger trigger; void encoder_change(struct device *dev, struct sensor_trigger *trigger) { + int err; + struct sensor_value value; + LOG_DBG(""); + + err = sensor_sample_fetch(dev); + if (err) { + LOG_ERR("Failed to fetch new EC11 sample"); + return; + } + + err = sensor_channel_get(dev, SENSOR_CHAN_ROTATION, &value); + if (err) { + LOG_DBG("Failed to get the sample for EC11 %d", err); + return; + } } void init_sensor() From c058757252c01b347bb432cea45e4a7bfb189738 Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Mon, 20 Jul 2020 22:47:50 -0400 Subject: [PATCH 04/16] Fetch/get implementation work. --- app/drivers/zephyr/ec11.c | 43 +++++++++++++++++---------------------- app/drivers/zephyr/ec11.h | 5 +++-- 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/app/drivers/zephyr/ec11.c b/app/drivers/zephyr/ec11.c index ef0c5c39..3e09cd69 100644 --- a/app/drivers/zephyr/ec11.c +++ b/app/drivers/zephyr/ec11.c @@ -24,7 +24,7 @@ static int ec11_sample_fetch(struct device *dev, enum sensor_channel chan) struct ec11_data *drv_data = dev->driver_data; const struct ec11_config *drv_cfg = dev->config_info; u8_t val; - u8_t delta; + s8_t delta; __ASSERT_NO_MSG(chan == SENSOR_CHAN_ALL || chan == SENSOR_CHAN_ROTATION); @@ -33,28 +33,26 @@ static int ec11_sample_fetch(struct device *dev, enum sensor_channel chan) LOG_DBG("prev: %d, new: %d", drv_data->ab_state, val); switch(val | (drv_data->ab_state << 2)) { - case 0b0001: case 0b0111: case 0b1110: - LOG_DBG("+1"); + case 0b0001: case 0b0111: case 0b1110: case 0b1000: delta = 1; break; + case 0b0010: case 0b0100: case 0b1101: case 0b1011: + delta = -1; + break; default: - LOG_DBG("FIGURE IT OUT!"); + delta = 0; break; } LOG_DBG("Delta: %d", delta); + drv_data->pulses += delta; + drv_data->ab_state = val; - // if (ec11_reg_read(drv_data, EC11_REG_TOBJ, &val) < 0) { - // return -EIO; - // } - - // if (val & EC11_DATA_INVALID_BIT) { - // return -EIO; - // } - - // drv_data->sample = arithmetic_shift_right((s16_t)val, 2); - + drv_data->ticks = drv_data->pulses / drv_cfg->resolution; + drv_data->delta = delta; + drv_data->pulses %= drv_cfg->resolution; + return 0; } @@ -63,17 +61,14 @@ static int ec11_channel_get(struct device *dev, struct sensor_value *val) { struct ec11_data *drv_data = dev->driver_data; + + if (chan != SENSOR_CHAN_ROTATION) { + return -ENOTSUP; + } - // s32_t uval; - - // if (chan != SENSOR_CHAN_AMBIENT_TEMP) { - // return -ENOTSUP; - // } - - // uval = (s32_t)drv_data->sample * EC11_TEMP_SCALE; - // val->val1 = uval / 1000000; - // val->val2 = uval % 1000000; - + val->val1 = drv_data->ticks; + val->val2 = drv_data->delta; + return 0; } diff --git a/app/drivers/zephyr/ec11.h b/app/drivers/zephyr/ec11.h index 524af2c0..8acc3a6c 100644 --- a/app/drivers/zephyr/ec11.h +++ b/app/drivers/zephyr/ec11.h @@ -31,8 +31,9 @@ struct ec11_data { struct device *a; struct device *b; u8_t ab_state; - s16_t pulse_state; - s16_t tick_state; + s8_t pulses; + s8_t ticks; + s8_t delta; #ifdef CONFIG_EC11_TRIGGER struct device *gpio; From b6b982fcef50938fcd271d41452a6c3e86a0c5c9 Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Mon, 20 Jul 2020 23:51:40 -0400 Subject: [PATCH 05/16] Code clean up --- app/drivers/zephyr/ec11_trigger.c | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/app/drivers/zephyr/ec11_trigger.c b/app/drivers/zephyr/ec11_trigger.c index 07493fbe..7e4a0353 100644 --- a/app/drivers/zephyr/ec11_trigger.c +++ b/app/drivers/zephyr/ec11_trigger.c @@ -82,25 +82,8 @@ static void ec11_thread_cb(void *arg) { struct device *dev = arg; struct ec11_data *drv_data = dev->driver_data; - const struct ec11_config *cfg = dev->config_info; - u16_t status; drv_data->handler(dev, &drv_data->trigger); - // gpio_pin_get(drv_data->a, cfg->a_pin) - - // if (ec11_reg_read(drv_data, EC11_REG_STATUS, &status) < 0) { - // return; - // } - - // if (status & EC11_DATA_READY_INT_BIT && - // drv_data->drdy_handler != NULL) { - // drv_data->drdy_handler(dev, &drv_data->drdy_trigger); - // } - - // if (status & EC11_TOBJ_TH_INT_BITS && - // drv_data->th_handler != NULL) { - // drv_data->th_handler(dev, &drv_data->th_trigger); - // } setup_int(dev, true); } From 7da9a1039f453d549318737d85603a7a8c87b1d9 Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Tue, 21 Jul 2020 13:16:15 -0400 Subject: [PATCH 06/16] Working encoder detection. --- app/drivers/zephyr/ec11.c | 15 ++++++++++++--- app/src/main.c | 2 ++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/drivers/zephyr/ec11.c b/app/drivers/zephyr/ec11.c index 3e09cd69..74c8f9b8 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; } diff --git a/app/src/main.c b/app/src/main.c index d04efae2..557dd619 100644 --- a/app/src/main.c +++ b/app/src/main.c @@ -39,6 +39,8 @@ void encoder_change(struct device *dev, struct sensor_trigger *trigger) LOG_DBG("Failed to get the sample for EC11 %d", err); return; } + + LOG_DBG("val1 %d val2 %d", value.val1, value.val2); } void init_sensor() From aa7c74fe075526c73cac8ae1e7df826f762fedc5 Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Tue, 21 Jul 2020 13:24:44 -0400 Subject: [PATCH 07/16] Filename fix for EN11 -> EC11. --- .../zephyr/dts/bindings/{alps,en11.yaml => alps,ec11.yaml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename app/drivers/zephyr/dts/bindings/{alps,en11.yaml => alps,ec11.yaml} (100%) diff --git a/app/drivers/zephyr/dts/bindings/alps,en11.yaml b/app/drivers/zephyr/dts/bindings/alps,ec11.yaml similarity index 100% rename from app/drivers/zephyr/dts/bindings/alps,en11.yaml rename to app/drivers/zephyr/dts/bindings/alps,ec11.yaml From ac9ba3ae7d6db496ba7ddccf434804cfebfa6dab Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Tue, 21 Jul 2020 13:29:21 -0400 Subject: [PATCH 08/16] Code cleanup for non-trigger mode. --- app/drivers/zephyr/ec11.c | 18 +++++++++++++++++- app/drivers/zephyr/ec11.h | 6 ------ app/drivers/zephyr/ec11_trigger.c | 17 ----------------- 3 files changed, 17 insertions(+), 24 deletions(-) diff --git a/app/drivers/zephyr/ec11.c b/app/drivers/zephyr/ec11.c index 74c8f9b8..9d724d53 100644 --- a/app/drivers/zephyr/ec11.c +++ b/app/drivers/zephyr/ec11.c @@ -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!"); diff --git a/app/drivers/zephyr/ec11.h b/app/drivers/zephyr/ec11.h index 8acc3a6c..b54e5328 100644 --- a/app/drivers/zephyr/ec11.h +++ b/app/drivers/zephyr/ec11.h @@ -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; diff --git a/app/drivers/zephyr/ec11_trigger.c b/app/drivers/zephyr/ec11_trigger.c index 7e4a0353..68f9bec4 100644 --- a/app/drivers/zephyr/ec11_trigger.c +++ b/app/drivers/zephyr/ec11_trigger.c @@ -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); From c619d36294374ffea018090938d3613454fe3aae Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Tue, 21 Jul 2020 13:37:02 -0400 Subject: [PATCH 09/16] Support multiple instances of the encoder. --- app/drivers/zephyr/ec11.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/app/drivers/zephyr/ec11.c b/app/drivers/zephyr/ec11.c index 9d724d53..357c5724 100644 --- a/app/drivers/zephyr/ec11.c +++ b/app/drivers/zephyr/ec11.c @@ -134,19 +134,20 @@ int ec11_init(struct device *dev) return 0; } -struct ec11_data ec11_data; +#define EC11_INST(n) \ + struct ec11_data ec11_data_##n; \ + const struct ec11_config ec11_cfg_##n = { \ + .a_label = DT_INST_GPIO_LABEL(n, a_gpios), \ + .a_pin = DT_INST_GPIO_PIN(n, a_gpios), \ + .a_flags = DT_INST_GPIO_FLAGS(n, a_gpios), \ + .b_label = DT_INST_GPIO_LABEL(n, b_gpios), \ + .b_pin = DT_INST_GPIO_PIN(n, b_gpios), \ + .b_flags = DT_INST_GPIO_FLAGS(n, b_gpios), \ + COND_CODE_0(DT_INST_NODE_HAS_PROP(n, resolution), (1), (DT_INST_PROP(n, resolution))), \ + }; \ + DEVICE_AND_API_INIT(ec11, DT_INST_LABEL(n), ec11_init, \ + &ec11_data_##n, \ + &ec11_cfg_##n, POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY, \ + &ec11_driver_api); -const struct ec11_config ec11_cfg = { - .a_label = DT_INST_GPIO_LABEL(0, a_gpios), - .a_pin = DT_INST_GPIO_PIN(0, a_gpios), - .a_flags = DT_INST_GPIO_FLAGS(0, a_gpios), - .b_label = DT_INST_GPIO_LABEL(0, b_gpios), - .b_pin = DT_INST_GPIO_PIN(0, b_gpios), - .b_flags = DT_INST_GPIO_FLAGS(0, b_gpios), - COND_CODE_0(DT_INST_NODE_HAS_PROP(0, resolution), (1), (DT_INST_PROP(0, resolution))), -}; - -DEVICE_AND_API_INIT(ec11, DT_INST_LABEL(0), ec11_init, - &ec11_data, - &ec11_cfg, POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY, - &ec11_driver_api); +DT_INST_FOREACH_STATUS_OKAY(EC11_INST) \ No newline at end of file From b48011ace61e28362b322aecd48dadd09775f8d3 Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Tue, 21 Jul 2020 13:40:16 -0400 Subject: [PATCH 10/16] Remove sensor test code. --- app/src/main.c | 42 ------------------------------------------ 1 file changed, 42 deletions(-) diff --git a/app/src/main.c b/app/src/main.c index 557dd619..defee20e 100644 --- a/app/src/main.c +++ b/app/src/main.c @@ -8,7 +8,6 @@ #include #include #include -#include #include LOG_MODULE_REGISTER(zmk, CONFIG_ZMK_LOG_LEVEL); @@ -19,44 +18,6 @@ LOG_MODULE_REGISTER(zmk, CONFIG_ZMK_LOG_LEVEL); #define ZMK_KSCAN_DEV DT_LABEL(ZMK_MATRIX_NODE_ID) -static struct sensor_trigger trigger; - -void encoder_change(struct device *dev, struct sensor_trigger *trigger) -{ - int err; - struct sensor_value value; - - LOG_DBG(""); - - err = sensor_sample_fetch(dev); - if (err) { - LOG_ERR("Failed to fetch new EC11 sample"); - return; - } - - err = sensor_channel_get(dev, SENSOR_CHAN_ROTATION, &value); - if (err) { - LOG_DBG("Failed to get the sample for EC11 %d", err); - return; - } - - LOG_DBG("val1 %d val2 %d", value.val1, value.val2); -} - -void init_sensor() -{ - struct device *dev = device_get_binding("Rotary Encoder"); - if (!dev) { - LOG_DBG("NO ENCODER!"); - return; - } - - trigger.type = SENSOR_TRIG_DATA_READY; - trigger.chan = SENSOR_CHAN_ROTATION; - - sensor_trigger_set(dev, &trigger, encoder_change); -} - void main(void) { printk("Welcome to ZMK!\n"); @@ -66,10 +27,7 @@ void main(void) return; } - #ifdef CONFIG_SETTINGS settings_load(); #endif - - init_sensor(); } From f3267e6030822abc594aadd4264508607dc5bb69 Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Tue, 21 Jul 2020 13:52:03 -0400 Subject: [PATCH 11/16] Tweaks for orientation and A/B pins for Kyria left --- app/boards/shields/kyria/kyria_left.overlay | 4 ++-- app/drivers/zephyr/ec11.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/boards/shields/kyria/kyria_left.overlay b/app/boards/shields/kyria/kyria_left.overlay index 43c9d88d..3b3df8c8 100644 --- a/app/boards/shields/kyria/kyria_left.overlay +++ b/app/boards/shields/kyria/kyria_left.overlay @@ -10,8 +10,8 @@ encoder: encoder0 { compatible = "alps,ec11"; label = "Rotary Encoder"; - a-gpios = <&pro_micro_d 5 (GPIO_ACTIVE_HIGH | GPIO_PULL_UP)>; - b-gpios = <&pro_micro_d 9 (GPIO_ACTIVE_HIGH | GPIO_PULL_UP)>; + a-gpios = <&pro_micro_d 9 (GPIO_ACTIVE_HIGH | GPIO_PULL_UP)>; + b-gpios = <&pro_micro_d 5 (GPIO_ACTIVE_HIGH | GPIO_PULL_UP)>; resolution = <4>; }; }; diff --git a/app/drivers/zephyr/ec11.c b/app/drivers/zephyr/ec11.c index 357c5724..1bc5d6a6 100644 --- a/app/drivers/zephyr/ec11.c +++ b/app/drivers/zephyr/ec11.c @@ -41,10 +41,10 @@ static int ec11_sample_fetch(struct device *dev, enum sensor_channel chan) switch(val | (drv_data->ab_state << 2)) { case 0b0010: case 0b0100: case 0b1101: case 0b1011: - delta = 1; + delta = -1; break; case 0b0001: case 0b0111: case 0b1110: case 0b1000: - delta = -1; + delta = 1; break; default: delta = 0; From 3338b3f7dea5bfb4c433c4aef12e636f92a06c94 Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Tue, 21 Jul 2020 13:53:43 -0400 Subject: [PATCH 12/16] Revert minor change to main. --- app/src/main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main.c b/app/src/main.c index defee20e..92ecc8b1 100644 --- a/app/src/main.c +++ b/app/src/main.c @@ -27,6 +27,7 @@ void main(void) return; } + #ifdef CONFIG_SETTINGS settings_load(); #endif From a734d58ffe6147be5e426b8c758da3b2237df7a0 Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Tue, 21 Jul 2020 14:01:15 -0400 Subject: [PATCH 13/16] More consistent DT for the split encoders. --- app/boards/shields/kyria/kyria.dtsi | 19 +++++++++++++++++++ app/boards/shields/kyria/kyria_left.overlay | 13 +++---------- app/boards/shields/kyria/kyria_right.overlay | 4 ++++ 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/app/boards/shields/kyria/kyria.dtsi b/app/boards/shields/kyria/kyria.dtsi index f96adf0f..87d78020 100644 --- a/app/boards/shields/kyria/kyria.dtsi +++ b/app/boards/shields/kyria/kyria.dtsi @@ -10,6 +10,7 @@ chosen { zmk,kscan = &kscan0; zmk,matrix_transform = &default_transform; + zmk,encoders = <&left_encoder &right_encoder>; }; default_transform: keymap_transform_0 { @@ -58,6 +59,24 @@ RC(2,0) RC(2,1) RC(2,2) RC(2,3) RC(2,4) RC(2,5) RC(2,6) RC(2,7) RC(2,8) RC(2,9) }; + left_encoder: encoder_left { + compatible = "alps,ec11"; + label = "LEFT_ENCODER"; + a-gpios = <&pro_micro_d 9 (GPIO_ACTIVE_HIGH | GPIO_PULL_UP)>; + b-gpios = <&pro_micro_d 5 (GPIO_ACTIVE_HIGH | GPIO_PULL_UP)>; + resolution = <4>; + status = "disabled"; + }; + + right_encoder: encoder_right { + compatible = "alps,ec11"; + label = "RIGHT_ENCODER"; + a-gpios = <&pro_micro_d 5 (GPIO_ACTIVE_HIGH | GPIO_PULL_UP)>; + b-gpios = <&pro_micro_d 9 (GPIO_ACTIVE_HIGH | GPIO_PULL_UP)>; + resolution = <4>; + status = "disabled"; + }; + // TODO: Encoder node(s) // TODO: OLED node // TODO: RGB node(s) diff --git a/app/boards/shields/kyria/kyria_left.overlay b/app/boards/shields/kyria/kyria_left.overlay index 3b3df8c8..29f648d7 100644 --- a/app/boards/shields/kyria/kyria_left.overlay +++ b/app/boards/shields/kyria/kyria_left.overlay @@ -6,16 +6,6 @@ #include "kyria.dtsi" -/ { - encoder: encoder0 { - compatible = "alps,ec11"; - label = "Rotary Encoder"; - a-gpios = <&pro_micro_d 9 (GPIO_ACTIVE_HIGH | GPIO_PULL_UP)>; - b-gpios = <&pro_micro_d 5 (GPIO_ACTIVE_HIGH | GPIO_PULL_UP)>; - resolution = <4>; - }; -}; - &kscan0 { col-gpios = <&pro_micro_a 3 GPIO_ACTIVE_HIGH> @@ -29,3 +19,6 @@ ; }; +&left_encoder { + status = "okay"; +}; \ No newline at end of file diff --git a/app/boards/shields/kyria/kyria_right.overlay b/app/boards/shields/kyria/kyria_right.overlay index b919bb2a..8163c95e 100644 --- a/app/boards/shields/kyria/kyria_right.overlay +++ b/app/boards/shields/kyria/kyria_right.overlay @@ -23,3 +23,7 @@ ; }; + +&right_encoder { + status = "okay"; +}; From ec74adb3b700572be9b15be2fc297e4c36b8a0bd Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Tue, 21 Jul 2020 14:01:48 -0400 Subject: [PATCH 14/16] Better chosen name. --- app/boards/shields/kyria/kyria.dtsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/boards/shields/kyria/kyria.dtsi b/app/boards/shields/kyria/kyria.dtsi index 87d78020..4efca8eb 100644 --- a/app/boards/shields/kyria/kyria.dtsi +++ b/app/boards/shields/kyria/kyria.dtsi @@ -10,7 +10,7 @@ chosen { zmk,kscan = &kscan0; zmk,matrix_transform = &default_transform; - zmk,encoders = <&left_encoder &right_encoder>; + zmk,sensors = <&left_encoder &right_encoder>; }; default_transform: keymap_transform_0 { From b49755b724201de32583e76af77caa6e4c68163b Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Tue, 21 Jul 2020 14:24:58 -0400 Subject: [PATCH 15/16] Skip chosen node for now. --- app/boards/shields/kyria/kyria.dtsi | 1 - 1 file changed, 1 deletion(-) diff --git a/app/boards/shields/kyria/kyria.dtsi b/app/boards/shields/kyria/kyria.dtsi index 4efca8eb..59d0c487 100644 --- a/app/boards/shields/kyria/kyria.dtsi +++ b/app/boards/shields/kyria/kyria.dtsi @@ -10,7 +10,6 @@ chosen { zmk,kscan = &kscan0; zmk,matrix_transform = &default_transform; - zmk,sensors = <&left_encoder &right_encoder>; }; default_transform: keymap_transform_0 { From 3a508c42d0f408b42e58f119f4f0132a87203ad1 Mon Sep 17 00:00:00 2001 From: Pete Johanson Date: Tue, 21 Jul 2020 14:28:59 -0400 Subject: [PATCH 16/16] Trailing newline fix. --- app/boards/shields/kyria/kyria_left.overlay | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/boards/shields/kyria/kyria_left.overlay b/app/boards/shields/kyria/kyria_left.overlay index 29f648d7..c8b5be27 100644 --- a/app/boards/shields/kyria/kyria_left.overlay +++ b/app/boards/shields/kyria/kyria_left.overlay @@ -21,4 +21,4 @@ &left_encoder { status = "okay"; -}; \ No newline at end of file +};