feat(mouse): Add PS/2 mouse/trackpoint/etc support

PS2 GPIO: Added initial structure

PS2 GPIO: Added interrupt handler and pin reading/writing helper functions

PS2 GPIO: Added reading mode

PS2 GPIO: Add zephyr PS2 API support for callback and read function

PS2 GPIO: Fix reading not working with real PS2 device

PS2 GPIO: Added write with separate edge rising callback

PS2 GPIO: Made single interrupt handler

PS2 GPIO: Switch to inactive and falling handler only

PS2 GPIO: Switch back to edge falling

PS2 GPIO: Working without writing

PS2 GPIO: Enable both edges (working)

PS2 GPIO: Somewhat working write

PS2 GPIO: Write with ack working, but read always wrong stop bit

PS2 GPIO: Cleanup code

PS2 GPIO: Fix write not working by increasing clock holding time

PS2 GPIO: Adde scl clock timeout for reads

PS2 GPIO: Add scl clock timeout for writes

PS2 GPIO: Moved pin config into separate functions (not working)

PS2 GPIO: Make read work by removing some logging

PS2 GPIO: Fixed memory issue with fifo

PS2 GPIO: Kind of working sometimes except for ack bit

PS2 GPIO: Working without ack

PS2 GPIO: Fix crash: Disable resend command in read abort

PS2 GPIO: Make write work (But next read fails)
PS2 GPIO:
PS2 GPIO: I think the next read fails because we swallow the first 0 bit when reading the ack.

PS2 GPIO: Disable logging go speed up processing

PS2 GPIO: Made writing mostly work; read afterwards inconsistent

PS2 GPIO: Added post write debug log

PS2 GPIO: Improved post-write reading success rate

PS2 GPIO: Adjust timings

PS2 GPIO: Added logging of time between interrupts

PS2 GPIO: Instead of sleep() for write line inhibition, do delayable work

PS2 GPIO: Compensate for missing stop bit in read when it happens directly after write

PS2 GPIO: Adding interrupt logging

PS2 GPIO: Fix set_scl() setting sda and set_sda() setting scl

PS2 GPIO: Make interrupt logging work for sends
PS2 GPIO:
PS2 GPIO: Add interrupt logging to read functions

PS2 GPIO: Add ability to disable interrupt callback during write inhibition phase

PS2 GPIO: Rename inhibit slc duration config option
PS2 GPIO:
PS2 GPIO: Add missing inhibit setting rename

PS2 GPIO: Improve handling of spurious interrupts after writing better
PS2 GPIO:
PS2 GPIO: Adjust scl timeouts

PS2 GPIO: Added logging helper
PS2 GPIO:
PS2 GPIO: Logging helper

PS2 GPIO: Start fixing original write functions

PS2 GPIO: Cleanup read code

PS2 GPIO: Cleanup write code

PS2 GPIO: Adjust read/write scl timeouts

PS2 GPIO: Disable logger

PS2 GPIO: Add custom interrupt logging

PS2 GPIO: Enable interrupt logger

PS2 GPIO: Added separate write scl timeout for the first clock

PS2 GPIO: Fix running out of memory due to read queue

PS2 GPIO: Allow disabling of interrupt logs

PS2 GPIO: Improve logging and comments

PS2 GPIO: Removed old interrupt code
PS2 GPIO:
PS2 GPIO: interrupt stuff
PS2 GPIO:
PS2 GPIO: x

PS 2 Mouse: Add initial mouse driver for testing PS2 driver

PS2 GPIO: Add ps2 device to callback

PS2 Mouse: Added initial mouse movement cmd parsing

PS2 Mouse: Added actual mouse movement
PS2 Mouse:
PS2 Mouse: Inverted y for zmk as that is what zmk thinks is up
PS2 Mouse:
PS2 Mouse: comm

PS2 Mouse: Changed config options to match zmk mouse naming

PS2 Mouse: Added options to invert x and y mouse movements

PS2 Mouse: Rename mouse movement to mouse activity

PS2 Mouse: Added mouse button support

PS2 GPIO: Small cleanup

PS2 GPIO: Move interrupt logging around

PS2 GPIO: Added write re-try on fail

PS2 GPIO: Initial attempt at write await response (not working)

PS2 GPIO: Revert "Initial attempt at write await response (not working)"
PS2 GPIO:
PS2 GPIO: This reverts commit 6e77047ba8f8537e076f3a583d03c6222874998c.

PS2 GPIO: Added reason do abort_read()

PS2 GPIO: Disable resend on read failure for debugging

PS2 GPIO: Initialize current write byte

PS2 GPIO: Added max read retry

PS2 GPIO: Disable log interrupt

PS2 GPIO: Made timings based on ps2 protocol defines
PS2 GPIO:
PS2 GPIO: Move settings

PS2 GPIO: Added write_byte_await_response()

PS2 GPIO: Fix write retry incorrect retry number log

PS2 Mouse: Sort defines

PS2 Mouse: Improve init sequence

PS2 Mouse: Removed unneeded stream mode enabling command

PS2 GPIO: Make no response in write_byte_await_response an failure

PS2 Mouse: During init send reset command on every 4th attempt

PS2 Mouse: Add sample rate setting support

PS2 Mouse: Start use mouse events for movements

PS2 GPIO: Change most logging to debug

PS2 Mouse: Change logs from inf to dbg

PS2 Mouse: Experiment with different mouse movement methods

PS2 Mouse: Report mouse activity through timer instead of as it arrives.

PS2 Mouse: Use zmk log level instead of ps2

PS2 GPIO: Moved retry logic into separate function that also resends on error resp from device
PS2 GPIO:
PS2 GPIO: Enable retry send for ps2 interface
PS2 GPIO:
PS2 GPIO: Fix write failure error code

