Skip to content

Commit

Permalink
refactor zmk
Browse files Browse the repository at this point in the history
  • Loading branch information
tokyo2006 committed Feb 3, 2025
1 parent eada76e commit 5aa03b1
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 137 deletions.
6 changes: 4 additions & 2 deletions build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
include:
- board: nice_nano_v2
shield: cygnus_central_dongle
artifact-name: cygnus_central_dongle
snippet: studio-rpc-usb-uart
cmake-args: -DCONFIG_ZMK_STUDIO=y -DCONFIG_ZMK_STUDIO_LOCKING=n
artifact-name: cygnus_central_dongle
- board: nice_nano_v2
shield: cygnus_peripheral_left
artifact-name: cygnus_peripheral_left
- board: nice_nano_v2
shield: cygnus_peripheral_right
artifact-name: cygnus_peripheral_right
- board: nice_nano_v2
shield: settings_reset
shield: settings_reset
56 changes: 56 additions & 0 deletions config/boards/shields/cygnus/cygnus-layouts.dtsi
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include <physical_layouts.dtsi>

/ {
cygnus_layout: cygnus_layout {
compatible = "zmk,physical-layout";
display-name = "Layout";
transform = <&default_transform>;

keys // w h x y rot rx ry
= <&key_physical_attrs 100 100 0 50 0 0 0>
, <&key_physical_attrs 100 100 100 50 0 0 0>
, <&key_physical_attrs 100 100 200 12 0 0 0>
, <&key_physical_attrs 100 100 300 0 0 0 0>
, <&key_physical_attrs 100 100 400 12 0 0 0>
, <&key_physical_attrs 100 100 500 37 0 0 0>
, <&key_physical_attrs 100 100 1050 37 0 0 0>
, <&key_physical_attrs 100 100 1150 12 0 0 0>
, <&key_physical_attrs 100 100 1250 0 0 0 0>
, <&key_physical_attrs 100 100 1350 12 0 0 0>
, <&key_physical_attrs 100 100 1450 50 0 0 0>
, <&key_physical_attrs 100 100 1550 50 0 0 0>
, <&key_physical_attrs 100 100 750 37 0 0 0>
, <&key_physical_attrs 100 100 850 37 0 0 0>
, <&key_physical_attrs 100 100 0 150 0 0 0>
, <&key_physical_attrs 100 100 100 150 0 0 0>
, <&key_physical_attrs 100 100 200 112 0 0 0>
, <&key_physical_attrs 100 100 300 100 0 0 0>
, <&key_physical_attrs 100 100 400 112 0 0 0>
, <&key_physical_attrs 100 100 500 137 0 0 0>
, <&key_physical_attrs 100 100 1050 137 0 0 0>
, <&key_physical_attrs 100 100 1150 112 0 0 0>
, <&key_physical_attrs 100 100 1250 100 0 0 0>
, <&key_physical_attrs 100 100 1350 112 0 0 0>
, <&key_physical_attrs 100 100 1450 150 0 0 0>
, <&key_physical_attrs 100 100 1550 150 0 0 0>
, <&key_physical_attrs 100 100 0 250 0 0 0>
, <&key_physical_attrs 100 100 100 250 0 0 0>
, <&key_physical_attrs 100 100 200 212 0 0 0>
, <&key_physical_attrs 100 100 300 200 0 0 0>
, <&key_physical_attrs 100 100 400 212 0 0 0>
, <&key_physical_attrs 100 100 500 237 0 0 0>
, <&key_physical_attrs 100 100 1050 237 0 0 0>
, <&key_physical_attrs 100 100 1150 212 0 0 0>
, <&key_physical_attrs 100 100 1250 200 0 0 0>
, <&key_physical_attrs 100 100 1350 212 0 0 0>
, <&key_physical_attrs 100 100 1450 250 0 0 0>
, <&key_physical_attrs 100 100 1550 250 0 0 0>
, <&key_physical_attrs 100 100 400 362 0 0 0>
, <&key_physical_attrs 100 100 550 362 3000 500 362>
, <&key_physical_attrs 100 150 675 312 3000 500 362>
, <&key_physical_attrs 100 150 875 312 (-3000) 1150 362>
, <&key_physical_attrs 100 100 1000 362 (-3000) 1150 362>
, <&key_physical_attrs 100 100 1150 362 0 0 0>
;
};
};
7 changes: 4 additions & 3 deletions config/boards/shields/cygnus/cygnus.dtsi
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#include <dt-bindings/zmk/matrix_transform.h>
#include "cygnus-layouts.dtsi"

