diff --git a/boards/shields/anglerfish/Kconfig.defconfig b/boards/shields/anglerfish/Kconfig.defconfig index 1ec604b..bba44c7 100644 --- a/boards/shields/anglerfish/Kconfig.defconfig +++ b/boards/shields/anglerfish/Kconfig.defconfig @@ -1,7 +1,7 @@ if SHIELD_ANGLERFISH_RIGHT config ZMK_KEYBOARD_NAME - default "anglerfish" + default "anglerfish-tb" config ZMK_SPLIT_ROLE_CENTRAL default y diff --git a/boards/shields/anglerfish/anglerfish.conf b/boards/shields/anglerfish/anglerfish.conf index bc2adab..9f1be77 100644 --- a/boards/shields/anglerfish/anglerfish.conf +++ b/boards/shields/anglerfish/anglerfish.conf @@ -5,8 +5,4 @@ CONFIG_ZMK_IDLE_SLEEP_TIMEOUT=900000 CONFIG_ZMK_BATTERY_REPORTING=y CONFIG_ZMK_LOGGING_MINIMAL=y -CONFIG_PS2_LOG_LEVEL_DBG=n -CONFIG_UART_LOG_LEVEL_DBG=n -CONFIG_LOG_MODE_IMMEDIATE=n CONFIG_LOG_PROCESS_THREAD_STARTUP_DELAY_MS=3000 - diff --git a/boards/shields/anglerfish/anglerfish.dtsi b/boards/shields/anglerfish/anglerfish.dtsi index c0c0953..89c80ea 100644 --- a/boards/shields/anglerfish/anglerfish.dtsi +++ b/boards/shields/anglerfish/anglerfish.dtsi @@ -30,184 +30,8 @@ <&pro_micro 21 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>, <&pro_micro 9 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>; }; - }; + &pro_micro_i2c { status = "disabled"; }; -/* - * PS/2 Mouse / Trackpoint - */ - -// Configure the SCL and SDA pins of the PS/2 mouse/tp using the `&pro_micro` -// notation. -// -// If possible, try to choose the blue high frequency pins to avoid -// bluetooth interference. -// -// On the nice!nano documentation these are green DX pins: -// https://nicekeyboards.com/docs/nice-nano/pinout-schematic -// -// Clock pin P0.24 -#define MOUSE_PS2_PIN_SCL_PRO_MICRO <&pro_micro 5 GPIO_ACTIVE_HIGH> -// Data pin P0.11. -#define MOUSE_PS2_PIN_SDA_PRO_MICRO <&pro_micro 7 GPIO_ACTIVE_HIGH> - - -// Uncomment and configure this pin if you have an extra free pin and want the -// controller to perform the Power-On-Reset sequence, which many trackpoints -// require, instead of using a trackpoint reset circuit. -// -// It's ok to use a low-frequency pin for this. -#define MOUSE_PS2_PIN_RST_PRO_MICRO <&pro_micro 6 GPIO_ACTIVE_HIGH> - - -// Now configure the same SDA pin using the pinctrl notation. -// -// For that you have to use the PX.XX notation of the nrf52 chip. -// -// On the nice!nano pinout they are shown in blue and purple next to the green -// DX pin. -// -// Enter it like `X, Y` without leading zeroes. -// Examples: -// D0 - P0.08: 0, 8 -// D15 - P1.13: 1, 13 -// -// We don't define the SCL pin, because UART uses a baud rate instead of -// a clock pin. -#define MOUSE_PS2_PIN_SDA_PINCTRL - - -// In UART two different pins are used for receiving and transmitting, but PS/2 -// uses the same pin for both. -// -// The UART config still requires both pins to be configured. So we use one of -// the nrf52 pins that are not exposed on the nice!nano board. -#define MOUSE_PS2_PIN_UNEXPOSED_TX -#define MOUSE_PS2_PIN_UNEXPOSED_RX - - -// The PS/2 GPIO driver -/ { - gpio_ps2: gpio_ps2 { - status = "disabled"; - compatible = "gpio-ps2"; - scl-gpios = MOUSE_PS2_PIN_SCL_PRO_MICRO; - sda-gpios = MOUSE_PS2_PIN_SDA_PRO_MICRO; - }; -}; - - -&pinctrl { - // This pinctrl state is used for receiving - // For `UART_TX`, set an unused and unexposed pin - // For `UART_RX`, set the PS/2 SDA pin number - uart0_ps2_default: uart0_ps2_default { - group1 { - psels = MOUSE_PS2_PIN_UNEXPOSED_TX, - MOUSE_PS2_PIN_SDA_PINCTRL; - }; - }; - - // Set this to the same pins as uart0_ps2_default - uart0_ps2_sleep: uart0_ps2_sleep { - group1 { - psels = MOUSE_PS2_PIN_UNEXPOSED_TX, - MOUSE_PS2_PIN_SDA_PINCTRL; - low-power-enable; - }; - }; - - // The nrf52 UART controller is not compatible with the PS/2 - // transmission frame. So we don't use UART for transmissions - // and instead use GPIO bitbanging. - // - // When we switch to transmit mode, we free up the SDA pin by switching - // UART to unexposed/unused pins. - // - // Then we can configure the pins to be used with the GPIO controller. - uart0_ps2_off: uart0_ps2_off { - group1 { - psels = MOUSE_PS2_PIN_UNEXPOSED_TX, - MOUSE_PS2_PIN_UNEXPOSED_RX; - }; - }; -}; - - -&uart0 { - status = "disabled"; - compatible = "nordic,nrf-uarte"; - - // PS/2 uses a clock pin to syncronize data transmissions. UART on the - // other hand uses a pre-defined frequency (baud rate). - // - // Fortunately, one of the available baud rates is very close to the - // frequency used in IBM/Lenovo trackpoints. - // - // You can find other configurable baud rates here: - // https://docs.zephyrproject.org/latest/build/dts/api/bindings/serial/nordic,nrf-uarte.html - // - // But most likely you won't need to adjust this. - // - // You can measure the frequency of your mouse/TP using a $5 logic - // analyzer from AliExpress. - // - // Actual frequency of PS/2 trackpoint: 67us - // Correspondent baud rate: 14,925 - // - // Closest available baud rate in zephyr: 14,400 - // Correspondent cycle length: 69.44 microseconds - // - // Calculations: - // - // Convert cycle length in microseconds into baud: - // 1 / PS2_CYCLE_LENGTH * 1000000 = BAUD - // 1 / 67 * 1000000 = 14,925 BAUD - // - // Convert baud into cycle length: - // 1 / BAUD * 1000000 = CYCLE_LEN (in microseconds) - // 1 / 14400 * 1000000 = 69.44 - // - current-speed = <14400>; - pinctrl-0 = <&uart0_ps2_default>; - pinctrl-1 = <&uart0_ps2_off>; - - pinctrl-names = "default", "sleep"; - - uart_ps2: uart_ps2 { - status="disabled"; - compatible = "uart-ps2"; - scl-gpios = MOUSE_PS2_PIN_SCL_PRO_MICRO; - sda-gpios = MOUSE_PS2_PIN_SDA_PRO_MICRO; - }; -}; - - -/ { - mouse_ps2: mouse_ps2 { - status = "disabled"; - compatible = "zmk,input-mouse-ps2"; - - // This will be overriden in your `xxx_right.overlay file`. - // ps2-device = <&gpio_ps2>; - ps2-device = <&uart_ps2>; - -#ifdef MOUSE_PS2_PIN_RST_PRO_MICRO - rst-gpios = MOUSE_PS2_PIN_RST_PRO_MICRO; -#endif - }; - - mouse_ps2_input_listener: mouse_ps2_input_listener { - compatible = "zmk,input-listener"; - status = "disabled"; - - device = <&mouse_ps2>; - - // Some of the available settings depend on the keymap. So they - // are adjusted in... - // ../../../includes/trackpoint.dtsi - }; -}; - diff --git a/boards/shields/anglerfish/anglerfish_right.overlay b/boards/shields/anglerfish/anglerfish_right.overlay index d54297c..ffdfd5e 100644 --- a/boards/shields/anglerfish/anglerfish_right.overlay +++ b/boards/shields/anglerfish/anglerfish_right.overlay @@ -12,261 +12,50 @@ <&pro_micro 18 GPIO_ACTIVE_HIGH>; }; -/* - * PS/2 Mouse / Trackpoint - */ - -// Enable PS/2 drivers on this side of the keyboard. -// MUST be the central. -// -// Comment out the following define to use the GPIO driver instead of UART -// (this is not recommended unless you can't use the UART driver for whatever -// reason) -#define MOUSE_PS2_DRIVER_UART - -#ifdef MOUSE_PS2_DRIVER_UART - &uart0 { - status = "okay"; - }; - &uart_ps2 { - status = "okay"; - }; -#else - &gpio_ps2 { - status = "okay"; +&pinctrl { + spi0_default: spi0_default { + group1 { + psels = , + , + ; + }; }; -#endif - -&mouse_ps2 { - status = "okay"; - -#ifdef MOUSE_PS2_DRIVER_UART - ps2-device = <&uart_ps2>; -#else - ps2-device = <&gpio_ps2>; -#endif -}; - -&mouse_ps2_input_listener { - status = "okay"; - - // Some of the available settings depend on the keymap. So they - // are adjusted in... - // ../../../includes/trackpoint.dtsi -}; - -// Adjust GPIO interrupt priority to the highest level. -// -// PS/2 events must be processed within 30-50us, but frequently bluetooth and -// other interrupts take longer to finish. -// -// Therefore we change the default GPIO priority to the highest level (0) and -// demote all BT interrupt priorities by one level using the kconfig settings: -// - CONFIG_BT_CTLR_LLL_PRIO 1 -// - CONFIG_BT_CTLR_ULL_HIGH_PRIO 2 -// - CONFIG_BT_CTLR_ULL_LOW_PRIOCONFIG 2 -// -// These config options are enabled automatically by the PS2 UART and GPIO -// drivers... so you don't have to enable them manually. -// -// Then we lower the interrupt priority of all other devices by 2 levels using -// the devicetree config below. -// -// This allows the PS/2 interrupts to be triggered faster and reduces -// transmission errors. -// -// If you are using the nice_nano_v2 board, you can reuse my config below. -// -// Otherwise, you can generate the interrupt overrides using the following -// script in my zmk fork with the PS/2 mouse driver: -// app/scripts/gen_interrupt_priority_overrides.py -// -// Make sure to do it on a zephyr.dts where the interrupts have not been -// adjusted yet (i.e. a config that doesn't have the the following options -// enabled). -// -// If you are building using a toolchain you can find the zephyr.dts in the -// build directory, which by default is: `app/build/zephyr/zephyr.dts` -// -// If you are building using the github actions, copy the output of the build -// step `xxxx_right - nice_nano_v2 Devicetree file` into a file and run the -// script on it. - -// gpiote should have the highest interrupt priority (0) -&gpiote { - interrupts = < 6 0 >; -}; - -// All other priorities should be two levels lower than their defaults -// (which is usually 1 and should be demoted to 3) -&clock { - interrupts = < 0 3 >; -}; - -&power { - interrupts = < 0 3 >; -}; - -&radio { - interrupts = < 1 3 >; -}; - -&uart0 { - interrupts = < 2 3 >; -}; -&i2c0 { - interrupts = < 3 3 >; + spi0_sleep: spi0_sleep { + group1 { + psels = , + , + ; + low-power-enable; + }; + }; }; &spi0 { - interrupts = < 3 3 >; -}; - -&i2c1 { - interrupts = < 4 3 >; -}; - -&spi1 { - interrupts = < 4 3 >; -}; - -&nfct { - interrupts = < 5 3 >; -}; - -&adc { - interrupts = < 7 3 >; -}; - -&timer0 { - interrupts = < 8 3 >; -}; - -&timer1 { - interrupts = < 9 3 >; -}; - -&timer2 { - interrupts = < 10 3 >; -}; - -&rtc0 { - interrupts = < 11 3 >; -}; - -&temp { - interrupts = < 12 3 >; -}; - -&rng { - interrupts = < 13 3 >; -}; - -&ecb { - interrupts = < 14 3 >; -}; - -&ccm { - interrupts = < 15 3 >; -}; - -&wdt { - interrupts = < 16 3 >; -}; - -&rtc1 { - interrupts = < 17 3 >; -}; - -&qdec { - interrupts = < 18 3 >; -}; - -&comp { - interrupts = < 19 3 >; -}; - -&egu0 { - interrupts = < 20 3 >; -}; - -&egu1 { - interrupts = < 21 3 >; -}; - -&egu2 { - interrupts = < 22 3 >; -}; - -&egu3 { - interrupts = < 23 3 >; -}; - -&egu4 { - interrupts = < 24 3 >; -}; - -&egu5 { - interrupts = < 25 3 >; -}; - -&timer3 { - interrupts = < 26 3 >; -}; - -&timer4 { - interrupts = < 27 3 >; -}; - -&pwm0 { - interrupts = < 28 3 >; -}; - -&pdm0 { - interrupts = < 29 3 >; -}; - -&pwm1 { - interrupts = < 33 3 >; -}; - -&pwm2 { - interrupts = < 34 3 >; -}; - -&spi2 { - interrupts = < 35 3 >; -}; - -&rtc2 { - interrupts = < 36 3 >; -}; - -&i2s0 { - interrupts = < 37 3 >; -}; - -&usbd { - interrupts = < 39 3 >; -}; - -&uart1 { - interrupts = < 40 3 >; -}; - -&qspi { - interrupts = < 41 3 >; -}; - -&pwm3 { - interrupts = < 45 3 >; -}; + status = "okay"; + compatible = "nordic,nrf-spim"; + pinctrl-0 = <&spi0_default>; + pinctrl-1 = <&spi0_sleep>; + pinctrl-names = "default", "sleep"; + cs-gpios = <&gpio0 9 GPIO_ACTIVE_LOW>; -&spi3 { - interrupts = < 47 3 >; + trackball: trackball@0 { + status = "okay"; + compatible = "pixart,pmw3610"; + reg = <0>; + spi-max-frequency = <2000000>; + irq-gpios = <&gpio0 6 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>; + + /* optional features */ + // snipe-layers = <1>; + // scroll-layers = <2 3>; + // automouse-layer = <4>; + }; }; -&cryptocell { - interrupts = < 42 3 >; +/ { + trackball_listener { + compatible = "zmk,input-listener"; + device = <&trackball>; + }; }; diff --git a/config/anglerfish.conf b/config/anglerfish.conf index 459bec3..88ccd24 100644 --- a/config/anglerfish.conf +++ b/config/anglerfish.conf @@ -1,6 +1,6 @@ +CONFIG_INPUT=y +CONFIG_PMW3610=y +CONFIG_SPI=y CONFIG_ZMK_BATTERY_REPORTING=y CONFIG_ZMK_BLE_EXPERIMENTAL_CONN=y -# Enable additional error mitigations to prevent cursor jumps -# Disabled by default and only recommended if using the GPIO PS2 driver -# CONFIG_ZMK_INPUT_MOUSE_PS2_ENABLE_ERROR_MITIGATION=n - +CONFIG_ZMK_MOUSE=y diff --git a/config/anglerfish.keymap b/config/anglerfish.keymap index bad4a9f..c543162 100644 --- a/config/anglerfish.keymap +++ b/config/anglerfish.keymap @@ -1,7 +1,6 @@ #include #include #include -#include #include #define VBASE 0 @@ -11,13 +10,6 @@ #define VBLTH 4 #define VFUNC 5 -#define HAS_MOUSE_KEYS -#define HAS_MOUSE_TP - -// Trackpoint includes -#include "includes/mouse_keys.dtsi" -#include "includes/mouse_tp.dtsi" - / { behaviors { hml: hml { @@ -198,9 +190,9 @@ nav { bindings = < // ╭───────────────┬─────────────┬────────────────┬─────────────────┬──────────────╮ ╭──────────────┬────────────────┬────────────────┬────────────────┬─────────────────╮ - &trans &trans &mkp RCLK &mkp LCLK &trans U_MSS_TP_S_I U_MSS_TP_V6_I U_MSS_TP_V6_D &trans U_MSS_RESET + &none &none &none &none &trans &none &none &none &trans &none // ├───────────────┼─────────────┼────────────────┼─────────────────┼──────────────┤ ├──────────────┼────────────────┼────────────────┼────────────────┼─────────────────┤ - &kp LGUI &kp LALT &kp LCTRL &kp LSHFT &trans U_MSS_TP_S_D &kp LEFT &kp DOWN &kp UP &kp RIGHT + &kp LGUI &kp LALT &kp LCTRL &kp LSHFT &trans &none &kp LEFT &kp DOWN &kp UP &kp RIGHT // ├───────────────┼─────────────┼────────────────┼─────────────────┼──────────────┤ ├──────────────┼────────────────┼────────────────┼────────────────┼─────────────────┤ &trans &trans &kp RG(K_COPY) &kp K_PASTE &trans &trans &kp HOME &kp END &kp PAGE_DOWN &kp PAGE_UP // ╰───────────────┴─────────────┴────────────────┼─────────────────┼──────────────┤ ├──────────────┼────────────────┼────────────────┴────────────────┴─────────────────╯ diff --git a/config/includes/mouse_keys.dtsi b/config/includes/mouse_keys.dtsi deleted file mode 100644 index 0830097..0000000 --- a/config/includes/mouse_keys.dtsi +++ /dev/null @@ -1,16 +0,0 @@ -#ifdef HAS_MOUSE_KEYS - #include - #include -#endif - - -// Below are settings and behavior defines for mouse keys. -&mmv { - acceleration-exponent = <1>; // Default: 1 - time-to-max-speed-ms = <300>; // Default: 300 -}; - -&msc { - acceleration-exponent = <0>; // Default: 0 - time-to-max-speed-ms = <300>; // Default: 300 -}; diff --git a/config/includes/mouse_tp.dtsi b/config/includes/mouse_tp.dtsi deleted file mode 100644 index 203170b..0000000 --- a/config/includes/mouse_tp.dtsi +++ /dev/null @@ -1,143 +0,0 @@ -#ifdef HAS_MOUSE_TP - #include - #include - - /* - * Key Behaviors to adjust settings - */ - - // They key codes below can be used to adjust the TP settings at runtime - // without needing to recompile the firmware. - // - // The values will be logged and saved in the config on the controller flash - // after 60s (CONFIG_ZMK_SETTINGS_SAVE_DEBOUNCE). - // - // On boot the settings will be restored again. - // - // If you prefer a more explicit way of configuration, you can also hardcode - // these settings in `&mouse_ps2`. - // - // If you set these settings in `&mouse_ps2`, you will still be able to - // adjust the values during runtime with these key codes, but after - // restarting the board the values in `&mouse_ps2` will be restored and not - // the ones stored in the flash using the key codes. - - - // How sensitive the trackpoint is - #define U_MSS_TP_S_I &mms MS_TP_SENSITIVITY_INCR - #define U_MSS_TP_S_D &mms MS_TP_SENSITIVITY_DECR - - - // The maximum speed the trackpoint will accelerate to - #define U_MSS_TP_V6_I &mms MS_TP_VALUE6_INCR - #define U_MSS_TP_V6_D &mms MS_TP_VALUE6_DECR - - - // I am not quite sure tbh... default seems fine. - #define U_MSS_TP_NI_I &mms MS_TP_NEG_INERTIA_INCR - #define U_MSS_TP_NI_D &mms MS_TP_NEG_INERTIA_DECR - - - // How hard you have to press to activate the "Press To Select" feature that - // lets you tap or press on the trackpoint to click. - // - // Not all trackpoints support it and you have to enable - // `tp-press-to-select;` in `&mouse_ps2` first. - #define U_MSS_TP_PT_I &mms MS_TP_PTS_THRESHOLD_INCR - #define U_MSS_TP_PT_D &mms MS_TP_PTS_THRESHOLD_DECR - - - // If you mess up the settings, you can use this key code to clear the - // settings from flash and re-set the default values on the TP. - // - // Make sure to wait at least CONFIG_ZMK_SETTINGS_SAVE_DEBOUNCE seconds (60 - // by default) before restarting the board to ensure the settings are - // written to flash storage. - #define U_MSS_RESET &mms MS_RESET - - - // If you prefer to set the settings in `&mouse_ps2`, you can use the key - // codes above to find the settings you like the most and then press this - // key code to output the settings to the log. - // - // Then you can add those values to `&mouse_ps2` - #define U_MSS_LOG &mms MS_LOG - - - /* - * Driver-specific configuration - */ - - &mouse_ps2 { - // Enables scroll wheel on mouse devices supporting the Intellimouse - // extension. - // scroll-mode; - - - // Disables clicking. Useful when using a PS2 driver that is prone to - // erros in transmissions to reduce accidental clicks. - // disable-clicking; - - // The frequency at which the mouse samples and sends data (in hz). - // The default rate is 100. You can try lowering it if you experience - // connection errors. - // - // Higher values than 100 are no improvement in my experience, but will - // increase battery life and potentially errors in transmissions. - // - // These values are allowed: 10,20,40,60,80,100,200 - // sampling-rate = <60>; - - - // Enable clicking by tapping on the TP. Not all TPs support this. - // tp-press-to-select; - // tp-press-to-select-threshold = <10>; - - - // How sensitive the TP is (Default: 128) - tp-sensitivity = <135>; - - - // The maximum mouse movement speed the TP will accelarate to (Default: 97) - tp-val6-upper-speed = <182>; - - - // Not quite sure what it does tbh :) (Default: 6) - tp-neg-inertia = <6>; - - - // Adjusts axis settings on the TP - // Works only on some trackpoints, but may be properly considered by the - // trackpoint's acceleration features (which may or may not have an - // impact). Alternatively consider achieving the same effect using the - // `zmk,input-configs` feature. - // tp-xy-swap; - // tp-x-invert; - // tp-y-invert; - - }; - - /* - * Input Config - */ - - &mouse_ps2_input_listener { - xy-swap; - x-invert; - y-invert; - - // Set the layer that should automatically activate when the mouse is - // moving. - layer-toggle = ; - - // How long the mouse needs to move for before the layer is activated (to - // avoid accidental activations while typing) (Default: 250) - layer-toggle-delay-ms = <250>; - - // How long to wait, after the last mouse movement, before deactivating - // the layer (Default: 250) - layer-toggle-timeout-ms = <250>; - }; - - -#endif diff --git a/config/west.yml b/config/west.yml index e935c45..1390ea2 100644 --- a/config/west.yml +++ b/config/west.yml @@ -1,15 +1,16 @@ manifest: remotes: - name: zmkfirmware - url-base: https://github.com/zmkfirmware - - name: urob - url-base: https://github.com/urob - - name: infused-kim - url-base: https://github.com/infused-kim + url-base: https://github.com/petejohanson + - name: inorichi + url-base: https://github.com/inorichi projects: - name: zmk - remote: infused-kim - revision: pr-testing/mouse_ps2_v2 + remote: zmkfirmware + revision: feat/pointers-move-scroll import: app/west.yml + - name: zmk-pmw3610-driver + remote: inorichi + revision: main self: path: config