PS2 GPIO: Cleanup write code slightly

PS2 GPIO: Disable interrupt logging

PS2 GPIO: Use just one function for parity checking

PS2 GPIO: Small cleanup of read and write
PS2 GPIO:
PS2 GPIO: Small comment improvement

PS2 GPIO: In read_interrupt, moved data bits to a more logical position
PS2 GPIO:
PS2 GPIO: Read interrupt fix

PS2 GPIO: Call zephyr PS2 callback from a worker

PS2 GPIO: Remove unneeded gpio config flags

PS2 GPIO: Allow to enable and disable interrupt log through kconfig

PS2 Mouse: Re-enable resend request due to packet misalignment

PS2 Mouse: Parse cmd buffer using a struct instead of pointers

PS2 Mouse: Cleanup and improve documentation

PS2 Mouse: Silence error on read data queue timeout

PS2 Mouse: Improved init sequence

PS2 Mouse: Move init functions around

PS2 Mouse: Added scroll mode

PS2 Mouse: Make scroll mode configurable

PS2 Mouse: Added functions to incr and decr sampling rate

PS2 GPIO: Update blocking timeout for retry changes

PS2 GPIO: Increased timeout for write_byte_await_response()

PS2 GPIO: Added custom work queue

PS2 Mouse: Added mouse settings behavior (with queue)

PS2 Mouse: Removed queue from mouse setting behavior
PS2 Mouse:
PS2 Mouse: A queue was added to the ps2 gpio driver itself. So there is no need for it here anymore.

PS2 GPIO: Don’t log error on timed out ps2_read()

PS2 Mouse: Added reset-on-power function for trackpoints

PS2 Mouse: Add command to check if device is trackpoint

PS2 Mouse: Added send_cmd function that can send multibyte commands and read response

PS2 Mouse: Added trackpoint press to select and sensitivity setting

PS2 Mouse: Add config option for tap to select

PS2 Mouse: Fixed power-on-reset

PS2 Mouse: Add trackpoint swap xy command

PS2 Mouse: Add swap xy setting

PS2 Mouse: Added option to invert x and y directly on the trackpoint

PS2 Mouse: Added negative inertia setting

PS2 Mouse: Added upper plateau speed (value6)

PS2 Mouse: Added press-to-select threshold

PS2 Mouse: Added keybindings for TP settings

PS2 GPIO: Increased log break time

PS2 GPIO: Re-enable re-send request on read error

PS2 GPIO: Fix outdated comment

PS2 GPIO: Reduce debug logging

PS2 Mouse: Reduce logging

PS2 Mouse: Added config option to disable clicking

PS2 Mouse: Added config option for sampling rate

PS2 GPIO: Automatically adjust BT priorities when PS2 GPIO driver is enabled

PS2 Mouse: Lower default priority of NRF IRQs

PS2 Mouse: Add out of alignment detection

PS2 Mouse: Simplify out of alignment check

PS2 GPIO: Fixed deadlock on write due to wrong wokr queue priorities

PS2 GPIO: Log reason for write finish

PS2 GPIO: Increase SCL timeout

PS2 GPIO: Add pos to abort read logging

PS2 GPIO: For writes read ack bit before interrupt logging

PS2 GPIO: Fix interrupt_log_add crash

PS2 GPIO: Make interrupt_log. log in background

PS2 GPIO: Decrease priority for inhibition wait thread

PS2 GPIO: Increase timeout for first write clock

PS2 GPIO: Add argument to interrupt_log

PS2 GPIO: Improve write debug logging

PS2 Mouse: Improve misalignment detection by checking if there was prev movement

PS2 Mouse: Fix crash caused by zephyr LOG bug due to transient strings
PS2 Mouse:
PS2 Mouse: https://github.com/zephyrproject-rtos/zephyr/issues/44996

PS2 GPIO: Use main write function for 0xfe retry cmd

PS2 GPIO: Add resend callback to gpio driver

PS2 GPIO: Increase inhibition delay timer

PS2 GPIO: Properly fail write if semaphore times out

PS2 Mouse: Added resend callback

PS2 Mouse: Fix TP incr/decrease not remembering prev value

PS2 Mouse: Reset cmd buffer on misalignment

PS2 Mouse: Re-enable abort on sharp movement

PS2 Mouse: Fix mouse scrolling unintendedly if mouse mode is disabled

PS2 Mouse: Log button presses as info

PS2 GPIO: Re-enable scl interrupt on write failure

PS2 GPIO: Increase write max retry

PS2 Mouse: Make compatible with zephyr 3.2 update

PS2 GPIO: Make compatible with zephyr 3.2

PS2 GPIO: Use new zephyr gpio_*_dt apis

PS2 Mouse: Use new zephyr gpio_*_dt apis

PS2 GPIO: Prevent lockout on resend by using cb worker

PS2 GPIO: Add missing interrupt detection

PS2 GPIO: Added write error code for semaphore timeout

PS2 GPIO: Added mutex to prevent multiple threads writing at once

PS2 Mouse: Treat packet overflow as mistransmission

PS2 Mouse: If multiple mouse buttons are changed in one packet, treat it as mistransmission

PS2 Mouse: Fix value6 functions actually setting neg inertia

PS2 Mouse: Remove kconfig setting for mouse

PS2 Mouse: Reordered includes

PS2 Mouse: Switched tp sensitivity setting from float to int

PS2 Mouse: Added setting saving and restoring

PS2 Mouse: Created proper, automatic Kconfig

PS2 Mouse: Reorder includes

PS2 GPIO: Enable PS2 GPIO driver automatically if the devicetree node is present

PS2 Mouse: Rename ps2_mouse to mouse_ps2