/ {

chosen {
zmk,kscan = &kscan0;
zmk,matrix_transform = &default_transform;
zmk,physical-layout = &cygnus_layout;
};

default_transform: keymap_transform_0 {
Expand All @@ -19,7 +20,7 @@
>;
};

kscan0: kscan {
kscan0: kscan {
compatible = "zmk,kscan-gpio-matrix";
label = "KSCAN";
diode-direction = "col2row";
Expand All @@ -31,4 +32,4 @@
;
};

};
};
3 changes: 2 additions & 1 deletion config/boards/shields/cygnus/cygnus_central_dongle.conf
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ CONFIG_ZMK_KSCAN_DEBOUNCE_RELEASE_MS=5
CONFIG_BT_CTLR_TX_PWR_PLUS_8=y
# 更改键盘默认显示名称
CONFIG_ZMK_KEYBOARD_NAME="Cygenus"
CONFIG_ZMK_MOUSE=y
CONFIG_ZMK_POINTING=y
CONFIG_PINCTRL=y
CONFIG_SPI=y
CONFIG_INPUT=y
Expand All @@ -37,3 +37,4 @@ CONFIG_PMW3610=y
CONFIG_PMW3610_SWAP_XY=y
CONFIG_PMW3610_INVERT_X=y
CONFIG_PMW3610_INVERT_Y=y
CONFIG_ZMK_POINTING_SMOOTH_SCROLLIN=y
119 changes: 13 additions & 106 deletions config/boards/shields/cygnus/cygnus_central_dongle.overlay
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,11 @@
*
* SPDX-License-Identifier: MIT
*/
#include <zephyr/dt-bindings/input/input-event-codes.h>
#include <input/processors.dtsi>
#include <dt-bindings/zmk/input_transform.h>
#include <input/processors.dtsi>
#include "cygnus.dtsi"
#define INPUT_EV_KEY 0x01 /**< Key event */
#define INPUT_EV_REL 0x02 /**< Relative coordinate event */
#define INPUT_EV_ABS 0x03 /**< Absolute coordinate event */
#define INPUT_EV_MSC 0x04 /**< Miscellaneous event */
#define INPUT_EV_VENDOR_START 0xf0 /**< Vendor specific event start */
#define INPUT_EV_VENDOR_STOP 0xff /**< Vendor specific event stop */

#define INPUT_REL_X 0x00 /**< Relative X coordinate */
#define INPUT_REL_Y 0x01 /**< Relative Y coordinate */
#define INPUT_REL_WHEEL 0x08 /**< Relative wheel coordinate */
#define INPUT_REL_HWHEEL 0x06 /**< Relative horizontal wheel coordinate */
#define INPUT_REL_MISC 0x09 /**< Relative misc coordinate */


&default_transform {
Expand Down Expand Up @@ -55,6 +47,11 @@
status = "disabled";
};

zephyr_udc0: &usbd {
compatible = "nordic,nrf-usbd";
status = "okay";
};

&spi1 {
compatible = "nordic,nrf-spim";
status = "okay";
Expand All @@ -76,100 +73,10 @@
};
};


