From 068626d1a74d3883a8ccb2cd514a217098e99420 Mon Sep 17 00:00:00 2001 From: Kevin Date: Tue, 1 Sep 2020 21:12:09 -0700 Subject: [PATCH 1/5] Some work on encoder docs --- docs/docs/dev-guide-add-encoders.md | 53 +++++++++++++++++++++++++++++ docs/docs/feature/encoders.md | 36 +++++++++++++++++++- docs/sidebars.js | 5 ++- 3 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 docs/docs/dev-guide-add-encoders.md diff --git a/docs/docs/dev-guide-add-encoders.md b/docs/docs/dev-guide-add-encoders.md new file mode 100644 index 00000000..79f353f1 --- /dev/null +++ b/docs/docs/dev-guide-add-encoders.md @@ -0,0 +1,53 @@ +--- +id: dev-guide-add-encoders +title: Adding Encoders +--- + +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + +EC11 encoder support can be added to your board or shield by adding the appropriate lines to your board/shield's .conf, .dtsi, and .overlay files. + + + + +In your .conf file you will need to add the following lines so that the EC11 drivers can be enabled: + +``` +# Uncomment to enable encoder +# CONFIG_EC11=y +# CONFIG_EC11_TRIGGER_GLOBAL_THREAD=y +``` + +These should be commented by default if encoders are optional, but can be uncommented if encoders are part of the original design. + + + +In your .dtsi file you will need to add the following lines to define the encoder sensor: + + +``` +left_encoder: encoder_left { + compatible = "alps,ec11"; + label = "LEFT_ENCODER"; + a-gpios = ; + b-gpios = ; + resolution = <4>; + }; +``` +Here you will have to replace PIN_A and PIN_B with the appropriate pins that your PCB utilizes for the encoder(s). + +For keyboards that use the Pro Micro or any of the Pro Micro replacements, Sparkfun's [Pro Micro Hookup Guide](https://learn.sparkfun.com/tutorials/pro-micro--fio-v3-hookup-guide/hardware-overview-pro-micro) has a pinout diagram that can be useful to determine the right pins. Reference either the blue numbers labeled "Arduino" (digital pins) or the green numbers labeled "Analog" (analog pins). For pins that are labeled as both digital and analog, refer to your specific board's .dtsi file to determine how you should refer to that pin. + +Replace `left` with `right` to define a right-side encoder, although note that support for peripheral side sensors is still in progress. + + + + + diff --git a/docs/docs/feature/encoders.md b/docs/docs/feature/encoders.md index 16537ad7..9f583cb5 100644 --- a/docs/docs/feature/encoders.md +++ b/docs/docs/feature/encoders.md @@ -3,4 +3,38 @@ title: Encoders sidebar_label: Encoders --- -TODO: Documentation on encoders. +Existing support for encoders in ZMK is focused around the EC11 rotary encoder with push button design used in the majority of current keyboard and macropad designs. + +## Enabling EC11 Encoders + +To enable encoders for boards that have existing encoder support, uncomment the `EC11_CONFIG=y` and `CONFIG_EC11_TRIGGER_GLOBAL_THREAD=y` lines in your board's .conf file in your `zmk-config/config` folder. Save and push your changes, then download and flash the new firmware. + +## Customizing EC11 Encoder Behavior + +Encoder behavior in ZMK is configured in two different locations as the push button and rotation behaviors are handled in two separate ways. + +### Push Button + +Keyboards and macropads with encoder support will typically take the two EC11 pins responsible for the push button and include them as part of the matrix for the keys. To configure what is sent by the push button, find the encoder's position in the keyboard matrix and assign it a behavior the same as you would any other key. + +### Rotation + +Rotation is handled separately as a type of sensor. The behavior for this is set by defining `sensor-bindings` within a layer but below the `bindings` for the regular keys in the following format: + +``` +sensor-bindings = ; +``` + +- `BINDING` is one of two rotation bindings that are currently defined, `&inc_dec_cp` for consumer key presses or `&inc_dec_kp` for normal key presses (see [Key Press](<(/docs/behavior/key-press)>) for the difference between the two). +- `CW_KEY` is the keycode activated by a clockwise turn. +- `CCW_KEY` is the keycode activated by a counter-clockwise turn. + +Behaviors for additional encoders can be configured by adding more `BINDING CW_KEY CCW_KEY` sets immediately after the first. + +As an example, a complete `sensor-bindings` for a Kyria would look like: + +``` +sensor-bindings = <&inc_dec_cp M_VOLU M_VOLD &inc_dec_kp PGUP PGDN>; +``` + +In this example, the left encoder is configured to control volume up and down while the right encoder sends either Page Up or Page Down. diff --git a/docs/sidebars.js b/docs/sidebars.js index 53c5cf3d..924010ea 100644 --- a/docs/sidebars.js +++ b/docs/sidebars.js @@ -23,6 +23,9 @@ module.exports = { "dev-posix-board", "dev-tests", ], - "Dev Guides": ["dev-guide-new-shield", "dev-guide-usb-logging"], + "Dev Guides": [ + "dev-guide-new-shield", + "dev-guide-add-encoders", + "dev-guide-usb-logging"], }, }; From 6f74e61dd383f7b62280f230dafa66014800bd78 Mon Sep 17 00:00:00 2001 From: Kevin Date: Wed, 2 Sep 2020 18:25:46 -0700 Subject: [PATCH 2/5] Added user and dev encoder docs --- docs/docs/dev-guide-new-shield.md | 79 +++++++++++++++++++++++++++++++ docs/docs/feature/encoders.md | 14 ++++-- docs/sidebars.js | 1 - 3 files changed, 88 insertions(+), 6 deletions(-) diff --git a/docs/docs/dev-guide-new-shield.md b/docs/docs/dev-guide-new-shield.md index 8556623d..7825d8bb 100644 --- a/docs/docs/dev-guide-new-shield.md +++ b/docs/docs/dev-guide-new-shield.md @@ -3,6 +3,9 @@ id: dev-guide-new-shield title: New Keyboard Shield --- +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + ## Overview This guide will walk through the steps necessary to add ZMK support for a keyboard the uses a (Pro Micro compatible) addon MCU board to provide the microprocessor. @@ -13,6 +16,7 @@ The high level steps are: - Add the shield overlay file to define the [KSCAN driver]() for detecting key press/release. - (Optional) Add the matrix transform for mapping KSCAN row/column values to sane key positions. This is needed for non-rectangular keyboards, or where the underlying row/column pin arrangement does not map one to one with logical locations on the keyboard. - Add a default keymap, which users can override in their own configs as needed. +- Add support for features such as encoders, OLED displays, or RGB underglow. It may be helpful to review the upstream [shields documentation](https://docs.zephyrproject.org/2.3.0/guides/porting/shields.html#shields) to get a proper understanding of the underlying system before continuing. @@ -195,6 +199,81 @@ Further documentation on behaviors and bindings is forthcoming, but a summary of - `trans` is the "transparent" behavior, useful to be place in higher layers above `mo` bindings to be sure the key release is handled by the lower layer. No binding arguments are required. - `mt` is the "mod-tap" behavior, and takes two binding arguments, the modifier to use if held, and the keycode to send if tapped. +## Adding Features + +### Encoders + +EC11 encoder support can be added to your board or shield by adding the appropriate lines to your board/shield's configuration (.conf), device tree (.dtsi), and overlay (.overlay) files. + + + + +In your configuration file you will need to add the following lines so that the encoders can be enabled/disabled: + +``` +# Uncomment to enable encoder +# CONFIG_EC11=y +# CONFIG_EC11_TRIGGER_GLOBAL_THREAD=y +``` + +These should be commented by default for encoders that are optional/can be swapped with switches, but can be uncommented if encoders are part of the default design. + +:::note +If building locally for split boards, you may need to add these lines to the specific half's configuration file as well as the combined configuration file. +::: + + + +In your device tree file you will need to add the following lines to define the encoder sensor: + + +``` +left_encoder: encoder_left { + compatible = "alps,ec11"; + label = "LEFT_ENCODER"; + a-gpios = ; + b-gpios = ; + resolution = <4>; + }; +``` +Here you will have to replace PIN_A and PIN_B with the appropriate pins that your PCB utilizes for the encoder(s). For keyboards that use the Pro Micro or any of the Pro Micro replacements, Sparkfun's [Pro Micro Hookup Guide](https://learn.sparkfun.com/tutorials/pro-micro--fio-v3-hookup-guide/hardware-overview-pro-micro) has a pinout diagram that can be useful to determine the right pins. Reference either the blue numbers labeled "Arduino" (digital pins) or the green numbers labeled "Analog" (analog pins). For pins that are labeled as both digital and analog, refer to your specific board's .dtsi file to determine how you should refer to that pin. + +Add additional encoders as necessary by duplicating the above lines, replacing `left` with whatever you would like to call your encoder, and updating the pins. Note that support for peripheral (right) side sensors over BLE is still in progress. + +Once you have defined the encoder sensors, you will have to add them to the list of sensors: + +``` +sensors { + compatible = "zmk,keymap-sensors"; + sensors = <&left_encoder &right_encoder>; + }; +``` + +In this example, a left_encoder and right_encoder are both added. Additional encoders can be added with spaces separating each, and the order they are added here determines the order in which you define their behavior in your keymap. + + + +Add the following lines to your overlay file(s) to enable the encoder: + +``` +&left_encoder { + status = "okay"; +}; +``` + +:::note +For split keyboards, make sure to add left hand encoders to the left .overlay file and right hand encoders to the right .overlay file. +::: + + + + ## Testing Once you've fully created the new keyboard shield definition, diff --git a/docs/docs/feature/encoders.md b/docs/docs/feature/encoders.md index 9f583cb5..a5a796d8 100644 --- a/docs/docs/feature/encoders.md +++ b/docs/docs/feature/encoders.md @@ -3,7 +3,7 @@ title: Encoders sidebar_label: Encoders --- -Existing support for encoders in ZMK is focused around the EC11 rotary encoder with push button design used in the majority of current keyboard and macropad designs. +Existing support for encoders in ZMK is focused around the five pin EC11 rotary encoder with push button design used in the majority of current keyboard and macropad designs. ## Enabling EC11 Encoders @@ -19,7 +19,7 @@ Keyboards and macropads with encoder support will typically take the two EC11 pi ### Rotation -Rotation is handled separately as a type of sensor. The behavior for this is set by defining `sensor-bindings` within a layer but below the `bindings` for the regular keys in the following format: +Rotation is handled separately as a type of sensor. The behavior for this is set in `sensor-bindings`, which is defined in each keymap layer in the following format: ``` sensor-bindings = ; @@ -29,12 +29,16 @@ sensor-bindings = ; - `CW_KEY` is the keycode activated by a clockwise turn. - `CCW_KEY` is the keycode activated by a counter-clockwise turn. -Behaviors for additional encoders can be configured by adding more `BINDING CW_KEY CCW_KEY` sets immediately after the first. +Additional encoders can be configured by adding more `BINDING CW_KEY CCW_KEY` sets immediately after the first. -As an example, a complete `sensor-bindings` for a Kyria would look like: +As an example, a complete `sensor-bindings` for a Kyria with two encoders could look like: ``` sensor-bindings = <&inc_dec_cp M_VOLU M_VOLD &inc_dec_kp PGUP PGDN>; ``` -In this example, the left encoder is configured to control volume up and down while the right encoder sends either Page Up or Page Down. +Here, the left encoder is configured to control volume up and down while the right encoder sends either Page Up or Page Down. + +## Adding Encoder Support + +See the [New Keyboard Shield](docs/dev-guide-new-shield) documentation for how to add or modify additional encoders to your shield. diff --git a/docs/sidebars.js b/docs/sidebars.js index 924010ea..fb82dfa7 100644 --- a/docs/sidebars.js +++ b/docs/sidebars.js @@ -25,7 +25,6 @@ module.exports = { ], "Dev Guides": [ "dev-guide-new-shield", - "dev-guide-add-encoders", "dev-guide-usb-logging"], }, }; From 2629aa354f3d908e3afc13e3cd12a79974d77234 Mon Sep 17 00:00:00 2001 From: Kevin Date: Wed, 2 Sep 2020 18:28:00 -0700 Subject: [PATCH 3/5] Removed old dev encoder page --- docs/docs/dev-guide-add-encoders.md | 53 ----------------------------- 1 file changed, 53 deletions(-) delete mode 100644 docs/docs/dev-guide-add-encoders.md diff --git a/docs/docs/dev-guide-add-encoders.md b/docs/docs/dev-guide-add-encoders.md deleted file mode 100644 index 79f353f1..00000000 --- a/docs/docs/dev-guide-add-encoders.md +++ /dev/null @@ -1,53 +0,0 @@ ---- -id: dev-guide-add-encoders -title: Adding Encoders ---- - -import Tabs from '@theme/Tabs'; -import TabItem from '@theme/TabItem'; - -EC11 encoder support can be added to your board or shield by adding the appropriate lines to your board/shield's .conf, .dtsi, and .overlay files. - - - - -In your .conf file you will need to add the following lines so that the EC11 drivers can be enabled: - -``` -# Uncomment to enable encoder -# CONFIG_EC11=y -# CONFIG_EC11_TRIGGER_GLOBAL_THREAD=y -``` - -These should be commented by default if encoders are optional, but can be uncommented if encoders are part of the original design. - - - -In your .dtsi file you will need to add the following lines to define the encoder sensor: - - -``` -left_encoder: encoder_left { - compatible = "alps,ec11"; - label = "LEFT_ENCODER"; - a-gpios = ; - b-gpios = ; - resolution = <4>; - }; -``` -Here you will have to replace PIN_A and PIN_B with the appropriate pins that your PCB utilizes for the encoder(s). - -For keyboards that use the Pro Micro or any of the Pro Micro replacements, Sparkfun's [Pro Micro Hookup Guide](https://learn.sparkfun.com/tutorials/pro-micro--fio-v3-hookup-guide/hardware-overview-pro-micro) has a pinout diagram that can be useful to determine the right pins. Reference either the blue numbers labeled "Arduino" (digital pins) or the green numbers labeled "Analog" (analog pins). For pins that are labeled as both digital and analog, refer to your specific board's .dtsi file to determine how you should refer to that pin. - -Replace `left` with `right` to define a right-side encoder, although note that support for peripheral side sensors is still in progress. - - - - - From 5eb50d7b181d2c61099b49f74b1b54c996370914 Mon Sep 17 00:00:00 2001 From: Kevin Date: Wed, 2 Sep 2020 18:36:35 -0700 Subject: [PATCH 4/5] Fixed links --- docs/docs/feature/encoders.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/docs/feature/encoders.md b/docs/docs/feature/encoders.md index a5a796d8..38ff9d31 100644 --- a/docs/docs/feature/encoders.md +++ b/docs/docs/feature/encoders.md @@ -25,7 +25,7 @@ Rotation is handled separately as a type of sensor. The behavior for this is set sensor-bindings = ; ``` -- `BINDING` is one of two rotation bindings that are currently defined, `&inc_dec_cp` for consumer key presses or `&inc_dec_kp` for normal key presses (see [Key Press](<(/docs/behavior/key-press)>) for the difference between the two). +- `BINDING` is one of two rotation bindings that are currently defined, `&inc_dec_cp` for consumer key presses or `&inc_dec_kp` for normal key presses (see [Key Press](/docs/behavior/key-press) for the difference between the two). - `CW_KEY` is the keycode activated by a clockwise turn. - `CCW_KEY` is the keycode activated by a counter-clockwise turn. @@ -41,4 +41,4 @@ Here, the left encoder is configured to control volume up and down while the rig ## Adding Encoder Support -See the [New Keyboard Shield](docs/dev-guide-new-shield) documentation for how to add or modify additional encoders to your shield. +See the [New Keyboard Shield](/docs/dev-guide-new-shield) documentation for how to add or modify additional encoders to your shield. From e904a098b3ad2af28485e0f79287ac3b04947d1c Mon Sep 17 00:00:00 2001 From: Kevin Date: Wed, 2 Sep 2020 21:12:22 -0700 Subject: [PATCH 5/5] Added keymap update to encoder docs --- docs/docs/dev-guide-new-shield.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/docs/docs/dev-guide-new-shield.md b/docs/docs/dev-guide-new-shield.md index 7825d8bb..bc5175bf 100644 --- a/docs/docs/dev-guide-new-shield.md +++ b/docs/docs/dev-guide-new-shield.md @@ -203,7 +203,7 @@ Further documentation on behaviors and bindings is forthcoming, but a summary of ### Encoders -EC11 encoder support can be added to your board or shield by adding the appropriate lines to your board/shield's configuration (.conf), device tree (.dtsi), and overlay (.overlay) files. +EC11 encoder support can be added to your board or shield by adding the appropriate lines to your board/shield's configuration (.conf), device tree (.dtsi), overlay (.overlay), and keymap (.keymap) files. @@ -271,6 +272,15 @@ Add the following lines to your overlay file(s) to enable the encoder: For split keyboards, make sure to add left hand encoders to the left .overlay file and right hand encoders to the right .overlay file. ::: + + +Add the following line to your keymap file to add default encoder behavior bindings: + +``` +sensor-bindings = <&inc_dec_cp M_VOLU M_VOLD>; +``` +Add additional bindings as necessary to match the default number of encoders on your board. See the [Encoders](/docs/feature/encoders) and [Keymap](/docs/feature/keymaps) feature documentation for more details. +