PS2 Mouse: Fully rename ps2_mouse to mouse_ps2

PS2 Mouse: Cleanup of mouse_ps2 function  naming and order

PS2 Mouse: Renamed activity cmd to packet

PS2 Mouse: Removed sampling rate from being set from keypresses

PS2 Mouse: Remove redudant decr/incr functions

PS2 Mouse: Rename array functions

PS2 Mouse: Ensure all functions have common prefix zmk_mouse_ps2

PS2 Mouse: Reduce logging

PS2 GPIO: Make sure all functions have the ps2_gpio prefix

PS2 UART: Added initial UART PS2 driver

PS2 UART: Made uart PS2 read work

PS2 UART: Refactored uart read code

PS2 UART: Added parity error checking

PS2 UART: Initial attempt at pincntrl switching

Revert "PS2 UART: Initial attempt at pincntrl switching"

This reverts commit 5538731a90031b7607f05775135385bbe14464dc.

PS2 UART: Initial version of GPIO write (not working)

PS2 UART: Kindoff working

PS2 UART: Working

PS2 UART: Small cleanup

PS2 UART: Adjust timings and improve comments

PS2 Mouse: Increase init priority to be after UART drivers

PS2 UART: Attempt to not block interrupt (not working, worker never called)

Revert "PS2 UART: Attempt to not block interrupt (not working, worker never called)"

This reverts commit 6c37f9a236137cc0ca873c6ee4afef3f69eb5708.

PS2 Mouse: Add config option to disable additional error mitigation

Auto Layer: Add automatic layer toggling on mouse movement

PS2 Mouse: Log transmission error reason

PS2 UART: Check read error in received_byte

PS2 UART: Added blocking write

Auto Layer: Fixes

Scroll Mode: Initial implementation

PS2 Mouse: Auto lint code

PS2 Mouse: Scroll mode improvements (uncommitted changes from 3 month ago)

PS2 GPIO: Apply new auto-format to ps2_gpio

PS2 UART: Apply new auto-format

PS2 GPIO: Make write mutex names unique

PS2 UART: Make write mutex names unique

PS2 GPIO: Fix zephyr 3.5 compile errors

PS2 UART: Fix zephyr 3.5 compile errors

Mouse Settings & Scroll Mode: Apply new auto-formatting

Mouse Settings: Silence zephyr 3.5 compile warnings

PS2 Mouse: Move to zephyr 3.5 input system

PS2 Mouse: Add mouse ps2 work queue

PS2 Mouse: Increase err_msg buffer size for zmk_mouse_ps2_send_cmd_resp to avoid truncating

PS2 UART: Attempt adding pinctrl states dynamically (unsuccessful)

Revert "PS2 UART: Attempt adding pinctrl states dynamically (unsuccessful)"

This reverts commit 1a2c3f6f6832a95a828675a093bef7070fbe5bac.

PS2 UART: Fix zephyr 3.5 pinctrl change error

the issue was that I was using the sleep pinctrl state, because I couldn't figure out how to create a custom state.

And in zephyr 3.2 that worked fine, but in 3.5 it disables the sleep state if CONFIG_PM_DEVICE=n.

So the state was missing.

Mouse Settings & Scroll Mode: Update mouse settings and scroll mode behaviors to new labelless behavior init method

PS2 Mouse: Disable restore of mouse PS2 settings

Mouse Auto Layer: Added toggle delay to prevent accidental activations

PS2 Mouse: Added script to generate interrupt priority overrides for zmk-config

PS2 Mouse: Don’t override interrupt priorities in all zmk builds by default

PS2 GPIO: Potentially fix SCL not being pulled down during write

PS2 UART: Potentially fix inhibition not being done correctly

PS2 Mouse: Reset device if invalid self-test result is received

PS2 UART: Fix PM_DEVICE not enabling

PS2 GPIO: Improve PS2 GPIO kconfig documentation

PS2 UART: Lower BT interrupt priorities

PS2 Mouse: Delay PS2 init sequence to give mouse time to send init data

PS2 UART: Fix first write not working

PS2 UART: Add debug write function

PS2 UART: Disable debug write function

PS2 UART: Log received bytes

PS2 UART: Use delayable instead of k_busy_wait

Revert "PS2 UART: Use delayable instead of k_busy_wait"

Realized that this is pointless, since that’s a blocking function anyways.

We need to not block in the interrupt handler rather than here.

This reverts commit eee0c35793ccccf40d72742d19cc85762423a103.

PS2 UART: Move scl interrupt into worker

PS2 UART: Add cur write pos

Revert "PS2 UART: Move scl interrupt into worker"

This reverts commit ea24c68b1af0f6e4a367622829d92f380d92a27f.

PS2 UART: Added async interrupt writing mode

PS2 UART: Ignore framing errors for 0xfa received bytes

PS2 UART: Log write and received bytes only in DBG

PS2 Mouse: Remove kconfig settings that are handled by input-config

PS2 Mouse: Moved sampling rate and press to select from kconfig to device tree

PS2 Mouse: Log when settings were set successfully

PS2 Mouse: Added devicetree settings for TP settings

Correct val6 default value

PS2 Mouse: Enable settings restore again

PS2 Mouse: Don’t restore runtime settings if device config is present

Mouse Settings: Added log and reset behavior

Adjust settings log

PS2 Mouse: Fix wrong type for tp press to select var

PS2 Mouse: Replace kconfig enable clicking with devicetree disable clicking

PS2 Mouse: Disable error mitigations by default

PS2 Mouse: Moved axis options from kconfig to devicetree

PS2 Mouse: Removed scroll mode behavior

PS2 Mouse: Move scroll mode from kconfig to devicetree

PS2 Mouse: Removed movement buffer / queue

Remove butter kconfigs