/{
trackball_listener {
/ {
trackball_listener: trackball_listener {
compatible = "zmk,input-listener";
status = "okay";
device = <&pd0>;
};
};


/{
/* auto toggle mouse key layer */
trackball_auto_mouse_listener {
compatible = "zmk,input-behavior-listener";
device = <&pd0>;
layers = <0>;
evt-type = <INPUT_EV_REL>;
x-input-code = <INPUT_REL_X>;
y-input-code = <INPUT_REL_Y>;
scale-multiplier = <1>;
scale-divisor = <1>;
bindings = <&ib_tog_layer 4>;
};

/* input config for mouse scroll mode on momentary mouse scoll layer */
trackball_scroll_listener {
compatible = "zmk,input-behavior-listener";
device = <&pd0>;
layers = <2>;
evt-type = <INPUT_EV_REL>;
/* slienting x-axis with alt event code */
x-input-code = <INPUT_REL_MISC>;
y-input-code = <INPUT_REL_WHEEL>;
/* invent scrolling direction */
y-invert;
/* align to CCW 180 degree */
rotate-deg = <180>;
/* scale-multiplier = <1>; */
scale-divisor = <8>;
/* NOTE 1: This settings do not compitable with y-invert and x-invert */
/* NOTE 2: Floating point computation requires alot of ram. */
/* This feature will cuase stackove flow with CONFIG_ZMK_USB_LOGGING=y *
/* bind a behavior to down scaling input value to (1/8) */
/* NOTE: This behavior is different to scale-divisor. */
/* The delta value is accumlated until result >= 1 after cast. */
/* The scrolling is preented in hi-res and allow precise scrolling */
bindings = <&ib_wheel_scaler_x 1 64>;
};

trackball_peripheral_snipe_listener {
compatible = "zmk,input-behavior-listener";
device = <&pd0>;
layers = <3>;
evt-type = <INPUT_EV_REL>;
x-input-code = <INPUT_REL_X>;
y-input-code = <INPUT_REL_Y>;
scale-multiplier = <1>;
scale-divisor = <1>;
/*rotate-deg = <315>;*/
bindings = <&ib_snipe_scaler_x 1 8 &ib_snipe_scaler_y 1 8>;
};

/* adjust cooldown waiting period for mouse key layer (MSK) after activated */
ib_tog_layer: ib_tog_layer {
compatible = "zmk,input-behavior-tog-layer";
#binding-cells = <1>;
time-to-live-ms = <2000>;
};

/* define a resolution down scaler only for INPUT_REL_WHEEL */
ib_wheel_scaler_x: ib_wheel_scaler_x {
compatible = "zmk,input-behavior-scaler";
#binding-cells = <2>;
evt-type = <INPUT_EV_REL>;
input-code = <INPUT_REL_WHEEL>;
};

ib_wheel_scaler_y: ib_wheel_scaler_y {
compatible = "zmk,input-behavior-scaler";
#binding-cells = <2>;
evt-type = <INPUT_EV_REL>;
input-code = <INPUT_REL_HWHEEL>;
};

ib_snipe_scaler_x: ib_snipe_scaler_x {
compatible = "zmk,input-behavior-scaler";
#binding-cells = <2>;
evt-type = <INPUT_EV_REL>;
input-code = <INPUT_REL_X>;
};

ib_snipe_scaler_y: ib_snipe_scaler_y {
compatible = "zmk,input-behavior-scaler";
#binding-cells = <2>;
evt-type = <INPUT_EV_REL>;
input-code = <INPUT_REL_Y>;
};
};
};
6 changes: 0 additions & 6 deletions config/boards/shields/cygnus/cygnus_peripheral_left.overlay
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,3 @@
, <&pro_micro 5 GPIO_ACTIVE_HIGH>
;
};

/ {
trackball: dummy_trackball {
compatible = "zmk,virtual-input";
};
};
6 changes: 0 additions & 6 deletions config/boards/shields/cygnus/cygnus_peripheral_right.overlay
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,3 @@

;
};

/ {
trackball: dummy_trackball {
compatible = "zmk,virtual-input";
};
};
6 changes: 3 additions & 3 deletions config/cygnus.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
{ "row": 0, "col": 9, "x": 15, "y": 0.75, "label": "0\n11" },
{ "row": 0, "col": 10, "x": 16, "y": 1.13, "label": "0\n12" },
{ "row": 0, "col": 11, "x": 17, "y": 1.13, "label": "0\n13" },

