From b44ec381f69233d1c2d32c6501189e4e339ff876 Mon Sep 17 00:00:00 2001
From: Seth Milliken <seth@araxia.net>
Date: Fri, 9 Feb 2024 01:02:49 -0800
Subject: [PATCH] feat(boards): add encoder support to planck

---
 app/boards/arm/planck/planck_rev6.dts       | 14 ++++++++++++++
 app/boards/arm/planck/planck_rev6.keymap    |  6 ++++++
 app/boards/arm/planck/planck_rev6.zmk.yml   |  1 +
 app/boards/arm/planck/planck_rev6_defconfig |  4 ++++
 4 files changed, 25 insertions(+)

diff --git a/app/boards/arm/planck/planck_rev6.dts b/app/boards/arm/planck/planck_rev6.dts
index b6f6fca4..5b8e16b2 100644
--- a/app/boards/arm/planck/planck_rev6.dts
+++ b/app/boards/arm/planck/planck_rev6.dts
@@ -44,6 +44,20 @@
             ;
     };
 
+    encoder: encoder {
+        compatible = "alps,ec11";
+        a-gpios = <&gpiob 12 GPIO_PULL_UP>;
+        b-gpios = <&gpiob 13 GPIO_PULL_UP>;
+        steps = <80>;
+        status = "disabled";
+    };
+
+    sensors: sensors {
+        compatible = "zmk,keymap-sensors";
+        sensors = <&encoder>;
+        triggers-per-rotation = <20>;
+    };
+
 layout_grid_transform:
     keymap_transform_0 {
         compatible = "zmk,matrix-transform";
diff --git a/app/boards/arm/planck/planck_rev6.keymap b/app/boards/arm/planck/planck_rev6.keymap
index 65138057..1386eadd 100644
--- a/app/boards/arm/planck/planck_rev6.keymap
+++ b/app/boards/arm/planck/planck_rev6.keymap
@@ -7,6 +7,11 @@
 #include <behaviors.dtsi>
 #include <dt-bindings/zmk/keys.h>
 
+/* Uncomment this block if using an encoder */
+//&encoder {
+//    status = "okay";
+//};
+
 / {
     keymap {
         compatible = "zmk,keymap";
@@ -23,6 +28,7 @@
                 &kp LSHFT &kp Z    &kp X &kp C &kp V &kp B  &kp N   &kp M  &kp COMMA &kp DOT &kp SLASH &kp RET
                 &trans   &kp LCTL &kp LALT &kp LGUI &mo 1 &trans &kp SPACE &mo 2 &kp LEFT &kp DOWN &kp UP &kp RIGHT
             >;
+            sensor-bindings = <&inc_dec_kp C_VOL_UP C_VOL_DN>;
         };
 
         lower {
diff --git a/app/boards/arm/planck/planck_rev6.zmk.yml b/app/boards/arm/planck/planck_rev6.zmk.yml
index 56c00006..f9d42424 100644
--- a/app/boards/arm/planck/planck_rev6.zmk.yml
+++ b/app/boards/arm/planck/planck_rev6.zmk.yml
@@ -5,6 +5,7 @@ type: board
 arch: arm
 features:
   - keys
+  - encoder
 outputs:
   - usb
 url: https://olkb.com/collections/planck
diff --git a/app/boards/arm/planck/planck_rev6_defconfig b/app/boards/arm/planck/planck_rev6_defconfig
index ce08f41d..f4530639 100644
--- a/app/boards/arm/planck/planck_rev6_defconfig
+++ b/app/boards/arm/planck/planck_rev6_defconfig
@@ -14,3 +14,7 @@ CONFIG_GPIO=y
 CONFIG_CLOCK_CONTROL=y
 
 CONFIG_ZMK_USB=y
+
+# Uncomment these two lines to add support for encoder to your firmware
+#CONFIG_EC11=y
+#CONFIG_EC11_TRIGGER_OWN_THREAD=y