PS2 Mouse: Moved mouse_ps2 driver to module

PS2 Mouse: Convert clicking to zephyr 3.5 input system

Mouse Auto Layer: Removed it in preparation for zephyr 3.5 module

PS2 UART: Fix Linking error due to missing config options if logging is disabled

PS2 UART: Replace data queue fifo with message queue to get rid of heap use

PS2 GPIO: Replace data queue fifo with message queue to get rid of heap use

Input Listener: Added logging

Auto Layer Toggle: Added initial version

Auto Layer Toggle: Changed how config is retrieved

Auto Layer Toggle: Adjust logging

Auto Layer Toggle: Remove dependency on urob’s “Zen display & battery tweaks”

That commit adds an additional parameter to the `zmk_keymap_layer_activate` function.

Need to find a better way to make the code compatible whether urob is used or not.

5796aa0104

PS2 GPIO & UART: Apply zmk auto-formatting

PS2 UART, GPIO, Mouse: Make resend callback optional to allow compilation without zephyr fork

PS2 Mouse & Auto Layer Toggle: Add urob compatibility option

PS2 Mouse: Remove unneeded file
This commit is contained in:
Kim Streich 2023-03-17 16:04:31 -06:00
parent dbbeb701ae
commit 8873bf937e
24 changed files with 5099 additions and 12 deletions

View file

@ -96,6 +96,8 @@ target_sources_ifdef(CONFIG_ZMK_USB app PRIVATE src/usb_hid.c)
target_sources_ifdef(CONFIG_ZMK_RGB_UNDERGLOW app PRIVATE src/rgb_underglow.c)
target_sources_ifdef(CONFIG_ZMK_BACKLIGHT app PRIVATE src/backlight.c)
target_sources_ifdef(CONFIG_ZMK_LOW_PRIORITY_WORK_QUEUE app PRIVATE src/workqueue.c)
target_sources_ifdef(CONFIG_ZMK_INPUT_MOUSE_PS2 app PRIVATE src/behaviors/behavior_mouse_setting.c)
target_sources(app PRIVATE src/main.c)
add_subdirectory(src/display/)

View file

@ -27,3 +27,4 @@
#include <behaviors/macros.dtsi>
#include <behaviors/soft_off.dtsi>
#include <behaviors/mouse_keys.dtsi>
#include <behaviors/mouse_setting.dtsi>

View file

@ -0,0 +1,14 @@
/*
* Copyright (c) 2020 The ZMK Contributors
*
* SPDX-License-Identifier: MIT
*/
/ {
behaviors {
mms: behavior_mouse_setting {
compatible = "zmk,behavior-mouse-setting";
#binding-cells = <1>;
};
};
};

View file

@ -0,0 +1,6 @@
description: Mouse Setting
compatible: "zmk,behavior-mouse-setting"
include: one_param.yaml

View file

@ -19,3 +19,18 @@ properties:
scale-divisor:
type: int
default: 1
layer-toggle:
type: int
default: -1
required: false
description: The layer that should be toggled when the mouse is moved.
layer-toggle-delay-ms:
type: int
default: 250
required: false
description: How many miliseconds of mouse activity are required before the layer is toggled on.
layer-toggle-timeout-ms:
type: int
default: 250
required: false
description: How many miliseconds of mouse inactivity are required before the layer is toggled off again.

View file

@ -0,0 +1,21 @@
/*
* Copyright (c) 2020 The ZMK Contributors
*
* SPDX-License-Identifier: MIT
*/
#pragma once
#define MS_LOG 0
#define MS_RESET 1
#define MS_TP_SENSITIVITY_INCR 10
#define MS_TP_SENSITIVITY_DECR 11
#define MS_TP_NEG_INERTIA_INCR 12
#define MS_TP_NEG_INERTIA_DECR 13
#define MS_TP_VALUE6_INCR 14
#define MS_TP_VALUE6_DECR 15
#define MS_TP_PTS_THRESHOLD_INCR 16
#define MS_TP_PTS_THRESHOLD_DECR 17

View file

@ -5,3 +5,5 @@ add_subdirectory_ifdef(CONFIG_GPIO gpio)
add_subdirectory_ifdef(CONFIG_KSCAN kscan)
add_subdirectory_ifdef(CONFIG_SENSOR sensor)
add_subdirectory_ifdef(CONFIG_DISPLAY display)
add_subdirectory_ifdef(CONFIG_PS2 ps2)
add_subdirectory_ifdef(CONFIG_INPUT input)

View file

@ -5,3 +5,5 @@ rsource "gpio/Kconfig"
rsource "kscan/Kconfig"
rsource "sensor/Kconfig"
rsource "display/Kconfig"
rsource "ps2/Kconfig"
rsource "input/Kconfig"

View file

@ -0,0 +1,6 @@
# Copyright (c) 2022 The ZMK Contributors
# SPDX-License-Identifier: MIT
zephyr_library_amend()
zephyr_library_sources_ifdef(CONFIG_ZMK_INPUT_MOUSE_PS2 input_mouse_ps2.c)

View file