{ "row": 0, "col": 12, "x": 9, "y": 1, "label": "0\n5" },
{ "row": 0, "col": 13, "x": 10, "y": 1, "label": "0\n5" },
{ "row": 1, "col": 0, "x": 1.5, "y": 2.13, "label": "1\n0" },
{ "row": 1, "col": 1, "x": 2.5, "y": 2.13, "label": "1\n1" },
{ "row": 1, "col": 2, "x": 3.5, "y": 1.75, "label": "1\n2" },
Expand All @@ -30,7 +31,6 @@
{ "row": 1, "col": 9, "x": 15, "y": 1.75, "label": "1\n11" },
{ "row": 1, "col": 10, "x": 16, "y": 2.13, "label": "1\n12" },
{ "row": 1, "col": 11, "x": 17, "y": 2.13, "label": "1\n13" },

{ "row": 2, "col": 0, "x": 1.5, "y": 3.13, "label": "2\n0" },
{ "row": 2, "col": 1, "x": 2.5, "y": 3.13, "label": "2\n1" },
{ "row": 2, "col": 2, "x": 3.5, "y": 2.75, "label": "2\n2" },
Expand All @@ -53,4 +53,4 @@
}
},
"sensors": []
}
}
55 changes: 53 additions & 2 deletions config/cygnus.keymap
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,63 @@
* SPDX-License-Identifier: MIT
*/

#include <behaviors/mouse_keys.dtsi>
#define ZMK_POINTING_DEFAULT_MOVE_VAL 1200 // 600
#define ZMK_POINTING_DEFAULT_SCRL_VAL 35 // 10
#include <input/processors.dtsi>
#include <behaviors.dtsi>
#include <dt-bindings/zmk/bt.h>
#include <dt-bindings/zmk/keys.h>
#include <dt-bindings/zmk/mouse.h>
#include <dt-bindings/zmk/outputs.h>
#include <dt-bindings/zmk/pointing.h>
#include <dt-bindings/zmk/ext_power.h>
#include <zephyr/dt-bindings/input/input-event-codes.h>

#define SCROLLER 1
#define MOUSE 4

/ {
zip_scroll_scaler: zip_scroll_scaler {
compatible = "zmk,input-processor-scaler";
#input-processor-cells = <2>;
type = <INPUT_EV_REL>;
codes = <INPUT_REL_WHEEL INPUT_REL_HWHEEL>;
track-remainders;
};
};

&mmv_input_listener {
input-processors = <&zip_xy_scaler 2 1>;
};

&msc_input_listener {
input-processors = <&zip_scroll_scaler 2 1>;
};

&msc {
acceleration-exponent = <0>; // 0
time-to-max-speed-ms = <0>; // 300
delay-ms = <0>; // 0
};

&mmv {
time-to-max-speed-ms = <400>;
acceleration-exponent = <1>;
};

&trackball_listener {
scroller {
layers = <SCROLLER>;
input-processors =
<&zip_xy_transform INPUT_TRANSFORM_Y_INVERT>,
<&zip_xy_scaler 1 10>,
<&zip_xy_to_scroll_mapper>;
};

snipe {
layers = <MOUSE>;
input-processors = <&zip_xy_scaler 1 3>;
};
};

&mt {
tapping-term-ms = <200>;
Expand Down
10 changes: 2 additions & 8 deletions config/west.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
manifest:
remotes:
- name: zmkfirmware
url-base: https://github.com/petejohanson
url-base: https://github.com/zmkfirmware
- name: badjeff
url-base: https://github.com/badjeff
projects:
- name: zmk
remote: zmkfirmware
revision: feat/pointers-move-scroll
revision: main
import: app/west.yml
- name: zmk-pmw3610-driver
remote: badjeff
revision: main
- name: zmk-split-peripheral-input-relay
remote: badjeff
revision: main
- name: zmk-input-behavior-listener
remote: badjeff
revision: main
self:
path: config

0 comments on commit 5aa03b1

Please sign in to comment.