Skip to content

Commit

Permalink
Add trackpad toggle and multi touch toggle behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
ReFil committed Feb 14, 2024
1 parent 75b56bf commit c9557ec
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ endif()

target_sources_ifdef(CONFIG_ZMK_RGB_UNDERGLOW app PRIVATE src/behaviors/behavior_rgb_underglow.c)
target_sources_ifdef(CONFIG_ZMK_BACKLIGHT app PRIVATE src/behaviors/behavior_backlight.c)
target_sources_ifdef(CONFIG_ZMK_TRACKPAD app PRIVATE src/behaviors/behavior_trackpad.c)

target_sources_ifdef(CONFIG_ZMK_BATTERY_REPORTING app PRIVATE src/events/battery_state_changed.c)
target_sources_ifdef(CONFIG_ZMK_BATTERY_REPORTING app PRIVATE src/battery.c)
Expand Down
3 changes: 2 additions & 1 deletion app/boards/arm/stp/stp.keymap
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <dt-bindings/zmk/keys.h>
#include <dt-bindings/zmk/reset.h>
#include <dt-bindings/zmk/outputs.h>
#include <dt-bindings/zmk/trackpad.h>


/ {
Expand Down Expand Up @@ -34,7 +35,7 @@
bindings = <
&none &kp C_MUTE &kp C_VOL_DN &kp C_VOL_UP &kp C_PREV &kp C_PP &kp C_NEXT &bl BL_DEC &bl BL_INC &kp C_BRI_DN &kp C_BRI_UP &bt BT_CLR &none &trans &none &none
&none &none &none &none &none &none &none &none &none &none &none &none &none &none &none
&none &none &none &none &none &none &none &none &none &none &none &none &none &sys_reset &none
&none &none &none &none &none &tp TP_MULTI_TOG &none &none &none &none &none &none &none &sys_reset &none
&none &none &none &none &none &none &none &none &none &none &none &none &bootloader &none
&none &none &none &none &none &none &none &none &none &none &none &none &none &none
&none &none &none &none &none &none &none &none &none &none &none
Expand Down
1 change: 1 addition & 0 deletions app/dts/behaviors.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@
#include <behaviors/backlight.dtsi>
#include <behaviors/macros.dtsi>
#include <behaviors/mouse_key_press.dtsi>
#include <behaviors/trackpad.dtsi>
14 changes: 14 additions & 0 deletions app/dts/behaviors/trackpad.dtsi
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright (c) 2024 The ZMK Contributors
*
* SPDX-License-Identifier: MIT
*/

/ {
behaviors {
/omit-if-no-ref/ tp: trackpad {
compatible = "zmk,behavior-trackpad";
#binding-cells = <1>;
};
};
};
8 changes: 8 additions & 0 deletions app/dts/bindings/behaviors/zmk,behavior-trackpad.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (c) 2024 The ZMK Contributors
# SPDX-License-Identifier: MIT

description: Trackpad

compatible: "zmk,behavior-trackpad"

include: one_param.yaml
6 changes: 6 additions & 0 deletions app/include/dt-bindings/zmk/trackpad.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#define TP_MULTI_TOG 0
#define TP_MULTI_ON 1
#define TP_MULTI_OFF 2
#define TP_TOG 3
#define TP_ON 4
#define TP_OFF 5
68 changes: 68 additions & 0 deletions app/src/behaviors/behavior_trackpad.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright (c) 2024 The ZMK Contributors
*
* SPDX-License-Identifier: MIT
*/

#define DT_DRV_COMPAT zmk_behavior_trackpad

#include <zephyr/device.h>
#include <drivers/behavior.h>
#include <zephyr/logging/log.h>

#include <dt-bindings/zmk/trackpad.h>
#include <zmk/trackpad.h>
#include <zmk/hid.h>
#include <zmk/keymap.h>

LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);

#if DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT)

static int behavior_trackpad_init(const struct device *dev) { return 0; }

static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event) {
switch (binding->param1) {
case TP_TOG: {
zmk_trackpad_set_enabled(!zmk_trackpad_get_enabled());
return 0;
}
case TP_ON: {
zmk_trackpad_set_enabled(true);
return 0;
}
case TP_OFF: {
zmk_trackpad_set_enabled(false);
return 0;
}
case TP_MULTI_TOG: {
zmk_hid_ptp_set_feature_mode_report(zmk_hid_ptp_get_feature_mode_report()->mode ? 0 : 3);
return 0;
}
case TP_MULTI_ON: {
zmk_hid_ptp_set_feature_mode_report(3);
return 0;
}
case TP_MULTI_OFF: {
zmk_hid_ptp_set_feature_mode_report(0);
return 0;
}
}
return -ENOTSUP;
}

static int on_keymap_binding_released(struct zmk_behavior_binding *binding,
struct zmk_behavior_binding_event event) {
return ZMK_BEHAVIOR_OPAQUE;
}

static const struct behavior_driver_api behavior_trackpad_driver_api = {
.binding_pressed = on_keymap_binding_pressed,
.binding_released = on_keymap_binding_released,
};

DEVICE_DT_INST_DEFINE(0, behavior_trackpad_init, NULL, NULL, NULL, APPLICATION,
CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, &behavior_trackpad_driver_api);

#endif /* DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT) */

0 comments on commit c9557ec

Please sign in to comment.