@ -0,0 +1,27 @@
# Copyright (c) 2022 The ZMK Contributors
# SPDX-License-Identifier: MIT
DT_COMPAT_ZMK_INPUT_PS2_MOUSE := zmk,input-mouse-ps2
config ZMK_INPUT_MOUSE_PS2
bool
default $(dt_compat_enabled,$(DT_COMPAT_ZMK_INPUT_PS2_MOUSE))
depends on (!ZMK_SPLIT || ZMK_SPLIT_ROLE_CENTRAL)
select ZMK_MOUSE
select PS2
config ZMK_INPUT_MOUSE_PS2_ENABLE_PS2_RESEND_CALLBACK
bool "Get notifications from the underluing PS2 protocol driver when the received data is invalid and when a resend is requested from the peripheral. This helps the mouse driver to re-align its command buffer and prevent unexpected clicks and jerky movements. With the ps2-uart driver this option is not really necessary, but is very useful for the ps2-gpio driver where mis-transmissions are frequent."
default n
if ZMK_INPUT_MOUSE_PS2
config ZMK_INPUT_MOUSE_PS2_ENABLE_UROB_COMPAT
bool "Makes the driver compatible with urob's zmk fork. His fork has commits that change the default zmk function definitions. This option adopts the code to make it compatible with his changes. Only enable it if you are using his fork or it will fail to compile."
default n
config ZMK_INPUT_MOUSE_PS2_ENABLE_ERROR_MITIGATION
bool "Tries to mitigate transmission errors. Only useful when using a PS2 driver that is prone to miscommunication like the GPIO bitbanging driver."
default n
endif # ZMK_INPUT_MOUSE_PS2

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,5 @@
# Copyright (c) 2023 The ZMK Contributors
# SPDX-License-Identifier: MIT
zephyr_library_sources_ifdef(CONFIG_PS2_GPIO ps2_gpio.c)
zephyr_library_sources_ifdef(CONFIG_PS2_UART ps2_uart.c)

View file

@ -0,0 +1,9 @@
# Copyright (c) 2023 The ZMK Contributors
# SPDX-License-Identifier: MIT
if PS2
rsource "Kconfig.gpio"
rsource "Kconfig.uart"
endif # PS2

View file

@ -0,0 +1,66 @@
# Copyright (c) 2017 Linaro Ltd.
# SPDX-License-Identifier: Apache-2.0
DT_COMPAT_PS2_GPIO := gpio-ps2
config PS2_GPIO
bool "GPIO bit banging PS/2 support"
default $(dt_compat_enabled,$(DT_COMPAT_PS2_GPIO))
help
Enable software driven (bit banging) PS/2 support using GPIO pins
if PS2_GPIO
config PS2_GPIO_ENABLE_PS2_RESEND_CALLBACK
bool "Notify the PS2 device driver (mouse driver) when the received data is invalid and a resend is requested from the peripheral. This can help the higher level PS2 device driver handle transmission errors with less side-effects, but it requires a forked zephyr. With the ps2-uart driver this option is not really necessary, but is very useful for the ps2-gpio driver."
default n
select ZMK_INPUT_MOUSE_PS2_ENABLE_PS2_RESEND_CALLBACK
# PS/2 events must be processed within 30-50us. Therefore we shift the
# BT_CTLR_LLL_PRIO from 0 to 1 and BT_CTLR_ULL_* priorities from 1 to 2.
# We then set the gpio priority to 0.
#
# The following also has to be added to the device tree to set GPIOTE to the
# highest priority:
# &gpiote {
# interrupts = < 0x6 0 >;
# };
#
# On top of that all other interrupts have to be set to priority 3 to prevent
# them from delaying the BT interrupts.
#
# Overrides can be generated using the following script in infused-kim's zmk
# fork:
# 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.
#
# This will increase the probability that the PS/2 interrupts are triggered in
# time.
config BT_CTLR_ADVANCED_FEATURES
default y
config BT_CTLR_LLL_PRIO
default 1
config BT_CTLR_ULL_HIGH_PRIO
default 2
config BT_CTLR_ULL_LOW_PRIO
default 2
config PS2_GPIO_INTERRUPT_LOG_ENABLED
bool "Enable extensive interrupt logging."
default n
endif # PS2_GPIO

View file

@ -0,0 +1,76 @@
# Copyright (c) 2017 Linaro Ltd.
# SPDX-License-Identifier: Apache-2.0
DT_COMPAT_PS2_UART := uart-ps2
config PS2_UART
bool "GPIO bit banging PS/2 support through UART"
default $(dt_compat_enabled,$(DT_COMPAT_PS2_UART))
select SERIAL
select UART_ASYNC_API
select UART_USE_RUNTIME_CONFIGURE
help
Enable software driven (bit banging) PS/2 support using UART on GPIO pins
if PS2_UART
config PS2_UART_WRITE_MODE_BLOCKING
bool "Don't use interrupts for writing data and instead block using timers."
default n
config PS2_UART_ENABLE_PS2_RESEND_CALLBACK
bool "Notify the PS2 device driver (mouse driver) when the received data is invalid and a resend is requested from the peripheral. This can help the higher level PS2 device driver handle transmission errors with less side-effects, but it requires a forked zephyr. With the ps2-uart driver this option is not really necessary, but is very useful for the ps2-gpio driver."
default n
select ZMK_INPUT_MOUSE_PS2_ENABLE_PS2_RESEND_CALLBACK
# PM_DEVICE is needed, because we use GPIO bitbanging for writing. And to
# release the data PIN that is used by the UART device, we use pinctrl to
# switch to the sleep state. But the sleep state is only included if PM_DEVICE
# is enabled.
config PM_DEVICE
default y
# PS/2 events must be processed within 30-50us. Therefore we shift the
# BT_CTLR_LLL_PRIO from 0 to 1 and BT_CTLR_ULL_* priorities from 1 to 2.
# We then set the gpio priority to 0.
#
# The following also has to be added to the device tree to set GPIOTE to the
# highest priority:
# &gpiote {
# interrupts = < 0x6 0 >;
# };
#
# On top of that all other interrupts have to be set to priority 3 to prevent
# them from delaying the BT interrupts.
#
# Overrides can be generated using the following script in infused-kim's zmk
# fork:
# 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.
#
# This will increase the probability that the PS/2 interrupts are triggered in
# time.
config BT_CTLR_ADVANCED_FEATURES
default y
config BT_CTLR_LLL_PRIO
default 1
config BT_CTLR_ULL_HIGH_PRIO
default 2
config BT_CTLR_ULL_LOW_PRIO
default 2
endif # PS2_UART

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,72 @@
description: PS2 mouse configuration
compatible: "zmk,input-mouse-ps2"
properties:
ps2-device:
type: phandle
required: true
description: |
The ps2 device the mouse should use.
rst-gpios:
type: phandle-array
required: false
description: GPIO to which the RST pin of the device is connected and on which the Power-On-Reset will be performed.
sampling-rate:
type: int
description: Adjusts the sensitivity setting on trackpoint devices. The allowed values are 10, 20, 40, 60, 80, 100, 200 and the default is 100.
enum:
- 10
- 20
- 40
- 60
- 80
- 100
- 200
scroll-mode:
type: boolean
description: Enables scroll wheel on mouse devices supporting the Intellimouse extension.
disable-clicking:
type: boolean
description: Disables clicking. Useful when using a PS2 driver that is prone to erros in transmissions to reduce accidental clicks.
tp-press-to-select:
type: boolean
description: Enables mouse clicking by pressing hard on the trackpoint. Not all trackpoints support this feature.
tp-press-to-select-threshold:
type: int
description: Adjusts how sensitive the press-to-select feature is. The range is 0 - 255 and the default is 8. You can also adjust this setting at runtime without recompiling using the &mms behavior. If this setting is enabled, then the runtime behavior won't be saved into the runtime settings.
tp-sensitivity:
type: int
description: Adjusts the sensitivity setting on trackpoint devices. The range is 0 - 255 and the default is 128. You can also adjust this setting at runtime without recompiling using the &mms behavior. If this setting is enabled, then the runtime behavior won't be saved into the runtime settings.
tp-neg-inertia:
type: int
description: Adjusts the negative inertia setting on trackpoint devices. The range is 0 - 255 and the default is 6. You can also adjust this setting at runtime without recompiling using the &mms behavior. If this setting is enabled, then the runtime behavior won't be saved into the runtime settings.
tp-val6-upper-speed:
type: int
description: Adjusts the negative value0 upper plateau speed setting on trackpoint devices. The range is 0 - 255 and the default is 97. You can also adjust this setting at runtime without recompiling using the &mms behavior. If this setting is enabled, then the runtime behavior won't be saved into the runtime settings.
tp-x-invert:
type: boolean
description: Enables x axis inversion on the trackpoint. Only works with some trackpoint devices, but is 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-y-invert:
type: boolean
description: Enables y axis inversion on the trackpoint. Only works with some trackpoint devices, but is 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:
type: boolean
description: Swaps the x and y axis on the trackpoint. Only works with some trackpoint devices, but may 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.
layer-toggle:
type: int
required: false
description: The layer that should be toggled when the mouse is moved.

View file

@ -0,0 +1,19 @@
# Copyright (c) 2019, Intel Corporation
# SPDX-License-Identifier: Apache-2.0
description: GPIO PS2
compatible: "gpio-ps2"
include: base.yaml
properties:
scl-gpios:
type: phandle-array
required: true
description: GPIO to which the SCL pin of the I2C bus is connected.
sda-gpios:
type: phandle-array
required: true
description: GPIO to which the SDA pin of the I2C bus is connected.

View file

@ -0,0 +1,18 @@
# Copyright (c) 2019, Intel Corporation
# SPDX-License-Identifier: Apache-2.0
description: GPIO PS2
compatible: "uart-ps2"
include: base.yaml
properties:
scl-gpios:
type: phandle-array
required: true
description: GPIO to which the SCL pin is connected.
sda-gpios:
type: phandle-array
required: true
description: GPIO to which the SDA pin is connected.

View file

@ -0,0 +1,15 @@
/*
* Copyright (c) 2021 The ZMK Contributors
*
* SPDX-License-Identifier: MIT
*/
#pragma once
int zmk_mouse_ps2_settings_log();
int zmk_mouse_ps2_settings_reset();
int zmk_mouse_ps2_tp_sensitivity_change(int amount);
int zmk_mouse_ps2_tp_neg_inertia_change(int amount);
int zmk_mouse_ps2_tp_value6_upper_plateau_speed_change(int amount);
int zmk_mouse_ps2_tp_pts_threshold_change(int amount);

View file

@ -0,0 +1,68 @@
#!/usr/bin/env python
"""
Script for generating interrupt adjustments for zephyr dts files.
Requirements:
- pip install devicetree
"""
import argparse
from devicetree import dtlib
def get_interrupt_nodes(dt):
interrupt_nodes = []
for node in dt.node_iter():
if 'interrupts' in node.props.keys():
interrupt_nodes.append(node)
return interrupt_nodes
def get_node_label(node):
label = node.labels[0]
return label
def gen_interrupt_adjustment_str(node, priority_incr):
label = get_node_label(node)
interrupt_val1, interrupt_priority = node.props['interrupts'].to_nums()
if label == 'gpiote':
new_priority = 0
else:
new_priority = interrupt_priority + priority_incr
adj_str = f'''
&{label} {{
interrupts = < {interrupt_val1} {new_priority} >;
}};
'''
return adj_str
def gen_interrupt_adjustment(dts_path, priority_incr):
dt = dtlib.DT(dts_path)
interrupt_nodes = get_interrupt_nodes(dt)
adjustments = ''
for node in interrupt_nodes:
adj_str = gen_interrupt_adjustment_str(node, priority_incr)
if get_node_label(node) == 'gpiote':
adjustments = adj_str + adjustments
else:
adjustments += adj_str
return adjustments
def main():
parser = argparse.ArgumentParser(description='Generate interrupt adjustments for zephyr.dts files.')
parser.add_argument('dts_path', metavar='DTS_PATH', type=str, help='Path to the zephyr.dts file')
parser.add_argument('-p', '--priority-incr', type=int, default=2, help='By how much to increase the priority (default: 2)')
args = parser.parse_args()
adj = gen_interrupt_adjustment(args.dts_path, args.priority_incr)
print(adj)
if __name__ == '__main__':
main()

View file

@ -0,0 +1,62 @@
#define DT_DRV_COMPAT zmk_behavior_mouse_setting
#include <zephyr/device.h>
#include <drivers/behavior.h>
#include <zephyr/logging/log.h>
#include <dt-bindings/zmk/mouse_settings.h>
#include <zmk/input_mouse_ps2.h>
#define INCREMENT_TP_SENSITIVITY 10
#define INCREMENT_TP_NEG_INERTIA 1
#define INCREMENT_TP_VALUE6 5
#define INCREMENT_TP_PTS_THRESHOLD 1
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event) {
switch (binding->param1) {
case MS_LOG:
return zmk_mouse_ps2_settings_log();
case MS_RESET:
return zmk_mouse_ps2_settings_reset();
case MS_TP_SENSITIVITY_INCR:
return zmk_mouse_ps2_tp_sensitivity_change(INCREMENT_TP_SENSITIVITY);
case MS_TP_SENSITIVITY_DECR:
return zmk_mouse_ps2_tp_sensitivity_change(-INCREMENT_TP_SENSITIVITY);
case MS_TP_NEG_INERTIA_INCR:
return zmk_mouse_ps2_tp_neg_inertia_change(INCREMENT_TP_NEG_INERTIA);
case MS_TP_NEG_INERTIA_DECR:
return zmk_mouse_ps2_tp_neg_inertia_change(-INCREMENT_TP_NEG_INERTIA);
case MS_TP_VALUE6_INCR:
return zmk_mouse_ps2_tp_value6_upper_plateau_speed_change(INCREMENT_TP_VALUE6);
case MS_TP_VALUE6_DECR:
return zmk_mouse_ps2_tp_value6_upper_plateau_speed_change(-INCREMENT_TP_VALUE6);
case MS_TP_PTS_THRESHOLD_INCR:
return zmk_mouse_ps2_tp_pts_threshold_change(INCREMENT_TP_PTS_THRESHOLD);
case MS_TP_PTS_THRESHOLD_DECR:
return zmk_mouse_ps2_tp_pts_threshold_change(-INCREMENT_TP_PTS_THRESHOLD);
}
return -ENOTSUP;
}
static int on_keymap_binding_released(struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event) {
return ZMK_BEHAVIOR_OPAQUE;
}
// Initialization Function
static int zmk_behavior_mouse_setting_init(const struct device *dev) { return 0; };
static const struct behavior_driver_api zmk_behavior_mouse_setting_driver_api = {
.binding_pressed = on_keymap_binding_pressed, .binding_released = on_keymap_binding_released};
BEHAVIOR_DT_INST_DEFINE(0, zmk_behavior_mouse_setting_init, NULL, NULL, NULL, POST_KERNEL,
CONFIG_KERNEL_INIT_PRIORITY_DEFAULT,
&zmk_behavior_mouse_setting_driver_api);

View file

@ -16,6 +16,7 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
#include <zephyr/dt-bindings/input/input-event-codes.h>
#include <zmk/endpoints.h>
#include <zmk/keymap.h>
#include <zmk/mouse/types.h>
#include <zmk/mouse/hid.h>
@ -39,6 +40,8 @@ struct input_listener_xy_data {
};
struct input_listener_data {
const struct device *dev;
union {
struct {
struct input_listener_xy_data data;
@ -48,6 +51,11 @@ struct input_listener_data {
uint8_t button_clear;
} mouse;
};
bool layer_toggle_layer_enabled;
int64_t layer_toggle_last_mouse_package_time;
struct k_work_delayable layer_toggle_activation_delay;
struct k_work_delayable layer_toggle_deactivation_delay;
};
struct input_listener_config {
@ -56,8 +64,39 @@ struct input_listener_config {
bool y_invert;
uint16_t scale_multiplier;
uint16_t scale_divisor;
int layer_toggle;
int layer_toggle_delay_ms;
int layer_toggle_timeout_ms;
};
void zmk_input_listener_layer_toggle_input_rel_received(const struct input_listener_config *config,
struct input_listener_data *data);
static char *get_input_code_name(struct input_event *evt) {
switch (evt->code) {
case INPUT_REL_X:
return "INPUT_REL_X";
case INPUT_REL_Y:
return "INPUT_REL_Y";
case INPUT_REL_WHEEL:
return "INPUT_REL_WHEEL";
case INPUT_REL_HWHEEL:
return "INPUT_REL_HWHEEL";
case INPUT_BTN_0:
return "INPUT_BTN_0";
case INPUT_BTN_1:
return "INPUT_BTN_1";
case INPUT_BTN_2:
return "INPUT_BTN_2";
case INPUT_BTN_3:
return "INPUT_BTN_3";
case INPUT_BTN_4:
return "INPUT_BTN_4";
default:
return "UNKNOWN";
}
}
static void handle_rel_code(struct input_listener_data *data, struct input_event *evt) {
switch (evt->code) {
case INPUT_REL_X:
@ -152,6 +191,10 @@ static void input_handler(const struct input_listener_config *config,
// First, filter to update the event data as needed.
filter_with_input_config(config, evt);
LOG_DBG("Got input_handler event: %s with value 0x%x", get_input_code_name(evt), evt->value);
zmk_input_listener_layer_toggle_input_rel_received(config, data);
switch (evt->type) {
case INPUT_EV_REL:
handle_rel_code(data, evt);
@ -200,23 +243,119 @@ static void input_handler(const struct input_listener_config *config,
}
}
void zmk_input_listener_layer_toggle_input_rel_received(const struct input_listener_config *config,
struct input_listener_data *data) {
if (config->layer_toggle == -1) {
return;
}
data->layer_toggle_last_mouse_package_time = k_uptime_get();
if (data->layer_toggle_layer_enabled == false) {
k_work_schedule(&data->layer_toggle_activation_delay,
K_MSEC(config->layer_toggle_delay_ms));
} else {
// Deactivate the layer if no further movement within
// layer_toggle_timeout_ms
k_work_reschedule(&data->layer_toggle_deactivation_delay,
K_MSEC(config->layer_toggle_timeout_ms));
}
}
void zmk_input_listener_layer_toggle_activate_layer(struct k_work *item) {
struct k_work_delayable *d_work = k_work_delayable_from_work(item);
struct input_listener_data *data =
CONTAINER_OF(d_work, struct input_listener_data, layer_toggle_activation_delay);
const struct input_listener_config *config = data->dev->config;
int64_t current_time = k_uptime_get();
int64_t last_mv_within_ms = current_time - data->layer_toggle_last_mouse_package_time;
if (last_mv_within_ms <= config->layer_toggle_timeout_ms * 0.1) {
LOG_INF("Activating layer %d due to mouse activity...", config->layer_toggle);
#if IS_ENABLED(CONFIG_ZMK_INPUT_MOUSE_PS2_ENABLE_UROB_COMPAT)
zmk_keymap_layer_activate(config->layer_toggle, false);
#else
zmk_keymap_layer_activate(config->layer_toggle);
#endif /* IS_ENABLED(CONFIG_ZMK_INPUT_MOUSE_PS2_ENABLE_UROB_COMPAT) */
data->layer_toggle_layer_enabled = true;
} else {
LOG_INF("Not activating mouse layer %d, because last mouse activity was %lldms ago",
config->layer_toggle, last_mv_within_ms);
}
}
void zmk_input_listener_layer_toggle_deactivate_layer(struct k_work *item) {
struct k_work_delayable *d_work = k_work_delayable_from_work(item);
struct input_listener_data *data =
CONTAINER_OF(d_work, struct input_listener_data, layer_toggle_deactivation_delay);
const struct input_listener_config *config = data->dev->config;
LOG_INF("Deactivating layer %d due to mouse activity...", config->layer_toggle);
if (zmk_keymap_layer_active(config->layer_toggle)) {
zmk_keymap_layer_deactivate(config->layer_toggle);
}
data->layer_toggle_layer_enabled = false;
}
static int zmk_input_listener_layer_toggle_init(const struct input_listener_config *config,
struct input_listener_data *data) {
k_work_init_delayable(&data->layer_toggle_activation_delay,
zmk_input_listener_layer_toggle_activate_layer);
k_work_init_delayable(&data->layer_toggle_deactivation_delay,
zmk_input_listener_layer_toggle_deactivate_layer);
return 0;
}
#endif // VALID_LISTENER_COUNT > 0
#define IL_INST(n) \
COND_CODE_1( \
DT_NODE_HAS_STATUS(DT_INST_PHANDLE(n, device), okay), \
(static const struct input_listener_config config_##n = \
{ \
.xy_swap = DT_INST_PROP(n, xy_swap), \
.x_invert = DT_INST_PROP(n, x_invert), \
.y_invert = DT_INST_PROP(n, y_invert), \
.scale_multiplier = DT_INST_PROP(n, scale_multiplier), \
.scale_divisor = DT_INST_PROP(n, scale_divisor), \
}; \
static struct input_listener_data data_##n = {}; \
void input_handler_##n(struct input_event *evt) { \
input_handler(&config_##n, &data_##n, evt); \
} INPUT_CALLBACK_DEFINE(DEVICE_DT_GET(DT_INST_PHANDLE(n, device)), input_handler_##n);), \
( \
static const struct input_listener_config config_##n = \
{ \
.xy_swap = DT_INST_PROP(n, xy_swap), \
.x_invert = DT_INST_PROP(n, x_invert), \
.y_invert = DT_INST_PROP(n, y_invert), \
.scale_multiplier = DT_INST_PROP(n, scale_multiplier), \
.scale_divisor = DT_INST_PROP(n, scale_divisor), \
.layer_toggle = DT_INST_PROP(n, layer_toggle), \
.layer_toggle_delay_ms = DT_INST_PROP(n, layer_toggle_delay_ms), \
.layer_toggle_timeout_ms = DT_INST_PROP(n, layer_toggle_timeout_ms), \
}; \
static struct input_listener_data data_##n = \
{ \
.dev = DEVICE_DT_INST_GET(n), \
.layer_toggle_layer_enabled = false, \
.layer_toggle_last_mouse_package_time = 0, \
}; \
void input_handler_##n(struct input_event *evt) { \
input_handler(&config_##n, &data_##n, evt); \
} INPUT_CALLBACK_DEFINE(DEVICE_DT_GET(DT_INST_PHANDLE(n, device)), input_handler_##n); \
\
static int zmk_input_listener_init_##n(const struct device *dev) { \
struct input_listener_data *data = dev->data; \
const struct input_listener_config *config = dev->config; \
\
zmk_input_listener_layer_toggle_init(config, data); \
\
return 0; \
} \
\
DEVICE_DT_INST_DEFINE(n, &zmk_input_listener_init_##n, NULL, &data_##n, &config_##n, \
POST_KERNEL, CONFIG_APPLICATION_INIT_PRIORITY, NULL);), \
())
DT_INST_FOREACH_STATUS_OKAY(IL_INST)